stackglue.h 8.1 KB

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