diff options
Diffstat (limited to 'fs/gfs2/lm.c')
-rw-r--r-- | fs/gfs2/lm.c | 238 |
1 files changed, 238 insertions, 0 deletions
diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c new file mode 100644 index 000000000000..3df8fa00442d --- /dev/null +++ b/fs/gfs2/lm.c | |||
@@ -0,0 +1,238 @@ | |||
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 | |||
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> | ||
17 | |||
18 | #include "gfs2.h" | ||
19 | #include "glock.h" | ||
20 | #include "lm.h" | ||
21 | #include "super.h" | ||
22 | |||
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 | |||
32 | int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent) | ||
33 | { | ||
34 | char *proto = sdp->sd_proto_name; | ||
35 | char *table = sdp->sd_table_name; | ||
36 | int flags = 0; | ||
37 | int error; | ||
38 | |||
39 | if (sdp->sd_args.ar_spectator) | ||
40 | flags |= LM_MFLAG_SPECTATOR; | ||
41 | |||
42 | fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table); | ||
43 | |||
44 | error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata, | ||
45 | gfs2_glock_cb, sdp, | ||
46 | GFS2_MIN_LVB_SIZE, flags, | ||
47 | &sdp->sd_lockstruct, &sdp->sd_kobj); | ||
48 | if (error) { | ||
49 | fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n", | ||
50 | proto, table, sdp->sd_args.ar_hostdata); | ||
51 | goto out; | ||
52 | } | ||
53 | |||
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 >= | ||
57 | GFS2_MIN_LVB_SIZE)) { | ||
58 | gfs2_unmount_lockproto(&sdp->sd_lockstruct); | ||
59 | goto out; | ||
60 | } | ||
61 | |||
62 | if (sdp->sd_args.ar_spectator) | ||
63 | snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table); | ||
64 | else | ||
65 | snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table, | ||
66 | sdp->sd_lockstruct.ls_jid); | ||
67 | |||
68 | fs_info(sdp, "Joined cluster. Now mounting FS...\n"); | ||
69 | |||
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; | ||
74 | } | ||
75 | |||
76 | out: | ||
77 | return error; | ||
78 | } | ||
79 | |||
80 | void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp) | ||
81 | { | ||
82 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
83 | sdp->sd_lockstruct.ls_ops->lm_others_may_mount( | ||
84 | sdp->sd_lockstruct.ls_lockspace); | ||
85 | } | ||
86 | |||
87 | void gfs2_lm_unmount(struct gfs2_sbd *sdp) | ||
88 | { | ||
89 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
90 | gfs2_unmount_lockproto(&sdp->sd_lockstruct); | ||
91 | } | ||
92 | |||
93 | int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) | ||
94 | { | ||
95 | va_list args; | ||
96 | |||
97 | if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags)) | ||
98 | return 0; | ||
99 | |||
100 | va_start(args, fmt); | ||
101 | vprintk(fmt, args); | ||
102 | va_end(args); | ||
103 | |||
104 | fs_err(sdp, "about to withdraw from the cluster\n"); | ||
105 | BUG_ON(sdp->sd_args.ar_debug); | ||
106 | |||
107 | |||
108 | fs_err(sdp, "waiting for outstanding I/O\n"); | ||
109 | |||
110 | /* FIXME: suspend dm device so oustanding bio's complete | ||
111 | and all further io requests fail */ | ||
112 | |||
113 | fs_err(sdp, "telling LM to withdraw\n"); | ||
114 | gfs2_withdraw_lockproto(&sdp->sd_lockstruct); | ||
115 | fs_err(sdp, "withdrawn\n"); | ||
116 | dump_stack(); | ||
117 | |||
118 | return -1; | ||
119 | } | ||
120 | |||
121 | int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name, | ||
122 | lm_lock_t **lockp) | ||
123 | { | ||
124 | int error; | ||
125 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
126 | error = -EIO; | ||
127 | else | ||
128 | error = sdp->sd_lockstruct.ls_ops->lm_get_lock( | ||
129 | sdp->sd_lockstruct.ls_lockspace, name, lockp); | ||
130 | return error; | ||
131 | } | ||
132 | |||
133 | void gfs2_lm_put_lock(struct gfs2_sbd *sdp, lm_lock_t *lock) | ||
134 | { | ||
135 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
136 | sdp->sd_lockstruct.ls_ops->lm_put_lock(lock); | ||
137 | } | ||
138 | |||
139 | unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock, | ||
140 | unsigned int cur_state, unsigned int req_state, | ||
141 | unsigned int flags) | ||
142 | { | ||
143 | int ret; | ||
144 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
145 | ret = 0; | ||
146 | else | ||
147 | ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, | ||
148 | cur_state, | ||
149 | req_state, flags); | ||
150 | return ret; | ||
151 | } | ||
152 | |||
153 | unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock, | ||
154 | unsigned int cur_state) | ||
155 | { | ||
156 | int ret; | ||
157 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
158 | ret = 0; | ||
159 | else | ||
160 | ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state); | ||
161 | return ret; | ||
162 | } | ||
163 | |||
164 | void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock) | ||
165 | { | ||
166 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
167 | sdp->sd_lockstruct.ls_ops->lm_cancel(lock); | ||
168 | } | ||
169 | |||
170 | int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp) | ||
171 | { | ||
172 | int error; | ||
173 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
174 | error = -EIO; | ||
175 | else | ||
176 | error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp); | ||
177 | return error; | ||
178 | } | ||
179 | |||
180 | void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) | ||
181 | { | ||
182 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
183 | sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb); | ||
184 | } | ||
185 | |||
186 | void gfs2_lm_sync_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) | ||
187 | { | ||
188 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
189 | sdp->sd_lockstruct.ls_ops->lm_sync_lvb(lock, lvb); | ||
190 | } | ||
191 | |||
192 | int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, | ||
193 | struct file *file, struct file_lock *fl) | ||
194 | { | ||
195 | int error; | ||
196 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
197 | error = -EIO; | ||
198 | else | ||
199 | error = sdp->sd_lockstruct.ls_ops->lm_plock_get( | ||
200 | sdp->sd_lockstruct.ls_lockspace, | ||
201 | name, file, fl); | ||
202 | return error; | ||
203 | } | ||
204 | |||
205 | int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name, | ||
206 | struct file *file, int cmd, struct file_lock *fl) | ||
207 | { | ||
208 | int error; | ||
209 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
210 | error = -EIO; | ||
211 | else | ||
212 | error = sdp->sd_lockstruct.ls_ops->lm_plock( | ||
213 | sdp->sd_lockstruct.ls_lockspace, | ||
214 | name, file, cmd, fl); | ||
215 | return error; | ||
216 | } | ||
217 | |||
218 | int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name, | ||
219 | struct file *file, struct file_lock *fl) | ||
220 | { | ||
221 | int error; | ||
222 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
223 | error = -EIO; | ||
224 | else | ||
225 | error = sdp->sd_lockstruct.ls_ops->lm_punlock( | ||
226 | sdp->sd_lockstruct.ls_lockspace, | ||
227 | name, file, fl); | ||
228 | return error; | ||
229 | } | ||
230 | |||
231 | void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid, | ||
232 | unsigned int message) | ||
233 | { | ||
234 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
235 | sdp->sd_lockstruct.ls_ops->lm_recovery_done( | ||
236 | sdp->sd_lockstruct.ls_lockspace, jid, message); | ||
237 | } | ||
238 | |||