Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2003 Sistina Software
0003  * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
0004  *
0005  * Device-Mapper dirty region log.
0006  *
0007  * This file is released under the LGPL.
0008  */
0009 
0010 #ifndef _LINUX_DM_DIRTY_LOG
0011 #define _LINUX_DM_DIRTY_LOG
0012 
0013 #ifdef __KERNEL__
0014 
0015 #include <linux/types.h>
0016 #include <linux/device-mapper.h>
0017 
0018 typedef sector_t region_t;
0019 
0020 struct dm_dirty_log_type;
0021 
0022 struct dm_dirty_log {
0023     struct dm_dirty_log_type *type;
0024     int (*flush_callback_fn)(struct dm_target *ti);
0025     void *context;
0026 };
0027 
0028 struct dm_dirty_log_type {
0029     const char *name;
0030     struct module *module;
0031 
0032     /* For internal device-mapper use */
0033     struct list_head list;
0034 
0035     int (*ctr)(struct dm_dirty_log *log, struct dm_target *ti,
0036            unsigned argc, char **argv);
0037     void (*dtr)(struct dm_dirty_log *log);
0038 
0039     /*
0040      * There are times when we don't want the log to touch
0041      * the disk.
0042      */
0043     int (*presuspend)(struct dm_dirty_log *log);
0044     int (*postsuspend)(struct dm_dirty_log *log);
0045     int (*resume)(struct dm_dirty_log *log);
0046 
0047     /*
0048      * Retrieves the smallest size of region that the log can
0049      * deal with.
0050      */
0051     uint32_t (*get_region_size)(struct dm_dirty_log *log);
0052 
0053     /*
0054      * A predicate to say whether a region is clean or not.
0055      * May block.
0056      */
0057     int (*is_clean)(struct dm_dirty_log *log, region_t region);
0058 
0059     /*
0060      *  Returns: 0, 1, -EWOULDBLOCK, < 0
0061      *
0062      * A predicate function to check the area given by
0063      * [sector, sector + len) is in sync.
0064      *
0065      * If -EWOULDBLOCK is returned the state of the region is
0066      * unknown, typically this will result in a read being
0067      * passed to a daemon to deal with, since a daemon is
0068      * allowed to block.
0069      */
0070     int (*in_sync)(struct dm_dirty_log *log, region_t region,
0071                int can_block);
0072 
0073     /*
0074      * Flush the current log state (eg, to disk).  This
0075      * function may block.
0076      */
0077     int (*flush)(struct dm_dirty_log *log);
0078 
0079     /*
0080      * Mark an area as clean or dirty.  These functions may
0081      * block, though for performance reasons blocking should
0082      * be extremely rare (eg, allocating another chunk of
0083      * memory for some reason).
0084      */
0085     void (*mark_region)(struct dm_dirty_log *log, region_t region);
0086     void (*clear_region)(struct dm_dirty_log *log, region_t region);
0087 
0088     /*
0089      * Returns: <0 (error), 0 (no region), 1 (region)
0090      *
0091      * The mirrord will need perform recovery on regions of
0092      * the mirror that are in the NOSYNC state.  This
0093      * function asks the log to tell the caller about the
0094      * next region that this machine should recover.
0095      *
0096      * Do not confuse this function with 'in_sync()', one
0097      * tells you if an area is synchronised, the other
0098      * assigns recovery work.
0099     */
0100     int (*get_resync_work)(struct dm_dirty_log *log, region_t *region);
0101 
0102     /*
0103      * This notifies the log that the resync status of a region
0104      * has changed.  It also clears the region from the recovering
0105      * list (if present).
0106      */
0107     void (*set_region_sync)(struct dm_dirty_log *log,
0108                 region_t region, int in_sync);
0109 
0110     /*
0111      * Returns the number of regions that are in sync.
0112      */
0113     region_t (*get_sync_count)(struct dm_dirty_log *log);
0114 
0115     /*
0116      * Support function for mirror status requests.
0117      */
0118     int (*status)(struct dm_dirty_log *log, status_type_t status_type,
0119               char *result, unsigned maxlen);
0120 
0121     /*
0122      * is_remote_recovering is necessary for cluster mirroring. It provides
0123      * a way to detect recovery on another node, so we aren't writing
0124      * concurrently.  This function is likely to block (when a cluster log
0125      * is used).
0126      *
0127      * Returns: 0, 1
0128      */
0129     int (*is_remote_recovering)(struct dm_dirty_log *log, region_t region);
0130 };
0131 
0132 int dm_dirty_log_type_register(struct dm_dirty_log_type *type);
0133 int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type);
0134 
0135 /*
0136  * Make sure you use these two functions, rather than calling
0137  * type->constructor/destructor() directly.
0138  */
0139 struct dm_dirty_log *dm_dirty_log_create(const char *type_name,
0140             struct dm_target *ti,
0141             int (*flush_callback_fn)(struct dm_target *ti),
0142             unsigned argc, char **argv);
0143 void dm_dirty_log_destroy(struct dm_dirty_log *log);
0144 
0145 #endif  /* __KERNEL__ */
0146 #endif  /* _LINUX_DM_DIRTY_LOG_H */