blob: e30673dd37e017565d801492dda8248754c8e6a8 [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
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>
Steven Whitehouse5c676f62006-02-27 17:23:27 -050016#include <linux/gfs2_ondisk.h>
Fabio Massimo Di Nitto7d308592006-09-19 07:56:29 +020017#include <linux/lm_interface.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000018
19#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050020#include "incore.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000021#include "glock.h"
22#include "lm.h"
23#include "super.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050024#include "util.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000025
26/**
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
31 *
32 * Returns: errno
33 */
34
35int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
36{
37 char *proto = sdp->sd_proto_name;
38 char *table = sdp->sd_table_name;
39 int flags = 0;
40 int error;
41
42 if (sdp->sd_args.ar_spectator)
43 flags |= LM_MFLAG_SPECTATOR;
44
45 fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table);
46
47 error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata,
48 gfs2_glock_cb, sdp,
49 GFS2_MIN_LVB_SIZE, flags,
50 &sdp->sd_lockstruct, &sdp->sd_kobj);
51 if (error) {
52 fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n",
53 proto, table, sdp->sd_args.ar_hostdata);
54 goto out;
55 }
56
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 >=
60 GFS2_MIN_LVB_SIZE)) {
61 gfs2_unmount_lockproto(&sdp->sd_lockstruct);
62 goto out;
63 }
64
65 if (sdp->sd_args.ar_spectator)
66 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table);
67 else
68 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table,
69 sdp->sd_lockstruct.ls_jid);
70
71 fs_info(sdp, "Joined cluster. Now mounting FS...\n");
72
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;
77 }
78
Steven Whitehousea91ea692006-09-04 12:04:26 -040079out:
David Teiglandb3b94fa2006-01-16 16:50:04 +000080 return error;
81}
82
83void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp)
84{
85 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
Steven Whitehouse568f4c92006-02-27 12:00:42 -050086 sdp->sd_lockstruct.ls_ops->lm_others_may_mount(
87 sdp->sd_lockstruct.ls_lockspace);
David Teiglandb3b94fa2006-01-16 16:50:04 +000088}
89
90void gfs2_lm_unmount(struct gfs2_sbd *sdp)
91{
92 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
93 gfs2_unmount_lockproto(&sdp->sd_lockstruct);
94}
95
96int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
97{
98 va_list args;
99
100 if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
101 return 0;
102
103 va_start(args, fmt);
104 vprintk(fmt, args);
105 va_end(args);
106
David Teiglandc3780512006-12-06 11:46:33 -0600107 fs_err(sdp, "about to withdraw this file system\n");
Steven Whitehouse3a8fe9b2006-02-27 11:00:37 -0500108 BUG_ON(sdp->sd_args.ar_debug);
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400109
David Teiglandb3b94fa2006-01-16 16:50:04 +0000110 fs_err(sdp, "telling LM to withdraw\n");
111 gfs2_withdraw_lockproto(&sdp->sd_lockstruct);
112 fs_err(sdp, "withdrawn\n");
113 dump_stack();
114
115 return -1;
116}
117
118int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name,
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400119 void **lockp)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000120{
Steven Whitehouse50299962006-09-04 09:49:55 -0400121 int error = -EIO;
122 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
Steven Whitehouse568f4c92006-02-27 12:00:42 -0500123 error = sdp->sd_lockstruct.ls_ops->lm_get_lock(
124 sdp->sd_lockstruct.ls_lockspace, name, lockp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000125 return error;
126}
127
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400128void gfs2_lm_put_lock(struct gfs2_sbd *sdp, void *lock)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000129{
130 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
131 sdp->sd_lockstruct.ls_ops->lm_put_lock(lock);
132}
133
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400134unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000135 unsigned int cur_state, unsigned int req_state,
136 unsigned int flags)
137{
Steven Whitehouse50299962006-09-04 09:49:55 -0400138 int ret = 0;
139 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
140 ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, cur_state,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000141 req_state, flags);
142 return ret;
143}
144
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400145unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, void *lock,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000146 unsigned int cur_state)
147{
Steven Whitehouse50299962006-09-04 09:49:55 -0400148 int ret = 0;
149 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000150 ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state);
151 return ret;
152}
153
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400154void gfs2_lm_cancel(struct gfs2_sbd *sdp, void *lock)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000155{
156 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
157 sdp->sd_lockstruct.ls_ops->lm_cancel(lock);
158}
159
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400160int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, void *lock, char **lvbp)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000161{
Steven Whitehouse50299962006-09-04 09:49:55 -0400162 int error = -EIO;
163 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000164 error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp);
165 return error;
166}
167
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400168void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, void *lock, char *lvb)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000169{
170 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
171 sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb);
172}
173
David Teiglandb3b94fa2006-01-16 16:50:04 +0000174int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name,
175 struct file *file, struct file_lock *fl)
176{
Steven Whitehouse50299962006-09-04 09:49:55 -0400177 int error = -EIO;
178 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000179 error = sdp->sd_lockstruct.ls_ops->lm_plock_get(
Steven Whitehouse50299962006-09-04 09:49:55 -0400180 sdp->sd_lockstruct.ls_lockspace, name, file, fl);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000181 return error;
182}
183
184int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name,
185 struct file *file, int cmd, struct file_lock *fl)
186{
Steven Whitehouse50299962006-09-04 09:49:55 -0400187 int error = -EIO;
188 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000189 error = sdp->sd_lockstruct.ls_ops->lm_plock(
Steven Whitehouse50299962006-09-04 09:49:55 -0400190 sdp->sd_lockstruct.ls_lockspace, name, file, cmd, fl);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000191 return error;
192}
193
194int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name,
195 struct file *file, struct file_lock *fl)
196{
Steven Whitehouse50299962006-09-04 09:49:55 -0400197 int error = -EIO;
198 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000199 error = sdp->sd_lockstruct.ls_ops->lm_punlock(
Steven Whitehouse50299962006-09-04 09:49:55 -0400200 sdp->sd_lockstruct.ls_lockspace, name, file, fl);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000201 return error;
202}
203
204void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid,
205 unsigned int message)
206{
207 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
Steven Whitehouse568f4c92006-02-27 12:00:42 -0500208 sdp->sd_lockstruct.ls_ops->lm_recovery_done(
209 sdp->sd_lockstruct.ls_lockspace, jid, message);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000210}
211