stackglue.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. /*
  27. * dlmconstants.h does not have a LOCAL flag. We hope to remove it
  28. * some day, but right now we need it. Let's fake it. This value is larger
  29. * than any flag in dlmconstants.h.
  30. */
  31. #define DLM_LKF_LOCAL 0x00100000
  32. /*
  33. * This shadows DLM_LOCKSPACE_LEN in fs/dlm/dlm_internal.h. That probably
  34. * wants to be in a public header.
  35. */
  36. #define GROUP_NAME_MAX 64
  37. /*
  38. * ocfs2_protocol_version changes when ocfs2 does something different in
  39. * its inter-node behavior. See dlmglue.c for more information.
  40. */
  41. struct ocfs2_protocol_version {
  42. u8 pv_major;
  43. u8 pv_minor;
  44. };
  45. /*
  46. * The ocfs2_locking_protocol defines the handlers called on ocfs2's behalf.
  47. */
  48. struct ocfs2_locking_protocol {
  49. struct ocfs2_protocol_version lp_max_version;
  50. void (*lp_lock_ast)(void *astarg);
  51. void (*lp_blocking_ast)(void *astarg, int level);
  52. void (*lp_unlock_ast)(void *astarg, int error);
  53. };
  54. /*
  55. * The dlm_lockstatus struct includes lvb space, but the dlm_lksb struct only
  56. * has a pointer to separately allocated lvb space. This struct exists only to
  57. * include in the lksb union to make space for a combined dlm_lksb and lvb.
  58. */
  59. struct fsdlm_lksb_plus_lvb {
  60. struct dlm_lksb lksb;
  61. char lvb[DLM_LVB_LEN];
  62. };
  63. /*
  64. * A union of all lock status structures. We define it here so that the
  65. * size of the union is known. Lock status structures are embedded in
  66. * ocfs2 inodes.
  67. */
  68. union ocfs2_dlm_lksb {
  69. struct dlm_lockstatus lksb_o2dlm;
  70. struct dlm_lksb lksb_fsdlm;
  71. struct fsdlm_lksb_plus_lvb padding;
  72. };
  73. /*
  74. * A cluster connection. Mostly opaque to ocfs2, the connection holds
  75. * state for the underlying stack. ocfs2 does use cc_version to determine
  76. * locking compatibility.
  77. */
  78. struct ocfs2_cluster_connection {
  79. char cc_name[GROUP_NAME_MAX];
  80. int cc_namelen;
  81. struct ocfs2_protocol_version cc_version;
  82. void (*cc_recovery_handler)(int node_num, void *recovery_data);
  83. void *cc_recovery_data;
  84. void *cc_lockspace;
  85. void *cc_private;
  86. };
  87. /*
  88. * Each cluster stack implements the stack operations structure. Not used
  89. * in the ocfs2 code, the stackglue code translates generic cluster calls
  90. * into stack operations.
  91. */
  92. struct ocfs2_stack_operations {
  93. /*
  94. * The fs code calls ocfs2_cluster_connect() to attach a new
  95. * filesystem to the cluster stack. The ->connect() op is passed
  96. * an ocfs2_cluster_connection with the name and recovery field
  97. * filled in.
  98. *
  99. * The stack must set up any notification mechanisms and create
  100. * the filesystem lockspace in the DLM. The lockspace should be
  101. * stored on cc_lockspace. Any other information can be stored on
  102. * cc_private.
  103. *
  104. * ->connect() must not return until it is guaranteed that
  105. *
  106. * - Node down notifications for the filesystem will be recieved
  107. * and passed to conn->cc_recovery_handler().
  108. * - Locking requests for the filesystem will be processed.
  109. */
  110. int (*connect)(struct ocfs2_cluster_connection *conn);
  111. /*
  112. * The fs code calls ocfs2_cluster_disconnect() when a filesystem
  113. * no longer needs cluster services. All DLM locks have been
  114. * dropped, and recovery notification is being ignored by the
  115. * fs code. The stack must disengage from the DLM and discontinue
  116. * recovery notification.
  117. *
  118. * Once ->disconnect() has returned, the connection structure will
  119. * be freed. Thus, a stack must not return from ->disconnect()
  120. * until it will no longer reference the conn pointer.
  121. *
  122. * If hangup_pending is zero, ocfs2_cluster_disconnect() will also
  123. * be dropping the reference on the module.
  124. */
  125. int (*disconnect)(struct ocfs2_cluster_connection *conn,
  126. int hangup_pending);
  127. /*
  128. * ocfs2_cluster_hangup() exists for compatibility with older
  129. * ocfs2 tools. Only the classic stack really needs it. As such
  130. * ->hangup() is not required of all stacks. See the comment by
  131. * ocfs2_cluster_hangup() for more details.
  132. *
  133. * Note that ocfs2_cluster_hangup() can only be called if
  134. * hangup_pending was passed to ocfs2_cluster_disconnect().
  135. */
  136. void (*hangup)(const char *group, int grouplen);
  137. /*
  138. * ->this_node() returns the cluster's unique identifier for the
  139. * local node.
  140. */
  141. int (*this_node)(unsigned int *node);
  142. /*
  143. * Call the underlying dlm lock function. The ->dlm_lock()
  144. * callback should convert the flags and mode as appropriate.
  145. *
  146. * ast and bast functions are not part of the call because the
  147. * stack will likely want to wrap ast and bast calls before passing
  148. * them to stack->sp_proto.
  149. */
  150. int (*dlm_lock)(struct ocfs2_cluster_connection *conn,
  151. int mode,
  152. union ocfs2_dlm_lksb *lksb,
  153. u32 flags,
  154. void *name,
  155. unsigned int namelen,
  156. void *astarg);
  157. /*
  158. * Call the underlying dlm unlock function. The ->dlm_unlock()
  159. * function should convert the flags as appropriate.
  160. *
  161. * The unlock ast is not passed, as the stack will want to wrap
  162. * it before calling stack->sp_proto->lp_unlock_ast().
  163. */
  164. int (*dlm_unlock)(struct ocfs2_cluster_connection *conn,
  165. union ocfs2_dlm_lksb *lksb,
  166. u32 flags,
  167. void *astarg);
  168. /*
  169. * Return the status of the current lock status block. The fs
  170. * code should never dereference the union. The ->lock_status()
  171. * callback pulls out the stack-specific lksb, converts the status
  172. * to a proper errno, and returns it.
  173. */
  174. int (*lock_status)(union ocfs2_dlm_lksb *lksb);
  175. /*
  176. * Pull the lvb pointer off of the stack-specific lksb.
  177. */
  178. void *(*lock_lvb)(union ocfs2_dlm_lksb *lksb);
  179. /*
  180. * This is an optoinal debugging hook. If provided, the
  181. * stack can dump debugging information about this lock.
  182. */
  183. void (*dump_lksb)(union ocfs2_dlm_lksb *lksb);
  184. };
  185. /*
  186. * Each stack plugin must describe itself by registering a
  187. * ocfs2_stack_plugin structure. This is only seen by stackglue and the
  188. * stack driver.
  189. */
  190. struct ocfs2_stack_plugin {
  191. char *sp_name;
  192. struct ocfs2_stack_operations *sp_ops;
  193. struct module *sp_owner;
  194. /* These are managed by the stackglue code. */
  195. struct list_head sp_list;
  196. unsigned int sp_count;
  197. struct ocfs2_locking_protocol *sp_proto;
  198. };
  199. /* Used by the filesystem */
  200. int ocfs2_cluster_connect(const char *stack_name,
  201. const char *group,
  202. int grouplen,
  203. void (*recovery_handler)(int node_num,
  204. void *recovery_data),
  205. void *recovery_data,
  206. struct ocfs2_cluster_connection **conn);
  207. int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn,
  208. int hangup_pending);
  209. void ocfs2_cluster_hangup(const char *group, int grouplen);
  210. int ocfs2_cluster_this_node(unsigned int *node);
  211. struct ocfs2_lock_res;
  212. int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn,
  213. int mode,
  214. union ocfs2_dlm_lksb *lksb,
  215. u32 flags,
  216. void *name,
  217. unsigned int namelen,
  218. struct ocfs2_lock_res *astarg);
  219. int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn,
  220. union ocfs2_dlm_lksb *lksb,
  221. u32 flags,
  222. struct ocfs2_lock_res *astarg);
  223. int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb);
  224. void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb);
  225. void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb);
  226. void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto);
  227. /* Used by stack plugins */
  228. int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin);
  229. void ocfs2_stack_glue_unregister(struct ocfs2_stack_plugin *plugin);
  230. #endif /* STACKGLUE_H */