David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 3 | * Copyright (C) 2004-2007 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 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 10 | #include <linux/bio.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 11 | #include <linux/sched.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/spinlock.h> |
| 14 | #include <linux/completion.h> |
| 15 | #include <linux/buffer_head.h> |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 16 | #include <linux/statfs.h> |
| 17 | #include <linux/seq_file.h> |
| 18 | #include <linux/mount.h> |
| 19 | #include <linux/kthread.h> |
| 20 | #include <linux/delay.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 21 | #include <linux/gfs2_ondisk.h> |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 22 | #include <linux/crc32.h> |
| 23 | #include <linux/time.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 24 | |
| 25 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 26 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 27 | #include "bmap.h" |
| 28 | #include "dir.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 29 | #include "glock.h" |
| 30 | #include "glops.h" |
| 31 | #include "inode.h" |
| 32 | #include "log.h" |
| 33 | #include "meta_io.h" |
| 34 | #include "quota.h" |
| 35 | #include "recovery.h" |
| 36 | #include "rgrp.h" |
| 37 | #include "super.h" |
| 38 | #include "trans.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 39 | #include "util.h" |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 40 | #include "sys.h" |
| 41 | #include "eattr.h" |
| 42 | |
| 43 | #define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x) |
| 44 | |
| 45 | enum { |
| 46 | Opt_lockproto, |
| 47 | Opt_locktable, |
| 48 | Opt_hostdata, |
| 49 | Opt_spectator, |
| 50 | Opt_ignore_local_fs, |
| 51 | Opt_localflocks, |
| 52 | Opt_localcaching, |
| 53 | Opt_debug, |
| 54 | Opt_nodebug, |
| 55 | Opt_upgrade, |
| 56 | Opt_acl, |
| 57 | Opt_noacl, |
| 58 | Opt_quota_off, |
| 59 | Opt_quota_account, |
| 60 | Opt_quota_on, |
| 61 | Opt_quota, |
| 62 | Opt_noquota, |
| 63 | Opt_suiddir, |
| 64 | Opt_nosuiddir, |
| 65 | Opt_data_writeback, |
| 66 | Opt_data_ordered, |
| 67 | Opt_meta, |
| 68 | Opt_discard, |
| 69 | Opt_nodiscard, |
| 70 | Opt_commit, |
| 71 | Opt_error, |
| 72 | }; |
| 73 | |
| 74 | static const match_table_t tokens = { |
| 75 | {Opt_lockproto, "lockproto=%s"}, |
| 76 | {Opt_locktable, "locktable=%s"}, |
| 77 | {Opt_hostdata, "hostdata=%s"}, |
| 78 | {Opt_spectator, "spectator"}, |
| 79 | {Opt_ignore_local_fs, "ignore_local_fs"}, |
| 80 | {Opt_localflocks, "localflocks"}, |
| 81 | {Opt_localcaching, "localcaching"}, |
| 82 | {Opt_debug, "debug"}, |
| 83 | {Opt_nodebug, "nodebug"}, |
| 84 | {Opt_upgrade, "upgrade"}, |
| 85 | {Opt_acl, "acl"}, |
| 86 | {Opt_noacl, "noacl"}, |
| 87 | {Opt_quota_off, "quota=off"}, |
| 88 | {Opt_quota_account, "quota=account"}, |
| 89 | {Opt_quota_on, "quota=on"}, |
| 90 | {Opt_quota, "quota"}, |
| 91 | {Opt_noquota, "noquota"}, |
| 92 | {Opt_suiddir, "suiddir"}, |
| 93 | {Opt_nosuiddir, "nosuiddir"}, |
| 94 | {Opt_data_writeback, "data=writeback"}, |
| 95 | {Opt_data_ordered, "data=ordered"}, |
| 96 | {Opt_meta, "meta"}, |
| 97 | {Opt_discard, "discard"}, |
| 98 | {Opt_nodiscard, "nodiscard"}, |
| 99 | {Opt_commit, "commit=%d"}, |
| 100 | {Opt_error, NULL} |
| 101 | }; |
| 102 | |
| 103 | /** |
| 104 | * gfs2_mount_args - Parse mount options |
| 105 | * @sdp: |
| 106 | * @data: |
| 107 | * |
| 108 | * Return: errno |
| 109 | */ |
| 110 | |
| 111 | int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *options) |
| 112 | { |
| 113 | char *o; |
| 114 | int token; |
| 115 | substring_t tmp[MAX_OPT_ARGS]; |
| 116 | int rv; |
| 117 | |
| 118 | /* Split the options into tokens with the "," character and |
| 119 | process them */ |
| 120 | |
| 121 | while (1) { |
| 122 | o = strsep(&options, ","); |
| 123 | if (o == NULL) |
| 124 | break; |
| 125 | if (*o == '\0') |
| 126 | continue; |
| 127 | |
| 128 | token = match_token(o, tokens, tmp); |
| 129 | switch (token) { |
| 130 | case Opt_lockproto: |
| 131 | match_strlcpy(args->ar_lockproto, &tmp[0], |
| 132 | GFS2_LOCKNAME_LEN); |
| 133 | break; |
| 134 | case Opt_locktable: |
| 135 | match_strlcpy(args->ar_locktable, &tmp[0], |
| 136 | GFS2_LOCKNAME_LEN); |
| 137 | break; |
| 138 | case Opt_hostdata: |
| 139 | match_strlcpy(args->ar_hostdata, &tmp[0], |
| 140 | GFS2_LOCKNAME_LEN); |
| 141 | break; |
| 142 | case Opt_spectator: |
| 143 | args->ar_spectator = 1; |
| 144 | break; |
| 145 | case Opt_ignore_local_fs: |
| 146 | args->ar_ignore_local_fs = 1; |
| 147 | break; |
| 148 | case Opt_localflocks: |
| 149 | args->ar_localflocks = 1; |
| 150 | break; |
| 151 | case Opt_localcaching: |
| 152 | args->ar_localcaching = 1; |
| 153 | break; |
| 154 | case Opt_debug: |
| 155 | args->ar_debug = 1; |
| 156 | break; |
| 157 | case Opt_nodebug: |
| 158 | args->ar_debug = 0; |
| 159 | break; |
| 160 | case Opt_upgrade: |
| 161 | args->ar_upgrade = 1; |
| 162 | break; |
| 163 | case Opt_acl: |
| 164 | args->ar_posix_acl = 1; |
| 165 | break; |
| 166 | case Opt_noacl: |
| 167 | args->ar_posix_acl = 0; |
| 168 | break; |
| 169 | case Opt_quota_off: |
| 170 | case Opt_noquota: |
| 171 | args->ar_quota = GFS2_QUOTA_OFF; |
| 172 | break; |
| 173 | case Opt_quota_account: |
| 174 | args->ar_quota = GFS2_QUOTA_ACCOUNT; |
| 175 | break; |
| 176 | case Opt_quota_on: |
| 177 | case Opt_quota: |
| 178 | args->ar_quota = GFS2_QUOTA_ON; |
| 179 | break; |
| 180 | case Opt_suiddir: |
| 181 | args->ar_suiddir = 1; |
| 182 | break; |
| 183 | case Opt_nosuiddir: |
| 184 | args->ar_suiddir = 0; |
| 185 | break; |
| 186 | case Opt_data_writeback: |
| 187 | args->ar_data = GFS2_DATA_WRITEBACK; |
| 188 | break; |
| 189 | case Opt_data_ordered: |
| 190 | args->ar_data = GFS2_DATA_ORDERED; |
| 191 | break; |
| 192 | case Opt_meta: |
| 193 | args->ar_meta = 1; |
| 194 | break; |
| 195 | case Opt_discard: |
| 196 | args->ar_discard = 1; |
| 197 | break; |
| 198 | case Opt_nodiscard: |
| 199 | args->ar_discard = 0; |
| 200 | break; |
| 201 | case Opt_commit: |
| 202 | rv = match_int(&tmp[0], &args->ar_commit); |
| 203 | if (rv || args->ar_commit <= 0) { |
| 204 | fs_info(sdp, "commit mount option requires a positive numeric argument\n"); |
| 205 | return rv ? rv : -EINVAL; |
| 206 | } |
| 207 | break; |
| 208 | case Opt_error: |
| 209 | default: |
| 210 | fs_info(sdp, "invalid mount option: %s\n", o); |
| 211 | return -EINVAL; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | return 0; |
| 216 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 217 | |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame] | 218 | /** |
| 219 | * gfs2_jindex_free - Clear all the journal index information |
| 220 | * @sdp: The GFS2 superblock |
| 221 | * |
| 222 | */ |
| 223 | |
| 224 | void gfs2_jindex_free(struct gfs2_sbd *sdp) |
| 225 | { |
| 226 | struct list_head list, *head; |
| 227 | struct gfs2_jdesc *jd; |
| 228 | struct gfs2_journal_extent *jext; |
| 229 | |
| 230 | spin_lock(&sdp->sd_jindex_spin); |
| 231 | list_add(&list, &sdp->sd_jindex_list); |
| 232 | list_del_init(&sdp->sd_jindex_list); |
| 233 | sdp->sd_journals = 0; |
| 234 | spin_unlock(&sdp->sd_jindex_spin); |
| 235 | |
| 236 | while (!list_empty(&list)) { |
| 237 | jd = list_entry(list.next, struct gfs2_jdesc, jd_list); |
| 238 | head = &jd->extent_list; |
| 239 | while (!list_empty(head)) { |
| 240 | jext = list_entry(head->next, |
| 241 | struct gfs2_journal_extent, |
| 242 | extent_list); |
| 243 | list_del(&jext->extent_list); |
| 244 | kfree(jext); |
| 245 | } |
| 246 | list_del(&jd->jd_list); |
| 247 | iput(jd->jd_inode); |
| 248 | kfree(jd); |
| 249 | } |
| 250 | } |
| 251 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 252 | static struct gfs2_jdesc *jdesc_find_i(struct list_head *head, unsigned int jid) |
| 253 | { |
| 254 | struct gfs2_jdesc *jd; |
| 255 | int found = 0; |
| 256 | |
| 257 | list_for_each_entry(jd, head, jd_list) { |
| 258 | if (jd->jd_jid == jid) { |
| 259 | found = 1; |
| 260 | break; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | if (!found) |
| 265 | jd = NULL; |
| 266 | |
| 267 | return jd; |
| 268 | } |
| 269 | |
| 270 | struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid) |
| 271 | { |
| 272 | struct gfs2_jdesc *jd; |
| 273 | |
| 274 | spin_lock(&sdp->sd_jindex_spin); |
| 275 | jd = jdesc_find_i(&sdp->sd_jindex_list, jid); |
| 276 | spin_unlock(&sdp->sd_jindex_spin); |
| 277 | |
| 278 | return jd; |
| 279 | } |
| 280 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 281 | int gfs2_jdesc_check(struct gfs2_jdesc *jd) |
| 282 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 283 | struct gfs2_inode *ip = GFS2_I(jd->jd_inode); |
| 284 | struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 285 | int ar; |
| 286 | int error; |
| 287 | |
Steven Whitehouse | c9e9888 | 2008-11-04 09:47:33 +0000 | [diff] [blame] | 288 | if (ip->i_disksize < (8 << 20) || ip->i_disksize > (1 << 30) || |
| 289 | (ip->i_disksize & (sdp->sd_sb.sb_bsize - 1))) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 290 | gfs2_consist_inode(ip); |
| 291 | return -EIO; |
| 292 | } |
Steven Whitehouse | c9e9888 | 2008-11-04 09:47:33 +0000 | [diff] [blame] | 293 | jd->jd_blocks = ip->i_disksize >> sdp->sd_sb.sb_bsize_shift; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 294 | |
Steven Whitehouse | c9e9888 | 2008-11-04 09:47:33 +0000 | [diff] [blame] | 295 | error = gfs2_write_alloc_required(ip, 0, ip->i_disksize, &ar); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 296 | if (!error && ar) { |
| 297 | gfs2_consist_inode(ip); |
| 298 | error = -EIO; |
| 299 | } |
| 300 | |
| 301 | return error; |
| 302 | } |
| 303 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 304 | /** |
| 305 | * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one |
| 306 | * @sdp: the filesystem |
| 307 | * |
| 308 | * Returns: errno |
| 309 | */ |
| 310 | |
| 311 | int gfs2_make_fs_rw(struct gfs2_sbd *sdp) |
| 312 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 313 | struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 314 | struct gfs2_glock *j_gl = ip->i_gl; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 315 | struct gfs2_holder t_gh; |
Al Viro | 5516762 | 2006-10-13 21:47:13 -0400 | [diff] [blame] | 316 | struct gfs2_log_header_host head; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 317 | int error; |
| 318 | |
Steven Whitehouse | 1c0f487 | 2007-01-22 12:10:39 -0500 | [diff] [blame] | 319 | error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, 0, &t_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 320 | if (error) |
| 321 | return error; |
| 322 | |
Steven Whitehouse | 1a14d3a | 2006-11-20 10:37:45 -0500 | [diff] [blame] | 323 | j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 324 | |
| 325 | error = gfs2_find_jhead(sdp->sd_jdesc, &head); |
| 326 | if (error) |
| 327 | goto fail; |
| 328 | |
| 329 | if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { |
| 330 | gfs2_consist(sdp); |
| 331 | error = -EIO; |
| 332 | goto fail; |
| 333 | } |
| 334 | |
| 335 | /* Initialize some head of the log stuff */ |
| 336 | sdp->sd_log_sequence = head.lh_sequence + 1; |
| 337 | gfs2_log_pointers_init(sdp, head.lh_blkno); |
| 338 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 339 | error = gfs2_quota_init(sdp); |
| 340 | if (error) |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 341 | goto fail; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 342 | |
| 343 | set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); |
| 344 | |
| 345 | gfs2_glock_dq_uninit(&t_gh); |
| 346 | |
| 347 | return 0; |
| 348 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 349 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 350 | t_gh.gh_flags |= GL_NOCACHE; |
| 351 | gfs2_glock_dq_uninit(&t_gh); |
| 352 | |
| 353 | return error; |
| 354 | } |
| 355 | |
Benjamin Marzinski | 1946f70 | 2009-06-25 15:09:51 -0500 | [diff] [blame^] | 356 | void gfs2_statfs_change_in(struct gfs2_statfs_change_host *sc, const void *buf) |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 357 | { |
| 358 | const struct gfs2_statfs_change *str = buf; |
| 359 | |
| 360 | sc->sc_total = be64_to_cpu(str->sc_total); |
| 361 | sc->sc_free = be64_to_cpu(str->sc_free); |
| 362 | sc->sc_dinodes = be64_to_cpu(str->sc_dinodes); |
| 363 | } |
| 364 | |
| 365 | static void gfs2_statfs_change_out(const struct gfs2_statfs_change_host *sc, void *buf) |
| 366 | { |
| 367 | struct gfs2_statfs_change *str = buf; |
| 368 | |
| 369 | str->sc_total = cpu_to_be64(sc->sc_total); |
| 370 | str->sc_free = cpu_to_be64(sc->sc_free); |
| 371 | str->sc_dinodes = cpu_to_be64(sc->sc_dinodes); |
| 372 | } |
| 373 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 374 | int gfs2_statfs_init(struct gfs2_sbd *sdp) |
| 375 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 376 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 377 | struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 378 | struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 379 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 380 | struct buffer_head *m_bh, *l_bh; |
| 381 | struct gfs2_holder gh; |
| 382 | int error; |
| 383 | |
| 384 | error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, |
| 385 | &gh); |
| 386 | if (error) |
| 387 | return error; |
| 388 | |
| 389 | error = gfs2_meta_inode_buffer(m_ip, &m_bh); |
| 390 | if (error) |
| 391 | goto out; |
| 392 | |
| 393 | if (sdp->sd_args.ar_spectator) { |
| 394 | spin_lock(&sdp->sd_statfs_spin); |
| 395 | gfs2_statfs_change_in(m_sc, m_bh->b_data + |
| 396 | sizeof(struct gfs2_dinode)); |
| 397 | spin_unlock(&sdp->sd_statfs_spin); |
| 398 | } else { |
| 399 | error = gfs2_meta_inode_buffer(l_ip, &l_bh); |
| 400 | if (error) |
| 401 | goto out_m_bh; |
| 402 | |
| 403 | spin_lock(&sdp->sd_statfs_spin); |
| 404 | gfs2_statfs_change_in(m_sc, m_bh->b_data + |
| 405 | sizeof(struct gfs2_dinode)); |
| 406 | gfs2_statfs_change_in(l_sc, l_bh->b_data + |
| 407 | sizeof(struct gfs2_dinode)); |
| 408 | spin_unlock(&sdp->sd_statfs_spin); |
| 409 | |
| 410 | brelse(l_bh); |
| 411 | } |
| 412 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 413 | out_m_bh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 414 | brelse(m_bh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 415 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 416 | gfs2_glock_dq_uninit(&gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 417 | return 0; |
| 418 | } |
| 419 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 420 | void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free, |
| 421 | s64 dinodes) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 422 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 423 | struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 424 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 425 | struct buffer_head *l_bh; |
| 426 | int error; |
| 427 | |
| 428 | error = gfs2_meta_inode_buffer(l_ip, &l_bh); |
| 429 | if (error) |
| 430 | return; |
| 431 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 432 | gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 433 | |
| 434 | spin_lock(&sdp->sd_statfs_spin); |
| 435 | l_sc->sc_total += total; |
| 436 | l_sc->sc_free += free; |
| 437 | l_sc->sc_dinodes += dinodes; |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 438 | gfs2_statfs_change_out(l_sc, l_bh->b_data + sizeof(struct gfs2_dinode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 439 | spin_unlock(&sdp->sd_statfs_spin); |
| 440 | |
| 441 | brelse(l_bh); |
| 442 | } |
| 443 | |
Benjamin Marzinski | 1946f70 | 2009-06-25 15:09:51 -0500 | [diff] [blame^] | 444 | void update_statfs(struct gfs2_sbd *sdp, struct buffer_head *m_bh, |
| 445 | struct buffer_head *l_bh) |
| 446 | { |
| 447 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); |
| 448 | struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); |
| 449 | struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; |
| 450 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
| 451 | |
| 452 | gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1); |
| 453 | |
| 454 | spin_lock(&sdp->sd_statfs_spin); |
| 455 | m_sc->sc_total += l_sc->sc_total; |
| 456 | m_sc->sc_free += l_sc->sc_free; |
| 457 | m_sc->sc_dinodes += l_sc->sc_dinodes; |
| 458 | memset(l_sc, 0, sizeof(struct gfs2_statfs_change)); |
| 459 | memset(l_bh->b_data + sizeof(struct gfs2_dinode), |
| 460 | 0, sizeof(struct gfs2_statfs_change)); |
| 461 | spin_unlock(&sdp->sd_statfs_spin); |
| 462 | |
| 463 | gfs2_trans_add_bh(m_ip->i_gl, m_bh, 1); |
| 464 | gfs2_statfs_change_out(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode)); |
| 465 | } |
| 466 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 467 | int gfs2_statfs_sync(struct gfs2_sbd *sdp) |
| 468 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 469 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); |
| 470 | struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 471 | struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; |
| 472 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 473 | struct gfs2_holder gh; |
| 474 | struct buffer_head *m_bh, *l_bh; |
| 475 | int error; |
| 476 | |
| 477 | error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, |
| 478 | &gh); |
| 479 | if (error) |
| 480 | return error; |
| 481 | |
| 482 | error = gfs2_meta_inode_buffer(m_ip, &m_bh); |
| 483 | if (error) |
| 484 | goto out; |
| 485 | |
| 486 | spin_lock(&sdp->sd_statfs_spin); |
| 487 | gfs2_statfs_change_in(m_sc, m_bh->b_data + |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 488 | sizeof(struct gfs2_dinode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 489 | if (!l_sc->sc_total && !l_sc->sc_free && !l_sc->sc_dinodes) { |
| 490 | spin_unlock(&sdp->sd_statfs_spin); |
| 491 | goto out_bh; |
| 492 | } |
| 493 | spin_unlock(&sdp->sd_statfs_spin); |
| 494 | |
| 495 | error = gfs2_meta_inode_buffer(l_ip, &l_bh); |
| 496 | if (error) |
| 497 | goto out_bh; |
| 498 | |
| 499 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0); |
| 500 | if (error) |
| 501 | goto out_bh2; |
| 502 | |
Benjamin Marzinski | 1946f70 | 2009-06-25 15:09:51 -0500 | [diff] [blame^] | 503 | update_statfs(sdp, m_bh, l_bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 504 | |
| 505 | gfs2_trans_end(sdp); |
| 506 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 507 | out_bh2: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 508 | brelse(l_bh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 509 | out_bh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 510 | brelse(m_bh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 511 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 512 | gfs2_glock_dq_uninit(&gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 513 | return error; |
| 514 | } |
| 515 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 516 | struct lfcc { |
| 517 | struct list_head list; |
| 518 | struct gfs2_holder gh; |
| 519 | }; |
| 520 | |
| 521 | /** |
| 522 | * gfs2_lock_fs_check_clean - Stop all writes to the FS and check that all |
| 523 | * journals are clean |
| 524 | * @sdp: the file system |
| 525 | * @state: the state to put the transaction lock into |
| 526 | * @t_gh: the hold on the transaction lock |
| 527 | * |
| 528 | * Returns: errno |
| 529 | */ |
| 530 | |
Adrian Bunk | 08bc2db | 2006-04-28 10:59:12 -0400 | [diff] [blame] | 531 | static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, |
| 532 | struct gfs2_holder *t_gh) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 533 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 534 | struct gfs2_inode *ip; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 535 | struct gfs2_jdesc *jd; |
| 536 | struct lfcc *lfcc; |
| 537 | LIST_HEAD(list); |
Al Viro | 5516762 | 2006-10-13 21:47:13 -0400 | [diff] [blame] | 538 | struct gfs2_log_header_host lh; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 539 | int error; |
| 540 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 541 | list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { |
| 542 | lfcc = kmalloc(sizeof(struct lfcc), GFP_KERNEL); |
| 543 | if (!lfcc) { |
| 544 | error = -ENOMEM; |
| 545 | goto out; |
| 546 | } |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 547 | ip = GFS2_I(jd->jd_inode); |
| 548 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &lfcc->gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 549 | if (error) { |
| 550 | kfree(lfcc); |
| 551 | goto out; |
| 552 | } |
| 553 | list_add(&lfcc->list, &list); |
| 554 | } |
| 555 | |
| 556 | error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_DEFERRED, |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 557 | GL_NOCACHE, t_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 558 | |
| 559 | list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { |
| 560 | error = gfs2_jdesc_check(jd); |
| 561 | if (error) |
| 562 | break; |
| 563 | error = gfs2_find_jhead(jd, &lh); |
| 564 | if (error) |
| 565 | break; |
| 566 | if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { |
| 567 | error = -EBUSY; |
| 568 | break; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | if (error) |
| 573 | gfs2_glock_dq_uninit(t_gh); |
| 574 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 575 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 576 | while (!list_empty(&list)) { |
| 577 | lfcc = list_entry(list.next, struct lfcc, list); |
| 578 | list_del(&lfcc->list); |
| 579 | gfs2_glock_dq_uninit(&lfcc->gh); |
| 580 | kfree(lfcc); |
| 581 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 582 | return error; |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * gfs2_freeze_fs - freezes the file system |
| 587 | * @sdp: the file system |
| 588 | * |
| 589 | * This function flushes data and meta data for all machines by |
| 590 | * aquiring the transaction log exclusively. All journals are |
| 591 | * ensured to be in a clean state as well. |
| 592 | * |
| 593 | * Returns: errno |
| 594 | */ |
| 595 | |
| 596 | int gfs2_freeze_fs(struct gfs2_sbd *sdp) |
| 597 | { |
| 598 | int error = 0; |
| 599 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 600 | mutex_lock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 601 | |
| 602 | if (!sdp->sd_freeze_count++) { |
| 603 | error = gfs2_lock_fs_check_clean(sdp, &sdp->sd_freeze_gh); |
| 604 | if (error) |
| 605 | sdp->sd_freeze_count--; |
| 606 | } |
| 607 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 608 | mutex_unlock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 609 | |
| 610 | return error; |
| 611 | } |
| 612 | |
| 613 | /** |
| 614 | * gfs2_unfreeze_fs - unfreezes the file system |
| 615 | * @sdp: the file system |
| 616 | * |
| 617 | * This function allows the file system to proceed by unlocking |
| 618 | * the exclusively held transaction lock. Other GFS2 nodes are |
| 619 | * now free to acquire the lock shared and go on with their lives. |
| 620 | * |
| 621 | */ |
| 622 | |
| 623 | void gfs2_unfreeze_fs(struct gfs2_sbd *sdp) |
| 624 | { |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 625 | mutex_lock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 626 | |
| 627 | if (sdp->sd_freeze_count && !--sdp->sd_freeze_count) |
| 628 | gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); |
| 629 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 630 | mutex_unlock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 633 | |
| 634 | /** |
| 635 | * gfs2_write_inode - Make sure the inode is stable on the disk |
| 636 | * @inode: The inode |
| 637 | * @sync: synchronous write flag |
| 638 | * |
| 639 | * Returns: errno |
| 640 | */ |
| 641 | |
| 642 | static int gfs2_write_inode(struct inode *inode, int sync) |
| 643 | { |
| 644 | struct gfs2_inode *ip = GFS2_I(inode); |
| 645 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
| 646 | struct gfs2_holder gh; |
| 647 | struct buffer_head *bh; |
| 648 | struct timespec atime; |
| 649 | struct gfs2_dinode *di; |
| 650 | int ret = 0; |
| 651 | |
| 652 | /* Check this is a "normal" inode, etc */ |
| 653 | if (!test_bit(GIF_USER, &ip->i_flags) || |
| 654 | (current->flags & PF_MEMALLOC)) |
| 655 | return 0; |
| 656 | ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
| 657 | if (ret) |
| 658 | goto do_flush; |
| 659 | ret = gfs2_trans_begin(sdp, RES_DINODE, 0); |
| 660 | if (ret) |
| 661 | goto do_unlock; |
| 662 | ret = gfs2_meta_inode_buffer(ip, &bh); |
| 663 | if (ret == 0) { |
| 664 | di = (struct gfs2_dinode *)bh->b_data; |
| 665 | atime.tv_sec = be64_to_cpu(di->di_atime); |
| 666 | atime.tv_nsec = be32_to_cpu(di->di_atime_nsec); |
| 667 | if (timespec_compare(&inode->i_atime, &atime) > 0) { |
| 668 | gfs2_trans_add_bh(ip->i_gl, bh, 1); |
| 669 | gfs2_dinode_out(ip, bh->b_data); |
| 670 | } |
| 671 | brelse(bh); |
| 672 | } |
| 673 | gfs2_trans_end(sdp); |
| 674 | do_unlock: |
| 675 | gfs2_glock_dq_uninit(&gh); |
| 676 | do_flush: |
| 677 | if (sync != 0) |
| 678 | gfs2_log_flush(GFS2_SB(inode), ip->i_gl); |
| 679 | return ret; |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one |
| 684 | * @sdp: the filesystem |
| 685 | * |
| 686 | * Returns: errno |
| 687 | */ |
| 688 | |
| 689 | static int gfs2_make_fs_ro(struct gfs2_sbd *sdp) |
| 690 | { |
| 691 | struct gfs2_holder t_gh; |
| 692 | int error; |
| 693 | |
| 694 | gfs2_quota_sync(sdp); |
| 695 | gfs2_statfs_sync(sdp); |
| 696 | |
| 697 | error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE, |
| 698 | &t_gh); |
| 699 | if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) |
| 700 | return error; |
| 701 | |
| 702 | gfs2_meta_syncfs(sdp); |
| 703 | gfs2_log_shutdown(sdp); |
| 704 | |
| 705 | clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); |
| 706 | |
| 707 | if (t_gh.gh_gl) |
| 708 | gfs2_glock_dq_uninit(&t_gh); |
| 709 | |
| 710 | gfs2_quota_cleanup(sdp); |
| 711 | |
| 712 | return error; |
| 713 | } |
| 714 | |
| 715 | static int gfs2_umount_recovery_wait(void *word) |
| 716 | { |
| 717 | schedule(); |
| 718 | return 0; |
| 719 | } |
| 720 | |
| 721 | /** |
| 722 | * gfs2_put_super - Unmount the filesystem |
| 723 | * @sb: The VFS superblock |
| 724 | * |
| 725 | */ |
| 726 | |
| 727 | static void gfs2_put_super(struct super_block *sb) |
| 728 | { |
| 729 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 730 | int error; |
| 731 | struct gfs2_jdesc *jd; |
| 732 | |
| 733 | /* Unfreeze the filesystem, if we need to */ |
| 734 | |
| 735 | mutex_lock(&sdp->sd_freeze_lock); |
| 736 | if (sdp->sd_freeze_count) |
| 737 | gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); |
| 738 | mutex_unlock(&sdp->sd_freeze_lock); |
| 739 | |
| 740 | /* No more recovery requests */ |
| 741 | set_bit(SDF_NORECOVERY, &sdp->sd_flags); |
| 742 | smp_mb(); |
| 743 | |
| 744 | /* Wait on outstanding recovery */ |
| 745 | restart: |
| 746 | spin_lock(&sdp->sd_jindex_spin); |
| 747 | list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { |
| 748 | if (!test_bit(JDF_RECOVERY, &jd->jd_flags)) |
| 749 | continue; |
| 750 | spin_unlock(&sdp->sd_jindex_spin); |
| 751 | wait_on_bit(&jd->jd_flags, JDF_RECOVERY, |
| 752 | gfs2_umount_recovery_wait, TASK_UNINTERRUPTIBLE); |
| 753 | goto restart; |
| 754 | } |
| 755 | spin_unlock(&sdp->sd_jindex_spin); |
| 756 | |
| 757 | kthread_stop(sdp->sd_quotad_process); |
| 758 | kthread_stop(sdp->sd_logd_process); |
| 759 | |
| 760 | if (!(sb->s_flags & MS_RDONLY)) { |
| 761 | error = gfs2_make_fs_ro(sdp); |
| 762 | if (error) |
| 763 | gfs2_io_error(sdp); |
| 764 | } |
| 765 | /* At this point, we're through modifying the disk */ |
| 766 | |
| 767 | /* Release stuff */ |
| 768 | |
| 769 | iput(sdp->sd_jindex); |
| 770 | iput(sdp->sd_inum_inode); |
| 771 | iput(sdp->sd_statfs_inode); |
| 772 | iput(sdp->sd_rindex); |
| 773 | iput(sdp->sd_quota_inode); |
| 774 | |
| 775 | gfs2_glock_put(sdp->sd_rename_gl); |
| 776 | gfs2_glock_put(sdp->sd_trans_gl); |
| 777 | |
| 778 | if (!sdp->sd_args.ar_spectator) { |
| 779 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); |
| 780 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); |
| 781 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); |
| 782 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); |
| 783 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); |
| 784 | iput(sdp->sd_ir_inode); |
| 785 | iput(sdp->sd_sc_inode); |
| 786 | iput(sdp->sd_qc_inode); |
| 787 | } |
| 788 | |
| 789 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); |
| 790 | gfs2_clear_rgrpd(sdp); |
| 791 | gfs2_jindex_free(sdp); |
| 792 | /* Take apart glock structures and buffer lists */ |
| 793 | gfs2_gl_hash_clear(sdp); |
| 794 | /* Unmount the locking protocol */ |
| 795 | gfs2_lm_unmount(sdp); |
| 796 | |
| 797 | /* At this point, we're through participating in the lockspace */ |
| 798 | gfs2_sys_fs_del(sdp); |
| 799 | } |
| 800 | |
| 801 | /** |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 802 | * gfs2_sync_fs - sync the filesystem |
| 803 | * @sb: the superblock |
| 804 | * |
| 805 | * Flushes the log to disk. |
| 806 | */ |
| 807 | |
| 808 | static int gfs2_sync_fs(struct super_block *sb, int wait) |
| 809 | { |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 810 | if (wait && sb->s_fs_info) |
| 811 | gfs2_log_flush(sb->s_fs_info, NULL); |
| 812 | return 0; |
| 813 | } |
| 814 | |
| 815 | /** |
| 816 | * gfs2_freeze - prevent further writes to the filesystem |
| 817 | * @sb: the VFS structure for the filesystem |
| 818 | * |
| 819 | */ |
| 820 | |
| 821 | static int gfs2_freeze(struct super_block *sb) |
| 822 | { |
| 823 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 824 | int error; |
| 825 | |
| 826 | if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) |
| 827 | return -EINVAL; |
| 828 | |
| 829 | for (;;) { |
| 830 | error = gfs2_freeze_fs(sdp); |
| 831 | if (!error) |
| 832 | break; |
| 833 | |
| 834 | switch (error) { |
| 835 | case -EBUSY: |
| 836 | fs_err(sdp, "waiting for recovery before freeze\n"); |
| 837 | break; |
| 838 | |
| 839 | default: |
| 840 | fs_err(sdp, "error freezing FS: %d\n", error); |
| 841 | break; |
| 842 | } |
| 843 | |
| 844 | fs_err(sdp, "retrying...\n"); |
| 845 | msleep(1000); |
| 846 | } |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | /** |
| 851 | * gfs2_unfreeze - reallow writes to the filesystem |
| 852 | * @sb: the VFS structure for the filesystem |
| 853 | * |
| 854 | */ |
| 855 | |
| 856 | static int gfs2_unfreeze(struct super_block *sb) |
| 857 | { |
| 858 | gfs2_unfreeze_fs(sb->s_fs_info); |
| 859 | return 0; |
| 860 | } |
| 861 | |
| 862 | /** |
| 863 | * statfs_fill - fill in the sg for a given RG |
| 864 | * @rgd: the RG |
| 865 | * @sc: the sc structure |
| 866 | * |
| 867 | * Returns: 0 on success, -ESTALE if the LVB is invalid |
| 868 | */ |
| 869 | |
| 870 | static int statfs_slow_fill(struct gfs2_rgrpd *rgd, |
| 871 | struct gfs2_statfs_change_host *sc) |
| 872 | { |
| 873 | gfs2_rgrp_verify(rgd); |
| 874 | sc->sc_total += rgd->rd_data; |
| 875 | sc->sc_free += rgd->rd_free; |
| 876 | sc->sc_dinodes += rgd->rd_dinodes; |
| 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | /** |
| 881 | * gfs2_statfs_slow - Stat a filesystem using asynchronous locking |
| 882 | * @sdp: the filesystem |
| 883 | * @sc: the sc info that will be returned |
| 884 | * |
| 885 | * Any error (other than a signal) will cause this routine to fall back |
| 886 | * to the synchronous version. |
| 887 | * |
| 888 | * FIXME: This really shouldn't busy wait like this. |
| 889 | * |
| 890 | * Returns: errno |
| 891 | */ |
| 892 | |
| 893 | static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc) |
| 894 | { |
| 895 | struct gfs2_holder ri_gh; |
| 896 | struct gfs2_rgrpd *rgd_next; |
| 897 | struct gfs2_holder *gha, *gh; |
| 898 | unsigned int slots = 64; |
| 899 | unsigned int x; |
| 900 | int done; |
| 901 | int error = 0, err; |
| 902 | |
| 903 | memset(sc, 0, sizeof(struct gfs2_statfs_change_host)); |
| 904 | gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL); |
| 905 | if (!gha) |
| 906 | return -ENOMEM; |
| 907 | |
| 908 | error = gfs2_rindex_hold(sdp, &ri_gh); |
| 909 | if (error) |
| 910 | goto out; |
| 911 | |
| 912 | rgd_next = gfs2_rgrpd_get_first(sdp); |
| 913 | |
| 914 | for (;;) { |
| 915 | done = 1; |
| 916 | |
| 917 | for (x = 0; x < slots; x++) { |
| 918 | gh = gha + x; |
| 919 | |
| 920 | if (gh->gh_gl && gfs2_glock_poll(gh)) { |
| 921 | err = gfs2_glock_wait(gh); |
| 922 | if (err) { |
| 923 | gfs2_holder_uninit(gh); |
| 924 | error = err; |
| 925 | } else { |
| 926 | if (!error) |
| 927 | error = statfs_slow_fill( |
| 928 | gh->gh_gl->gl_object, sc); |
| 929 | gfs2_glock_dq_uninit(gh); |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | if (gh->gh_gl) |
| 934 | done = 0; |
| 935 | else if (rgd_next && !error) { |
| 936 | error = gfs2_glock_nq_init(rgd_next->rd_gl, |
| 937 | LM_ST_SHARED, |
| 938 | GL_ASYNC, |
| 939 | gh); |
| 940 | rgd_next = gfs2_rgrpd_get_next(rgd_next); |
| 941 | done = 0; |
| 942 | } |
| 943 | |
| 944 | if (signal_pending(current)) |
| 945 | error = -ERESTARTSYS; |
| 946 | } |
| 947 | |
| 948 | if (done) |
| 949 | break; |
| 950 | |
| 951 | yield(); |
| 952 | } |
| 953 | |
| 954 | gfs2_glock_dq_uninit(&ri_gh); |
| 955 | |
| 956 | out: |
| 957 | kfree(gha); |
| 958 | return error; |
| 959 | } |
| 960 | |
| 961 | /** |
| 962 | * gfs2_statfs_i - Do a statfs |
| 963 | * @sdp: the filesystem |
| 964 | * @sg: the sg structure |
| 965 | * |
| 966 | * Returns: errno |
| 967 | */ |
| 968 | |
| 969 | static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc) |
| 970 | { |
| 971 | struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; |
| 972 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
| 973 | |
| 974 | spin_lock(&sdp->sd_statfs_spin); |
| 975 | |
| 976 | *sc = *m_sc; |
| 977 | sc->sc_total += l_sc->sc_total; |
| 978 | sc->sc_free += l_sc->sc_free; |
| 979 | sc->sc_dinodes += l_sc->sc_dinodes; |
| 980 | |
| 981 | spin_unlock(&sdp->sd_statfs_spin); |
| 982 | |
| 983 | if (sc->sc_free < 0) |
| 984 | sc->sc_free = 0; |
| 985 | if (sc->sc_free > sc->sc_total) |
| 986 | sc->sc_free = sc->sc_total; |
| 987 | if (sc->sc_dinodes < 0) |
| 988 | sc->sc_dinodes = 0; |
| 989 | |
| 990 | return 0; |
| 991 | } |
| 992 | |
| 993 | /** |
| 994 | * gfs2_statfs - Gather and return stats about the filesystem |
| 995 | * @sb: The superblock |
| 996 | * @statfsbuf: The buffer |
| 997 | * |
| 998 | * Returns: 0 on success or error code |
| 999 | */ |
| 1000 | |
| 1001 | static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 1002 | { |
| 1003 | struct super_block *sb = dentry->d_inode->i_sb; |
| 1004 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 1005 | struct gfs2_statfs_change_host sc; |
| 1006 | int error; |
| 1007 | |
| 1008 | if (gfs2_tune_get(sdp, gt_statfs_slow)) |
| 1009 | error = gfs2_statfs_slow(sdp, &sc); |
| 1010 | else |
| 1011 | error = gfs2_statfs_i(sdp, &sc); |
| 1012 | |
| 1013 | if (error) |
| 1014 | return error; |
| 1015 | |
| 1016 | buf->f_type = GFS2_MAGIC; |
| 1017 | buf->f_bsize = sdp->sd_sb.sb_bsize; |
| 1018 | buf->f_blocks = sc.sc_total; |
| 1019 | buf->f_bfree = sc.sc_free; |
| 1020 | buf->f_bavail = sc.sc_free; |
| 1021 | buf->f_files = sc.sc_dinodes + sc.sc_free; |
| 1022 | buf->f_ffree = sc.sc_free; |
| 1023 | buf->f_namelen = GFS2_FNAMESIZE; |
| 1024 | |
| 1025 | return 0; |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * gfs2_remount_fs - called when the FS is remounted |
| 1030 | * @sb: the filesystem |
| 1031 | * @flags: the remount flags |
| 1032 | * @data: extra data passed in (not used right now) |
| 1033 | * |
| 1034 | * Returns: errno |
| 1035 | */ |
| 1036 | |
| 1037 | static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) |
| 1038 | { |
| 1039 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 1040 | struct gfs2_args args = sdp->sd_args; /* Default to current settings */ |
| 1041 | struct gfs2_tune *gt = &sdp->sd_tune; |
| 1042 | int error; |
| 1043 | |
| 1044 | spin_lock(>->gt_spin); |
| 1045 | args.ar_commit = gt->gt_log_flush_secs; |
| 1046 | spin_unlock(>->gt_spin); |
| 1047 | error = gfs2_mount_args(sdp, &args, data); |
| 1048 | if (error) |
| 1049 | return error; |
| 1050 | |
| 1051 | /* Not allowed to change locking details */ |
| 1052 | if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) || |
| 1053 | strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) || |
| 1054 | strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata)) |
| 1055 | return -EINVAL; |
| 1056 | |
| 1057 | /* Some flags must not be changed */ |
| 1058 | if (args_neq(&args, &sdp->sd_args, spectator) || |
| 1059 | args_neq(&args, &sdp->sd_args, ignore_local_fs) || |
| 1060 | args_neq(&args, &sdp->sd_args, localflocks) || |
| 1061 | args_neq(&args, &sdp->sd_args, localcaching) || |
| 1062 | args_neq(&args, &sdp->sd_args, meta)) |
| 1063 | return -EINVAL; |
| 1064 | |
| 1065 | if (sdp->sd_args.ar_spectator) |
| 1066 | *flags |= MS_RDONLY; |
| 1067 | |
| 1068 | if ((sb->s_flags ^ *flags) & MS_RDONLY) { |
| 1069 | if (*flags & MS_RDONLY) |
| 1070 | error = gfs2_make_fs_ro(sdp); |
| 1071 | else |
| 1072 | error = gfs2_make_fs_rw(sdp); |
| 1073 | if (error) |
| 1074 | return error; |
| 1075 | } |
| 1076 | |
| 1077 | sdp->sd_args = args; |
| 1078 | if (sdp->sd_args.ar_posix_acl) |
| 1079 | sb->s_flags |= MS_POSIXACL; |
| 1080 | else |
| 1081 | sb->s_flags &= ~MS_POSIXACL; |
| 1082 | spin_lock(>->gt_spin); |
| 1083 | gt->gt_log_flush_secs = args.ar_commit; |
| 1084 | spin_unlock(>->gt_spin); |
| 1085 | |
| 1086 | return 0; |
| 1087 | } |
| 1088 | |
| 1089 | /** |
| 1090 | * gfs2_drop_inode - Drop an inode (test for remote unlink) |
| 1091 | * @inode: The inode to drop |
| 1092 | * |
| 1093 | * If we've received a callback on an iopen lock then its because a |
| 1094 | * remote node tried to deallocate the inode but failed due to this node |
| 1095 | * still having the inode open. Here we mark the link count zero |
| 1096 | * since we know that it must have reached zero if the GLF_DEMOTE flag |
| 1097 | * is set on the iopen glock. If we didn't do a disk read since the |
| 1098 | * remote node removed the final link then we might otherwise miss |
| 1099 | * this event. This check ensures that this node will deallocate the |
| 1100 | * inode's blocks, or alternatively pass the baton on to another |
| 1101 | * node for later deallocation. |
| 1102 | */ |
| 1103 | |
| 1104 | static void gfs2_drop_inode(struct inode *inode) |
| 1105 | { |
| 1106 | struct gfs2_inode *ip = GFS2_I(inode); |
| 1107 | |
| 1108 | if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) { |
| 1109 | struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl; |
| 1110 | if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags)) |
| 1111 | clear_nlink(inode); |
| 1112 | } |
| 1113 | generic_drop_inode(inode); |
| 1114 | } |
| 1115 | |
| 1116 | /** |
| 1117 | * gfs2_clear_inode - Deallocate an inode when VFS is done with it |
| 1118 | * @inode: The VFS inode |
| 1119 | * |
| 1120 | */ |
| 1121 | |
| 1122 | static void gfs2_clear_inode(struct inode *inode) |
| 1123 | { |
| 1124 | struct gfs2_inode *ip = GFS2_I(inode); |
| 1125 | |
| 1126 | /* This tells us its a "real" inode and not one which only |
| 1127 | * serves to contain an address space (see rgrp.c, meta_io.c) |
| 1128 | * which therefore doesn't have its own glocks. |
| 1129 | */ |
| 1130 | if (test_bit(GIF_USER, &ip->i_flags)) { |
| 1131 | ip->i_gl->gl_object = NULL; |
| 1132 | gfs2_glock_put(ip->i_gl); |
| 1133 | ip->i_gl = NULL; |
| 1134 | if (ip->i_iopen_gh.gh_gl) { |
| 1135 | ip->i_iopen_gh.gh_gl->gl_object = NULL; |
| 1136 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); |
| 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | static int is_ancestor(const struct dentry *d1, const struct dentry *d2) |
| 1142 | { |
| 1143 | do { |
| 1144 | if (d1 == d2) |
| 1145 | return 1; |
| 1146 | d1 = d1->d_parent; |
| 1147 | } while (!IS_ROOT(d1)); |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
| 1151 | /** |
| 1152 | * gfs2_show_options - Show mount options for /proc/mounts |
| 1153 | * @s: seq_file structure |
| 1154 | * @mnt: vfsmount |
| 1155 | * |
| 1156 | * Returns: 0 on success or error code |
| 1157 | */ |
| 1158 | |
| 1159 | static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) |
| 1160 | { |
| 1161 | struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info; |
| 1162 | struct gfs2_args *args = &sdp->sd_args; |
| 1163 | int lfsecs; |
| 1164 | |
| 1165 | if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir)) |
| 1166 | seq_printf(s, ",meta"); |
| 1167 | if (args->ar_lockproto[0]) |
| 1168 | seq_printf(s, ",lockproto=%s", args->ar_lockproto); |
| 1169 | if (args->ar_locktable[0]) |
| 1170 | seq_printf(s, ",locktable=%s", args->ar_locktable); |
| 1171 | if (args->ar_hostdata[0]) |
| 1172 | seq_printf(s, ",hostdata=%s", args->ar_hostdata); |
| 1173 | if (args->ar_spectator) |
| 1174 | seq_printf(s, ",spectator"); |
| 1175 | if (args->ar_ignore_local_fs) |
| 1176 | seq_printf(s, ",ignore_local_fs"); |
| 1177 | if (args->ar_localflocks) |
| 1178 | seq_printf(s, ",localflocks"); |
| 1179 | if (args->ar_localcaching) |
| 1180 | seq_printf(s, ",localcaching"); |
| 1181 | if (args->ar_debug) |
| 1182 | seq_printf(s, ",debug"); |
| 1183 | if (args->ar_upgrade) |
| 1184 | seq_printf(s, ",upgrade"); |
| 1185 | if (args->ar_posix_acl) |
| 1186 | seq_printf(s, ",acl"); |
| 1187 | if (args->ar_quota != GFS2_QUOTA_DEFAULT) { |
| 1188 | char *state; |
| 1189 | switch (args->ar_quota) { |
| 1190 | case GFS2_QUOTA_OFF: |
| 1191 | state = "off"; |
| 1192 | break; |
| 1193 | case GFS2_QUOTA_ACCOUNT: |
| 1194 | state = "account"; |
| 1195 | break; |
| 1196 | case GFS2_QUOTA_ON: |
| 1197 | state = "on"; |
| 1198 | break; |
| 1199 | default: |
| 1200 | state = "unknown"; |
| 1201 | break; |
| 1202 | } |
| 1203 | seq_printf(s, ",quota=%s", state); |
| 1204 | } |
| 1205 | if (args->ar_suiddir) |
| 1206 | seq_printf(s, ",suiddir"); |
| 1207 | if (args->ar_data != GFS2_DATA_DEFAULT) { |
| 1208 | char *state; |
| 1209 | switch (args->ar_data) { |
| 1210 | case GFS2_DATA_WRITEBACK: |
| 1211 | state = "writeback"; |
| 1212 | break; |
| 1213 | case GFS2_DATA_ORDERED: |
| 1214 | state = "ordered"; |
| 1215 | break; |
| 1216 | default: |
| 1217 | state = "unknown"; |
| 1218 | break; |
| 1219 | } |
| 1220 | seq_printf(s, ",data=%s", state); |
| 1221 | } |
| 1222 | if (args->ar_discard) |
| 1223 | seq_printf(s, ",discard"); |
| 1224 | lfsecs = sdp->sd_tune.gt_log_flush_secs; |
| 1225 | if (lfsecs != 60) |
| 1226 | seq_printf(s, ",commit=%d", lfsecs); |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | /* |
| 1231 | * We have to (at the moment) hold the inodes main lock to cover |
| 1232 | * the gap between unlocking the shared lock on the iopen lock and |
| 1233 | * taking the exclusive lock. I'd rather do a shared -> exclusive |
| 1234 | * conversion on the iopen lock, but we can change that later. This |
| 1235 | * is safe, just less efficient. |
| 1236 | */ |
| 1237 | |
| 1238 | static void gfs2_delete_inode(struct inode *inode) |
| 1239 | { |
| 1240 | struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; |
| 1241 | struct gfs2_inode *ip = GFS2_I(inode); |
| 1242 | struct gfs2_holder gh; |
| 1243 | int error; |
| 1244 | |
| 1245 | if (!test_bit(GIF_USER, &ip->i_flags)) |
| 1246 | goto out; |
| 1247 | |
| 1248 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
| 1249 | if (unlikely(error)) { |
| 1250 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); |
| 1251 | goto out; |
| 1252 | } |
| 1253 | |
| 1254 | gfs2_glock_dq_wait(&ip->i_iopen_gh); |
| 1255 | gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh); |
| 1256 | error = gfs2_glock_nq(&ip->i_iopen_gh); |
| 1257 | if (error) |
| 1258 | goto out_truncate; |
| 1259 | |
| 1260 | if (S_ISDIR(inode->i_mode) && |
| 1261 | (ip->i_diskflags & GFS2_DIF_EXHASH)) { |
| 1262 | error = gfs2_dir_exhash_dealloc(ip); |
| 1263 | if (error) |
| 1264 | goto out_unlock; |
| 1265 | } |
| 1266 | |
| 1267 | if (ip->i_eattr) { |
| 1268 | error = gfs2_ea_dealloc(ip); |
| 1269 | if (error) |
| 1270 | goto out_unlock; |
| 1271 | } |
| 1272 | |
| 1273 | if (!gfs2_is_stuffed(ip)) { |
| 1274 | error = gfs2_file_dealloc(ip); |
| 1275 | if (error) |
| 1276 | goto out_unlock; |
| 1277 | } |
| 1278 | |
| 1279 | error = gfs2_dinode_dealloc(ip); |
| 1280 | if (error) |
| 1281 | goto out_unlock; |
| 1282 | |
| 1283 | out_truncate: |
| 1284 | error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); |
| 1285 | if (error) |
| 1286 | goto out_unlock; |
| 1287 | /* Needs to be done before glock release & also in a transaction */ |
| 1288 | truncate_inode_pages(&inode->i_data, 0); |
| 1289 | gfs2_trans_end(sdp); |
| 1290 | |
| 1291 | out_unlock: |
| 1292 | if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) |
| 1293 | gfs2_glock_dq(&ip->i_iopen_gh); |
| 1294 | gfs2_holder_uninit(&ip->i_iopen_gh); |
| 1295 | gfs2_glock_dq_uninit(&gh); |
| 1296 | if (error && error != GLR_TRYFAILED && error != -EROFS) |
| 1297 | fs_warn(sdp, "gfs2_delete_inode: %d\n", error); |
| 1298 | out: |
| 1299 | truncate_inode_pages(&inode->i_data, 0); |
| 1300 | clear_inode(inode); |
| 1301 | } |
| 1302 | |
| 1303 | static struct inode *gfs2_alloc_inode(struct super_block *sb) |
| 1304 | { |
| 1305 | struct gfs2_inode *ip; |
| 1306 | |
| 1307 | ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL); |
| 1308 | if (ip) { |
| 1309 | ip->i_flags = 0; |
| 1310 | ip->i_gl = NULL; |
| 1311 | } |
| 1312 | return &ip->i_inode; |
| 1313 | } |
| 1314 | |
| 1315 | static void gfs2_destroy_inode(struct inode *inode) |
| 1316 | { |
| 1317 | kmem_cache_free(gfs2_inode_cachep, inode); |
| 1318 | } |
| 1319 | |
| 1320 | const struct super_operations gfs2_super_ops = { |
| 1321 | .alloc_inode = gfs2_alloc_inode, |
| 1322 | .destroy_inode = gfs2_destroy_inode, |
| 1323 | .write_inode = gfs2_write_inode, |
| 1324 | .delete_inode = gfs2_delete_inode, |
| 1325 | .put_super = gfs2_put_super, |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1326 | .sync_fs = gfs2_sync_fs, |
| 1327 | .freeze_fs = gfs2_freeze, |
| 1328 | .unfreeze_fs = gfs2_unfreeze, |
| 1329 | .statfs = gfs2_statfs, |
| 1330 | .remount_fs = gfs2_remount_fs, |
| 1331 | .clear_inode = gfs2_clear_inode, |
| 1332 | .drop_inode = gfs2_drop_inode, |
| 1333 | .show_options = gfs2_show_options, |
| 1334 | }; |
| 1335 | |