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 | |
| 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 Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 16 | #include <linux/gfs2_ondisk.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 "lm_interface.h" |
| 20 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 21 | #include "glock.h" |
| 22 | #include "lm.h" |
| 23 | #include "super.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 24 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 25 | |
| 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 | |
| 35 | int 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 | |
| 79 | out: |
| 80 | return error; |
| 81 | } |
| 82 | |
| 83 | void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp) |
| 84 | { |
| 85 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 86 | sdp->sd_lockstruct.ls_ops->lm_others_may_mount( |
| 87 | sdp->sd_lockstruct.ls_lockspace); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void 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 | |
| 96 | int 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 | |
| 107 | fs_err(sdp, "about to withdraw from the cluster\n"); |
Steven Whitehouse | 3a8fe9b | 2006-02-27 11:00:37 -0500 | [diff] [blame] | 108 | BUG_ON(sdp->sd_args.ar_debug); |
| 109 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 110 | |
| 111 | fs_err(sdp, "waiting for outstanding I/O\n"); |
| 112 | |
| 113 | /* FIXME: suspend dm device so oustanding bio's complete |
| 114 | and all further io requests fail */ |
| 115 | |
| 116 | fs_err(sdp, "telling LM to withdraw\n"); |
| 117 | gfs2_withdraw_lockproto(&sdp->sd_lockstruct); |
| 118 | fs_err(sdp, "withdrawn\n"); |
| 119 | dump_stack(); |
| 120 | |
| 121 | return -1; |
| 122 | } |
| 123 | |
| 124 | int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name, |
| 125 | lm_lock_t **lockp) |
| 126 | { |
| 127 | int error; |
| 128 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 129 | error = -EIO; |
| 130 | else |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 131 | error = sdp->sd_lockstruct.ls_ops->lm_get_lock( |
| 132 | sdp->sd_lockstruct.ls_lockspace, name, lockp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 133 | return error; |
| 134 | } |
| 135 | |
| 136 | void gfs2_lm_put_lock(struct gfs2_sbd *sdp, lm_lock_t *lock) |
| 137 | { |
| 138 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 139 | sdp->sd_lockstruct.ls_ops->lm_put_lock(lock); |
| 140 | } |
| 141 | |
| 142 | unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock, |
| 143 | unsigned int cur_state, unsigned int req_state, |
| 144 | unsigned int flags) |
| 145 | { |
| 146 | int ret; |
| 147 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 148 | ret = 0; |
| 149 | else |
| 150 | ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, |
| 151 | cur_state, |
| 152 | req_state, flags); |
| 153 | return ret; |
| 154 | } |
| 155 | |
| 156 | unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock, |
| 157 | unsigned int cur_state) |
| 158 | { |
| 159 | int ret; |
| 160 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 161 | ret = 0; |
| 162 | else |
| 163 | ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state); |
| 164 | return ret; |
| 165 | } |
| 166 | |
| 167 | void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock) |
| 168 | { |
| 169 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 170 | sdp->sd_lockstruct.ls_ops->lm_cancel(lock); |
| 171 | } |
| 172 | |
| 173 | int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp) |
| 174 | { |
| 175 | int error; |
| 176 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 177 | error = -EIO; |
| 178 | else |
| 179 | error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp); |
| 180 | return error; |
| 181 | } |
| 182 | |
| 183 | void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) |
| 184 | { |
| 185 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 186 | sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb); |
| 187 | } |
| 188 | |
Adrian Bunk | 08bc2db | 2006-04-28 10:59:12 -0400 | [diff] [blame] | 189 | #if 0 |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 190 | void gfs2_lm_sync_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) |
| 191 | { |
| 192 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 193 | sdp->sd_lockstruct.ls_ops->lm_sync_lvb(lock, lvb); |
| 194 | } |
Adrian Bunk | 08bc2db | 2006-04-28 10:59:12 -0400 | [diff] [blame] | 195 | #endif /* 0 */ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 196 | |
| 197 | int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, |
| 198 | struct file *file, struct file_lock *fl) |
| 199 | { |
| 200 | int error; |
| 201 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 202 | error = -EIO; |
| 203 | else |
| 204 | error = sdp->sd_lockstruct.ls_ops->lm_plock_get( |
| 205 | sdp->sd_lockstruct.ls_lockspace, |
| 206 | name, file, fl); |
| 207 | return error; |
| 208 | } |
| 209 | |
| 210 | int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name, |
| 211 | struct file *file, int cmd, struct file_lock *fl) |
| 212 | { |
| 213 | int error; |
| 214 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 215 | error = -EIO; |
| 216 | else |
| 217 | error = sdp->sd_lockstruct.ls_ops->lm_plock( |
| 218 | sdp->sd_lockstruct.ls_lockspace, |
| 219 | name, file, cmd, fl); |
| 220 | return error; |
| 221 | } |
| 222 | |
| 223 | int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name, |
| 224 | struct file *file, struct file_lock *fl) |
| 225 | { |
| 226 | int error; |
| 227 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 228 | error = -EIO; |
| 229 | else |
| 230 | error = sdp->sd_lockstruct.ls_ops->lm_punlock( |
| 231 | sdp->sd_lockstruct.ls_lockspace, |
| 232 | name, file, fl); |
| 233 | return error; |
| 234 | } |
| 235 | |
| 236 | void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid, |
| 237 | unsigned int message) |
| 238 | { |
| 239 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 240 | sdp->sd_lockstruct.ls_ops->lm_recovery_done( |
| 241 | sdp->sd_lockstruct.ls_lockspace, jid, message); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 242 | } |
| 243 | |