diff options
author | David Teigland <teigland@redhat.com> | 2006-01-16 11:50:04 -0500 |
---|---|---|
committer | Steven Whitehouse <swhiteho@redhat.com> | 2006-01-16 11:50:04 -0500 |
commit | b3b94faa5fe5968827ba0640ee9fba4b3e7f736e (patch) | |
tree | 70bd6068b050d2c46e338484f8b03fae4365c6c3 /fs/gfs2/lm.c | |
parent | f7825dcf8c7301cfd3724eb40c5b443cc85ab7b8 (diff) |
[GFS2] The core of GFS2
This patch contains all the core files for GFS2.
Signed-off-by: David Teigland <teigland@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2/lm.c')
-rw-r--r-- | fs/gfs2/lm.c | 235 |
1 files changed, 235 insertions, 0 deletions
diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c new file mode 100644 index 000000000000..cc7442261b2e --- /dev/null +++ b/fs/gfs2/lm.c | |||
@@ -0,0 +1,235 @@ | |||
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(sdp->sd_lockstruct.ls_lockspace); | ||
84 | } | ||
85 | |||
86 | void gfs2_lm_unmount(struct gfs2_sbd *sdp) | ||
87 | { | ||
88 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
89 | gfs2_unmount_lockproto(&sdp->sd_lockstruct); | ||
90 | } | ||
91 | |||
92 | int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) | ||
93 | { | ||
94 | va_list args; | ||
95 | |||
96 | if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags)) | ||
97 | return 0; | ||
98 | |||
99 | va_start(args, fmt); | ||
100 | vprintk(fmt, args); | ||
101 | va_end(args); | ||
102 | |||
103 | fs_err(sdp, "about to withdraw from the cluster\n"); | ||
104 | if (sdp->sd_args.ar_debug) | ||
105 | BUG(); | ||
106 | |||
107 | fs_err(sdp, "waiting for outstanding I/O\n"); | ||
108 | |||
109 | /* FIXME: suspend dm device so oustanding bio's complete | ||
110 | and all further io requests fail */ | ||
111 | |||
112 | fs_err(sdp, "telling LM to withdraw\n"); | ||
113 | gfs2_withdraw_lockproto(&sdp->sd_lockstruct); | ||
114 | fs_err(sdp, "withdrawn\n"); | ||
115 | dump_stack(); | ||
116 | |||
117 | return -1; | ||
118 | } | ||
119 | |||
120 | int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name, | ||
121 | lm_lock_t **lockp) | ||
122 | { | ||
123 | int error; | ||
124 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
125 | error = -EIO; | ||
126 | else | ||
127 | error = sdp->sd_lockstruct.ls_ops->lm_get_lock(sdp->sd_lockstruct.ls_lockspace, name, lockp); | ||
128 | return error; | ||
129 | } | ||
130 | |||
131 | void gfs2_lm_put_lock(struct gfs2_sbd *sdp, lm_lock_t *lock) | ||
132 | { | ||
133 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
134 | sdp->sd_lockstruct.ls_ops->lm_put_lock(lock); | ||
135 | } | ||
136 | |||
137 | unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock, | ||
138 | unsigned int cur_state, unsigned int req_state, | ||
139 | unsigned int flags) | ||
140 | { | ||
141 | int ret; | ||
142 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
143 | ret = 0; | ||
144 | else | ||
145 | ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, | ||
146 | cur_state, | ||
147 | req_state, flags); | ||
148 | return ret; | ||
149 | } | ||
150 | |||
151 | unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock, | ||
152 | unsigned int cur_state) | ||
153 | { | ||
154 | int ret; | ||
155 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
156 | ret = 0; | ||
157 | else | ||
158 | ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state); | ||
159 | return ret; | ||
160 | } | ||
161 | |||
162 | void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock) | ||
163 | { | ||
164 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
165 | sdp->sd_lockstruct.ls_ops->lm_cancel(lock); | ||
166 | } | ||
167 | |||
168 | int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp) | ||
169 | { | ||
170 | int error; | ||
171 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
172 | error = -EIO; | ||
173 | else | ||
174 | error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp); | ||
175 | return error; | ||
176 | } | ||
177 | |||
178 | void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) | ||
179 | { | ||
180 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
181 | sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb); | ||
182 | } | ||
183 | |||
184 | void gfs2_lm_sync_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) | ||
185 | { | ||
186 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
187 | sdp->sd_lockstruct.ls_ops->lm_sync_lvb(lock, lvb); | ||
188 | } | ||
189 | |||
190 | int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, | ||
191 | struct file *file, struct file_lock *fl) | ||
192 | { | ||
193 | int error; | ||
194 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
195 | error = -EIO; | ||
196 | else | ||
197 | error = sdp->sd_lockstruct.ls_ops->lm_plock_get( | ||
198 | sdp->sd_lockstruct.ls_lockspace, | ||
199 | name, file, fl); | ||
200 | return error; | ||
201 | } | ||
202 | |||
203 | int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name, | ||
204 | struct file *file, int cmd, struct file_lock *fl) | ||
205 | { | ||
206 | int error; | ||
207 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
208 | error = -EIO; | ||
209 | else | ||
210 | error = sdp->sd_lockstruct.ls_ops->lm_plock( | ||
211 | sdp->sd_lockstruct.ls_lockspace, | ||
212 | name, file, cmd, fl); | ||
213 | return error; | ||
214 | } | ||
215 | |||
216 | int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name, | ||
217 | struct file *file, struct file_lock *fl) | ||
218 | { | ||
219 | int error; | ||
220 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | ||
221 | error = -EIO; | ||
222 | else | ||
223 | error = sdp->sd_lockstruct.ls_ops->lm_punlock( | ||
224 | sdp->sd_lockstruct.ls_lockspace, | ||
225 | name, file, fl); | ||
226 | return error; | ||
227 | } | ||
228 | |||
229 | void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid, | ||
230 | unsigned int message) | ||
231 | { | ||
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); | ||
234 | } | ||
235 | |||