stackglue.h 9.1 KB

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