dm-log-userspace.h 15 KB

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