Merge master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
[linux-2.6] / fs / gfs2 / lm.c
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2006 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 version 2.
8  */
9
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>
17
18 #include "gfs2.h"
19 #include "incore.h"
20 #include "glock.h"
21 #include "lm.h"
22 #include "super.h"
23 #include "util.h"
24
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
30  *
31  * Returns: errno
32  */
33
34 int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
35 {
36         char *proto = sdp->sd_proto_name;
37         char *table = sdp->sd_table_name;
38         int flags = 0;
39         int error;
40
41         if (sdp->sd_args.ar_spectator)
42                 flags |= LM_MFLAG_SPECTATOR;
43
44         fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table);
45
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;
54         }
55
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;
62         }
63
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);
69
70         fs_info(sdp, "Joined cluster. Now mounting FS...\n");
71
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;
76         }
77
78 out:
79         return error;
80 }
81
82 void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp)
83 {
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);
87 }
88
89 void gfs2_lm_unmount(struct gfs2_sbd *sdp)
90 {
91         if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
92                 gfs2_unmount_lockproto(&sdp->sd_lockstruct);
93 }
94
95 int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
96 {
97         va_list args;
98
99         if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
100                 return 0;
101
102         va_start(args, fmt);
103         vprintk(fmt, args);
104         va_end(args);
105
106         fs_err(sdp, "about to withdraw this file system\n");
107         BUG_ON(sdp->sd_args.ar_debug);
108
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();
113
114         return -1;
115 }
116
117 int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name,
118                      void **lockp)
119 {
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;
125 }
126
127 void gfs2_lm_put_lock(struct gfs2_sbd *sdp, void *lock)
128 {
129         if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
130                 sdp->sd_lockstruct.ls_ops->lm_put_lock(lock);
131 }
132
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)
136 {
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;
142 }
143
144 unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, void *lock,
145                             unsigned int cur_state)
146 {
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;
151 }
152
153 void gfs2_lm_cancel(struct gfs2_sbd *sdp, void *lock)
154 {
155         if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
156                 sdp->sd_lockstruct.ls_ops->lm_cancel(lock);
157 }
158
159 int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, void *lock, char **lvbp)
160 {
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;
165 }
166
167 void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, void *lock, char *lvb)
168 {
169         if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
170                 sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb);
171 }
172
173 int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name,
174                       struct file *file, struct file_lock *fl)
175 {
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;
181 }
182
183 int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name,
184                   struct file *file, int cmd, struct file_lock *fl)
185 {
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;
191 }
192
193 int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name,
194                     struct file *file, struct file_lock *fl)
195 {
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;
201 }
202
203 void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid,
204                            unsigned int message)
205 {
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);
209 }
210