lm.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 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/sched.h>
  10. #include <linux/slab.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/completion.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/delay.h>
  15. #include <linux/gfs2_ondisk.h>
  16. #include <linux/lm_interface.h>
  17. #include "gfs2.h"
  18. #include "incore.h"
  19. #include "glock.h"
  20. #include "lm.h"
  21. #include "super.h"
  22. #include "util.h"
  23. /**
  24. * gfs2_lm_mount - mount a locking protocol
  25. * @sdp: the filesystem
  26. * @args: mount arguements
  27. * @silent: if 1, don't complain if the FS isn't a GFS2 fs
  28. *
  29. * Returns: errno
  30. */
  31. int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
  32. {
  33. char *proto = sdp->sd_proto_name;
  34. char *table = sdp->sd_table_name;
  35. int flags = 0;
  36. int error;
  37. if (sdp->sd_args.ar_spectator)
  38. flags |= LM_MFLAG_SPECTATOR;
  39. fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table);
  40. error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata,
  41. gfs2_glock_cb, sdp,
  42. GFS2_MIN_LVB_SIZE, flags,
  43. &sdp->sd_lockstruct, &sdp->sd_kobj);
  44. if (error) {
  45. fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n",
  46. proto, table, sdp->sd_args.ar_hostdata);
  47. goto out;
  48. }
  49. if (gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lockspace) ||
  50. gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_ops) ||
  51. gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lvb_size >=
  52. GFS2_MIN_LVB_SIZE)) {
  53. gfs2_unmount_lockproto(&sdp->sd_lockstruct);
  54. goto out;
  55. }
  56. if (sdp->sd_args.ar_spectator)
  57. snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table);
  58. else
  59. snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table,
  60. sdp->sd_lockstruct.ls_jid);
  61. fs_info(sdp, "Joined cluster. Now mounting FS...\n");
  62. if ((sdp->sd_lockstruct.ls_flags & LM_LSFLAG_LOCAL) &&
  63. !sdp->sd_args.ar_ignore_local_fs) {
  64. sdp->sd_args.ar_localflocks = 1;
  65. sdp->sd_args.ar_localcaching = 1;
  66. }
  67. out:
  68. return error;
  69. }
  70. void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp)
  71. {
  72. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  73. sdp->sd_lockstruct.ls_ops->lm_others_may_mount(
  74. sdp->sd_lockstruct.ls_lockspace);
  75. }
  76. void gfs2_lm_unmount(struct gfs2_sbd *sdp)
  77. {
  78. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  79. gfs2_unmount_lockproto(&sdp->sd_lockstruct);
  80. }
  81. int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
  82. {
  83. va_list args;
  84. if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
  85. return 0;
  86. va_start(args, fmt);
  87. vprintk(fmt, args);
  88. va_end(args);
  89. fs_err(sdp, "about to withdraw this file system\n");
  90. BUG_ON(sdp->sd_args.ar_debug);
  91. fs_err(sdp, "telling LM to withdraw\n");
  92. gfs2_withdraw_lockproto(&sdp->sd_lockstruct);
  93. fs_err(sdp, "withdrawn\n");
  94. dump_stack();
  95. return -1;
  96. }
  97. int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name,
  98. void **lockp)
  99. {
  100. int error = -EIO;
  101. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  102. error = sdp->sd_lockstruct.ls_ops->lm_get_lock(
  103. sdp->sd_lockstruct.ls_lockspace, name, lockp);
  104. return error;
  105. }
  106. void gfs2_lm_put_lock(struct gfs2_sbd *sdp, void *lock)
  107. {
  108. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  109. sdp->sd_lockstruct.ls_ops->lm_put_lock(lock);
  110. }
  111. unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock,
  112. unsigned int cur_state, unsigned int req_state,
  113. unsigned int flags)
  114. {
  115. int ret = 0;
  116. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  117. ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, cur_state,
  118. req_state, flags);
  119. return ret;
  120. }
  121. unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, void *lock,
  122. unsigned int cur_state)
  123. {
  124. int ret = 0;
  125. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  126. ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state);
  127. return ret;
  128. }
  129. void gfs2_lm_cancel(struct gfs2_sbd *sdp, void *lock)
  130. {
  131. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  132. sdp->sd_lockstruct.ls_ops->lm_cancel(lock);
  133. }
  134. int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, void *lock, char **lvbp)
  135. {
  136. int error = -EIO;
  137. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  138. error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp);
  139. return error;
  140. }
  141. void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, void *lock, char *lvb)
  142. {
  143. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  144. sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb);
  145. }
  146. int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name,
  147. struct file *file, struct file_lock *fl)
  148. {
  149. int error = -EIO;
  150. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  151. error = sdp->sd_lockstruct.ls_ops->lm_plock_get(
  152. sdp->sd_lockstruct.ls_lockspace, name, file, fl);
  153. return error;
  154. }
  155. int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name,
  156. struct file *file, int cmd, struct file_lock *fl)
  157. {
  158. int error = -EIO;
  159. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  160. error = sdp->sd_lockstruct.ls_ops->lm_plock(
  161. sdp->sd_lockstruct.ls_lockspace, name, file, cmd, fl);
  162. return error;
  163. }
  164. int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name,
  165. struct file *file, struct file_lock *fl)
  166. {
  167. int error = -EIO;
  168. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  169. error = sdp->sd_lockstruct.ls_ops->lm_punlock(
  170. sdp->sd_lockstruct.ls_lockspace, name, file, fl);
  171. return error;
  172. }
  173. void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid,
  174. unsigned int message)
  175. {
  176. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  177. sdp->sd_lockstruct.ls_ops->lm_recovery_done(
  178. sdp->sd_lockstruct.ls_lockspace, jid, message);
  179. }