main.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. #include <linux/module.h>
  10. #include <linux/slab.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/types.h>
  14. #include <linux/fs.h>
  15. #include <linux/smp_lock.h>
  16. #include <linux/lm_interface.h>
  17. struct nolock_lockspace {
  18. unsigned int nl_lvb_size;
  19. };
  20. static const struct lm_lockops nolock_ops;
  21. static int nolock_mount(char *table_name, char *host_data,
  22. lm_callback_t cb, void *cb_data,
  23. unsigned int min_lvb_size, int flags,
  24. struct lm_lockstruct *lockstruct,
  25. struct kobject *fskobj)
  26. {
  27. char *c;
  28. unsigned int jid;
  29. struct nolock_lockspace *nl;
  30. c = strstr(host_data, "jid=");
  31. if (!c)
  32. jid = 0;
  33. else {
  34. c += 4;
  35. sscanf(c, "%u", &jid);
  36. }
  37. nl = kzalloc(sizeof(struct nolock_lockspace), GFP_KERNEL);
  38. if (!nl)
  39. return -ENOMEM;
  40. nl->nl_lvb_size = min_lvb_size;
  41. lockstruct->ls_jid = jid;
  42. lockstruct->ls_first = 1;
  43. lockstruct->ls_lvb_size = min_lvb_size;
  44. lockstruct->ls_lockspace = nl;
  45. lockstruct->ls_ops = &nolock_ops;
  46. lockstruct->ls_flags = LM_LSFLAG_LOCAL;
  47. return 0;
  48. }
  49. static void nolock_others_may_mount(void *lockspace)
  50. {
  51. }
  52. static void nolock_unmount(void *lockspace)
  53. {
  54. struct nolock_lockspace *nl = lockspace;
  55. kfree(nl);
  56. }
  57. static void nolock_withdraw(void *lockspace)
  58. {
  59. }
  60. /**
  61. * nolock_get_lock - get a lm_lock_t given a descripton of the lock
  62. * @lockspace: the lockspace the lock lives in
  63. * @name: the name of the lock
  64. * @lockp: return the lm_lock_t here
  65. *
  66. * Returns: 0 on success, -EXXX on failure
  67. */
  68. static int nolock_get_lock(void *lockspace, struct lm_lockname *name,
  69. void **lockp)
  70. {
  71. *lockp = lockspace;
  72. return 0;
  73. }
  74. /**
  75. * nolock_put_lock - get rid of a lock structure
  76. * @lock: the lock to throw away
  77. *
  78. */
  79. static void nolock_put_lock(void *lock)
  80. {
  81. }
  82. /**
  83. * nolock_lock - acquire a lock
  84. * @lock: the lock to manipulate
  85. * @cur_state: the current state
  86. * @req_state: the requested state
  87. * @flags: modifier flags
  88. *
  89. * Returns: A bitmap of LM_OUT_*
  90. */
  91. static unsigned int nolock_lock(void *lock, unsigned int cur_state,
  92. unsigned int req_state, unsigned int flags)
  93. {
  94. return req_state | LM_OUT_CACHEABLE;
  95. }
  96. /**
  97. * nolock_unlock - unlock a lock
  98. * @lock: the lock to manipulate
  99. * @cur_state: the current state
  100. *
  101. * Returns: 0
  102. */
  103. static unsigned int nolock_unlock(void *lock, unsigned int cur_state)
  104. {
  105. return 0;
  106. }
  107. static void nolock_cancel(void *lock)
  108. {
  109. }
  110. /**
  111. * nolock_hold_lvb - hold on to a lock value block
  112. * @lock: the lock the LVB is associated with
  113. * @lvbp: return the lm_lvb_t here
  114. *
  115. * Returns: 0 on success, -EXXX on failure
  116. */
  117. static int nolock_hold_lvb(void *lock, char **lvbp)
  118. {
  119. struct nolock_lockspace *nl = lock;
  120. int error = 0;
  121. *lvbp = kzalloc(nl->nl_lvb_size, GFP_KERNEL);
  122. if (!*lvbp)
  123. error = -ENOMEM;
  124. return error;
  125. }
  126. /**
  127. * nolock_unhold_lvb - release a LVB
  128. * @lock: the lock the LVB is associated with
  129. * @lvb: the lock value block
  130. *
  131. */
  132. static void nolock_unhold_lvb(void *lock, char *lvb)
  133. {
  134. kfree(lvb);
  135. }
  136. static int nolock_plock_get(void *lockspace, struct lm_lockname *name,
  137. struct file *file, struct file_lock *fl)
  138. {
  139. struct file_lock tmp;
  140. int ret;
  141. ret = posix_test_lock(file, fl, &tmp);
  142. fl->fl_type = F_UNLCK;
  143. if (ret)
  144. memcpy(fl, &tmp, sizeof(struct file_lock));
  145. return 0;
  146. }
  147. static int nolock_plock(void *lockspace, struct lm_lockname *name,
  148. struct file *file, int cmd, struct file_lock *fl)
  149. {
  150. int error;
  151. error = posix_lock_file_wait(file, fl);
  152. return error;
  153. }
  154. static int nolock_punlock(void *lockspace, struct lm_lockname *name,
  155. struct file *file, struct file_lock *fl)
  156. {
  157. int error;
  158. error = posix_lock_file_wait(file, fl);
  159. return error;
  160. }
  161. static void nolock_recovery_done(void *lockspace, unsigned int jid,
  162. unsigned int message)
  163. {
  164. }
  165. static const struct lm_lockops nolock_ops = {
  166. .lm_proto_name = "lock_nolock",
  167. .lm_mount = nolock_mount,
  168. .lm_others_may_mount = nolock_others_may_mount,
  169. .lm_unmount = nolock_unmount,
  170. .lm_withdraw = nolock_withdraw,
  171. .lm_get_lock = nolock_get_lock,
  172. .lm_put_lock = nolock_put_lock,
  173. .lm_lock = nolock_lock,
  174. .lm_unlock = nolock_unlock,
  175. .lm_cancel = nolock_cancel,
  176. .lm_hold_lvb = nolock_hold_lvb,
  177. .lm_unhold_lvb = nolock_unhold_lvb,
  178. .lm_plock_get = nolock_plock_get,
  179. .lm_plock = nolock_plock,
  180. .lm_punlock = nolock_punlock,
  181. .lm_recovery_done = nolock_recovery_done,
  182. .lm_owner = THIS_MODULE,
  183. };
  184. static int __init init_nolock(void)
  185. {
  186. int error;
  187. error = gfs2_register_lockproto(&nolock_ops);
  188. if (error) {
  189. printk(KERN_WARNING
  190. "lock_nolock: can't register protocol: %d\n", error);
  191. return error;
  192. }
  193. printk(KERN_INFO
  194. "Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__);
  195. return 0;
  196. }
  197. static void __exit exit_nolock(void)
  198. {
  199. gfs2_unregister_lockproto(&nolock_ops);
  200. }
  201. module_init(init_nolock);
  202. module_exit(exit_nolock);
  203. MODULE_DESCRIPTION("GFS Nolock Locking Module");
  204. MODULE_AUTHOR("Red Hat, Inc.");
  205. MODULE_LICENSE("GPL");