lock_dlm.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2005 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 LOCK_DLM_DOT_H
  10. #define LOCK_DLM_DOT_H
  11. #include <linux/module.h>
  12. #include <linux/slab.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/module.h>
  15. #include <linux/types.h>
  16. #include <linux/string.h>
  17. #include <linux/list.h>
  18. #include <linux/socket.h>
  19. #include <linux/delay.h>
  20. #include <linux/kthread.h>
  21. #include <linux/kobject.h>
  22. #include <linux/fcntl.h>
  23. #include <linux/wait.h>
  24. #include <net/sock.h>
  25. #include <linux/dlm.h>
  26. #include <linux/lm_interface.h>
  27. /*
  28. * Internally, we prefix things with gdlm_ and GDLM_ (for gfs-dlm) since a
  29. * prefix of lock_dlm_ gets awkward. Externally, GFS refers to this module
  30. * as "lock_dlm".
  31. */
  32. #define GDLM_STRNAME_BYTES 24
  33. #define GDLM_LVB_SIZE 32
  34. #define GDLM_DROP_COUNT 50000
  35. #define GDLM_DROP_PERIOD 60
  36. #define GDLM_NAME_LEN 128
  37. /* GFS uses 12 bytes to identify a resource (32 bit type + 64 bit number).
  38. We sprintf these numbers into a 24 byte string of hex values to make them
  39. human-readable (to make debugging simpler.) */
  40. struct gdlm_strname {
  41. unsigned char name[GDLM_STRNAME_BYTES];
  42. unsigned short namelen;
  43. };
  44. enum {
  45. DFL_BLOCK_LOCKS = 0,
  46. DFL_SPECTATOR = 1,
  47. DFL_WITHDRAW = 2,
  48. };
  49. struct gdlm_ls {
  50. u32 id;
  51. int jid;
  52. int first;
  53. int first_done;
  54. unsigned long flags;
  55. struct kobject kobj;
  56. char clustername[GDLM_NAME_LEN];
  57. char fsname[GDLM_NAME_LEN];
  58. int fsflags;
  59. dlm_lockspace_t *dlm_lockspace;
  60. lm_callback_t fscb;
  61. struct gfs2_sbd *sdp;
  62. int recover_jid;
  63. int recover_jid_done;
  64. int recover_jid_status;
  65. spinlock_t async_lock;
  66. struct list_head complete;
  67. struct list_head blocking;
  68. struct list_head delayed;
  69. struct list_head submit;
  70. struct list_head all_locks;
  71. u32 all_locks_count;
  72. wait_queue_head_t wait_control;
  73. struct task_struct *thread1;
  74. struct task_struct *thread2;
  75. wait_queue_head_t thread_wait;
  76. unsigned long drop_time;
  77. int drop_locks_count;
  78. int drop_locks_period;
  79. };
  80. enum {
  81. LFL_NOBLOCK = 0,
  82. LFL_NOCACHE = 1,
  83. LFL_DLM_UNLOCK = 2,
  84. LFL_DLM_CANCEL = 3,
  85. LFL_SYNC_LVB = 4,
  86. LFL_FORCE_PROMOTE = 5,
  87. LFL_REREQUEST = 6,
  88. LFL_ACTIVE = 7,
  89. LFL_INLOCK = 8,
  90. LFL_CANCEL = 9,
  91. LFL_NOBAST = 10,
  92. LFL_HEADQUE = 11,
  93. LFL_UNLOCK_DELETE = 12,
  94. };
  95. struct gdlm_lock {
  96. struct gdlm_ls *ls;
  97. struct lm_lockname lockname;
  98. char *lvb;
  99. struct dlm_lksb lksb;
  100. s16 cur;
  101. s16 req;
  102. s16 prev_req;
  103. u32 lkf; /* dlm flags DLM_LKF_ */
  104. unsigned long flags; /* lock_dlm flags LFL_ */
  105. int bast_mode; /* protected by async_lock */
  106. struct completion ast_wait;
  107. struct list_head clist; /* complete */
  108. struct list_head blist; /* blocking */
  109. struct list_head delay_list; /* delayed */
  110. struct list_head all_list; /* all locks for the fs */
  111. struct gdlm_lock *hold_null; /* NL lock for hold_lvb */
  112. };
  113. #define gdlm_assert(assertion, fmt, args...) \
  114. do { \
  115. if (unlikely(!(assertion))) { \
  116. printk(KERN_EMERG "lock_dlm: fatal assertion failed \"%s\"\n" \
  117. "lock_dlm: " fmt "\n", \
  118. #assertion, ##args); \
  119. BUG(); \
  120. } \
  121. } while (0)
  122. #define log_print(lev, fmt, arg...) printk(lev "lock_dlm: " fmt "\n" , ## arg)
  123. #define log_info(fmt, arg...) log_print(KERN_INFO , fmt , ## arg)
  124. #define log_error(fmt, arg...) log_print(KERN_ERR , fmt , ## arg)
  125. #ifdef LOCK_DLM_LOG_DEBUG
  126. #define log_debug(fmt, arg...) log_print(KERN_DEBUG , fmt , ## arg)
  127. #else
  128. #define log_debug(fmt, arg...)
  129. #endif
  130. /* sysfs.c */
  131. int gdlm_sysfs_init(void);
  132. void gdlm_sysfs_exit(void);
  133. int gdlm_kobject_setup(struct gdlm_ls *, struct kobject *);
  134. void gdlm_kobject_release(struct gdlm_ls *);
  135. /* thread.c */
  136. int gdlm_init_threads(struct gdlm_ls *);
  137. void gdlm_release_threads(struct gdlm_ls *);
  138. /* lock.c */
  139. s16 gdlm_make_lmstate(s16);
  140. void gdlm_queue_delayed(struct gdlm_lock *);
  141. void gdlm_submit_delayed(struct gdlm_ls *);
  142. int gdlm_release_all_locks(struct gdlm_ls *);
  143. void gdlm_delete_lp(struct gdlm_lock *);
  144. unsigned int gdlm_do_lock(struct gdlm_lock *);
  145. int gdlm_get_lock(void *, struct lm_lockname *, void **);
  146. void gdlm_put_lock(void *);
  147. unsigned int gdlm_lock(void *, unsigned int, unsigned int, unsigned int);
  148. unsigned int gdlm_unlock(void *, unsigned int);
  149. void gdlm_cancel(void *);
  150. int gdlm_hold_lvb(void *, char **);
  151. void gdlm_unhold_lvb(void *, char *);
  152. /* plock.c */
  153. int gdlm_plock_init(void);
  154. void gdlm_plock_exit(void);
  155. int gdlm_plock(void *, struct lm_lockname *, struct file *, int,
  156. struct file_lock *);
  157. int gdlm_plock_get(void *, struct lm_lockname *, struct file *,
  158. struct file_lock *);
  159. int gdlm_punlock(void *, struct lm_lockname *, struct file *,
  160. struct file_lock *);
  161. #endif