1 /* SPDX-License-Identifier: LGPL-2.0+ WITH Linux-syscall-note */
3 * Copyright (C) 2006-2009 Red Hat, Inc.
5 * This file is released under the LGPL.
8 #ifndef __DM_LOG_USERSPACE_H__
9 #define __DM_LOG_USERSPACE_H__
11 #include <linux/types.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 * A NUL-terminated string that is the name of the device that is used
58 * as the backing store for the log data. 'dm_get_device' will be called
59 * on this device. ('dm_put_device' will be called on this device
60 * automatically after calling DM_ULOG_DTR.) If there is no device needed
61 * for log data, 'data_size' in the dm_ulog_request struct should be 0.
63 * The UUID contained in the dm_ulog_request structure is the reference that
64 * will be used by all request types to a specific log. The constructor must
65 * record this association with the instance created.
67 * When the request has been processed, user-space must return the
68 * dm_ulog_request to the kernel - setting the 'error' field, filling the
69 * data field with the log device if necessary, and setting 'data_size'
75 * DM_ULOG_DTR corresponds to (found in dm-dirty-log.h):
76 * void (*dtr)(struct dm_dirty_log *log);
78 * Payload-to-userspace:
79 * A single string containing all the argv arguments separated by ' 's
81 * None. ('data_size' in the dm_ulog_request struct should be 0.)
83 * The UUID contained in the dm_ulog_request structure is all that is
84 * necessary to identify the log instance being destroyed. There is no
87 * When the request has been processed, user-space must return the
88 * dm_ulog_request to the kernel - setting the 'error' field and clearing
89 * 'data_size' appropriately.
94 * DM_ULOG_PRESUSPEND corresponds to (found in dm-dirty-log.h):
95 * int (*presuspend)(struct dm_dirty_log *log);
97 * Payload-to-userspace:
102 * The UUID contained in the dm_ulog_request structure is all that is
103 * necessary to identify the log instance being presuspended. There is no
106 * When the request has been processed, user-space must return the
107 * dm_ulog_request to the kernel - setting the 'error' field and
108 * 'data_size' appropriately.
110 #define DM_ULOG_PRESUSPEND 3
113 * DM_ULOG_POSTSUSPEND corresponds to (found in dm-dirty-log.h):
114 * int (*postsuspend)(struct dm_dirty_log *log);
116 * Payload-to-userspace:
121 * The UUID contained in the dm_ulog_request structure is all that is
122 * necessary to identify the log instance being postsuspended. There is no
125 * When the request has been processed, user-space must return the
126 * dm_ulog_request to the kernel - setting the 'error' field and
127 * 'data_size' appropriately.
129 #define DM_ULOG_POSTSUSPEND 4
132 * DM_ULOG_RESUME corresponds to (found in dm-dirty-log.h):
133 * int (*resume)(struct dm_dirty_log *log);
135 * Payload-to-userspace:
140 * The UUID contained in the dm_ulog_request structure is all that is
141 * necessary to identify the log instance being resumed. There is no
144 * When the request has been processed, user-space must return the
145 * dm_ulog_request to the kernel - setting the 'error' field and
146 * 'data_size' appropriately.
148 #define DM_ULOG_RESUME 5
151 * DM_ULOG_GET_REGION_SIZE corresponds to (found in dm-dirty-log.h):
152 * __u32 (*get_region_size)(struct dm_dirty_log *log);
154 * Payload-to-userspace:
157 * __u64 - contains the region size
159 * The region size is something that was determined at constructor time.
160 * It is returned in the payload area and 'data_size' is set to
163 * When the request has been processed, user-space must return the
164 * dm_ulog_request to the kernel - setting the 'error' field appropriately.
166 #define DM_ULOG_GET_REGION_SIZE 6
169 * DM_ULOG_IS_CLEAN corresponds to (found in dm-dirty-log.h):
170 * int (*is_clean)(struct dm_dirty_log *log, region_t region);
172 * Payload-to-userspace:
173 * __u64 - the region to get clean status on
175 * __s64 - 1 if clean, 0 otherwise
177 * Payload is sizeof(__u64) and contains the region for which the clean
178 * status is being made.
180 * When the request has been processed, user-space must return the
181 * dm_ulog_request to the kernel - filling the payload with 0 (not clean) or
182 * 1 (clean), setting 'data_size' and 'error' appropriately.
184 #define DM_ULOG_IS_CLEAN 7
187 * DM_ULOG_IN_SYNC corresponds to (found in dm-dirty-log.h):
188 * int (*in_sync)(struct dm_dirty_log *log, region_t region,
191 * Payload-to-userspace:
192 * __u64 - the region to get sync status on
194 * __s64 - 1 if in-sync, 0 otherwise
196 * Exactly the same as 'is_clean' above, except this time asking "has the
197 * region been recovered?" vs. "is the region not being modified?"
199 #define DM_ULOG_IN_SYNC 8
202 * DM_ULOG_FLUSH corresponds to (found in dm-dirty-log.h):
203 * int (*flush)(struct dm_dirty_log *log);
205 * Payload-to-userspace:
206 * If the 'integrated_flush' directive is present in the constructor
207 * table, the payload is as same as DM_ULOG_MARK_REGION:
208 * __u64 [] - region(s) to mark
214 * If the 'integrated_flush' option was used during the creation of the
215 * log, mark region requests are carried as payload in the flush request.
216 * Piggybacking the mark requests in this way allows for fewer communications
217 * between kernel and userspace.
219 * When the request has been processed, user-space must return the
220 * dm_ulog_request to the kernel - setting the 'error' field and clearing
221 * 'data_size' appropriately.
223 #define DM_ULOG_FLUSH 9
226 * DM_ULOG_MARK_REGION corresponds to (found in dm-dirty-log.h):
227 * void (*mark_region)(struct dm_dirty_log *log, region_t region);
229 * Payload-to-userspace:
230 * __u64 [] - region(s) to mark
234 * Incoming payload contains the one or more regions to mark dirty.
235 * The number of regions contained in the payload can be determined from
236 * 'data_size/sizeof(__u64)'.
238 * When the request has been processed, user-space must return the
239 * dm_ulog_request to the kernel - setting the 'error' field and clearing
240 * 'data_size' appropriately.
242 #define DM_ULOG_MARK_REGION 10
245 * DM_ULOG_CLEAR_REGION corresponds to (found in dm-dirty-log.h):
246 * void (*clear_region)(struct dm_dirty_log *log, region_t region);
248 * Payload-to-userspace:
249 * __u64 [] - region(s) to clear
253 * Incoming payload contains the one or more regions to mark clean.
254 * The number of regions contained in the payload can be determined from
255 * 'data_size/sizeof(__u64)'.
257 * When the request has been processed, user-space must return the
258 * dm_ulog_request to the kernel - setting the 'error' field and clearing
259 * 'data_size' appropriately.
261 #define DM_ULOG_CLEAR_REGION 11
264 * DM_ULOG_GET_RESYNC_WORK corresponds to (found in dm-dirty-log.h):
265 * int (*get_resync_work)(struct dm_dirty_log *log, region_t *region);
267 * Payload-to-userspace:
271 * __s64 i; -- 1 if recovery necessary, 0 otherwise
272 * __u64 r; -- The region to recover if i=1
274 * 'data_size' should be set appropriately.
276 * When the request has been processed, user-space must return the
277 * dm_ulog_request to the kernel - setting the 'error' field appropriately.
279 #define DM_ULOG_GET_RESYNC_WORK 12
282 * DM_ULOG_SET_REGION_SYNC corresponds to (found in dm-dirty-log.h):
283 * void (*set_region_sync)(struct dm_dirty_log *log,
284 * region_t region, int in_sync);
286 * Payload-to-userspace:
288 * __u64 - region to set sync state on
289 * __s64 - 0 if not-in-sync, 1 if in-sync
294 * When the request has been processed, user-space must return the
295 * dm_ulog_request to the kernel - setting the 'error' field and clearing
296 * 'data_size' appropriately.
298 #define DM_ULOG_SET_REGION_SYNC 13
301 * DM_ULOG_GET_SYNC_COUNT corresponds to (found in dm-dirty-log.h):
302 * region_t (*get_sync_count)(struct dm_dirty_log *log);
304 * Payload-to-userspace:
307 * __u64 - the number of in-sync regions
309 * No incoming payload. Kernel-bound payload contains the number of
310 * regions that are in-sync (in a size_t).
312 * When the request has been processed, user-space must return the
313 * dm_ulog_request to the kernel - setting the 'error' field and
314 * 'data_size' appropriately.
316 #define DM_ULOG_GET_SYNC_COUNT 14
319 * DM_ULOG_STATUS_INFO corresponds to (found in dm-dirty-log.h):
320 * int (*status)(struct dm_dirty_log *log, STATUSTYPE_INFO,
321 * char *result, unsigned maxlen);
323 * Payload-to-userspace:
326 * Character string containing STATUSTYPE_INFO
328 * When the request has been processed, user-space must return the
329 * dm_ulog_request to the kernel - setting the 'error' field and
330 * 'data_size' appropriately.
332 #define DM_ULOG_STATUS_INFO 15
335 * DM_ULOG_STATUS_TABLE corresponds to (found in dm-dirty-log.h):
336 * int (*status)(struct dm_dirty_log *log, STATUSTYPE_TABLE,
337 * char *result, unsigned maxlen);
339 * Payload-to-userspace:
342 * Character string containing STATUSTYPE_TABLE
344 * When the request has been processed, user-space must return the
345 * dm_ulog_request to the kernel - setting the 'error' field and
346 * 'data_size' appropriately.
348 #define DM_ULOG_STATUS_TABLE 16
351 * DM_ULOG_IS_REMOTE_RECOVERING corresponds to (found in dm-dirty-log.h):
352 * int (*is_remote_recovering)(struct dm_dirty_log *log, region_t region);
354 * Payload-to-userspace:
355 * __u64 - region to determine recovery status on
358 * __s64 is_recovering; -- 0 if no, 1 if yes
359 * __u64 in_sync_hint; -- lowest region still needing resync
362 * When the request has been processed, user-space must return the
363 * dm_ulog_request to the kernel - setting the 'error' field and
364 * 'data_size' appropriately.
366 #define DM_ULOG_IS_REMOTE_RECOVERING 17
369 * (DM_ULOG_REQUEST_MASK & request_type) to get the request type
371 * Payload-to-userspace:
372 * A single string containing all the argv arguments separated by ' 's
374 * None. ('data_size' in the dm_ulog_request struct should be 0.)
376 * We are reserving 8 bits of the 32-bit 'request_type' field for the
377 * various request types above. The remaining 24-bits are currently
378 * set to zero and are reserved for future use and compatibility concerns.
380 * User-space should always use DM_ULOG_REQUEST_TYPE to acquire the
381 * request type from the 'request_type' field to maintain forward compatibility.
383 #define DM_ULOG_REQUEST_MASK 0xFF
384 #define DM_ULOG_REQUEST_TYPE(request_type) \
385 (DM_ULOG_REQUEST_MASK & (request_type))
388 * DM_ULOG_REQUEST_VERSION is incremented when there is a
389 * change to the way information is passed between kernel
390 * and userspace. This could be a structure change of
391 * dm_ulog_request or a change in the way requests are
392 * issued/handled. Changes are outlined here:
393 * version 1: Initial implementation
394 * version 2: DM_ULOG_CTR allowed to return a string containing a
395 * device name that is to be registered with DM via
397 * version 3: DM_ULOG_FLUSH is capable of carrying payload for marking
398 * regions. This "integrated flush" reduces the number of
399 * requests between the kernel and userspace by effectively
400 * merging 'mark' and 'flush' requests. A constructor table
401 * argument ('integrated_flush') is required to turn this
402 * feature on, so it is backwards compatible with older
403 * userspace versions.
405 #define DM_ULOG_REQUEST_VERSION 3
407 struct dm_ulog_request {
409 * The local unique identifier (luid) and the universally unique
410 * identifier (uuid) are used to tie a request to a specific
411 * mirror log. A single machine log could probably make due with
412 * just the 'luid', but a cluster-aware log must use the 'uuid' and
413 * the 'luid'. The uuid is what is required for node to node
414 * communication concerning a particular log, but the 'luid' helps
415 * differentiate between logs that are being swapped and have the
416 * same 'uuid'. (Think "live" and "inactive" device-mapper tables.)
419 char uuid[DM_UUID_LEN];
420 char padding[3]; /* Padding because DM_UUID_LEN = 129 */
422 __u32 version; /* See DM_ULOG_REQUEST_VERSION */
423 __s32 error; /* Used to report back processing errors */
425 __u32 seq; /* Sequence number for request */
426 __u32 request_type; /* DM_ULOG_* defined above */
427 __u32 data_size; /* How much data (not including this struct) */
432 #endif /* __DM_LOG_USERSPACE_H__ */