David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Steven Whitehouse | 3a8a9a1 | 2006-05-18 15:09:15 -0400 | [diff] [blame] | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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 |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 15 | #include <linux/gfs2_ondisk.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 16 | #include <linux/lm_interface.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 17 | |
| 18 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 19 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 20 | #include "glock.h" |
| 21 | #include "lm.h" |
| 22 | #include "super.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 23 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 78 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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))) |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 85 | sdp->sd_lockstruct.ls_ops->lm_others_may_mount( |
| 86 | sdp->sd_lockstruct.ls_lockspace); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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 | |
David Teigland | c378051 | 2006-12-06 11:46:33 -0600 | [diff] [blame] | 106 | fs_err(sdp, "about to withdraw this file system\n"); |
Steven Whitehouse | 3a8fe9b | 2006-02-27 11:00:37 -0500 | [diff] [blame] | 107 | BUG_ON(sdp->sd_args.ar_debug); |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 108 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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, |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 118 | void **lockp) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 119 | { |
Steven Whitehouse | 5029996 | 2006-09-04 09:49:55 -0400 | [diff] [blame] | 120 | int error = -EIO; |
| 121 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 122 | error = sdp->sd_lockstruct.ls_ops->lm_get_lock( |
| 123 | sdp->sd_lockstruct.ls_lockspace, name, lockp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 124 | return error; |
| 125 | } |
| 126 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 127 | void gfs2_lm_put_lock(struct gfs2_sbd *sdp, void *lock) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 128 | { |
| 129 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 130 | sdp->sd_lockstruct.ls_ops->lm_put_lock(lock); |
| 131 | } |
| 132 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 133 | unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 134 | unsigned int cur_state, unsigned int req_state, |
| 135 | unsigned int flags) |
| 136 | { |
Steven Whitehouse | 5029996 | 2006-09-04 09:49:55 -0400 | [diff] [blame] | 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, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 140 | req_state, flags); |
| 141 | return ret; |
| 142 | } |
| 143 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 144 | unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, void *lock, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 145 | unsigned int cur_state) |
| 146 | { |
Steven Whitehouse | 5029996 | 2006-09-04 09:49:55 -0400 | [diff] [blame] | 147 | int ret = 0; |
| 148 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 149 | ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state); |
| 150 | return ret; |
| 151 | } |
| 152 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 153 | void gfs2_lm_cancel(struct gfs2_sbd *sdp, void *lock) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 154 | { |
| 155 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 156 | sdp->sd_lockstruct.ls_ops->lm_cancel(lock); |
| 157 | } |
| 158 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 159 | int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, void *lock, char **lvbp) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 160 | { |
Steven Whitehouse | 5029996 | 2006-09-04 09:49:55 -0400 | [diff] [blame] | 161 | int error = -EIO; |
| 162 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 163 | error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp); |
| 164 | return error; |
| 165 | } |
| 166 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 167 | void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, void *lock, char *lvb) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 168 | { |
| 169 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 170 | sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb); |
| 171 | } |
| 172 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 173 | int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, |
| 174 | struct file *file, struct file_lock *fl) |
| 175 | { |
Steven Whitehouse | 5029996 | 2006-09-04 09:49:55 -0400 | [diff] [blame] | 176 | int error = -EIO; |
| 177 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 178 | error = sdp->sd_lockstruct.ls_ops->lm_plock_get( |
Steven Whitehouse | 5029996 | 2006-09-04 09:49:55 -0400 | [diff] [blame] | 179 | sdp->sd_lockstruct.ls_lockspace, name, file, fl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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 | { |
Steven Whitehouse | 5029996 | 2006-09-04 09:49:55 -0400 | [diff] [blame] | 186 | int error = -EIO; |
| 187 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 188 | error = sdp->sd_lockstruct.ls_ops->lm_plock( |
Steven Whitehouse | 5029996 | 2006-09-04 09:49:55 -0400 | [diff] [blame] | 189 | sdp->sd_lockstruct.ls_lockspace, name, file, cmd, fl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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 | { |
Steven Whitehouse | 5029996 | 2006-09-04 09:49:55 -0400 | [diff] [blame] | 196 | int error = -EIO; |
| 197 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 198 | error = sdp->sd_lockstruct.ls_ops->lm_punlock( |
Steven Whitehouse | 5029996 | 2006-09-04 09:49:55 -0400 | [diff] [blame] | 199 | sdp->sd_lockstruct.ls_lockspace, name, file, fl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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))) |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 207 | sdp->sd_lockstruct.ls_ops->lm_recovery_done( |
| 208 | sdp->sd_lockstruct.ls_lockspace, jid, message); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 209 | } |
| 210 | |