dm-log-userspace.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. * None. ('data_size' in the dm_ulog_request struct should be 0.)
  52. *
  53. * The UUID contained in the dm_ulog_request structure is the reference that
  54. * will be used by all request types to a specific log. The constructor must
  55. * record this assotiation with instance created.
  56. *
  57. * When the request has been processed, user-space must return the
  58. * dm_ulog_request to the kernel - setting the 'error' field and
  59. * 'data_size' appropriately.
  60. */
  61. #define DM_ULOG_CTR 1
  62. /*
  63. * DM_ULOG_DTR corresponds to (found in dm-dirty-log.h):
  64. * void (*dtr)(struct dm_dirty_log *log);
  65. *
  66. * Payload-to-userspace:
  67. * A single string containing all the argv arguments separated by ' 's
  68. * Payload-to-kernel:
  69. * None. ('data_size' in the dm_ulog_request struct should be 0.)
  70. *
  71. * The UUID contained in the dm_ulog_request structure is all that is
  72. * necessary to identify the log instance being destroyed. There is no
  73. * payload data.
  74. *
  75. * When the request has been processed, user-space must return the
  76. * dm_ulog_request to the kernel - setting the 'error' field and clearing
  77. * 'data_size' appropriately.
  78. */
  79. #define DM_ULOG_DTR 2
  80. /*
  81. * DM_ULOG_PRESUSPEND corresponds to (found in dm-dirty-log.h):
  82. * int (*presuspend)(struct dm_dirty_log *log);
  83. *
  84. * Payload-to-userspace:
  85. * None.
  86. * Payload-to-kernel:
  87. * None.
  88. *
  89. * The UUID contained in the dm_ulog_request structure is all that is
  90. * necessary to identify the log instance being presuspended. There is no
  91. * payload data.
  92. *
  93. * When the request has been processed, user-space must return the
  94. * dm_ulog_request to the kernel - setting the 'error' field and
  95. * 'data_size' appropriately.
  96. */
  97. #define DM_ULOG_PRESUSPEND 3
  98. /*
  99. * DM_ULOG_POSTSUSPEND corresponds to (found in dm-dirty-log.h):
  100. * int (*postsuspend)(struct dm_dirty_log *log);
  101. *
  102. * Payload-to-userspace:
  103. * None.
  104. * Payload-to-kernel:
  105. * None.
  106. *
  107. * The UUID contained in the dm_ulog_request structure is all that is
  108. * necessary to identify the log instance being postsuspended. There is no
  109. * payload data.
  110. *
  111. * When the request has been processed, user-space must return the
  112. * dm_ulog_request to the kernel - setting the 'error' field and
  113. * 'data_size' appropriately.
  114. */
  115. #define DM_ULOG_POSTSUSPEND 4
  116. /*
  117. * DM_ULOG_RESUME corresponds to (found in dm-dirty-log.h):
  118. * int (*resume)(struct dm_dirty_log *log);
  119. *
  120. * Payload-to-userspace:
  121. * None.
  122. * Payload-to-kernel:
  123. * None.
  124. *
  125. * The UUID contained in the dm_ulog_request structure is all that is
  126. * necessary to identify the log instance being resumed. There is no
  127. * payload data.
  128. *
  129. * When the request has been processed, user-space must return the
  130. * dm_ulog_request to the kernel - setting the 'error' field and
  131. * 'data_size' appropriately.
  132. */
  133. #define DM_ULOG_RESUME 5
  134. /*
  135. * DM_ULOG_GET_REGION_SIZE corresponds to (found in dm-dirty-log.h):
  136. * uint32_t (*get_region_size)(struct dm_dirty_log *log);
  137. *
  138. * Payload-to-userspace:
  139. * None.
  140. * Payload-to-kernel:
  141. * uint64_t - contains the region size
  142. *
  143. * The region size is something that was determined at constructor time.
  144. * It is returned in the payload area and 'data_size' is set to
  145. * reflect this.
  146. *
  147. * When the request has been processed, user-space must return the
  148. * dm_ulog_request to the kernel - setting the 'error' field appropriately.
  149. */
  150. #define DM_ULOG_GET_REGION_SIZE 6
  151. /*
  152. * DM_ULOG_IS_CLEAN corresponds to (found in dm-dirty-log.h):
  153. * int (*is_clean)(struct dm_dirty_log *log, region_t region);
  154. *
  155. * Payload-to-userspace:
  156. * uint64_t - the region to get clean status on
  157. * Payload-to-kernel:
  158. * int64_t - 1 if clean, 0 otherwise
  159. *
  160. * Payload is sizeof(uint64_t) and contains the region for which the clean
  161. * status is being made.
  162. *
  163. * When the request has been processed, user-space must return the
  164. * dm_ulog_request to the kernel - filling the payload with 0 (not clean) or
  165. * 1 (clean), setting 'data_size' and 'error' appropriately.
  166. */
  167. #define DM_ULOG_IS_CLEAN 7
  168. /*
  169. * DM_ULOG_IN_SYNC corresponds to (found in dm-dirty-log.h):
  170. * int (*in_sync)(struct dm_dirty_log *log, region_t region,
  171. * int can_block);
  172. *
  173. * Payload-to-userspace:
  174. * uint64_t - the region to get sync status on
  175. * Payload-to-kernel:
  176. * int64_t - 1 if in-sync, 0 otherwise
  177. *
  178. * Exactly the same as 'is_clean' above, except this time asking "has the
  179. * region been recovered?" vs. "is the region not being modified?"
  180. */
  181. #define DM_ULOG_IN_SYNC 8
  182. /*
  183. * DM_ULOG_FLUSH corresponds to (found in dm-dirty-log.h):
  184. * int (*flush)(struct dm_dirty_log *log);
  185. *
  186. * Payload-to-userspace:
  187. * None.
  188. * Payload-to-kernel:
  189. * None.
  190. *
  191. * No incoming or outgoing payload. Simply flush log state to disk.
  192. *
  193. * When the request has been processed, user-space must return the
  194. * dm_ulog_request to the kernel - setting the 'error' field and clearing
  195. * 'data_size' appropriately.
  196. */
  197. #define DM_ULOG_FLUSH 9
  198. /*
  199. * DM_ULOG_MARK_REGION corresponds to (found in dm-dirty-log.h):
  200. * void (*mark_region)(struct dm_dirty_log *log, region_t region);
  201. *
  202. * Payload-to-userspace:
  203. * uint64_t [] - region(s) to mark
  204. * Payload-to-kernel:
  205. * None.
  206. *
  207. * Incoming payload contains the one or more regions to mark dirty.
  208. * The number of regions contained in the payload can be determined from
  209. * 'data_size/sizeof(uint64_t)'.
  210. *
  211. * When the request has been processed, user-space must return the
  212. * dm_ulog_request to the kernel - setting the 'error' field and clearing
  213. * 'data_size' appropriately.
  214. */
  215. #define DM_ULOG_MARK_REGION 10
  216. /*
  217. * DM_ULOG_CLEAR_REGION corresponds to (found in dm-dirty-log.h):
  218. * void (*clear_region)(struct dm_dirty_log *log, region_t region);
  219. *
  220. * Payload-to-userspace:
  221. * uint64_t [] - region(s) to clear
  222. * Payload-to-kernel:
  223. * None.
  224. *
  225. * Incoming payload contains the one or more regions to mark clean.
  226. * The number of regions contained in the payload can be determined from
  227. * 'data_size/sizeof(uint64_t)'.
  228. *
  229. * When the request has been processed, user-space must return the
  230. * dm_ulog_request to the kernel - setting the 'error' field and clearing
  231. * 'data_size' appropriately.
  232. */
  233. #define DM_ULOG_CLEAR_REGION 11
  234. /*
  235. * DM_ULOG_GET_RESYNC_WORK corresponds to (found in dm-dirty-log.h):
  236. * int (*get_resync_work)(struct dm_dirty_log *log, region_t *region);
  237. *
  238. * Payload-to-userspace:
  239. * None.
  240. * Payload-to-kernel:
  241. * {
  242. * int64_t i; -- 1 if recovery necessary, 0 otherwise
  243. * uint64_t r; -- The region to recover if i=1
  244. * }
  245. * 'data_size' should be set appropriately.
  246. *
  247. * When the request has been processed, user-space must return the
  248. * dm_ulog_request to the kernel - setting the 'error' field appropriately.
  249. */
  250. #define DM_ULOG_GET_RESYNC_WORK 12
  251. /*
  252. * DM_ULOG_SET_REGION_SYNC corresponds to (found in dm-dirty-log.h):
  253. * void (*set_region_sync)(struct dm_dirty_log *log,
  254. * region_t region, int in_sync);
  255. *
  256. * Payload-to-userspace:
  257. * {
  258. * uint64_t - region to set sync state on
  259. * int64_t - 0 if not-in-sync, 1 if in-sync
  260. * }
  261. * Payload-to-kernel:
  262. * None.
  263. *
  264. * When the request has been processed, user-space must return the
  265. * dm_ulog_request to the kernel - setting the 'error' field and clearing
  266. * 'data_size' appropriately.
  267. */
  268. #define DM_ULOG_SET_REGION_SYNC 13
  269. /*
  270. * DM_ULOG_GET_SYNC_COUNT corresponds to (found in dm-dirty-log.h):
  271. * region_t (*get_sync_count)(struct dm_dirty_log *log);
  272. *
  273. * Payload-to-userspace:
  274. * None.
  275. * Payload-to-kernel:
  276. * uint64_t - the number of in-sync regions
  277. *
  278. * No incoming payload. Kernel-bound payload contains the number of
  279. * regions that are in-sync (in a size_t).
  280. *
  281. * When the request has been processed, user-space must return the
  282. * dm_ulog_request to the kernel - setting the 'error' field and
  283. * 'data_size' appropriately.
  284. */
  285. #define DM_ULOG_GET_SYNC_COUNT 14
  286. /*
  287. * DM_ULOG_STATUS_INFO corresponds to (found in dm-dirty-log.h):
  288. * int (*status)(struct dm_dirty_log *log, STATUSTYPE_INFO,
  289. * char *result, unsigned maxlen);
  290. *
  291. * Payload-to-userspace:
  292. * None.
  293. * Payload-to-kernel:
  294. * Character string containing STATUSTYPE_INFO
  295. *
  296. * When the request has been processed, user-space must return the
  297. * dm_ulog_request to the kernel - setting the 'error' field and
  298. * 'data_size' appropriately.
  299. */
  300. #define DM_ULOG_STATUS_INFO 15
  301. /*
  302. * DM_ULOG_STATUS_TABLE corresponds to (found in dm-dirty-log.h):
  303. * int (*status)(struct dm_dirty_log *log, STATUSTYPE_TABLE,
  304. * char *result, unsigned maxlen);
  305. *
  306. * Payload-to-userspace:
  307. * None.
  308. * Payload-to-kernel:
  309. * Character string containing STATUSTYPE_TABLE
  310. *
  311. * When the request has been processed, user-space must return the
  312. * dm_ulog_request to the kernel - setting the 'error' field and
  313. * 'data_size' appropriately.
  314. */
  315. #define DM_ULOG_STATUS_TABLE 16
  316. /*
  317. * DM_ULOG_IS_REMOTE_RECOVERING corresponds to (found in dm-dirty-log.h):
  318. * int (*is_remote_recovering)(struct dm_dirty_log *log, region_t region);
  319. *
  320. * Payload-to-userspace:
  321. * uint64_t - region to determine recovery status on
  322. * Payload-to-kernel:
  323. * {
  324. * int64_t is_recovering; -- 0 if no, 1 if yes
  325. * uint64_t in_sync_hint; -- lowest region still needing resync
  326. * }
  327. *
  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.
  331. */
  332. #define DM_ULOG_IS_REMOTE_RECOVERING 17
  333. /*
  334. * (DM_ULOG_REQUEST_MASK & request_type) to get the request type
  335. *
  336. * Payload-to-userspace:
  337. * A single string containing all the argv arguments separated by ' 's
  338. * Payload-to-kernel:
  339. * None. ('data_size' in the dm_ulog_request struct should be 0.)
  340. *
  341. * We are reserving 8 bits of the 32-bit 'request_type' field for the
  342. * various request types above. The remaining 24-bits are currently
  343. * set to zero and are reserved for future use and compatibility concerns.
  344. *
  345. * User-space should always use DM_ULOG_REQUEST_TYPE to acquire the
  346. * request type from the 'request_type' field to maintain forward compatibility.
  347. */
  348. #define DM_ULOG_REQUEST_MASK 0xFF
  349. #define DM_ULOG_REQUEST_TYPE(request_type) \
  350. (DM_ULOG_REQUEST_MASK & (request_type))
  351. /*
  352. * DM_ULOG_REQUEST_VERSION is incremented when there is a
  353. * change to the way information is passed between kernel
  354. * and userspace. This could be a structure change of
  355. * dm_ulog_request or a change in the way requests are
  356. * issued/handled. Changes are outlined here:
  357. * version 1: Initial implementation
  358. */
  359. #define DM_ULOG_REQUEST_VERSION 1
  360. struct dm_ulog_request {
  361. /*
  362. * The local unique identifier (luid) and the universally unique
  363. * identifier (uuid) are used to tie a request to a specific
  364. * mirror log. A single machine log could probably make due with
  365. * just the 'luid', but a cluster-aware log must use the 'uuid' and
  366. * the 'luid'. The uuid is what is required for node to node
  367. * communication concerning a particular log, but the 'luid' helps
  368. * differentiate between logs that are being swapped and have the
  369. * same 'uuid'. (Think "live" and "inactive" device-mapper tables.)
  370. */
  371. uint64_t luid;
  372. char uuid[DM_UUID_LEN];
  373. char padding[3]; /* Padding because DM_UUID_LEN = 129 */
  374. uint32_t version; /* See DM_ULOG_REQUEST_VERSION */
  375. int32_t error; /* Used to report back processing errors */
  376. uint32_t seq; /* Sequence number for request */
  377. uint32_t request_type; /* DM_ULOG_* defined above */
  378. uint32_t data_size; /* How much data (not including this struct) */
  379. char data[0];
  380. };
  381. #endif /* __DM_LOG_USERSPACE_H__ */