glock.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 __GLOCK_DOT_H__
  10. #define __GLOCK_DOT_H__
  11. #include <linux/sched.h>
  12. #include <linux/parser.h>
  13. #include "incore.h"
  14. /* Options for hostdata parser */
  15. enum {
  16. Opt_jid,
  17. Opt_id,
  18. Opt_first,
  19. Opt_nodir,
  20. Opt_err,
  21. };
  22. /*
  23. * lm_lockname types
  24. */
  25. #define LM_TYPE_RESERVED 0x00
  26. #define LM_TYPE_NONDISK 0x01
  27. #define LM_TYPE_INODE 0x02
  28. #define LM_TYPE_RGRP 0x03
  29. #define LM_TYPE_META 0x04
  30. #define LM_TYPE_IOPEN 0x05
  31. #define LM_TYPE_FLOCK 0x06
  32. #define LM_TYPE_PLOCK 0x07
  33. #define LM_TYPE_QUOTA 0x08
  34. #define LM_TYPE_JOURNAL 0x09
  35. /*
  36. * lm_lock() states
  37. *
  38. * SHARED is compatible with SHARED, not with DEFERRED or EX.
  39. * DEFERRED is compatible with DEFERRED, not with SHARED or EX.
  40. */
  41. #define LM_ST_UNLOCKED 0
  42. #define LM_ST_EXCLUSIVE 1
  43. #define LM_ST_DEFERRED 2
  44. #define LM_ST_SHARED 3
  45. /*
  46. * lm_lock() flags
  47. *
  48. * LM_FLAG_TRY
  49. * Don't wait to acquire the lock if it can't be granted immediately.
  50. *
  51. * LM_FLAG_TRY_1CB
  52. * Send one blocking callback if TRY is set and the lock is not granted.
  53. *
  54. * LM_FLAG_NOEXP
  55. * GFS sets this flag on lock requests it makes while doing journal recovery.
  56. * These special requests should not be blocked due to the recovery like
  57. * ordinary locks would be.
  58. *
  59. * LM_FLAG_ANY
  60. * A SHARED request may also be granted in DEFERRED, or a DEFERRED request may
  61. * also be granted in SHARED. The preferred state is whichever is compatible
  62. * with other granted locks, or the specified state if no other locks exist.
  63. *
  64. * LM_FLAG_PRIORITY
  65. * Override fairness considerations. Suppose a lock is held in a shared state
  66. * and there is a pending request for the deferred state. A shared lock
  67. * request with the priority flag would be allowed to bypass the deferred
  68. * request and directly join the other shared lock. A shared lock request
  69. * without the priority flag might be forced to wait until the deferred
  70. * requested had acquired and released the lock.
  71. */
  72. #define LM_FLAG_TRY 0x00000001
  73. #define LM_FLAG_TRY_1CB 0x00000002
  74. #define LM_FLAG_NOEXP 0x00000004
  75. #define LM_FLAG_ANY 0x00000008
  76. #define LM_FLAG_PRIORITY 0x00000010
  77. #define GL_ASYNC 0x00000040
  78. #define GL_EXACT 0x00000080
  79. #define GL_SKIP 0x00000100
  80. #define GL_ATIME 0x00000200
  81. #define GL_NOCACHE 0x00000400
  82. /*
  83. * lm_lock() and lm_async_cb return flags
  84. *
  85. * LM_OUT_ST_MASK
  86. * Masks the lower two bits of lock state in the returned value.
  87. *
  88. * LM_OUT_CANCELED
  89. * The lock request was canceled.
  90. *
  91. * LM_OUT_ASYNC
  92. * The result of the request will be returned in an LM_CB_ASYNC callback.
  93. *
  94. */
  95. #define LM_OUT_ST_MASK 0x00000003
  96. #define LM_OUT_CANCELED 0x00000008
  97. #define LM_OUT_ASYNC 0x00000080
  98. #define LM_OUT_ERROR 0x00000100
  99. /*
  100. * lm_recovery_done() messages
  101. */
  102. #define LM_RD_GAVEUP 308
  103. #define LM_RD_SUCCESS 309
  104. #define GLR_TRYFAILED 13
  105. struct lm_lockops {
  106. const char *lm_proto_name;
  107. int (*lm_mount) (struct gfs2_sbd *sdp, const char *fsname);
  108. void (*lm_unmount) (struct gfs2_sbd *sdp);
  109. void (*lm_withdraw) (struct gfs2_sbd *sdp);
  110. void (*lm_put_lock) (struct kmem_cache *cachep, void *gl);
  111. unsigned int (*lm_lock) (struct gfs2_glock *gl,
  112. unsigned int req_state, unsigned int flags);
  113. void (*lm_cancel) (struct gfs2_glock *gl);
  114. const match_table_t *lm_tokens;
  115. };
  116. #define LM_FLAG_TRY 0x00000001
  117. #define LM_FLAG_TRY_1CB 0x00000002
  118. #define LM_FLAG_NOEXP 0x00000004
  119. #define LM_FLAG_ANY 0x00000008
  120. #define LM_FLAG_PRIORITY 0x00000010
  121. #define GL_ASYNC 0x00000040
  122. #define GL_EXACT 0x00000080
  123. #define GL_SKIP 0x00000100
  124. #define GL_NOCACHE 0x00000400
  125. #define GLR_TRYFAILED 13
  126. extern struct workqueue_struct *gfs2_delete_workqueue;
  127. static inline struct gfs2_holder *gfs2_glock_is_locked_by_me(struct gfs2_glock *gl)
  128. {
  129. struct gfs2_holder *gh;
  130. struct pid *pid;
  131. /* Look in glock's list of holders for one with current task as owner */
  132. spin_lock(&gl->gl_spin);
  133. pid = task_pid(current);
  134. list_for_each_entry(gh, &gl->gl_holders, gh_list) {
  135. if (!test_bit(HIF_HOLDER, &gh->gh_iflags))
  136. break;
  137. if (gh->gh_owner_pid == pid)
  138. goto out;
  139. }
  140. gh = NULL;
  141. out:
  142. spin_unlock(&gl->gl_spin);
  143. return gh;
  144. }
  145. static inline int gfs2_glock_is_held_excl(struct gfs2_glock *gl)
  146. {
  147. return gl->gl_state == LM_ST_EXCLUSIVE;
  148. }
  149. static inline int gfs2_glock_is_held_dfrd(struct gfs2_glock *gl)
  150. {
  151. return gl->gl_state == LM_ST_DEFERRED;
  152. }
  153. static inline int gfs2_glock_is_held_shrd(struct gfs2_glock *gl)
  154. {
  155. return gl->gl_state == LM_ST_SHARED;
  156. }
  157. static inline int gfs2_glock_is_blocking(struct gfs2_glock *gl)
  158. {
  159. int ret;
  160. spin_lock(&gl->gl_spin);
  161. ret = test_bit(GLF_DEMOTE, &gl->gl_flags);
  162. spin_unlock(&gl->gl_spin);
  163. return ret;
  164. }
  165. int gfs2_glock_get(struct gfs2_sbd *sdp,
  166. u64 number, const struct gfs2_glock_operations *glops,
  167. int create, struct gfs2_glock **glp);
  168. void gfs2_glock_hold(struct gfs2_glock *gl);
  169. void gfs2_glock_put_nolock(struct gfs2_glock *gl);
  170. int gfs2_glock_put(struct gfs2_glock *gl);
  171. void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags,
  172. struct gfs2_holder *gh);
  173. void gfs2_holder_reinit(unsigned int state, unsigned flags,
  174. struct gfs2_holder *gh);
  175. void gfs2_holder_uninit(struct gfs2_holder *gh);
  176. int gfs2_glock_nq(struct gfs2_holder *gh);
  177. int gfs2_glock_poll(struct gfs2_holder *gh);
  178. int gfs2_glock_wait(struct gfs2_holder *gh);
  179. void gfs2_glock_dq(struct gfs2_holder *gh);
  180. void gfs2_glock_dq_wait(struct gfs2_holder *gh);
  181. void gfs2_glock_dq_uninit(struct gfs2_holder *gh);
  182. int gfs2_glock_nq_num(struct gfs2_sbd *sdp,
  183. u64 number, const struct gfs2_glock_operations *glops,
  184. unsigned int state, int flags, struct gfs2_holder *gh);
  185. int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs);
  186. void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs);
  187. void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs);
  188. void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...);
  189. /**
  190. * gfs2_glock_nq_init - intialize a holder and enqueue it on a glock
  191. * @gl: the glock
  192. * @state: the state we're requesting
  193. * @flags: the modifier flags
  194. * @gh: the holder structure
  195. *
  196. * Returns: 0, GLR_*, or errno
  197. */
  198. static inline int gfs2_glock_nq_init(struct gfs2_glock *gl,
  199. unsigned int state, int flags,
  200. struct gfs2_holder *gh)
  201. {
  202. int error;
  203. gfs2_holder_init(gl, state, flags, gh);
  204. error = gfs2_glock_nq(gh);
  205. if (error)
  206. gfs2_holder_uninit(gh);
  207. return error;
  208. }
  209. /* Lock Value Block functions */
  210. int gfs2_lvb_hold(struct gfs2_glock *gl);
  211. void gfs2_lvb_unhold(struct gfs2_glock *gl);
  212. void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state);
  213. void gfs2_glock_complete(struct gfs2_glock *gl, int ret);
  214. void gfs2_reclaim_glock(struct gfs2_sbd *sdp);
  215. void gfs2_gl_hash_clear(struct gfs2_sbd *sdp);
  216. void gfs2_glock_finish_truncate(struct gfs2_inode *ip);
  217. void gfs2_glock_thaw(struct gfs2_sbd *sdp);
  218. int __init gfs2_glock_init(void);
  219. void gfs2_glock_exit(void);
  220. int gfs2_create_debugfs_file(struct gfs2_sbd *sdp);
  221. void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp);
  222. int gfs2_register_debugfs(void);
  223. void gfs2_unregister_debugfs(void);
  224. extern const struct lm_lockops gfs2_dlm_ops;
  225. #endif /* __GLOCK_DOT_H__ */