dm-log-userspace.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. * None.
  193. * Payload-to-kernel:
  194. * None.
  195. *
  196. * No incoming or outgoing payload. Simply flush log state to disk.
  197. *
  198. * When the request has been processed, user-space must return the
  199. * dm_ulog_request to the kernel - setting the 'error' field and clearing
  200. * 'data_size' appropriately.
  201. */
  202. #define DM_ULOG_FLUSH 9
  203. /*
  204. * DM_ULOG_MARK_REGION corresponds to (found in dm-dirty-log.h):
  205. * void (*mark_region)(struct dm_dirty_log *log, region_t region);
  206. *
  207. * Payload-to-userspace:
  208. * uint64_t [] - region(s) to mark
  209. * Payload-to-kernel:
  210. * None.
  211. *
  212. * Incoming payload contains the one or more regions to mark dirty.
  213. * The number of regions contained in the payload can be determined from
  214. * 'data_size/sizeof(uint64_t)'.
  215. *
  216. * When the request has been processed, user-space must return the
  217. * dm_ulog_request to the kernel - setting the 'error' field and clearing
  218. * 'data_size' appropriately.
  219. */
  220. #define DM_ULOG_MARK_REGION 10
  221. /*
  222. * DM_ULOG_CLEAR_REGION corresponds to (found in dm-dirty-log.h):
  223. * void (*clear_region)(struct dm_dirty_log *log, region_t region);
  224. *
  225. * Payload-to-userspace:
  226. * uint64_t [] - region(s) to clear
  227. * Payload-to-kernel:
  228. * None.
  229. *
  230. * Incoming payload contains the one or more regions to mark clean.
  231. * The number of regions contained in the payload can be determined from
  232. * 'data_size/sizeof(uint64_t)'.
  233. *
  234. * When the request has been processed, user-space must return the
  235. * dm_ulog_request to the kernel - setting the 'error' field and clearing
  236. * 'data_size' appropriately.
  237. */
  238. #define DM_ULOG_CLEAR_REGION 11
  239. /*
  240. * DM_ULOG_GET_RESYNC_WORK corresponds to (found in dm-dirty-log.h):
  241. * int (*get_resync_work)(struct dm_dirty_log *log, region_t *region);
  242. *
  243. * Payload-to-userspace:
  244. * None.
  245. * Payload-to-kernel:
  246. * {
  247. * int64_t i; -- 1 if recovery necessary, 0 otherwise
  248. * uint64_t r; -- The region to recover if i=1
  249. * }
  250. * 'data_size' should be set appropriately.
  251. *
  252. * When the request has been processed, user-space must return the
  253. * dm_ulog_request to the kernel - setting the 'error' field appropriately.
  254. */
  255. #define DM_ULOG_GET_RESYNC_WORK 12
  256. /*
  257. * DM_ULOG_SET_REGION_SYNC corresponds to (found in dm-dirty-log.h):
  258. * void (*set_region_sync)(struct dm_dirty_log *log,
  259. * region_t region, int in_sync);
  260. *
  261. * Payload-to-userspace:
  262. * {
  263. * uint64_t - region to set sync state on
  264. * int64_t - 0 if not-in-sync, 1 if in-sync
  265. * }
  266. * Payload-to-kernel:
  267. * None.
  268. *
  269. * When the request has been processed, user-space must return the
  270. * dm_ulog_request to the kernel - setting the 'error' field and clearing
  271. * 'data_size' appropriately.
  272. */
  273. #define DM_ULOG_SET_REGION_SYNC 13
  274. /*
  275. * DM_ULOG_GET_SYNC_COUNT corresponds to (found in dm-dirty-log.h):
  276. * region_t (*get_sync_count)(struct dm_dirty_log *log);
  277. *
  278. * Payload-to-userspace:
  279. * None.
  280. * Payload-to-kernel:
  281. * uint64_t - the number of in-sync regions
  282. *
  283. * No incoming payload. Kernel-bound payload contains the number of
  284. * regions that are in-sync (in a size_t).
  285. *
  286. * When the request has been processed, user-space must return the
  287. * dm_ulog_request to the kernel - setting the 'error' field and
  288. * 'data_size' appropriately.
  289. */
  290. #define DM_ULOG_GET_SYNC_COUNT 14
  291. /*
  292. * DM_ULOG_STATUS_INFO corresponds to (found in dm-dirty-log.h):
  293. * int (*status)(struct dm_dirty_log *log, STATUSTYPE_INFO,
  294. * char *result, unsigned maxlen);
  295. *
  296. * Payload-to-userspace:
  297. * None.
  298. * Payload-to-kernel:
  299. * Character string containing STATUSTYPE_INFO
  300. *
  301. * When the request has been processed, user-space must return the
  302. * dm_ulog_request to the kernel - setting the 'error' field and
  303. * 'data_size' appropriately.
  304. */
  305. #define DM_ULOG_STATUS_INFO 15
  306. /*
  307. * DM_ULOG_STATUS_TABLE corresponds to (found in dm-dirty-log.h):
  308. * int (*status)(struct dm_dirty_log *log, STATUSTYPE_TABLE,
  309. * char *result, unsigned maxlen);
  310. *
  311. * Payload-to-userspace:
  312. * None.
  313. * Payload-to-kernel:
  314. * Character string containing STATUSTYPE_TABLE
  315. *
  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.
  319. */
  320. #define DM_ULOG_STATUS_TABLE 16
  321. /*
  322. * DM_ULOG_IS_REMOTE_RECOVERING corresponds to (found in dm-dirty-log.h):
  323. * int (*is_remote_recovering)(struct dm_dirty_log *log, region_t region);
  324. *
  325. * Payload-to-userspace:
  326. * uint64_t - region to determine recovery status on
  327. * Payload-to-kernel:
  328. * {
  329. * int64_t is_recovering; -- 0 if no, 1 if yes
  330. * uint64_t in_sync_hint; -- lowest region still needing resync
  331. * }
  332. *
  333. * When the request has been processed, user-space must return the
  334. * dm_ulog_request to the kernel - setting the 'error' field and
  335. * 'data_size' appropriately.
  336. */
  337. #define DM_ULOG_IS_REMOTE_RECOVERING 17
  338. /*
  339. * (DM_ULOG_REQUEST_MASK & request_type) to get the request type
  340. *
  341. * Payload-to-userspace:
  342. * A single string containing all the argv arguments separated by ' 's
  343. * Payload-to-kernel:
  344. * None. ('data_size' in the dm_ulog_request struct should be 0.)
  345. *
  346. * We are reserving 8 bits of the 32-bit 'request_type' field for the
  347. * various request types above. The remaining 24-bits are currently
  348. * set to zero and are reserved for future use and compatibility concerns.
  349. *
  350. * User-space should always use DM_ULOG_REQUEST_TYPE to acquire the
  351. * request type from the 'request_type' field to maintain forward compatibility.
  352. */
  353. #define DM_ULOG_REQUEST_MASK 0xFF
  354. #define DM_ULOG_REQUEST_TYPE(request_type) \
  355. (DM_ULOG_REQUEST_MASK & (request_type))
  356. /*
  357. * DM_ULOG_REQUEST_VERSION is incremented when there is a
  358. * change to the way information is passed between kernel
  359. * and userspace. This could be a structure change of
  360. * dm_ulog_request or a change in the way requests are
  361. * issued/handled. Changes are outlined here:
  362. * version 1: Initial implementation
  363. * version 2: DM_ULOG_CTR allowed to return a string containing a
  364. * device name that is to be registered with DM via
  365. * 'dm_get_device'.
  366. */
  367. #define DM_ULOG_REQUEST_VERSION 2
  368. struct dm_ulog_request {
  369. /*
  370. * The local unique identifier (luid) and the universally unique
  371. * identifier (uuid) are used to tie a request to a specific
  372. * mirror log. A single machine log could probably make due with
  373. * just the 'luid', but a cluster-aware log must use the 'uuid' and
  374. * the 'luid'. The uuid is what is required for node to node
  375. * communication concerning a particular log, but the 'luid' helps
  376. * differentiate between logs that are being swapped and have the
  377. * same 'uuid'. (Think "live" and "inactive" device-mapper tables.)
  378. */
  379. uint64_t luid;
  380. char uuid[DM_UUID_LEN];
  381. char padding[3]; /* Padding because DM_UUID_LEN = 129 */
  382. uint32_t version; /* See DM_ULOG_REQUEST_VERSION */
  383. int32_t error; /* Used to report back processing errors */
  384. uint32_t seq; /* Sequence number for request */
  385. uint32_t request_type; /* DM_ULOG_* defined above */
  386. uint32_t data_size; /* How much data (not including this struct) */
  387. char data[0];
  388. };
  389. #endif /* __DM_LOG_USERSPACE_H__ */