Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / fs / gfs2 / lm.c
blobcfcc39b86a5369287e78b6f658c41374964122ee
1 /*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 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 version 2.
8 */
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>
18 #include "gfs2.h"
19 #include "incore.h"
20 #include "glock.h"
21 #include "lm.h"
22 #include "super.h"
23 #include "util.h"
25 /**
26 * gfs2_lm_mount - mount a locking protocol
27 * @sdp: the filesystem
28 * @args: mount arguements
29 * @silent: if 1, don't complain if the FS isn't a GFS2 fs
31 * Returns: errno
34 int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
36 char *proto = sdp->sd_proto_name;
37 char *table = sdp->sd_table_name;
38 int flags = 0;
39 int error;
41 if (sdp->sd_args.ar_spectator)
42 flags |= LM_MFLAG_SPECTATOR;
44 fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table);
46 error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata,
47 gfs2_glock_cb, sdp,
48 GFS2_MIN_LVB_SIZE, flags,
49 &sdp->sd_lockstruct, &sdp->sd_kobj);
50 if (error) {
51 fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n",
52 proto, table, sdp->sd_args.ar_hostdata);
53 goto out;
56 if (gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lockspace) ||
57 gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_ops) ||
58 gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lvb_size >=
59 GFS2_MIN_LVB_SIZE)) {
60 gfs2_unmount_lockproto(&sdp->sd_lockstruct);
61 goto out;
64 if (sdp->sd_args.ar_spectator)
65 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table);
66 else
67 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table,
68 sdp->sd_lockstruct.ls_jid);
70 fs_info(sdp, "Joined cluster. Now mounting FS...\n");
72 if ((sdp->sd_lockstruct.ls_flags & LM_LSFLAG_LOCAL) &&
73 !sdp->sd_args.ar_ignore_local_fs) {
74 sdp->sd_args.ar_localflocks = 1;
75 sdp->sd_args.ar_localcaching = 1;
78 out:
79 return error;
82 void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp)
84 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
85 sdp->sd_lockstruct.ls_ops->lm_others_may_mount(
86 sdp->sd_lockstruct.ls_lockspace);
89 void gfs2_lm_unmount(struct gfs2_sbd *sdp)
91 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
92 gfs2_unmount_lockproto(&sdp->sd_lockstruct);
95 int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
97 va_list args;
99 if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
100 return 0;
102 va_start(args, fmt);
103 vprintk(fmt, args);
104 va_end(args);
106 fs_err(sdp, "about to withdraw this file system\n");
107 BUG_ON(sdp->sd_args.ar_debug);
109 fs_err(sdp, "telling LM to withdraw\n");
110 gfs2_withdraw_lockproto(&sdp->sd_lockstruct);
111 fs_err(sdp, "withdrawn\n");
112 dump_stack();
114 return -1;
117 int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name,
118 void **lockp)
120 int error = -EIO;
121 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
122 error = sdp->sd_lockstruct.ls_ops->lm_get_lock(
123 sdp->sd_lockstruct.ls_lockspace, name, lockp);
124 return error;
127 void gfs2_lm_put_lock(struct gfs2_sbd *sdp, void *lock)
129 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
130 sdp->sd_lockstruct.ls_ops->lm_put_lock(lock);
133 unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock,
134 unsigned int cur_state, unsigned int req_state,
135 unsigned int flags)
137 int ret = 0;
138 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
139 ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, cur_state,
140 req_state, flags);
141 return ret;
144 unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, void *lock,
145 unsigned int cur_state)
147 int ret = 0;
148 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
149 ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state);
150 return ret;
153 void gfs2_lm_cancel(struct gfs2_sbd *sdp, void *lock)
155 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
156 sdp->sd_lockstruct.ls_ops->lm_cancel(lock);
159 int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, void *lock, char **lvbp)
161 int error = -EIO;
162 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
163 error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp);
164 return error;
167 void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, void *lock, char *lvb)
169 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
170 sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb);
173 int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name,
174 struct file *file, struct file_lock *fl)
176 int error = -EIO;
177 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
178 error = sdp->sd_lockstruct.ls_ops->lm_plock_get(
179 sdp->sd_lockstruct.ls_lockspace, name, file, fl);
180 return error;
183 int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name,
184 struct file *file, int cmd, struct file_lock *fl)
186 int error = -EIO;
187 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
188 error = sdp->sd_lockstruct.ls_ops->lm_plock(
189 sdp->sd_lockstruct.ls_lockspace, name, file, cmd, fl);
190 return error;
193 int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name,
194 struct file *file, struct file_lock *fl)
196 int error = -EIO;
197 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
198 error = sdp->sd_lockstruct.ls_ops->lm_punlock(
199 sdp->sd_lockstruct.ls_lockspace, name, file, fl);
200 return error;
203 void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid,
204 unsigned int message)
206 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
207 sdp->sd_lockstruct.ls_ops->lm_recovery_done(
208 sdp->sd_lockstruct.ls_lockspace, jid, message);