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.
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 <linux/lm_interface.h>
27 * gfs2_lm_mount - mount a locking protocol
28 * @sdp: the filesystem
29 * @args: mount arguements
30 * @silent: if 1, don't complain if the FS isn't a GFS2 fs
35 int gfs2_lm_mount(struct gfs2_sbd
*sdp
, int silent
)
37 char *proto
= sdp
->sd_proto_name
;
38 char *table
= sdp
->sd_table_name
;
42 if (sdp
->sd_args
.ar_spectator
)
43 flags
|= LM_MFLAG_SPECTATOR
;
45 fs_info(sdp
, "Trying to join cluster \"%s\", \"%s\"\n", proto
, table
);
47 error
= gfs2_mount_lockproto(proto
, table
, sdp
->sd_args
.ar_hostdata
,
49 GFS2_MIN_LVB_SIZE
, flags
,
50 &sdp
->sd_lockstruct
, &sdp
->sd_kobj
);
52 fs_info(sdp
, "can't mount proto=%s, table=%s, hostdata=%s\n",
53 proto
, table
, sdp
->sd_args
.ar_hostdata
);
57 if (gfs2_assert_warn(sdp
, sdp
->sd_lockstruct
.ls_lockspace
) ||
58 gfs2_assert_warn(sdp
, sdp
->sd_lockstruct
.ls_ops
) ||
59 gfs2_assert_warn(sdp
, sdp
->sd_lockstruct
.ls_lvb_size
>=
61 gfs2_unmount_lockproto(&sdp
->sd_lockstruct
);
65 if (sdp
->sd_args
.ar_spectator
)
66 snprintf(sdp
->sd_fsname
, GFS2_FSNAME_LEN
, "%s.s", table
);
68 snprintf(sdp
->sd_fsname
, GFS2_FSNAME_LEN
, "%s.%u", table
,
69 sdp
->sd_lockstruct
.ls_jid
);
71 fs_info(sdp
, "Joined cluster. Now mounting FS...\n");
73 if ((sdp
->sd_lockstruct
.ls_flags
& LM_LSFLAG_LOCAL
) &&
74 !sdp
->sd_args
.ar_ignore_local_fs
) {
75 sdp
->sd_args
.ar_localflocks
= 1;
76 sdp
->sd_args
.ar_localcaching
= 1;
83 void gfs2_lm_others_may_mount(struct gfs2_sbd
*sdp
)
85 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
86 sdp
->sd_lockstruct
.ls_ops
->lm_others_may_mount(
87 sdp
->sd_lockstruct
.ls_lockspace
);
90 void gfs2_lm_unmount(struct gfs2_sbd
*sdp
)
92 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
93 gfs2_unmount_lockproto(&sdp
->sd_lockstruct
);
96 int gfs2_lm_withdraw(struct gfs2_sbd
*sdp
, char *fmt
, ...)
100 if (test_and_set_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
))
107 fs_err(sdp
, "about to withdraw this file system\n");
108 BUG_ON(sdp
->sd_args
.ar_debug
);
110 fs_err(sdp
, "telling LM to withdraw\n");
111 gfs2_withdraw_lockproto(&sdp
->sd_lockstruct
);
112 fs_err(sdp
, "withdrawn\n");
118 int gfs2_lm_get_lock(struct gfs2_sbd
*sdp
, struct lm_lockname
*name
,
122 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
123 error
= sdp
->sd_lockstruct
.ls_ops
->lm_get_lock(
124 sdp
->sd_lockstruct
.ls_lockspace
, name
, lockp
);
128 void gfs2_lm_put_lock(struct gfs2_sbd
*sdp
, void *lock
)
130 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
131 sdp
->sd_lockstruct
.ls_ops
->lm_put_lock(lock
);
134 unsigned int gfs2_lm_lock(struct gfs2_sbd
*sdp
, void *lock
,
135 unsigned int cur_state
, unsigned int req_state
,
139 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
140 ret
= sdp
->sd_lockstruct
.ls_ops
->lm_lock(lock
, cur_state
,
145 unsigned int gfs2_lm_unlock(struct gfs2_sbd
*sdp
, void *lock
,
146 unsigned int cur_state
)
149 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
150 ret
= sdp
->sd_lockstruct
.ls_ops
->lm_unlock(lock
, cur_state
);
154 void gfs2_lm_cancel(struct gfs2_sbd
*sdp
, void *lock
)
156 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
157 sdp
->sd_lockstruct
.ls_ops
->lm_cancel(lock
);
160 int gfs2_lm_hold_lvb(struct gfs2_sbd
*sdp
, void *lock
, char **lvbp
)
163 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
164 error
= sdp
->sd_lockstruct
.ls_ops
->lm_hold_lvb(lock
, lvbp
);
168 void gfs2_lm_unhold_lvb(struct gfs2_sbd
*sdp
, void *lock
, char *lvb
)
170 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
171 sdp
->sd_lockstruct
.ls_ops
->lm_unhold_lvb(lock
, lvb
);
174 int gfs2_lm_plock_get(struct gfs2_sbd
*sdp
, struct lm_lockname
*name
,
175 struct file
*file
, struct file_lock
*fl
)
178 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
179 error
= sdp
->sd_lockstruct
.ls_ops
->lm_plock_get(
180 sdp
->sd_lockstruct
.ls_lockspace
, name
, file
, fl
);
184 int gfs2_lm_plock(struct gfs2_sbd
*sdp
, struct lm_lockname
*name
,
185 struct file
*file
, int cmd
, struct file_lock
*fl
)
188 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
189 error
= sdp
->sd_lockstruct
.ls_ops
->lm_plock(
190 sdp
->sd_lockstruct
.ls_lockspace
, name
, file
, cmd
, fl
);
194 int gfs2_lm_punlock(struct gfs2_sbd
*sdp
, struct lm_lockname
*name
,
195 struct file
*file
, struct file_lock
*fl
)
198 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
199 error
= sdp
->sd_lockstruct
.ls_ops
->lm_punlock(
200 sdp
->sd_lockstruct
.ls_lockspace
, name
, file
, fl
);
204 void gfs2_lm_recovery_done(struct gfs2_sbd
*sdp
, unsigned int jid
,
205 unsigned int message
)
207 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
208 sdp
->sd_lockstruct
.ls_ops
->lm_recovery_done(
209 sdp
->sd_lockstruct
.ls_lockspace
, jid
, message
);