stackglue.h 8.8 KB

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