stackglue.h 8.9 KB

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