blob: cfcc39b86a5369287e78b6f658c41374964122ee [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehouse3a8a9a12006-05-18 15:09:15 -04003 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
9
David Teiglandb3b94fa2006-01-16 16:50:04 +000010#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>
Steven Whitehouse5c676f62006-02-27 17:23:27 -050015#include <linux/gfs2_ondisk.h>
Fabio Massimo Di Nitto7d308592006-09-19 07:56:29 +020016#include <linux/lm_interface.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000017
18#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050019#include "incore.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000020#include "glock.h"
21#include "lm.h"
22#include "super.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050023#include "util.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000024
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
34int 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
Steven Whitehousea91ea692006-09-04 12:04:26 -040078out:
David Teiglandb3b94fa2006-01-16 16:50:04 +000079 return error;
80}
81
82void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp)
83{
84 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
Steven Whitehouse568f4c92006-02-27 12:00:42 -050085 sdp->sd_lockstruct.ls_ops->lm_others_may_mount(
86 sdp->sd_lockstruct.ls_lockspace);
David Teiglandb3b94fa2006-01-16 16:50:04 +000087}
88
89void 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
95int 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
David Teiglandc3780512006-12-06 11:46:33 -0600106 fs_err(sdp, "about to withdraw this file system\n");
Steven Whitehouse3a8fe9b2006-02-27 11:00:37 -0500107 BUG_ON(sdp->sd_args.ar_debug);
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400108
David Teiglandb3b94fa2006-01-16 16:50:04 +0000109 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
117int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name,
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400118 void **lockp)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000119{
Steven Whitehouse50299962006-09-04 09:49:55 -0400120 int error = -EIO;
121 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
Steven Whitehouse568f4c92006-02-27 12:00:42 -0500122 error = sdp->sd_lockstruct.ls_ops->lm_get_lock(
123 sdp->sd_lockstruct.ls_lockspace, name, lockp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000124 return error;
125}
126
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400127void gfs2_lm_put_lock(struct gfs2_sbd *sdp, void *lock)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000128{
129 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
130 sdp->sd_lockstruct.ls_ops->lm_put_lock(lock);
131}
132
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400133unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000134 unsigned int cur_state, unsigned int req_state,
135 unsigned int flags)
136{
Steven Whitehouse50299962006-09-04 09:49:55 -0400137 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,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000140 req_state, flags);
141 return ret;
142}
143
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400144unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, void *lock,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000145 unsigned int cur_state)
146{
Steven Whitehouse50299962006-09-04 09:49:55 -0400147 int ret = 0;
148 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000149 ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state);
150 return ret;
151}
152
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400153void gfs2_lm_cancel(struct gfs2_sbd *sdp, void *lock)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000154{
155 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
156 sdp->sd_lockstruct.ls_ops->lm_cancel(lock);
157}
158
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400159int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, void *lock, char **lvbp)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000160{
Steven Whitehouse50299962006-09-04 09:49:55 -0400161 int error = -EIO;
162 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000163 error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp);
164 return error;
165}
166
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400167void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, void *lock, char *lvb)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000168{
169 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
170 sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb);
171}
172
David Teiglandb3b94fa2006-01-16 16:50:04 +0000173int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name,
174 struct file *file, struct file_lock *fl)
175{
Steven Whitehouse50299962006-09-04 09:49:55 -0400176 int error = -EIO;
177 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000178 error = sdp->sd_lockstruct.ls_ops->lm_plock_get(
Steven Whitehouse50299962006-09-04 09:49:55 -0400179 sdp->sd_lockstruct.ls_lockspace, name, file, fl);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000180 return error;
181}
182
183int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name,
184 struct file *file, int cmd, struct file_lock *fl)
185{
Steven Whitehouse50299962006-09-04 09:49:55 -0400186 int error = -EIO;
187 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000188 error = sdp->sd_lockstruct.ls_ops->lm_plock(
Steven Whitehouse50299962006-09-04 09:49:55 -0400189 sdp->sd_lockstruct.ls_lockspace, name, file, cmd, fl);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000190 return error;
191}
192
193int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name,
194 struct file *file, struct file_lock *fl)
195{
Steven Whitehouse50299962006-09-04 09:49:55 -0400196 int error = -EIO;
197 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000198 error = sdp->sd_lockstruct.ls_ops->lm_punlock(
Steven Whitehouse50299962006-09-04 09:49:55 -0400199 sdp->sd_lockstruct.ls_lockspace, name, file, fl);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000200 return error;
201}
202
203void 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)))
Steven Whitehouse568f4c92006-02-27 12:00:42 -0500207 sdp->sd_lockstruct.ls_ops->lm_recovery_done(
208 sdp->sd_lockstruct.ls_lockspace, jid, message);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000209}
210