main.c 5.6 KB

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