4 * Copyright (C) 2006-2009 Red Hat, Inc.
6 * This file is released under the LGPL.
9 #ifndef __DM_LOG_USERSPACE_H__
10 #define __DM_LOG_USERSPACE_H__
12 #include <linux/dm-ioctl.h> /* For DM_UUID_LEN */
15 * The device-mapper userspace log module consists of a kernel component and
16 * a user-space component. The kernel component implements the API defined
17 * in dm-dirty-log.h. Its purpose is simply to pass the parameters and
18 * return values of those API functions between kernel and user-space.
20 * Below are defined the 'request_types' - DM_ULOG_CTR, DM_ULOG_DTR, etc.
21 * These request types represent the different functions in the device-mapper
22 * dirty log API. Each of these is described in more detail below.
24 * The user-space program must listen for requests from the kernel (representing
25 * the various API functions) and process them.
27 * User-space begins by setting up the communication link (error checking
28 * removed for clarity):
29 * fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
30 * addr.nl_family = AF_NETLINK;
31 * addr.nl_groups = CN_IDX_DM;
33 * r = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
34 * opt = addr.nl_groups;
35 * setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &opt, sizeof(opt));
37 * User-space will then wait to receive requests form the kernel, which it
38 * will process as described below. The requests are received in the form,
39 * ((struct dm_ulog_request) + (additional data)). Depending on the request
40 * type, there may or may not be 'additional data'. In the descriptions below,
41 * you will see 'Payload-to-userspace' and 'Payload-to-kernel'. The
42 * 'Payload-to-userspace' is what the kernel sends in 'additional data' as
43 * necessary parameters to complete the request. The 'Payload-to-kernel' is
44 * the 'additional data' returned to the kernel that contains the necessary
45 * results of the request. The 'data_size' field in the dm_ulog_request
46 * structure denotes the availability and amount of payload data.
50 * DM_ULOG_CTR corresponds to (found in dm-dirty-log.h):
51 * int (*ctr)(struct dm_dirty_log *log, struct dm_target *ti,
52 * unsigned argc, char **argv);
54 * Payload-to-userspace:
55 * A single string containing all the argv arguments separated by ' 's
57 * None. ('data_size' in the dm_ulog_request struct should be 0.)
59 * The UUID contained in the dm_ulog_request structure is the reference that
60 * will be used by all request types to a specific log. The constructor must
61 * record this assotiation with instance created.
63 * When the request has been processed, user-space must return the
64 * dm_ulog_request to the kernel - setting the 'error' field and
65 * 'data_size' appropriately.
70 * DM_ULOG_DTR corresponds to (found in dm-dirty-log.h):
71 * void (*dtr)(struct dm_dirty_log *log);
73 * Payload-to-userspace:
74 * A single string containing all the argv arguments separated by ' 's
76 * None. ('data_size' in the dm_ulog_request struct should be 0.)
78 * The UUID contained in the dm_ulog_request structure is all that is
79 * necessary to identify the log instance being destroyed. There is no
82 * When the request has been processed, user-space must return the
83 * dm_ulog_request to the kernel - setting the 'error' field and clearing
84 * 'data_size' appropriately.
89 * DM_ULOG_PRESUSPEND corresponds to (found in dm-dirty-log.h):
90 * int (*presuspend)(struct dm_dirty_log *log);
92 * Payload-to-userspace:
97 * The UUID contained in the dm_ulog_request structure is all that is
98 * necessary to identify the log instance being presuspended. There is no
101 * When the request has been processed, user-space must return the
102 * dm_ulog_request to the kernel - setting the 'error' field and
103 * 'data_size' appropriately.
105 #define DM_ULOG_PRESUSPEND 3
108 * DM_ULOG_POSTSUSPEND corresponds to (found in dm-dirty-log.h):
109 * int (*postsuspend)(struct dm_dirty_log *log);
111 * Payload-to-userspace:
116 * The UUID contained in the dm_ulog_request structure is all that is
117 * necessary to identify the log instance being postsuspended. There is no
120 * When the request has been processed, user-space must return the
121 * dm_ulog_request to the kernel - setting the 'error' field and
122 * 'data_size' appropriately.
124 #define DM_ULOG_POSTSUSPEND 4
127 * DM_ULOG_RESUME corresponds to (found in dm-dirty-log.h):
128 * int (*resume)(struct dm_dirty_log *log);
130 * Payload-to-userspace:
135 * The UUID contained in the dm_ulog_request structure is all that is
136 * necessary to identify the log instance being resumed. There is no
139 * When the request has been processed, user-space must return the
140 * dm_ulog_request to the kernel - setting the 'error' field and
141 * 'data_size' appropriately.
143 #define DM_ULOG_RESUME 5
146 * DM_ULOG_GET_REGION_SIZE corresponds to (found in dm-dirty-log.h):
147 * uint32_t (*get_region_size)(struct dm_dirty_log *log);
149 * Payload-to-userspace:
152 * uint64_t - contains the region size
154 * The region size is something that was determined at constructor time.
155 * It is returned in the payload area and 'data_size' is set to
158 * When the request has been processed, user-space must return the
159 * dm_ulog_request to the kernel - setting the 'error' field appropriately.
161 #define DM_ULOG_GET_REGION_SIZE 6
164 * DM_ULOG_IS_CLEAN corresponds to (found in dm-dirty-log.h):
165 * int (*is_clean)(struct dm_dirty_log *log, region_t region);
167 * Payload-to-userspace:
168 * uint64_t - the region to get clean status on
170 * int64_t - 1 if clean, 0 otherwise
172 * Payload is sizeof(uint64_t) and contains the region for which the clean
173 * status is being made.
175 * When the request has been processed, user-space must return the
176 * dm_ulog_request to the kernel - filling the payload with 0 (not clean) or
177 * 1 (clean), setting 'data_size' and 'error' appropriately.
179 #define DM_ULOG_IS_CLEAN 7
182 * DM_ULOG_IN_SYNC corresponds to (found in dm-dirty-log.h):
183 * int (*in_sync)(struct dm_dirty_log *log, region_t region,
186 * Payload-to-userspace:
187 * uint64_t - the region to get sync status on
189 * int64_t - 1 if in-sync, 0 otherwise
191 * Exactly the same as 'is_clean' above, except this time asking "has the
192 * region been recovered?" vs. "is the region not being modified?"
194 #define DM_ULOG_IN_SYNC 8
197 * DM_ULOG_FLUSH corresponds to (found in dm-dirty-log.h):
198 * int (*flush)(struct dm_dirty_log *log);
200 * Payload-to-userspace:
205 * No incoming or outgoing payload. Simply flush log state to disk.
207 * When the request has been processed, user-space must return the
208 * dm_ulog_request to the kernel - setting the 'error' field and clearing
209 * 'data_size' appropriately.
211 #define DM_ULOG_FLUSH 9
214 * DM_ULOG_MARK_REGION corresponds to (found in dm-dirty-log.h):
215 * void (*mark_region)(struct dm_dirty_log *log, region_t region);
217 * Payload-to-userspace:
218 * uint64_t [] - region(s) to mark
222 * Incoming payload contains the one or more regions to mark dirty.
223 * The number of regions contained in the payload can be determined from
224 * 'data_size/sizeof(uint64_t)'.
226 * When the request has been processed, user-space must return the
227 * dm_ulog_request to the kernel - setting the 'error' field and clearing
228 * 'data_size' appropriately.
230 #define DM_ULOG_MARK_REGION 10
233 * DM_ULOG_CLEAR_REGION corresponds to (found in dm-dirty-log.h):
234 * void (*clear_region)(struct dm_dirty_log *log, region_t region);
236 * Payload-to-userspace:
237 * uint64_t [] - region(s) to clear
241 * Incoming payload contains the one or more regions to mark clean.
242 * The number of regions contained in the payload can be determined from
243 * 'data_size/sizeof(uint64_t)'.
245 * When the request has been processed, user-space must return the
246 * dm_ulog_request to the kernel - setting the 'error' field and clearing
247 * 'data_size' appropriately.
249 #define DM_ULOG_CLEAR_REGION 11
252 * DM_ULOG_GET_RESYNC_WORK corresponds to (found in dm-dirty-log.h):
253 * int (*get_resync_work)(struct dm_dirty_log *log, region_t *region);
255 * Payload-to-userspace:
259 * int64_t i; -- 1 if recovery necessary, 0 otherwise
260 * uint64_t r; -- The region to recover if i=1
262 * 'data_size' should be set appropriately.
264 * When the request has been processed, user-space must return the
265 * dm_ulog_request to the kernel - setting the 'error' field appropriately.
267 #define DM_ULOG_GET_RESYNC_WORK 12
270 * DM_ULOG_SET_REGION_SYNC corresponds to (found in dm-dirty-log.h):
271 * void (*set_region_sync)(struct dm_dirty_log *log,
272 * region_t region, int in_sync);
274 * Payload-to-userspace:
276 * uint64_t - region to set sync state on
277 * int64_t - 0 if not-in-sync, 1 if in-sync
282 * When the request has been processed, user-space must return the
283 * dm_ulog_request to the kernel - setting the 'error' field and clearing
284 * 'data_size' appropriately.
286 #define DM_ULOG_SET_REGION_SYNC 13
289 * DM_ULOG_GET_SYNC_COUNT corresponds to (found in dm-dirty-log.h):
290 * region_t (*get_sync_count)(struct dm_dirty_log *log);
292 * Payload-to-userspace:
295 * uint64_t - the number of in-sync regions
297 * No incoming payload. Kernel-bound payload contains the number of
298 * regions that are in-sync (in a size_t).
300 * When the request has been processed, user-space must return the
301 * dm_ulog_request to the kernel - setting the 'error' field and
302 * 'data_size' appropriately.
304 #define DM_ULOG_GET_SYNC_COUNT 14
307 * DM_ULOG_STATUS_INFO corresponds to (found in dm-dirty-log.h):
308 * int (*status)(struct dm_dirty_log *log, STATUSTYPE_INFO,
309 * char *result, unsigned maxlen);
311 * Payload-to-userspace:
314 * Character string containing STATUSTYPE_INFO
316 * When the request has been processed, user-space must return the
317 * dm_ulog_request to the kernel - setting the 'error' field and
318 * 'data_size' appropriately.
320 #define DM_ULOG_STATUS_INFO 15
323 * DM_ULOG_STATUS_TABLE corresponds to (found in dm-dirty-log.h):
324 * int (*status)(struct dm_dirty_log *log, STATUSTYPE_TABLE,
325 * char *result, unsigned maxlen);
327 * Payload-to-userspace:
330 * Character string containing STATUSTYPE_TABLE
332 * When the request has been processed, user-space must return the
333 * dm_ulog_request to the kernel - setting the 'error' field and
334 * 'data_size' appropriately.
336 #define DM_ULOG_STATUS_TABLE 16
339 * DM_ULOG_IS_REMOTE_RECOVERING corresponds to (found in dm-dirty-log.h):
340 * int (*is_remote_recovering)(struct dm_dirty_log *log, region_t region);
342 * Payload-to-userspace:
343 * uint64_t - region to determine recovery status on
346 * int64_t is_recovering; -- 0 if no, 1 if yes
347 * uint64_t in_sync_hint; -- lowest region still needing resync
350 * When the request has been processed, user-space must return the
351 * dm_ulog_request to the kernel - setting the 'error' field and
352 * 'data_size' appropriately.
354 #define DM_ULOG_IS_REMOTE_RECOVERING 17
357 * (DM_ULOG_REQUEST_MASK & request_type) to get the request type
359 * Payload-to-userspace:
360 * A single string containing all the argv arguments separated by ' 's
362 * None. ('data_size' in the dm_ulog_request struct should be 0.)
364 * We are reserving 8 bits of the 32-bit 'request_type' field for the
365 * various request types above. The remaining 24-bits are currently
366 * set to zero and are reserved for future use and compatibility concerns.
368 * User-space should always use DM_ULOG_REQUEST_TYPE to aquire the
369 * request type from the 'request_type' field to maintain forward compatibility.
371 #define DM_ULOG_REQUEST_MASK 0xFF
372 #define DM_ULOG_REQUEST_TYPE(request_type) \
373 (DM_ULOG_REQUEST_MASK & (request_type))
375 struct dm_ulog_request
{
377 * The local unique identifier (luid) and the universally unique
378 * identifier (uuid) are used to tie a request to a specific
379 * mirror log. A single machine log could probably make due with
380 * just the 'luid', but a cluster-aware log must use the 'uuid' and
381 * the 'luid'. The uuid is what is required for node to node
382 * communication concerning a particular log, but the 'luid' helps
383 * differentiate between logs that are being swapped and have the
384 * same 'uuid'. (Think "live" and "inactive" device-mapper tables.)
387 char uuid
[DM_UUID_LEN
];
388 char padding
[7]; /* Padding because DM_UUID_LEN = 129 */
390 int32_t error
; /* Used to report back processing errors */
392 uint32_t seq
; /* Sequence number for request */
393 uint32_t request_type
; /* DM_ULOG_* defined above */
394 uint32_t data_size
; /* How much data (not including this struct) */
399 #endif /* __DM_LOG_USERSPACE_H__ */