lm_interface.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #ifndef __LM_INTERFACE_DOT_H__
  10. #define __LM_INTERFACE_DOT_H__
  11. /*
  12. * Opaque handles represent the lock module's lockspace structure, the lock
  13. * module's lock structures, and GFS's file system (superblock) structure.
  14. */
  15. typedef void lm_lockspace_t;
  16. typedef void lm_lock_t;
  17. struct gfs2_sbd;
  18. typedef void (*lm_callback_t) (struct gfs2_sbd *sdp, unsigned int type, void *data);
  19. /*
  20. * lm_mount() flags
  21. *
  22. * LM_MFLAG_SPECTATOR
  23. * GFS is asking to join the filesystem's lockspace, but it doesn't want to
  24. * modify the filesystem. The lock module shouldn't assign a journal to the FS
  25. * mount. It shouldn't send recovery callbacks to the FS mount. If the node
  26. * dies or withdraws, all locks can be wiped immediately.
  27. */
  28. #define LM_MFLAG_SPECTATOR 0x00000001
  29. /*
  30. * lm_lockstruct flags
  31. *
  32. * LM_LSFLAG_LOCAL
  33. * The lock_nolock module returns LM_LSFLAG_LOCAL to GFS, indicating that GFS
  34. * can make single-node optimizations.
  35. */
  36. #define LM_LSFLAG_LOCAL 0x00000001
  37. /*
  38. * lm_lockname types
  39. */
  40. #define LM_TYPE_RESERVED 0x00
  41. #define LM_TYPE_NONDISK 0x01
  42. #define LM_TYPE_INODE 0x02
  43. #define LM_TYPE_RGRP 0x03
  44. #define LM_TYPE_META 0x04
  45. #define LM_TYPE_IOPEN 0x05
  46. #define LM_TYPE_FLOCK 0x06
  47. #define LM_TYPE_PLOCK 0x07
  48. #define LM_TYPE_QUOTA 0x08
  49. #define LM_TYPE_JOURNAL 0x09
  50. /*
  51. * lm_lock() states
  52. *
  53. * SHARED is compatible with SHARED, not with DEFERRED or EX.
  54. * DEFERRED is compatible with DEFERRED, not with SHARED or EX.
  55. */
  56. #define LM_ST_UNLOCKED 0
  57. #define LM_ST_EXCLUSIVE 1
  58. #define LM_ST_DEFERRED 2
  59. #define LM_ST_SHARED 3
  60. /*
  61. * lm_lock() flags
  62. *
  63. * LM_FLAG_TRY
  64. * Don't wait to acquire the lock if it can't be granted immediately.
  65. *
  66. * LM_FLAG_TRY_1CB
  67. * Send one blocking callback if TRY is set and the lock is not granted.
  68. *
  69. * LM_FLAG_NOEXP
  70. * GFS sets this flag on lock requests it makes while doing journal recovery.
  71. * These special requests should not be blocked due to the recovery like
  72. * ordinary locks would be.
  73. *
  74. * LM_FLAG_ANY
  75. * A SHARED request may also be granted in DEFERRED, or a DEFERRED request may
  76. * also be granted in SHARED. The preferred state is whichever is compatible
  77. * with other granted locks, or the specified state if no other locks exist.
  78. *
  79. * LM_FLAG_PRIORITY
  80. * Override fairness considerations. Suppose a lock is held in a shared state
  81. * and there is a pending request for the deferred state. A shared lock
  82. * request with the priority flag would be allowed to bypass the deferred
  83. * request and directly join the other shared lock. A shared lock request
  84. * without the priority flag might be forced to wait until the deferred
  85. * requested had acquired and released the lock.
  86. */
  87. #define LM_FLAG_TRY 0x00000001
  88. #define LM_FLAG_TRY_1CB 0x00000002
  89. #define LM_FLAG_NOEXP 0x00000004
  90. #define LM_FLAG_ANY 0x00000008
  91. #define LM_FLAG_PRIORITY 0x00000010
  92. /*
  93. * lm_lock() and lm_async_cb return flags
  94. *
  95. * LM_OUT_ST_MASK
  96. * Masks the lower two bits of lock state in the returned value.
  97. *
  98. * LM_OUT_CACHEABLE
  99. * The lock hasn't been released so GFS can continue to cache data for it.
  100. *
  101. * LM_OUT_CANCELED
  102. * The lock request was canceled.
  103. *
  104. * LM_OUT_ASYNC
  105. * The result of the request will be returned in an LM_CB_ASYNC callback.
  106. */
  107. #define LM_OUT_ST_MASK 0x00000003
  108. #define LM_OUT_CACHEABLE 0x00000004
  109. #define LM_OUT_CANCELED 0x00000008
  110. #define LM_OUT_ASYNC 0x00000080
  111. #define LM_OUT_ERROR 0x00000100
  112. /*
  113. * lm_callback_t types
  114. *
  115. * LM_CB_NEED_E LM_CB_NEED_D LM_CB_NEED_S
  116. * Blocking callback, a remote node is requesting the given lock in
  117. * EXCLUSIVE, DEFERRED, or SHARED.
  118. *
  119. * LM_CB_NEED_RECOVERY
  120. * The given journal needs to be recovered.
  121. *
  122. * LM_CB_DROPLOCKS
  123. * Reduce the number of cached locks.
  124. *
  125. * LM_CB_ASYNC
  126. * The given lock has been granted.
  127. */
  128. #define LM_CB_NEED_E 257
  129. #define LM_CB_NEED_D 258
  130. #define LM_CB_NEED_S 259
  131. #define LM_CB_NEED_RECOVERY 260
  132. #define LM_CB_DROPLOCKS 261
  133. #define LM_CB_ASYNC 262
  134. /*
  135. * lm_recovery_done() messages
  136. */
  137. #define LM_RD_GAVEUP 308
  138. #define LM_RD_SUCCESS 309
  139. struct lm_lockname {
  140. u64 ln_number;
  141. unsigned int ln_type;
  142. };
  143. #define lm_name_equal(name1, name2) \
  144. (((name1)->ln_number == (name2)->ln_number) && \
  145. ((name1)->ln_type == (name2)->ln_type)) \
  146. struct lm_async_cb {
  147. struct lm_lockname lc_name;
  148. int lc_ret;
  149. };
  150. struct lm_lockstruct;
  151. struct lm_lockops {
  152. char lm_proto_name[256];
  153. /*
  154. * Mount/Unmount
  155. */
  156. int (*lm_mount) (char *table_name, char *host_data,
  157. lm_callback_t cb, struct gfs2_sbd *sdp,
  158. unsigned int min_lvb_size, int flags,
  159. struct lm_lockstruct *lockstruct,
  160. struct kobject *fskobj);
  161. void (*lm_others_may_mount) (lm_lockspace_t *lockspace);
  162. void (*lm_unmount) (lm_lockspace_t *lockspace);
  163. void (*lm_withdraw) (lm_lockspace_t *lockspace);
  164. /*
  165. * Lock oriented operations
  166. */
  167. int (*lm_get_lock) (lm_lockspace_t *lockspace,
  168. struct lm_lockname *name, lm_lock_t **lockp);
  169. void (*lm_put_lock) (lm_lock_t *lock);
  170. unsigned int (*lm_lock) (lm_lock_t *lock, unsigned int cur_state,
  171. unsigned int req_state, unsigned int flags);
  172. unsigned int (*lm_unlock) (lm_lock_t *lock, unsigned int cur_state);
  173. void (*lm_cancel) (lm_lock_t *lock);
  174. int (*lm_hold_lvb) (lm_lock_t *lock, char **lvbp);
  175. void (*lm_unhold_lvb) (lm_lock_t *lock, char *lvb);
  176. void (*lm_sync_lvb) (lm_lock_t *lock, char *lvb);
  177. /*
  178. * Posix Lock oriented operations
  179. */
  180. int (*lm_plock_get) (lm_lockspace_t *lockspace,
  181. struct lm_lockname *name,
  182. struct file *file, struct file_lock *fl);
  183. int (*lm_plock) (lm_lockspace_t *lockspace,
  184. struct lm_lockname *name,
  185. struct file *file, int cmd, struct file_lock *fl);
  186. int (*lm_punlock) (lm_lockspace_t *lockspace,
  187. struct lm_lockname *name,
  188. struct file *file, struct file_lock *fl);
  189. /*
  190. * Client oriented operations
  191. */
  192. void (*lm_recovery_done) (lm_lockspace_t *lockspace, unsigned int jid,
  193. unsigned int message);
  194. struct module *lm_owner;
  195. };
  196. /*
  197. * lm_mount() return values
  198. *
  199. * ls_jid - the journal ID this node should use
  200. * ls_first - this node is the first to mount the file system
  201. * ls_lvb_size - size in bytes of lock value blocks
  202. * ls_lockspace - lock module's context for this file system
  203. * ls_ops - lock module's functions
  204. * ls_flags - lock module features
  205. */
  206. struct lm_lockstruct {
  207. unsigned int ls_jid;
  208. unsigned int ls_first;
  209. unsigned int ls_lvb_size;
  210. lm_lockspace_t *ls_lockspace;
  211. struct lm_lockops *ls_ops;
  212. int ls_flags;
  213. };
  214. /*
  215. * Lock module bottom interface. A lock module makes itself available to GFS
  216. * with these functions.
  217. */
  218. int gfs2_register_lockproto(struct lm_lockops *proto);
  219. void gfs2_unregister_lockproto(struct lm_lockops *proto);
  220. /*
  221. * Lock module top interface. GFS calls these functions when mounting or
  222. * unmounting a file system.
  223. */
  224. int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data,
  225. lm_callback_t cb, struct gfs2_sbd *sdp,
  226. unsigned int min_lvb_size, int flags,
  227. struct lm_lockstruct *lockstruct,
  228. struct kobject *fskobj);
  229. void gfs2_unmount_lockproto(struct lm_lockstruct *lockstruct);
  230. void gfs2_withdraw_lockproto(struct lm_lockstruct *lockstruct);
  231. #endif /* __LM_INTERFACE_DOT_H__ */