dm-log-userspace.h revision 1.1.1.1 1 1.1 haad /* $NetBSD: dm-log-userspace.h,v 1.1.1.1 2009/12/02 00:25:40 haad Exp $ */
2 1.1 haad
3 1.1 haad /*
4 1.1 haad * Copyright (C) 2006-2009 Red Hat, Inc.
5 1.1 haad *
6 1.1 haad * This file is released under the LGPL.
7 1.1 haad */
8 1.1 haad
9 1.1 haad #ifndef __DM_LOG_USERSPACE_H__
10 1.1 haad #define __DM_LOG_USERSPACE_H__
11 1.1 haad
12 1.1 haad #include <linux/dm-ioctl.h> /* For DM_UUID_LEN */
13 1.1 haad
14 1.1 haad /*
15 1.1 haad * The device-mapper userspace log module consists of a kernel component and
16 1.1 haad * a user-space component. The kernel component implements the API defined
17 1.1 haad * in dm-dirty-log.h. Its purpose is simply to pass the parameters and
18 1.1 haad * return values of those API functions between kernel and user-space.
19 1.1 haad *
20 1.1 haad * Below are defined the 'request_types' - DM_ULOG_CTR, DM_ULOG_DTR, etc.
21 1.1 haad * These request types represent the different functions in the device-mapper
22 1.1 haad * dirty log API. Each of these is described in more detail below.
23 1.1 haad *
24 1.1 haad * The user-space program must listen for requests from the kernel (representing
25 1.1 haad * the various API functions) and process them.
26 1.1 haad *
27 1.1 haad * User-space begins by setting up the communication link (error checking
28 1.1 haad * removed for clarity):
29 1.1 haad * fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
30 1.1 haad * addr.nl_family = AF_NETLINK;
31 1.1 haad * addr.nl_groups = CN_IDX_DM;
32 1.1 haad * addr.nl_pid = 0;
33 1.1 haad * r = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
34 1.1 haad * opt = addr.nl_groups;
35 1.1 haad * setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &opt, sizeof(opt));
36 1.1 haad *
37 1.1 haad * User-space will then wait to receive requests form the kernel, which it
38 1.1 haad * will process as described below. The requests are received in the form,
39 1.1 haad * ((struct dm_ulog_request) + (additional data)). Depending on the request
40 1.1 haad * type, there may or may not be 'additional data'. In the descriptions below,
41 1.1 haad * you will see 'Payload-to-userspace' and 'Payload-to-kernel'. The
42 1.1 haad * 'Payload-to-userspace' is what the kernel sends in 'additional data' as
43 1.1 haad * necessary parameters to complete the request. The 'Payload-to-kernel' is
44 1.1 haad * the 'additional data' returned to the kernel that contains the necessary
45 1.1 haad * results of the request. The 'data_size' field in the dm_ulog_request
46 1.1 haad * structure denotes the availability and amount of payload data.
47 1.1 haad */
48 1.1 haad
49 1.1 haad /*
50 1.1 haad * DM_ULOG_CTR corresponds to (found in dm-dirty-log.h):
51 1.1 haad * int (*ctr)(struct dm_dirty_log *log, struct dm_target *ti,
52 1.1 haad * unsigned argc, char **argv);
53 1.1 haad *
54 1.1 haad * Payload-to-userspace:
55 1.1 haad * A single string containing all the argv arguments separated by ' 's
56 1.1 haad * Payload-to-kernel:
57 1.1 haad * None. ('data_size' in the dm_ulog_request struct should be 0.)
58 1.1 haad *
59 1.1 haad * The UUID contained in the dm_ulog_request structure is the reference that
60 1.1 haad * will be used by all request types to a specific log. The constructor must
61 1.1 haad * record this assotiation with instance created.
62 1.1 haad *
63 1.1 haad * When the request has been processed, user-space must return the
64 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and
65 1.1 haad * 'data_size' appropriately.
66 1.1 haad */
67 1.1 haad #define DM_ULOG_CTR 1
68 1.1 haad
69 1.1 haad /*
70 1.1 haad * DM_ULOG_DTR corresponds to (found in dm-dirty-log.h):
71 1.1 haad * void (*dtr)(struct dm_dirty_log *log);
72 1.1 haad *
73 1.1 haad * Payload-to-userspace:
74 1.1 haad * A single string containing all the argv arguments separated by ' 's
75 1.1 haad * Payload-to-kernel:
76 1.1 haad * None. ('data_size' in the dm_ulog_request struct should be 0.)
77 1.1 haad *
78 1.1 haad * The UUID contained in the dm_ulog_request structure is all that is
79 1.1 haad * necessary to identify the log instance being destroyed. There is no
80 1.1 haad * payload data.
81 1.1 haad *
82 1.1 haad * When the request has been processed, user-space must return the
83 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and clearing
84 1.1 haad * 'data_size' appropriately.
85 1.1 haad */
86 1.1 haad #define DM_ULOG_DTR 2
87 1.1 haad
88 1.1 haad /*
89 1.1 haad * DM_ULOG_PRESUSPEND corresponds to (found in dm-dirty-log.h):
90 1.1 haad * int (*presuspend)(struct dm_dirty_log *log);
91 1.1 haad *
92 1.1 haad * Payload-to-userspace:
93 1.1 haad * None.
94 1.1 haad * Payload-to-kernel:
95 1.1 haad * None.
96 1.1 haad *
97 1.1 haad * The UUID contained in the dm_ulog_request structure is all that is
98 1.1 haad * necessary to identify the log instance being presuspended. There is no
99 1.1 haad * payload data.
100 1.1 haad *
101 1.1 haad * When the request has been processed, user-space must return the
102 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and
103 1.1 haad * 'data_size' appropriately.
104 1.1 haad */
105 1.1 haad #define DM_ULOG_PRESUSPEND 3
106 1.1 haad
107 1.1 haad /*
108 1.1 haad * DM_ULOG_POSTSUSPEND corresponds to (found in dm-dirty-log.h):
109 1.1 haad * int (*postsuspend)(struct dm_dirty_log *log);
110 1.1 haad *
111 1.1 haad * Payload-to-userspace:
112 1.1 haad * None.
113 1.1 haad * Payload-to-kernel:
114 1.1 haad * None.
115 1.1 haad *
116 1.1 haad * The UUID contained in the dm_ulog_request structure is all that is
117 1.1 haad * necessary to identify the log instance being postsuspended. There is no
118 1.1 haad * payload data.
119 1.1 haad *
120 1.1 haad * When the request has been processed, user-space must return the
121 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and
122 1.1 haad * 'data_size' appropriately.
123 1.1 haad */
124 1.1 haad #define DM_ULOG_POSTSUSPEND 4
125 1.1 haad
126 1.1 haad /*
127 1.1 haad * DM_ULOG_RESUME corresponds to (found in dm-dirty-log.h):
128 1.1 haad * int (*resume)(struct dm_dirty_log *log);
129 1.1 haad *
130 1.1 haad * Payload-to-userspace:
131 1.1 haad * None.
132 1.1 haad * Payload-to-kernel:
133 1.1 haad * None.
134 1.1 haad *
135 1.1 haad * The UUID contained in the dm_ulog_request structure is all that is
136 1.1 haad * necessary to identify the log instance being resumed. There is no
137 1.1 haad * payload data.
138 1.1 haad *
139 1.1 haad * When the request has been processed, user-space must return the
140 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and
141 1.1 haad * 'data_size' appropriately.
142 1.1 haad */
143 1.1 haad #define DM_ULOG_RESUME 5
144 1.1 haad
145 1.1 haad /*
146 1.1 haad * DM_ULOG_GET_REGION_SIZE corresponds to (found in dm-dirty-log.h):
147 1.1 haad * uint32_t (*get_region_size)(struct dm_dirty_log *log);
148 1.1 haad *
149 1.1 haad * Payload-to-userspace:
150 1.1 haad * None.
151 1.1 haad * Payload-to-kernel:
152 1.1 haad * uint64_t - contains the region size
153 1.1 haad *
154 1.1 haad * The region size is something that was determined at constructor time.
155 1.1 haad * It is returned in the payload area and 'data_size' is set to
156 1.1 haad * reflect this.
157 1.1 haad *
158 1.1 haad * When the request has been processed, user-space must return the
159 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field appropriately.
160 1.1 haad */
161 1.1 haad #define DM_ULOG_GET_REGION_SIZE 6
162 1.1 haad
163 1.1 haad /*
164 1.1 haad * DM_ULOG_IS_CLEAN corresponds to (found in dm-dirty-log.h):
165 1.1 haad * int (*is_clean)(struct dm_dirty_log *log, region_t region);
166 1.1 haad *
167 1.1 haad * Payload-to-userspace:
168 1.1 haad * uint64_t - the region to get clean status on
169 1.1 haad * Payload-to-kernel:
170 1.1 haad * int64_t - 1 if clean, 0 otherwise
171 1.1 haad *
172 1.1 haad * Payload is sizeof(uint64_t) and contains the region for which the clean
173 1.1 haad * status is being made.
174 1.1 haad *
175 1.1 haad * When the request has been processed, user-space must return the
176 1.1 haad * dm_ulog_request to the kernel - filling the payload with 0 (not clean) or
177 1.1 haad * 1 (clean), setting 'data_size' and 'error' appropriately.
178 1.1 haad */
179 1.1 haad #define DM_ULOG_IS_CLEAN 7
180 1.1 haad
181 1.1 haad /*
182 1.1 haad * DM_ULOG_IN_SYNC corresponds to (found in dm-dirty-log.h):
183 1.1 haad * int (*in_sync)(struct dm_dirty_log *log, region_t region,
184 1.1 haad * int can_block);
185 1.1 haad *
186 1.1 haad * Payload-to-userspace:
187 1.1 haad * uint64_t - the region to get sync status on
188 1.1 haad * Payload-to-kernel:
189 1.1 haad * int64_t - 1 if in-sync, 0 otherwise
190 1.1 haad *
191 1.1 haad * Exactly the same as 'is_clean' above, except this time asking "has the
192 1.1 haad * region been recovered?" vs. "is the region not being modified?"
193 1.1 haad */
194 1.1 haad #define DM_ULOG_IN_SYNC 8
195 1.1 haad
196 1.1 haad /*
197 1.1 haad * DM_ULOG_FLUSH corresponds to (found in dm-dirty-log.h):
198 1.1 haad * int (*flush)(struct dm_dirty_log *log);
199 1.1 haad *
200 1.1 haad * Payload-to-userspace:
201 1.1 haad * None.
202 1.1 haad * Payload-to-kernel:
203 1.1 haad * None.
204 1.1 haad *
205 1.1 haad * No incoming or outgoing payload. Simply flush log state to disk.
206 1.1 haad *
207 1.1 haad * When the request has been processed, user-space must return the
208 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and clearing
209 1.1 haad * 'data_size' appropriately.
210 1.1 haad */
211 1.1 haad #define DM_ULOG_FLUSH 9
212 1.1 haad
213 1.1 haad /*
214 1.1 haad * DM_ULOG_MARK_REGION corresponds to (found in dm-dirty-log.h):
215 1.1 haad * void (*mark_region)(struct dm_dirty_log *log, region_t region);
216 1.1 haad *
217 1.1 haad * Payload-to-userspace:
218 1.1 haad * uint64_t [] - region(s) to mark
219 1.1 haad * Payload-to-kernel:
220 1.1 haad * None.
221 1.1 haad *
222 1.1 haad * Incoming payload contains the one or more regions to mark dirty.
223 1.1 haad * The number of regions contained in the payload can be determined from
224 1.1 haad * 'data_size/sizeof(uint64_t)'.
225 1.1 haad *
226 1.1 haad * When the request has been processed, user-space must return the
227 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and clearing
228 1.1 haad * 'data_size' appropriately.
229 1.1 haad */
230 1.1 haad #define DM_ULOG_MARK_REGION 10
231 1.1 haad
232 1.1 haad /*
233 1.1 haad * DM_ULOG_CLEAR_REGION corresponds to (found in dm-dirty-log.h):
234 1.1 haad * void (*clear_region)(struct dm_dirty_log *log, region_t region);
235 1.1 haad *
236 1.1 haad * Payload-to-userspace:
237 1.1 haad * uint64_t [] - region(s) to clear
238 1.1 haad * Payload-to-kernel:
239 1.1 haad * None.
240 1.1 haad *
241 1.1 haad * Incoming payload contains the one or more regions to mark clean.
242 1.1 haad * The number of regions contained in the payload can be determined from
243 1.1 haad * 'data_size/sizeof(uint64_t)'.
244 1.1 haad *
245 1.1 haad * When the request has been processed, user-space must return the
246 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and clearing
247 1.1 haad * 'data_size' appropriately.
248 1.1 haad */
249 1.1 haad #define DM_ULOG_CLEAR_REGION 11
250 1.1 haad
251 1.1 haad /*
252 1.1 haad * DM_ULOG_GET_RESYNC_WORK corresponds to (found in dm-dirty-log.h):
253 1.1 haad * int (*get_resync_work)(struct dm_dirty_log *log, region_t *region);
254 1.1 haad *
255 1.1 haad * Payload-to-userspace:
256 1.1 haad * None.
257 1.1 haad * Payload-to-kernel:
258 1.1 haad * {
259 1.1 haad * int64_t i; -- 1 if recovery necessary, 0 otherwise
260 1.1 haad * uint64_t r; -- The region to recover if i=1
261 1.1 haad * }
262 1.1 haad * 'data_size' should be set appropriately.
263 1.1 haad *
264 1.1 haad * When the request has been processed, user-space must return the
265 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field appropriately.
266 1.1 haad */
267 1.1 haad #define DM_ULOG_GET_RESYNC_WORK 12
268 1.1 haad
269 1.1 haad /*
270 1.1 haad * DM_ULOG_SET_REGION_SYNC corresponds to (found in dm-dirty-log.h):
271 1.1 haad * void (*set_region_sync)(struct dm_dirty_log *log,
272 1.1 haad * region_t region, int in_sync);
273 1.1 haad *
274 1.1 haad * Payload-to-userspace:
275 1.1 haad * {
276 1.1 haad * uint64_t - region to set sync state on
277 1.1 haad * int64_t - 0 if not-in-sync, 1 if in-sync
278 1.1 haad * }
279 1.1 haad * Payload-to-kernel:
280 1.1 haad * None.
281 1.1 haad *
282 1.1 haad * When the request has been processed, user-space must return the
283 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and clearing
284 1.1 haad * 'data_size' appropriately.
285 1.1 haad */
286 1.1 haad #define DM_ULOG_SET_REGION_SYNC 13
287 1.1 haad
288 1.1 haad /*
289 1.1 haad * DM_ULOG_GET_SYNC_COUNT corresponds to (found in dm-dirty-log.h):
290 1.1 haad * region_t (*get_sync_count)(struct dm_dirty_log *log);
291 1.1 haad *
292 1.1 haad * Payload-to-userspace:
293 1.1 haad * None.
294 1.1 haad * Payload-to-kernel:
295 1.1 haad * uint64_t - the number of in-sync regions
296 1.1 haad *
297 1.1 haad * No incoming payload. Kernel-bound payload contains the number of
298 1.1 haad * regions that are in-sync (in a size_t).
299 1.1 haad *
300 1.1 haad * When the request has been processed, user-space must return the
301 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and
302 1.1 haad * 'data_size' appropriately.
303 1.1 haad */
304 1.1 haad #define DM_ULOG_GET_SYNC_COUNT 14
305 1.1 haad
306 1.1 haad /*
307 1.1 haad * DM_ULOG_STATUS_INFO corresponds to (found in dm-dirty-log.h):
308 1.1 haad * int (*status)(struct dm_dirty_log *log, STATUSTYPE_INFO,
309 1.1 haad * char *result, unsigned maxlen);
310 1.1 haad *
311 1.1 haad * Payload-to-userspace:
312 1.1 haad * None.
313 1.1 haad * Payload-to-kernel:
314 1.1 haad * Character string containing STATUSTYPE_INFO
315 1.1 haad *
316 1.1 haad * When the request has been processed, user-space must return the
317 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and
318 1.1 haad * 'data_size' appropriately.
319 1.1 haad */
320 1.1 haad #define DM_ULOG_STATUS_INFO 15
321 1.1 haad
322 1.1 haad /*
323 1.1 haad * DM_ULOG_STATUS_TABLE corresponds to (found in dm-dirty-log.h):
324 1.1 haad * int (*status)(struct dm_dirty_log *log, STATUSTYPE_TABLE,
325 1.1 haad * char *result, unsigned maxlen);
326 1.1 haad *
327 1.1 haad * Payload-to-userspace:
328 1.1 haad * None.
329 1.1 haad * Payload-to-kernel:
330 1.1 haad * Character string containing STATUSTYPE_TABLE
331 1.1 haad *
332 1.1 haad * When the request has been processed, user-space must return the
333 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and
334 1.1 haad * 'data_size' appropriately.
335 1.1 haad */
336 1.1 haad #define DM_ULOG_STATUS_TABLE 16
337 1.1 haad
338 1.1 haad /*
339 1.1 haad * DM_ULOG_IS_REMOTE_RECOVERING corresponds to (found in dm-dirty-log.h):
340 1.1 haad * int (*is_remote_recovering)(struct dm_dirty_log *log, region_t region);
341 1.1 haad *
342 1.1 haad * Payload-to-userspace:
343 1.1 haad * uint64_t - region to determine recovery status on
344 1.1 haad * Payload-to-kernel:
345 1.1 haad * {
346 1.1 haad * int64_t is_recovering; -- 0 if no, 1 if yes
347 1.1 haad * uint64_t in_sync_hint; -- lowest region still needing resync
348 1.1 haad * }
349 1.1 haad *
350 1.1 haad * When the request has been processed, user-space must return the
351 1.1 haad * dm_ulog_request to the kernel - setting the 'error' field and
352 1.1 haad * 'data_size' appropriately.
353 1.1 haad */
354 1.1 haad #define DM_ULOG_IS_REMOTE_RECOVERING 17
355 1.1 haad
356 1.1 haad /*
357 1.1 haad * (DM_ULOG_REQUEST_MASK & request_type) to get the request type
358 1.1 haad *
359 1.1 haad * Payload-to-userspace:
360 1.1 haad * A single string containing all the argv arguments separated by ' 's
361 1.1 haad * Payload-to-kernel:
362 1.1 haad * None. ('data_size' in the dm_ulog_request struct should be 0.)
363 1.1 haad *
364 1.1 haad * We are reserving 8 bits of the 32-bit 'request_type' field for the
365 1.1 haad * various request types above. The remaining 24-bits are currently
366 1.1 haad * set to zero and are reserved for future use and compatibility concerns.
367 1.1 haad *
368 1.1 haad * User-space should always use DM_ULOG_REQUEST_TYPE to aquire the
369 1.1 haad * request type from the 'request_type' field to maintain forward compatibility.
370 1.1 haad */
371 1.1 haad #define DM_ULOG_REQUEST_MASK 0xFF
372 1.1 haad #define DM_ULOG_REQUEST_TYPE(request_type) \
373 1.1 haad (DM_ULOG_REQUEST_MASK & (request_type))
374 1.1 haad
375 1.1 haad struct dm_ulog_request {
376 1.1 haad /*
377 1.1 haad * The local unique identifier (luid) and the universally unique
378 1.1 haad * identifier (uuid) are used to tie a request to a specific
379 1.1 haad * mirror log. A single machine log could probably make due with
380 1.1 haad * just the 'luid', but a cluster-aware log must use the 'uuid' and
381 1.1 haad * the 'luid'. The uuid is what is required for node to node
382 1.1 haad * communication concerning a particular log, but the 'luid' helps
383 1.1 haad * differentiate between logs that are being swapped and have the
384 1.1 haad * same 'uuid'. (Think "live" and "inactive" device-mapper tables.)
385 1.1 haad */
386 1.1 haad uint64_t luid;
387 1.1 haad char uuid[DM_UUID_LEN];
388 1.1 haad char padding[7]; /* Padding because DM_UUID_LEN = 129 */
389 1.1 haad
390 1.1 haad int32_t error; /* Used to report back processing errors */
391 1.1 haad
392 1.1 haad uint32_t seq; /* Sequence number for request */
393 1.1 haad uint32_t request_type; /* DM_ULOG_* defined above */
394 1.1 haad uint32_t data_size; /* How much data (not including this struct) */
395 1.1 haad
396 1.1 haad char data[0];
397 1.1 haad };
398 1.1 haad
399 1.1 haad #endif /* __DM_LOG_USERSPACE_H__ */
400