lm_interface.h 7.4 KB

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