2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
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.
10 #include <linux/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <linux/delay.h>
16 #include <asm/semaphore.h>
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
32 int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
34 char *proto = sdp->sd_proto_name;
35 char *table = sdp->sd_table_name;
39 if (sdp->sd_args.ar_spectator)
40 flags |= LM_MFLAG_SPECTATOR;
42 fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table);
44 error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata,
46 GFS2_MIN_LVB_SIZE, flags,
47 &sdp->sd_lockstruct, &sdp->sd_kobj);
49 fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n",
50 proto, table, sdp->sd_args.ar_hostdata);
54 if (gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lockspace) ||
55 gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_ops) ||
56 gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lvb_size >=
58 gfs2_unmount_lockproto(&sdp->sd_lockstruct);
62 if (sdp->sd_args.ar_spectator)
63 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table);
65 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table,
66 sdp->sd_lockstruct.ls_jid);
68 fs_info(sdp, "Joined cluster. Now mounting FS...\n");
70 if ((sdp->sd_lockstruct.ls_flags & LM_LSFLAG_LOCAL) &&
71 !sdp->sd_args.ar_ignore_local_fs) {
72 sdp->sd_args.ar_localflocks = 1;
73 sdp->sd_args.ar_localcaching = 1;
80 void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp)
82 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
83 sdp->sd_lockstruct.ls_ops->lm_others_may_mount(sdp->sd_lockstruct.ls_lockspace);
86 void gfs2_lm_unmount(struct gfs2_sbd *sdp)
88 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
89 gfs2_unmount_lockproto(&sdp->sd_lockstruct);
92 int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
96 if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
103 fs_err(sdp, "about to withdraw from the cluster\n");
104 BUG_ON(sdp->sd_args.ar_debug);
107 fs_err(sdp, "waiting for outstanding I/O\n");
109 /* FIXME: suspend dm device so oustanding bio's complete
110 and all further io requests fail */
112 fs_err(sdp, "telling LM to withdraw\n");
113 gfs2_withdraw_lockproto(&sdp->sd_lockstruct);
114 fs_err(sdp, "withdrawn\n");
120 int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name,
124 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
127 error = sdp->sd_lockstruct.ls_ops->lm_get_lock(sdp->sd_lockstruct.ls_lockspace, name, lockp);
131 void gfs2_lm_put_lock(struct gfs2_sbd *sdp, lm_lock_t *lock)
133 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
134 sdp->sd_lockstruct.ls_ops->lm_put_lock(lock);
137 unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock,
138 unsigned int cur_state, unsigned int req_state,
142 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
145 ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock,
151 unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock,
152 unsigned int cur_state)
155 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
158 ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state);
162 void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock)
164 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
165 sdp->sd_lockstruct.ls_ops->lm_cancel(lock);
168 int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp)
171 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
174 error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp);
178 void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb)
180 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
181 sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb);
184 void gfs2_lm_sync_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb)
186 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
187 sdp->sd_lockstruct.ls_ops->lm_sync_lvb(lock, lvb);
190 int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name,
191 struct file *file, struct file_lock *fl)
194 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
197 error = sdp->sd_lockstruct.ls_ops->lm_plock_get(
198 sdp->sd_lockstruct.ls_lockspace,
203 int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name,
204 struct file *file, int cmd, struct file_lock *fl)
207 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
210 error = sdp->sd_lockstruct.ls_ops->lm_plock(
211 sdp->sd_lockstruct.ls_lockspace,
212 name, file, cmd, fl);
216 int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name,
217 struct file *file, struct file_lock *fl)
220 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
223 error = sdp->sd_lockstruct.ls_ops->lm_punlock(
224 sdp->sd_lockstruct.ls_lockspace,
229 void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid,
230 unsigned int message)
232 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
233 sdp->sd_lockstruct.ls_ops->lm_recovery_done(sdp->sd_lockstruct.ls_lockspace, jid, message);