stackglue.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * stackglue.h
  4. *
  5. * Glue to the underlying cluster stack.
  6. *
  7. * Copyright (C) 2007 Oracle. All rights reserved.
  8. */
  9. #ifndef STACKGLUE_H
  10. #define STACKGLUE_H
  11. #include <linux/types.h>
  12. #include <linux/list.h>
  13. #include <linux/dlmconstants.h>
  14. #include "dlm/dlmapi.h"
  15. #include <linux/dlm.h>
  16. /* Needed for plock-related prototypes */
  17. struct file;
  18. struct file_lock;
  19. /*
  20. * dlmconstants.h does not have a LOCAL flag. We hope to remove it
  21. * some day, but right now we need it. Let's fake it. This value is larger
  22. * than any flag in dlmconstants.h.
  23. */
  24. #define DLM_LKF_LOCAL 0x00100000
  25. /*
  26. * This shadows DLM_LOCKSPACE_LEN in fs/dlm/dlm_internal.h. That probably
  27. * wants to be in a public header.
  28. */
  29. #define GROUP_NAME_MAX 64
  30. /* This shadows OCFS2_CLUSTER_NAME_LEN */
  31. #define CLUSTER_NAME_MAX 16
  32. /*
  33. * ocfs2_protocol_version changes when ocfs2 does something different in
  34. * its inter-node behavior. See dlmglue.c for more information.
  35. */
  36. struct ocfs2_protocol_version {
  37. u8 pv_major;
  38. u8 pv_minor;
  39. };
  40. /*
  41. * The dlm_lockstatus struct includes lvb space, but the dlm_lksb struct only
  42. * has a pointer to separately allocated lvb space. This struct exists only to
  43. * include in the lksb union to make space for a combined dlm_lksb and lvb.
  44. */
  45. struct fsdlm_lksb_plus_lvb {
  46. struct dlm_lksb lksb;
  47. char lvb[DLM_LVB_LEN];
  48. };
  49. /*
  50. * A union of all lock status structures. We define it here so that the
  51. * size of the union is known. Lock status structures are embedded in
  52. * ocfs2 inodes.
  53. */
  54. struct ocfs2_cluster_connection;
  55. struct ocfs2_dlm_lksb {
  56. union {
  57. struct dlm_lockstatus lksb_o2dlm;
  58. struct dlm_lksb lksb_fsdlm;
  59. struct fsdlm_lksb_plus_lvb padding;
  60. };
  61. struct ocfs2_cluster_connection *lksb_conn;
  62. };
  63. /*
  64. * The ocfs2_locking_protocol defines the handlers called on ocfs2's behalf.
  65. */
  66. struct ocfs2_locking_protocol {
  67. struct ocfs2_protocol_version lp_max_version;
  68. void (*lp_lock_ast)(struct ocfs2_dlm_lksb *lksb);
  69. void (*lp_blocking_ast)(struct ocfs2_dlm_lksb *lksb, int level);
  70. void (*lp_unlock_ast)(struct ocfs2_dlm_lksb *lksb, int error);
  71. };
  72. /*
  73. * A cluster connection. Mostly opaque to ocfs2, the connection holds
  74. * state for the underlying stack. ocfs2 does use cc_version to determine
  75. * locking compatibility.
  76. */
  77. struct ocfs2_cluster_connection {
  78. char cc_name[GROUP_NAME_MAX + 1];
  79. int cc_namelen;
  80. char cc_cluster_name[CLUSTER_NAME_MAX + 1];
  81. int cc_cluster_name_len;
  82. struct ocfs2_protocol_version cc_version;
  83. struct ocfs2_locking_protocol *cc_proto;
  84. void (*cc_recovery_handler)(int node_num, void *recovery_data);
  85. void *cc_recovery_data;
  86. void *cc_lockspace;
  87. void *cc_private;
  88. };
  89. /*
  90. * Each cluster stack implements the stack operations structure. Not used
  91. * in the ocfs2 code, the stackglue code translates generic cluster calls
  92. * into stack operations.
  93. */
  94. struct ocfs2_stack_operations {
  95. /*
  96. * The fs code calls ocfs2_cluster_connect() to attach a new
  97. * filesystem to the cluster stack. The ->connect() op is passed
  98. * an ocfs2_cluster_connection with the name and recovery field
  99. * filled in.
  100. *
  101. * The stack must set up any notification mechanisms and create
  102. * the filesystem lockspace in the DLM. The lockspace should be
  103. * stored on cc_lockspace. Any other information can be stored on
  104. * cc_private.
  105. *
  106. * ->connect() must not return until it is guaranteed that
  107. *
  108. * - Node down notifications for the filesystem will be received
  109. * and passed to conn->cc_recovery_handler().
  110. * - Locking requests for the filesystem will be processed.
  111. */
  112. int (*connect)(struct ocfs2_cluster_connection *conn);
  113. /*
  114. * The fs code calls ocfs2_cluster_disconnect() when a filesystem
  115. * no longer needs cluster services. All DLM locks have been
  116. * dropped, and recovery notification is being ignored by the
  117. * fs code. The stack must disengage from the DLM and discontinue
  118. * recovery notification.
  119. *
  120. * Once ->disconnect() has returned, the connection structure will
  121. * be freed. Thus, a stack must not return from ->disconnect()
  122. * until it will no longer reference the conn pointer.
  123. *
  124. * Once this call returns, the stack glue will be dropping this
  125. * connection's reference on the module.
  126. */
  127. int (*disconnect)(struct ocfs2_cluster_connection *conn);
  128. /*
  129. * ->this_node() returns the cluster's unique identifier for the
  130. * local node.
  131. */
  132. int (*this_node)(struct ocfs2_cluster_connection *conn,
  133. unsigned int *node);
  134. /*
  135. * Call the underlying dlm lock function. The ->dlm_lock()
  136. * callback should convert the flags and mode as appropriate.
  137. *
  138. * ast and bast functions are not part of the call because the
  139. * stack will likely want to wrap ast and bast calls before passing
  140. * them to stack->sp_proto. There is no astarg. The lksb will
  141. * be passed back to the ast and bast functions. The caller can
  142. * use this to find their object.
  143. */
  144. int (*dlm_lock)(struct ocfs2_cluster_connection *conn,
  145. int mode,
  146. struct ocfs2_dlm_lksb *lksb,
  147. u32 flags,
  148. void *name,
  149. unsigned int namelen);
  150. /*
  151. * Call the underlying dlm unlock function. The ->dlm_unlock()
  152. * function should convert the flags as appropriate.
  153. *
  154. * The unlock ast is not passed, as the stack will want to wrap
  155. * it before calling stack->sp_proto->lp_unlock_ast(). There is
  156. * no astarg. The lksb will be passed back to the unlock ast
  157. * function. The caller can use this to find their object.
  158. */
  159. int (*dlm_unlock)(struct ocfs2_cluster_connection *conn,
  160. struct ocfs2_dlm_lksb *lksb,
  161. u32 flags);
  162. /*
  163. * Return the status of the current lock status block. The fs
  164. * code should never dereference the union. The ->lock_status()
  165. * callback pulls out the stack-specific lksb, converts the status
  166. * to a proper errno, and returns it.
  167. */
  168. int (*lock_status)(struct ocfs2_dlm_lksb *lksb);
  169. /*
  170. * Return non-zero if the LVB is valid.
  171. */
  172. int (*lvb_valid)(struct ocfs2_dlm_lksb *lksb);
  173. /*
  174. * Pull the lvb pointer off of the stack-specific lksb.
  175. */
  176. void *(*lock_lvb)(struct ocfs2_dlm_lksb *lksb);
  177. /*
  178. * Cluster-aware posix locks
  179. *
  180. * This is NULL for stacks which do not support posix locks.
  181. */
  182. int (*plock)(struct ocfs2_cluster_connection *conn,
  183. u64 ino,
  184. struct file *file,
  185. int cmd,
  186. struct file_lock *fl);
  187. /*
  188. * This is an optional debugging hook. If provided, the
  189. * stack can dump debugging information about this lock.
  190. */
  191. void (*dump_lksb)(struct ocfs2_dlm_lksb *lksb);
  192. };
  193. /*
  194. * Each stack plugin must describe itself by registering a
  195. * ocfs2_stack_plugin structure. This is only seen by stackglue and the
  196. * stack driver.
  197. */
  198. struct ocfs2_stack_plugin {
  199. char *sp_name;
  200. const struct ocfs2_stack_operations *sp_ops;
  201. struct module *sp_owner;
  202. /* These are managed by the stackglue code. */
  203. struct list_head sp_list;
  204. unsigned int sp_count;
  205. struct ocfs2_protocol_version sp_max_proto;
  206. };
  207. /* Used by the filesystem */
  208. int ocfs2_cluster_connect(const char *stack_name,
  209. const char *cluster_name,
  210. int cluster_name_len,
  211. const char *group,
  212. int grouplen,
  213. struct ocfs2_locking_protocol *lproto,
  214. void (*recovery_handler)(int node_num,
  215. void *recovery_data),
  216. void *recovery_data,
  217. struct ocfs2_cluster_connection **conn);
  218. /*
  219. * Used by callers that don't store their stack name. They must ensure
  220. * all nodes have the same stack.
  221. */
  222. int ocfs2_cluster_connect_agnostic(const char *group,
  223. int grouplen,
  224. struct ocfs2_locking_protocol *lproto,
  225. void (*recovery_handler)(int node_num,
  226. void *recovery_data),
  227. void *recovery_data,
  228. struct ocfs2_cluster_connection **conn);
  229. int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn,
  230. int hangup_pending);
  231. void ocfs2_cluster_hangup(const char *group, int grouplen);
  232. int ocfs2_cluster_this_node(struct ocfs2_cluster_connection *conn,
  233. unsigned int *node);
  234. struct ocfs2_lock_res;
  235. int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn,
  236. int mode,
  237. struct ocfs2_dlm_lksb *lksb,
  238. u32 flags,
  239. void *name,
  240. unsigned int namelen);
  241. int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn,
  242. struct ocfs2_dlm_lksb *lksb,
  243. u32 flags);
  244. int ocfs2_dlm_lock_status(struct ocfs2_dlm_lksb *lksb);
  245. int ocfs2_dlm_lvb_valid(struct ocfs2_dlm_lksb *lksb);
  246. void *ocfs2_dlm_lvb(struct ocfs2_dlm_lksb *lksb);
  247. void ocfs2_dlm_dump_lksb(struct ocfs2_dlm_lksb *lksb);
  248. int ocfs2_stack_supports_plocks(void);
  249. int ocfs2_plock(struct ocfs2_cluster_connection *conn, u64 ino,
  250. struct file *file, int cmd, struct file_lock *fl);
  251. void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_proto);
  252. /* Used by stack plugins */
  253. int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin);
  254. void ocfs2_stack_glue_unregister(struct ocfs2_stack_plugin *plugin);
  255. extern struct kset *ocfs2_kset;
  256. #endif /* STACKGLUE_H */