Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / drivers / md / dm-log.h
1 /*
2  * Copyright (C) 2003 Sistina Software
3  *
4  * This file is released under the LGPL.
5  */
6
7 #ifndef DM_DIRTY_LOG
8 #define DM_DIRTY_LOG
9
10 #include "dm.h"
11
12 /*
13  * Values returned by get_failure_response()
14  *   DMLOG_IOERR_IGNORE:  ignore device failures
15  *   DMLOG_IOERR_BLOCK:     issue dm event, and do not complete
16  *                 I/O until presuspend is recieved.
17  */
18 #define DMLOG_IOERR_IGNORE 0
19 #define DMLOG_IOERR_BLOCK  1
20
21 typedef sector_t region_t;
22
23 struct dirty_log_type;
24
25 struct dirty_log {
26         struct dirty_log_type *type;
27         void *context;
28 };
29
30 struct dirty_log_type {
31         struct list_head list;
32         const char *name;
33         struct module *module;
34         unsigned int use_count;
35         unsigned int flags;
36
37         int (*ctr)(struct dirty_log *log, struct dm_target *ti,
38                    unsigned int argc, char **argv);
39         void (*dtr)(struct dirty_log *log);
40
41         /*
42          * There are times when we don't want the log to touch
43          * the disk.
44          */
45         int (*presuspend)(struct dirty_log *log);
46         int (*postsuspend)(struct dirty_log *log);
47         int (*resume)(struct dirty_log *log);
48
49         /*
50          * Retrieves the smallest size of region that the log can
51          * deal with.
52          */
53         uint32_t (*get_region_size)(struct dirty_log *log);
54
55         /*
56          * A predicate to say whether a region is clean or not.
57          * May block.
58          */
59         int (*is_clean)(struct dirty_log *log, region_t region);
60
61         /*
62          *  Returns: 0, 1, -EWOULDBLOCK, < 0
63          *
64          * A predicate function to check the area given by
65          * [sector, sector + len) is in sync.
66          *
67          * If -EWOULDBLOCK is returned the state of the region is
68          * unknown, typically this will result in a read being
69          * passed to a daemon to deal with, since a daemon is
70          * allowed to block.
71          */
72         int (*in_sync)(struct dirty_log *log, region_t region, int can_block);
73
74         /*
75          * Flush the current log state (eg, to disk).  This
76          * function may block.
77          */
78         int (*flush)(struct dirty_log *log);
79
80         /*
81          * Mark an area as clean or dirty.  These functions may
82          * block, though for performance reasons blocking should
83          * be extremely rare (eg, allocating another chunk of
84          * memory for some reason).
85          */
86         void (*mark_region)(struct dirty_log *log, region_t region);
87         void (*clear_region)(struct dirty_log *log, region_t region);
88
89         /*
90          * Returns: <0 (error), 0 (no region), 1 (region)
91          *
92          * The mirrord will need perform recovery on regions of
93          * the mirror that are in the NOSYNC state.  This
94          * function asks the log to tell the caller about the
95          * next region that this machine should recover.
96          *
97          * Do not confuse this function with 'in_sync()', one
98          * tells you if an area is synchronised, the other
99          * assigns recovery work.
100         */
101         int (*get_resync_work)(struct dirty_log *log, region_t *region);
102
103         /*
104          * This notifies the log that the resync status of a region
105          * has changed.  It also clears the region from the recovering
106          * list (if present).
107          */
108         void (*set_region_sync)(struct dirty_log *log,
109                                 region_t region, int in_sync);
110
111         /*
112          * Returns the number of regions that are in sync.
113          */
114         region_t (*get_sync_count)(struct dirty_log *log);
115
116         /*
117          * Support function for mirror status requests.
118          */
119         int (*status)(struct dirty_log *log, status_type_t status_type,
120                       char *result, unsigned int maxlen);
121
122         /*
123          * Return the code describing what to do in the event
124          * of a device failure.
125          */
126         int (*get_failure_response)(struct dirty_log *log);
127
128         /*
129          * Returns: 0, 1
130          *
131          * This is necessary for cluster mirroring. It provides
132          * a way to detect recovery on another node, so we
133          * aren't writing concurrently.  This function is likely
134          * to block (when a cluster log is used).
135          */
136         int (*is_remote_recovering)(struct dirty_log *log, region_t region);
137
138         int (*reserved[5])(int a);
139 };
140
141 int dm_register_dirty_log_type(struct dirty_log_type *type);
142 int dm_unregister_dirty_log_type(struct dirty_log_type *type);
143
144
145 /*
146  * Make sure you use these two functions, rather than calling
147  * type->constructor/destructor() directly.
148  */
149 struct dirty_log *dm_create_dirty_log(const char *type_name, struct dm_target *ti,
150                                       unsigned int argc, char **argv);
151 void dm_destroy_dirty_log(struct dirty_log *log);
152
153 /*
154  * init/exit functions.
155  */
156 int dm_dirty_log_init(void);
157 void dm_dirty_log_exit(void);
158
159 #endif