main.c 4.9 KB

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