stackglue.h 7.4 KB

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