main.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  5. ** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
  6. **
  7. ** This copyrighted material is made available to anyone wishing to use,
  8. ** modify, copy, or redistribute it subject to the terms and conditions
  9. ** of the GNU General Public License v.2.
  10. **
  11. *******************************************************************************
  12. ******************************************************************************/
  13. #include <linux/module.h>
  14. #include <linux/slab.h>
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/types.h>
  18. #include <linux/fs.h>
  19. #include <linux/smp_lock.h>
  20. #include "../../lm_interface.h"
  21. struct nolock_lockspace {
  22. unsigned int nl_lvb_size;
  23. };
  24. struct lm_lockops nolock_ops;
  25. /**
  26. * nolock_mount - mount a nolock lockspace
  27. * @table_name: the name of the space to mount
  28. * @host_data: host specific data
  29. * @cb: the callback
  30. * @fsdata:
  31. * @min_lvb_size:
  32. * @flags:
  33. * @lockstruct: the structure of crap to fill in
  34. *
  35. * Returns: 0 on success, -EXXX on failure
  36. */
  37. static int nolock_mount(char *table_name, char *host_data,
  38. lm_callback_t cb, lm_fsdata_t *fsdata,
  39. unsigned int min_lvb_size, int flags,
  40. struct lm_lockstruct *lockstruct)
  41. {
  42. char *c;
  43. unsigned int jid;
  44. struct nolock_lockspace *nl;
  45. /* If there is a "jid=" in the hostdata, return that jid.
  46. Otherwise, return zero. */
  47. c = strstr(host_data, "jid=");
  48. if (!c)
  49. jid = 0;
  50. else {
  51. c += 4;
  52. sscanf(c, "%u", &jid);
  53. }
  54. nl = kmalloc(sizeof(struct nolock_lockspace), GFP_KERNEL);
  55. if (!nl)
  56. return -ENOMEM;
  57. memset(nl, 0, sizeof(struct nolock_lockspace));
  58. nl->nl_lvb_size = min_lvb_size;
  59. lockstruct->ls_jid = jid;
  60. lockstruct->ls_first = 1;
  61. lockstruct->ls_lvb_size = min_lvb_size;
  62. lockstruct->ls_lockspace = (lm_lockspace_t *)nl;
  63. lockstruct->ls_ops = &nolock_ops;
  64. lockstruct->ls_flags = LM_LSFLAG_LOCAL;
  65. return 0;
  66. }
  67. /**
  68. * nolock_others_may_mount - unmount a lock space
  69. * @lockspace: the lockspace to unmount
  70. *
  71. */
  72. static void nolock_others_may_mount(lm_lockspace_t *lockspace)
  73. {
  74. }
  75. /**
  76. * nolock_unmount - unmount a lock space
  77. * @lockspace: the lockspace to unmount
  78. *
  79. */
  80. static void nolock_unmount(lm_lockspace_t *lockspace)
  81. {
  82. struct nolock_lockspace *nl = (struct nolock_lockspace *)lockspace;
  83. kfree(nl);
  84. }
  85. /**
  86. * nolock_withdraw - withdraw from a lock space
  87. * @lockspace: the lockspace
  88. *
  89. */
  90. static void nolock_withdraw(lm_lockspace_t *lockspace)
  91. {
  92. }
  93. /**
  94. * nolock_get_lock - get a lm_lock_t given a descripton of the lock
  95. * @lockspace: the lockspace the lock lives in
  96. * @name: the name of the lock
  97. * @lockp: return the lm_lock_t here
  98. *
  99. * Returns: 0 on success, -EXXX on failure
  100. */
  101. static int nolock_get_lock(lm_lockspace_t *lockspace, struct lm_lockname *name,
  102. lm_lock_t **lockp)
  103. {
  104. *lockp = (lm_lock_t *)lockspace;
  105. return 0;
  106. }
  107. /**
  108. * nolock_put_lock - get rid of a lock structure
  109. * @lock: the lock to throw away
  110. *
  111. */
  112. static void nolock_put_lock(lm_lock_t *lock)
  113. {
  114. }
  115. /**
  116. * nolock_lock - acquire a lock
  117. * @lock: the lock to manipulate
  118. * @cur_state: the current state
  119. * @req_state: the requested state
  120. * @flags: modifier flags
  121. *
  122. * Returns: A bitmap of LM_OUT_*
  123. */
  124. static unsigned int nolock_lock(lm_lock_t *lock, unsigned int cur_state,
  125. unsigned int req_state, unsigned int flags)
  126. {
  127. return req_state | LM_OUT_CACHEABLE;
  128. }
  129. /**
  130. * nolock_unlock - unlock a lock
  131. * @lock: the lock to manipulate
  132. * @cur_state: the current state
  133. *
  134. * Returns: 0
  135. */
  136. static unsigned int nolock_unlock(lm_lock_t *lock, unsigned int cur_state)
  137. {
  138. return 0;
  139. }
  140. /**
  141. * nolock_cancel - cancel a request on a lock
  142. * @lock: the lock to cancel request for
  143. *
  144. */
  145. static void nolock_cancel(lm_lock_t *lock)
  146. {
  147. }
  148. /**
  149. * nolock_hold_lvb - hold on to a lock value block
  150. * @lock: the lock the LVB is associated with
  151. * @lvbp: return the lm_lvb_t here
  152. *
  153. * Returns: 0 on success, -EXXX on failure
  154. */
  155. static int nolock_hold_lvb(lm_lock_t *lock, char **lvbp)
  156. {
  157. struct nolock_lockspace *nl = (struct nolock_lockspace *)lock;
  158. int error = 0;
  159. *lvbp = kmalloc(nl->nl_lvb_size, GFP_KERNEL);
  160. if (*lvbp)
  161. memset(*lvbp, 0, nl->nl_lvb_size);
  162. else
  163. error = -ENOMEM;
  164. return error;
  165. }
  166. /**
  167. * nolock_unhold_lvb - release a LVB
  168. * @lock: the lock the LVB is associated with
  169. * @lvb: the lock value block
  170. *
  171. */
  172. static void nolock_unhold_lvb(lm_lock_t *lock, char *lvb)
  173. {
  174. kfree(lvb);
  175. }
  176. /**
  177. * nolock_sync_lvb - sync out the value of a lvb
  178. * @lock: the lock the LVB is associated with
  179. * @lvb: the lock value block
  180. *
  181. */
  182. static void nolock_sync_lvb(lm_lock_t *lock, char *lvb)
  183. {
  184. }
  185. /**
  186. * nolock_plock_get -
  187. * @lockspace: the lockspace
  188. * @name:
  189. * @file:
  190. * @fl:
  191. *
  192. * Returns: errno
  193. */
  194. static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name,
  195. struct file *file, struct file_lock *fl)
  196. {
  197. struct file_lock *tmp;
  198. lock_kernel();
  199. tmp = posix_test_lock(file, fl);
  200. fl->fl_type = F_UNLCK;
  201. if (tmp)
  202. memcpy(fl, tmp, sizeof(struct file_lock));
  203. unlock_kernel();
  204. return 0;
  205. }
  206. /**
  207. * nolock_plock -
  208. * @lockspace: the lockspace
  209. * @name:
  210. * @file:
  211. * @cmd:
  212. * @fl:
  213. *
  214. * Returns: errno
  215. */
  216. static int nolock_plock(lm_lockspace_t *lockspace, struct lm_lockname *name,
  217. struct file *file, int cmd, struct file_lock *fl)
  218. {
  219. int error;
  220. lock_kernel();
  221. error = posix_lock_file_wait(file, fl);
  222. unlock_kernel();
  223. return error;
  224. }
  225. /**
  226. * nolock_punlock -
  227. * @lockspace: the lockspace
  228. * @name:
  229. * @file:
  230. * @fl:
  231. *
  232. * Returns: errno
  233. */
  234. static int nolock_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name,
  235. struct file *file, struct file_lock *fl)
  236. {
  237. int error;
  238. lock_kernel();
  239. error = posix_lock_file_wait(file, fl);
  240. unlock_kernel();
  241. return error;
  242. }
  243. /**
  244. * nolock_recovery_done - reset the expired locks for a given jid
  245. * @lockspace: the lockspace
  246. * @jid: the jid
  247. *
  248. */
  249. static void nolock_recovery_done(lm_lockspace_t *lockspace, unsigned int jid,
  250. unsigned int message)
  251. {
  252. }
  253. struct lm_lockops nolock_ops = {
  254. .lm_proto_name = "lock_nolock",
  255. .lm_mount = nolock_mount,
  256. .lm_others_may_mount = nolock_others_may_mount,
  257. .lm_unmount = nolock_unmount,
  258. .lm_withdraw = nolock_withdraw,
  259. .lm_get_lock = nolock_get_lock,
  260. .lm_put_lock = nolock_put_lock,
  261. .lm_lock = nolock_lock,
  262. .lm_unlock = nolock_unlock,
  263. .lm_cancel = nolock_cancel,
  264. .lm_hold_lvb = nolock_hold_lvb,
  265. .lm_unhold_lvb = nolock_unhold_lvb,
  266. .lm_sync_lvb = nolock_sync_lvb,
  267. .lm_plock_get = nolock_plock_get,
  268. .lm_plock = nolock_plock,
  269. .lm_punlock = nolock_punlock,
  270. .lm_recovery_done = nolock_recovery_done,
  271. .lm_owner = THIS_MODULE,
  272. };
  273. /**
  274. * init_nolock - Initialize the nolock module
  275. *
  276. * Returns: 0 on success, -EXXX on failure
  277. */
  278. int __init init_nolock(void)
  279. {
  280. int error;
  281. error = lm_register_proto(&nolock_ops);
  282. if (error) {
  283. printk("lock_nolock: can't register protocol: %d\n", error);
  284. return error;
  285. }
  286. printk("Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__);
  287. return 0;
  288. }
  289. /**
  290. * exit_nolock - cleanup the nolock module
  291. *
  292. */
  293. void __exit exit_nolock(void)
  294. {
  295. lm_unregister_proto(&nolock_ops);
  296. }
  297. module_init(init_nolock);
  298. module_exit(exit_nolock);
  299. MODULE_DESCRIPTION("GFS Nolock Locking Module");
  300. MODULE_AUTHOR("Red Hat, Inc.");
  301. MODULE_LICENSE("GPL");