dm-log-userspace.h 15 KB

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