main.c 4.9 KB

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