drbd_genl.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. * General overview:
  3. * full generic netlink message:
  4. * |nlmsghdr|genlmsghdr|<payload>
  5. *
  6. * payload:
  7. * |optional fixed size family header|<sequence of netlink attributes>
  8. *
  9. * sequence of netlink attributes:
  10. * I chose to have all "top level" attributes NLA_NESTED,
  11. * corresponding to some real struct.
  12. * So we have a sequence of |tla, len|<nested nla sequence>
  13. *
  14. * nested nla sequence:
  15. * may be empty, or contain a sequence of netlink attributes
  16. * representing the struct fields.
  17. *
  18. * The tag number of any field (regardless of containing struct)
  19. * will be available as T_ ## field_name,
  20. * so you cannot have the same field name in two differnt structs.
  21. *
  22. * The tag numbers themselves are per struct, though,
  23. * so should always begin at 1 (not 0, that is the special "NLA_UNSPEC" type,
  24. * which we won't use here).
  25. * The tag numbers are used as index in the respective nla_policy array.
  26. *
  27. * GENL_struct(tag_name, tag_number, struct name, struct fields) - struct and policy
  28. * genl_magic_struct.h
  29. * generates the struct declaration,
  30. * generates an entry in the tla enum,
  31. * genl_magic_func.h
  32. * generates an entry in the static tla policy
  33. * with .type = NLA_NESTED
  34. * generates the static <struct_name>_nl_policy definition,
  35. * and static conversion functions
  36. *
  37. * genl_magic_func.h
  38. *
  39. * GENL_mc_group(group)
  40. * genl_magic_struct.h
  41. * does nothing
  42. * genl_magic_func.h
  43. * defines and registers the mcast group,
  44. * and provides a send helper
  45. *
  46. * GENL_notification(op_name, op_num, mcast_group, tla list)
  47. * These are notifications to userspace.
  48. *
  49. * genl_magic_struct.h
  50. * generates an entry in the genl_ops enum,
  51. * genl_magic_func.h
  52. * does nothing
  53. *
  54. * mcast group: the name of the mcast group this notification should be
  55. * expected on
  56. * tla list: the list of expected top level attributes,
  57. * for documentation and sanity checking.
  58. *
  59. * GENL_op(op_name, op_num, flags and handler, tla list) - "genl operations"
  60. * These are requests from userspace.
  61. *
  62. * _op and _notification share the same "number space",
  63. * op_nr will be assigned to "genlmsghdr->cmd"
  64. *
  65. * genl_magic_struct.h
  66. * generates an entry in the genl_ops enum,
  67. * genl_magic_func.h
  68. * generates an entry in the static genl_ops array,
  69. * and static register/unregister functions to
  70. * genl_register_family_with_ops().
  71. *
  72. * flags and handler:
  73. * GENL_op_init( .doit = x, .dumpit = y, .flags = something)
  74. * GENL_doit(x) => .dumpit = NULL, .flags = GENL_ADMIN_PERM
  75. * tla list: the list of expected top level attributes,
  76. * for documentation and sanity checking.
  77. */
  78. /*
  79. * STRUCTS
  80. */
  81. /* this is sent kernel -> userland on various error conditions, and contains
  82. * informational textual info, which is supposedly human readable.
  83. * The computer relevant return code is in the drbd_genlmsghdr.
  84. */
  85. GENL_struct(DRBD_NLA_CFG_REPLY, 1, drbd_cfg_reply,
  86. /* "arbitrary" size strings, nla_policy.len = 0 */
  87. __str_field(1, GENLA_F_MANDATORY, info_text, 0)
  88. )
  89. /* Configuration requests typically need a context to operate on.
  90. * Possible keys are device minor (fits in the drbd_genlmsghdr),
  91. * the replication link (aka connection) name,
  92. * and/or the replication group (aka resource) name,
  93. * and the volume id within the resource. */
  94. GENL_struct(DRBD_NLA_CFG_CONTEXT, 2, drbd_cfg_context,
  95. /* currently only 256 volumes per group,
  96. * but maybe we still change that */
  97. __u32_field(1, GENLA_F_MANDATORY, ctx_volume)
  98. __str_field(2, GENLA_F_MANDATORY, ctx_conn_name, 128)
  99. )
  100. GENL_struct(DRBD_NLA_DISK_CONF, 3, disk_conf,
  101. __u64_field(1, GENLA_F_MANDATORY, disk_size)
  102. __str_field(2, GENLA_F_REQUIRED, backing_dev, 128)
  103. __str_field(3, GENLA_F_REQUIRED, meta_dev, 128)
  104. __u32_field(4, GENLA_F_REQUIRED, meta_dev_idx)
  105. __u32_field(5, GENLA_F_MANDATORY, max_bio_bvecs)
  106. __u32_field(6, GENLA_F_MANDATORY, on_io_error)
  107. __u32_field(7, GENLA_F_MANDATORY, fencing)
  108. __flg_field(8, GENLA_F_MANDATORY, no_disk_barrier)
  109. __flg_field(9, GENLA_F_MANDATORY, no_disk_flush)
  110. __flg_field(10, GENLA_F_MANDATORY, no_disk_drain)
  111. __flg_field(11, GENLA_F_MANDATORY, no_md_flush)
  112. __flg_field(12, GENLA_F_MANDATORY, use_bmbv)
  113. )
  114. GENL_struct(DRBD_NLA_SYNCER_CONF, 4, syncer_conf,
  115. __u32_field(1, GENLA_F_MANDATORY, rate)
  116. __u32_field(2, GENLA_F_MANDATORY, after)
  117. __u32_field(3, GENLA_F_MANDATORY, al_extents)
  118. __str_field(4, GENLA_F_MANDATORY, cpu_mask, 32)
  119. __str_field(5, GENLA_F_MANDATORY, verify_alg, SHARED_SECRET_MAX)
  120. __str_field(6, GENLA_F_MANDATORY, csums_alg, SHARED_SECRET_MAX)
  121. __flg_field(7, GENLA_F_MANDATORY, use_rle)
  122. __u32_field(8, GENLA_F_MANDATORY, on_no_data)
  123. __u32_field(9, GENLA_F_MANDATORY, c_plan_ahead)
  124. __u32_field(10, GENLA_F_MANDATORY, c_delay_target)
  125. __u32_field(11, GENLA_F_MANDATORY, c_fill_target)
  126. __u32_field(12, GENLA_F_MANDATORY, c_max_rate)
  127. __u32_field(13, GENLA_F_MANDATORY, c_min_rate)
  128. )
  129. GENL_struct(DRBD_NLA_NET_CONF, 5, net_conf,
  130. __str_field(1, GENLA_F_MANDATORY | GENLA_F_SENSITIVE,
  131. shared_secret, SHARED_SECRET_MAX)
  132. __str_field(2, GENLA_F_MANDATORY, cram_hmac_alg, SHARED_SECRET_MAX)
  133. __str_field(3, GENLA_F_MANDATORY, integrity_alg, SHARED_SECRET_MAX)
  134. __str_field(4, GENLA_F_REQUIRED, my_addr, 128)
  135. __str_field(5, GENLA_F_REQUIRED, peer_addr, 128)
  136. __u32_field(6, GENLA_F_REQUIRED, wire_protocol)
  137. __u32_field(7, GENLA_F_MANDATORY, try_connect_int)
  138. __u32_field(8, GENLA_F_MANDATORY, timeout)
  139. __u32_field(9, GENLA_F_MANDATORY, ping_int)
  140. __u32_field(10, GENLA_F_MANDATORY, ping_timeo)
  141. __u32_field(11, GENLA_F_MANDATORY, sndbuf_size)
  142. __u32_field(12, GENLA_F_MANDATORY, rcvbuf_size)
  143. __u32_field(13, GENLA_F_MANDATORY, ko_count)
  144. __u32_field(14, GENLA_F_MANDATORY, max_buffers)
  145. __u32_field(15, GENLA_F_MANDATORY, max_epoch_size)
  146. __u32_field(16, GENLA_F_MANDATORY, unplug_watermark)
  147. __u32_field(17, GENLA_F_MANDATORY, after_sb_0p)
  148. __u32_field(18, GENLA_F_MANDATORY, after_sb_1p)
  149. __u32_field(19, GENLA_F_MANDATORY, after_sb_2p)
  150. __u32_field(20, GENLA_F_MANDATORY, rr_conflict)
  151. __u32_field(21, GENLA_F_MANDATORY, on_congestion)
  152. __u32_field(22, GENLA_F_MANDATORY, cong_fill)
  153. __u32_field(23, GENLA_F_MANDATORY, cong_extents)
  154. __flg_field(24, GENLA_F_MANDATORY, two_primaries)
  155. __flg_field(25, GENLA_F_MANDATORY, want_lose)
  156. __flg_field(26, GENLA_F_MANDATORY, no_cork)
  157. __flg_field(27, GENLA_F_MANDATORY, always_asbp)
  158. __flg_field(28, GENLA_F_MANDATORY, dry_run)
  159. )
  160. GENL_struct(DRBD_NLA_SET_ROLE_PARMS, 6, set_role_parms,
  161. __flg_field(1, GENLA_F_MANDATORY, assume_uptodate)
  162. )
  163. GENL_struct(DRBD_NLA_RESIZE_PARMS, 7, resize_parms,
  164. __u64_field(1, GENLA_F_MANDATORY, resize_size)
  165. __flg_field(2, GENLA_F_MANDATORY, resize_force)
  166. __flg_field(3, GENLA_F_MANDATORY, no_resync)
  167. )
  168. GENL_struct(DRBD_NLA_STATE_INFO, 8, state_info,
  169. /* the reason of the broadcast,
  170. * if this is an event triggered broadcast. */
  171. __u32_field(1, GENLA_F_MANDATORY, sib_reason)
  172. __u32_field(2, GENLA_F_REQUIRED, current_state)
  173. __u64_field(3, GENLA_F_MANDATORY, capacity)
  174. __u64_field(4, GENLA_F_MANDATORY, ed_uuid)
  175. /* These are for broadcast from after state change work.
  176. * prev_state and new_state are from the moment the state change took
  177. * place, new_state is not neccessarily the same as current_state,
  178. * there may have been more state changes since. Which will be
  179. * broadcasted soon, in their respective after state change work. */
  180. __u32_field(5, GENLA_F_MANDATORY, prev_state)
  181. __u32_field(6, GENLA_F_MANDATORY, new_state)
  182. /* if we have a local disk: */
  183. __bin_field(7, GENLA_F_MANDATORY, uuids, (UI_SIZE*sizeof(__u64)))
  184. __u32_field(8, GENLA_F_MANDATORY, disk_flags)
  185. __u64_field(9, GENLA_F_MANDATORY, bits_total)
  186. __u64_field(10, GENLA_F_MANDATORY, bits_oos)
  187. /* and in case resync or online verify is active */
  188. __u64_field(11, GENLA_F_MANDATORY, bits_rs_total)
  189. __u64_field(12, GENLA_F_MANDATORY, bits_rs_failed)
  190. /* for pre and post notifications of helper execution */
  191. __str_field(13, GENLA_F_MANDATORY, helper, 32)
  192. __u32_field(14, GENLA_F_MANDATORY, helper_exit_code)
  193. )
  194. GENL_struct(DRBD_NLA_START_OV_PARMS, 9, start_ov_parms,
  195. __u64_field(1, GENLA_F_MANDATORY, ov_start_sector)
  196. )
  197. GENL_struct(DRBD_NLA_NEW_C_UUID_PARMS, 10, new_c_uuid_parms,
  198. __flg_field(1, GENLA_F_MANDATORY, clear_bm)
  199. )
  200. GENL_struct(DRBD_NLA_TIMEOUT_PARMS, 11, timeout_parms,
  201. __u32_field(1, GENLA_F_REQUIRED, timeout_type)
  202. )
  203. GENL_struct(DRBD_NLA_DISCONNECT_PARMS, 12, disconnect_parms,
  204. __flg_field(1, GENLA_F_MANDATORY, force_disconnect)
  205. )
  206. /*
  207. * Notifications and commands (genlmsghdr->cmd)
  208. */
  209. GENL_mc_group(events)
  210. /* kernel -> userspace announcement of changes */
  211. GENL_notification(
  212. DRBD_EVENT, 1, events,
  213. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED)
  214. GENL_tla_expected(DRBD_NLA_STATE_INFO, GENLA_F_REQUIRED)
  215. GENL_tla_expected(DRBD_NLA_NET_CONF, GENLA_F_MANDATORY)
  216. GENL_tla_expected(DRBD_NLA_DISK_CONF, GENLA_F_MANDATORY)
  217. GENL_tla_expected(DRBD_NLA_SYNCER_CONF, GENLA_F_MANDATORY)
  218. )
  219. /* query kernel for specific or all info */
  220. GENL_op(
  221. DRBD_ADM_GET_STATUS, 2,
  222. GENL_op_init(
  223. .doit = drbd_adm_get_status,
  224. .dumpit = drbd_adm_get_status_all,
  225. /* anyone may ask for the status,
  226. * it is broadcasted anyways */
  227. ),
  228. /* To select the object .doit.
  229. * Or a subset of objects in .dumpit. */
  230. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_MANDATORY)
  231. )
  232. #if 0
  233. /* TO BE DONE */
  234. /* create or destroy resources, aka replication groups */
  235. GENL_op(DRBD_ADM_CREATE_RESOURCE, 3, GENL_doit(drbd_adm_create_resource),
  236. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  237. GENL_op(DRBD_ADM_DELETE_RESOURCE, 4, GENL_doit(drbd_adm_delete_resource),
  238. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  239. #endif
  240. /* add DRBD minor devices as volumes to resources */
  241. GENL_op(DRBD_ADM_ADD_MINOR, 5, GENL_doit(drbd_adm_add_minor),
  242. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  243. GENL_op(DRBD_ADM_DEL_MINOR, 6, GENL_doit(drbd_adm_delete_minor),
  244. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  245. /* add or delete replication links to resources */
  246. GENL_op(DRBD_ADM_ADD_LINK, 7, GENL_doit(drbd_adm_create_connection),
  247. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  248. GENL_op(DRBD_ADM_DEL_LINK, 8, GENL_doit(drbd_adm_delete_connection),
  249. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  250. /* operates on replication links */
  251. GENL_op(DRBD_ADM_SYNCER, 9,
  252. GENL_doit(drbd_adm_syncer),
  253. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED)
  254. GENL_tla_expected(DRBD_NLA_SYNCER_CONF, GENLA_F_MANDATORY)
  255. )
  256. GENL_op(
  257. DRBD_ADM_CONNECT, 10,
  258. GENL_doit(drbd_adm_connect),
  259. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED)
  260. GENL_tla_expected(DRBD_NLA_NET_CONF, GENLA_F_REQUIRED)
  261. )
  262. GENL_op(DRBD_ADM_DISCONNECT, 11, GENL_doit(drbd_adm_disconnect),
  263. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  264. /* operates on minors */
  265. GENL_op(DRBD_ADM_ATTACH, 12,
  266. GENL_doit(drbd_adm_attach),
  267. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED)
  268. GENL_tla_expected(DRBD_NLA_DISK_CONF, GENLA_F_REQUIRED)
  269. )
  270. GENL_op(
  271. DRBD_ADM_RESIZE, 13,
  272. GENL_doit(drbd_adm_resize),
  273. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED)
  274. GENL_tla_expected(DRBD_NLA_RESIZE_PARMS, GENLA_F_MANDATORY)
  275. )
  276. /* operates on all volumes within a resource */
  277. GENL_op(
  278. DRBD_ADM_PRIMARY, 14,
  279. GENL_doit(drbd_adm_set_role),
  280. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED)
  281. GENL_tla_expected(DRBD_NLA_SET_ROLE_PARMS, GENLA_F_REQUIRED)
  282. )
  283. GENL_op(
  284. DRBD_ADM_SECONDARY, 15,
  285. GENL_doit(drbd_adm_set_role),
  286. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED)
  287. GENL_tla_expected(DRBD_NLA_SET_ROLE_PARMS, GENLA_F_REQUIRED)
  288. )
  289. GENL_op(
  290. DRBD_ADM_NEW_C_UUID, 16,
  291. GENL_doit(drbd_adm_new_c_uuid),
  292. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED)
  293. GENL_tla_expected(DRBD_NLA_NEW_C_UUID_PARMS, GENLA_F_MANDATORY)
  294. )
  295. GENL_op(
  296. DRBD_ADM_START_OV, 17,
  297. GENL_doit(drbd_adm_start_ov),
  298. GENL_tla_expected(DRBD_NLA_START_OV_PARMS, GENLA_F_MANDATORY)
  299. )
  300. GENL_op(DRBD_ADM_DETACH, 18, GENL_doit(drbd_adm_detach),
  301. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  302. GENL_op(DRBD_ADM_INVALIDATE, 19, GENL_doit(drbd_adm_invalidate),
  303. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  304. GENL_op(DRBD_ADM_INVAL_PEER, 20, GENL_doit(drbd_adm_invalidate_peer),
  305. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  306. GENL_op(DRBD_ADM_PAUSE_SYNC, 21, GENL_doit(drbd_adm_pause_sync),
  307. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  308. GENL_op(DRBD_ADM_RESUME_SYNC, 22, GENL_doit(drbd_adm_resume_sync),
  309. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  310. GENL_op(DRBD_ADM_SUSPEND_IO, 23, GENL_doit(drbd_adm_suspend_io),
  311. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  312. GENL_op(DRBD_ADM_RESUME_IO, 24, GENL_doit(drbd_adm_resume_io),
  313. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  314. GENL_op(DRBD_ADM_OUTDATE, 25, GENL_doit(drbd_adm_outdate),
  315. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
  316. GENL_op(DRBD_ADM_GET_TIMEOUT_TYPE, 26, GENL_doit(drbd_adm_get_timeout_type),
  317. GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))