dm-log-userspace.h 15 KB

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