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