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 | 091806ed | 2008-04-29 12:35:48 -0500 | [diff] [blame] | 3 | * Copyright (C) 2004-2008 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> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 15 | #include <linux/statfs.h> |
| 16 | #include <linux/seq_file.h> |
| 17 | #include <linux/mount.h> |
| 18 | #include <linux/kthread.h> |
| 19 | #include <linux/delay.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 20 | #include <linux/gfs2_ondisk.h> |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 21 | #include <linux/crc32.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 22 | #include <linux/lm_interface.h> |
Steven Whitehouse | 719ee34 | 2008-09-18 13:53:59 +0100 | [diff] [blame] | 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 "glock.h" |
| 28 | #include "inode.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 29 | #include "log.h" |
| 30 | #include "mount.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 31 | #include "quota.h" |
| 32 | #include "recovery.h" |
| 33 | #include "rgrp.h" |
| 34 | #include "super.h" |
| 35 | #include "sys.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 36 | #include "util.h" |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 37 | #include "trans.h" |
| 38 | #include "dir.h" |
| 39 | #include "eattr.h" |
| 40 | #include "bmap.h" |
Steven Whitehouse | 719ee34 | 2008-09-18 13:53:59 +0100 | [diff] [blame] | 41 | #include "meta_io.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * gfs2_write_inode - Make sure the inode is stable on the disk |
| 45 | * @inode: The inode |
| 46 | * @sync: synchronous write flag |
| 47 | * |
| 48 | * Returns: errno |
| 49 | */ |
| 50 | |
| 51 | static int gfs2_write_inode(struct inode *inode, int sync) |
| 52 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 53 | struct gfs2_inode *ip = GFS2_I(inode); |
Steven Whitehouse | 719ee34 | 2008-09-18 13:53:59 +0100 | [diff] [blame] | 54 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
| 55 | struct gfs2_holder gh; |
| 56 | struct buffer_head *bh; |
| 57 | struct timespec atime; |
| 58 | struct gfs2_dinode *di; |
| 59 | int ret = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 60 | |
Steven Whitehouse | 719ee34 | 2008-09-18 13:53:59 +0100 | [diff] [blame] | 61 | /* Check this is a "normal" inode, etc */ |
| 62 | if (!test_bit(GIF_USER, &ip->i_flags) || |
| 63 | (current->flags & PF_MEMALLOC)) |
| 64 | return 0; |
| 65 | ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
| 66 | if (ret) |
| 67 | goto do_flush; |
| 68 | ret = gfs2_trans_begin(sdp, RES_DINODE, 0); |
| 69 | if (ret) |
| 70 | goto do_unlock; |
| 71 | ret = gfs2_meta_inode_buffer(ip, &bh); |
| 72 | if (ret == 0) { |
| 73 | di = (struct gfs2_dinode *)bh->b_data; |
| 74 | atime.tv_sec = be64_to_cpu(di->di_atime); |
| 75 | atime.tv_nsec = be32_to_cpu(di->di_atime_nsec); |
| 76 | if (timespec_compare(&inode->i_atime, &atime) > 0) { |
| 77 | gfs2_trans_add_bh(ip->i_gl, bh, 1); |
| 78 | gfs2_dinode_out(ip, bh->b_data); |
| 79 | } |
| 80 | brelse(bh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 81 | } |
Steven Whitehouse | 719ee34 | 2008-09-18 13:53:59 +0100 | [diff] [blame] | 82 | gfs2_trans_end(sdp); |
| 83 | do_unlock: |
| 84 | gfs2_glock_dq_uninit(&gh); |
| 85 | do_flush: |
| 86 | if (sync != 0) |
| 87 | gfs2_log_flush(GFS2_SB(inode), ip->i_gl); |
| 88 | return ret; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 92 | * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one |
| 93 | * @sdp: the filesystem |
| 94 | * |
| 95 | * Returns: errno |
| 96 | */ |
| 97 | |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame] | 98 | static int gfs2_make_fs_ro(struct gfs2_sbd *sdp) |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 99 | { |
| 100 | struct gfs2_holder t_gh; |
| 101 | int error; |
| 102 | |
| 103 | gfs2_quota_sync(sdp); |
| 104 | gfs2_statfs_sync(sdp); |
| 105 | |
| 106 | error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE, |
| 107 | &t_gh); |
| 108 | if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) |
| 109 | return error; |
| 110 | |
| 111 | gfs2_meta_syncfs(sdp); |
| 112 | gfs2_log_shutdown(sdp); |
| 113 | |
| 114 | clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); |
| 115 | |
| 116 | if (t_gh.gh_gl) |
| 117 | gfs2_glock_dq_uninit(&t_gh); |
| 118 | |
| 119 | gfs2_quota_cleanup(sdp); |
| 120 | |
| 121 | return error; |
| 122 | } |
| 123 | |
| 124 | /** |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame] | 125 | * gfs2_put_super - Unmount the filesystem |
| 126 | * @sb: The VFS superblock |
| 127 | * |
| 128 | */ |
| 129 | |
| 130 | static void gfs2_put_super(struct super_block *sb) |
| 131 | { |
| 132 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 133 | int error; |
| 134 | |
| 135 | /* Unfreeze the filesystem, if we need to */ |
| 136 | |
| 137 | mutex_lock(&sdp->sd_freeze_lock); |
| 138 | if (sdp->sd_freeze_count) |
| 139 | gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); |
| 140 | mutex_unlock(&sdp->sd_freeze_lock); |
| 141 | |
| 142 | kthread_stop(sdp->sd_quotad_process); |
| 143 | kthread_stop(sdp->sd_logd_process); |
| 144 | kthread_stop(sdp->sd_recoverd_process); |
| 145 | |
| 146 | if (!(sb->s_flags & MS_RDONLY)) { |
| 147 | error = gfs2_make_fs_ro(sdp); |
| 148 | if (error) |
| 149 | gfs2_io_error(sdp); |
| 150 | } |
| 151 | /* At this point, we're through modifying the disk */ |
| 152 | |
| 153 | /* Release stuff */ |
| 154 | |
| 155 | iput(sdp->sd_jindex); |
| 156 | iput(sdp->sd_inum_inode); |
| 157 | iput(sdp->sd_statfs_inode); |
| 158 | iput(sdp->sd_rindex); |
| 159 | iput(sdp->sd_quota_inode); |
| 160 | |
| 161 | gfs2_glock_put(sdp->sd_rename_gl); |
| 162 | gfs2_glock_put(sdp->sd_trans_gl); |
| 163 | |
| 164 | if (!sdp->sd_args.ar_spectator) { |
| 165 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); |
| 166 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); |
| 167 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); |
| 168 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); |
| 169 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); |
| 170 | iput(sdp->sd_ir_inode); |
| 171 | iput(sdp->sd_sc_inode); |
| 172 | iput(sdp->sd_qc_inode); |
| 173 | } |
| 174 | |
| 175 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); |
| 176 | gfs2_clear_rgrpd(sdp); |
| 177 | gfs2_jindex_free(sdp); |
| 178 | /* Take apart glock structures and buffer lists */ |
| 179 | gfs2_gl_hash_clear(sdp); |
| 180 | /* Unmount the locking protocol */ |
| 181 | gfs2_lm_unmount(sdp); |
| 182 | |
| 183 | /* At this point, we're through participating in the lockspace */ |
| 184 | gfs2_sys_fs_del(sdp); |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /** |
Steven Whitehouse | 4a22195 | 2006-11-01 09:57:57 -0500 | [diff] [blame] | 188 | * gfs2_write_super |
| 189 | * @sb: the superblock |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 190 | * |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 191 | */ |
| 192 | |
| 193 | static void gfs2_write_super(struct super_block *sb) |
| 194 | { |
Steven Whitehouse | 4a22195 | 2006-11-01 09:57:57 -0500 | [diff] [blame] | 195 | sb->s_dirt = 0; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * gfs2_sync_fs - sync the filesystem |
| 200 | * @sb: the superblock |
| 201 | * |
| 202 | * Flushes the log to disk. |
| 203 | */ |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 204 | |
Steven Whitehouse | 4a22195 | 2006-11-01 09:57:57 -0500 | [diff] [blame] | 205 | static int gfs2_sync_fs(struct super_block *sb, int wait) |
| 206 | { |
| 207 | sb->s_dirt = 0; |
Bob Peterson | 9171f5a | 2008-06-09 12:08:23 -0500 | [diff] [blame] | 208 | if (wait && sb->s_fs_info) |
Steven Whitehouse | b004157 | 2006-11-23 10:51:34 -0500 | [diff] [blame] | 209 | gfs2_log_flush(sb->s_fs_info, NULL); |
Steven Whitehouse | 4a22195 | 2006-11-01 09:57:57 -0500 | [diff] [blame] | 210 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /** |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 214 | * gfs2_freeze - prevent further writes to the filesystem |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 215 | * @sb: the VFS structure for the filesystem |
| 216 | * |
| 217 | */ |
| 218 | |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 219 | static int gfs2_freeze(struct super_block *sb) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 220 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 221 | struct gfs2_sbd *sdp = sb->s_fs_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 222 | int error; |
| 223 | |
David Teigland | c378051 | 2006-12-06 11:46:33 -0600 | [diff] [blame] | 224 | if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 225 | return -EINVAL; |
David Teigland | c378051 | 2006-12-06 11:46:33 -0600 | [diff] [blame] | 226 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 227 | for (;;) { |
| 228 | error = gfs2_freeze_fs(sdp); |
| 229 | if (!error) |
| 230 | break; |
| 231 | |
| 232 | switch (error) { |
| 233 | case -EBUSY: |
| 234 | fs_err(sdp, "waiting for recovery before freeze\n"); |
| 235 | break; |
| 236 | |
| 237 | default: |
| 238 | fs_err(sdp, "error freezing FS: %d\n", error); |
| 239 | break; |
| 240 | } |
| 241 | |
| 242 | fs_err(sdp, "retrying...\n"); |
| 243 | msleep(1000); |
| 244 | } |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 245 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /** |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 249 | * gfs2_unfreeze - reallow writes to the filesystem |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 250 | * @sb: the VFS structure for the filesystem |
| 251 | * |
| 252 | */ |
| 253 | |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 254 | static int gfs2_unfreeze(struct super_block *sb) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 255 | { |
Steven Whitehouse | 2bdbc5d | 2006-09-05 09:34:20 -0400 | [diff] [blame] | 256 | gfs2_unfreeze_fs(sb->s_fs_info); |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 257 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /** |
Steven Whitehouse | 2bfb644 | 2008-11-26 13:30:49 +0000 | [diff] [blame] | 261 | * statfs_fill - fill in the sg for a given RG |
| 262 | * @rgd: the RG |
| 263 | * @sc: the sc structure |
| 264 | * |
| 265 | * Returns: 0 on success, -ESTALE if the LVB is invalid |
| 266 | */ |
| 267 | |
| 268 | static int statfs_slow_fill(struct gfs2_rgrpd *rgd, |
| 269 | struct gfs2_statfs_change_host *sc) |
| 270 | { |
| 271 | gfs2_rgrp_verify(rgd); |
| 272 | sc->sc_total += rgd->rd_data; |
| 273 | sc->sc_free += rgd->rd_free; |
| 274 | sc->sc_dinodes += rgd->rd_dinodes; |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * gfs2_statfs_slow - Stat a filesystem using asynchronous locking |
| 280 | * @sdp: the filesystem |
| 281 | * @sc: the sc info that will be returned |
| 282 | * |
| 283 | * Any error (other than a signal) will cause this routine to fall back |
| 284 | * to the synchronous version. |
| 285 | * |
| 286 | * FIXME: This really shouldn't busy wait like this. |
| 287 | * |
| 288 | * Returns: errno |
| 289 | */ |
| 290 | |
| 291 | static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc) |
| 292 | { |
| 293 | struct gfs2_holder ri_gh; |
| 294 | struct gfs2_rgrpd *rgd_next; |
| 295 | struct gfs2_holder *gha, *gh; |
| 296 | unsigned int slots = 64; |
| 297 | unsigned int x; |
| 298 | int done; |
| 299 | int error = 0, err; |
| 300 | |
| 301 | memset(sc, 0, sizeof(struct gfs2_statfs_change_host)); |
| 302 | gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL); |
| 303 | if (!gha) |
| 304 | return -ENOMEM; |
| 305 | |
| 306 | error = gfs2_rindex_hold(sdp, &ri_gh); |
| 307 | if (error) |
| 308 | goto out; |
| 309 | |
| 310 | rgd_next = gfs2_rgrpd_get_first(sdp); |
| 311 | |
| 312 | for (;;) { |
| 313 | done = 1; |
| 314 | |
| 315 | for (x = 0; x < slots; x++) { |
| 316 | gh = gha + x; |
| 317 | |
| 318 | if (gh->gh_gl && gfs2_glock_poll(gh)) { |
| 319 | err = gfs2_glock_wait(gh); |
| 320 | if (err) { |
| 321 | gfs2_holder_uninit(gh); |
| 322 | error = err; |
| 323 | } else { |
| 324 | if (!error) |
| 325 | error = statfs_slow_fill( |
| 326 | gh->gh_gl->gl_object, sc); |
| 327 | gfs2_glock_dq_uninit(gh); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | if (gh->gh_gl) |
| 332 | done = 0; |
| 333 | else if (rgd_next && !error) { |
| 334 | error = gfs2_glock_nq_init(rgd_next->rd_gl, |
| 335 | LM_ST_SHARED, |
| 336 | GL_ASYNC, |
| 337 | gh); |
| 338 | rgd_next = gfs2_rgrpd_get_next(rgd_next); |
| 339 | done = 0; |
| 340 | } |
| 341 | |
| 342 | if (signal_pending(current)) |
| 343 | error = -ERESTARTSYS; |
| 344 | } |
| 345 | |
| 346 | if (done) |
| 347 | break; |
| 348 | |
| 349 | yield(); |
| 350 | } |
| 351 | |
| 352 | gfs2_glock_dq_uninit(&ri_gh); |
| 353 | |
| 354 | out: |
| 355 | kfree(gha); |
| 356 | return error; |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * gfs2_statfs_i - Do a statfs |
| 361 | * @sdp: the filesystem |
| 362 | * @sg: the sg structure |
| 363 | * |
| 364 | * Returns: errno |
| 365 | */ |
| 366 | |
| 367 | static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc) |
| 368 | { |
| 369 | struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; |
| 370 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
| 371 | |
| 372 | spin_lock(&sdp->sd_statfs_spin); |
| 373 | |
| 374 | *sc = *m_sc; |
| 375 | sc->sc_total += l_sc->sc_total; |
| 376 | sc->sc_free += l_sc->sc_free; |
| 377 | sc->sc_dinodes += l_sc->sc_dinodes; |
| 378 | |
| 379 | spin_unlock(&sdp->sd_statfs_spin); |
| 380 | |
| 381 | if (sc->sc_free < 0) |
| 382 | sc->sc_free = 0; |
| 383 | if (sc->sc_free > sc->sc_total) |
| 384 | sc->sc_free = sc->sc_total; |
| 385 | if (sc->sc_dinodes < 0) |
| 386 | sc->sc_dinodes = 0; |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | /** |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 392 | * gfs2_statfs - Gather and return stats about the filesystem |
| 393 | * @sb: The superblock |
| 394 | * @statfsbuf: The buffer |
| 395 | * |
| 396 | * Returns: 0 on success or error code |
| 397 | */ |
| 398 | |
Steven Whitehouse | 0c0834a | 2006-07-03 11:38:01 -0400 | [diff] [blame] | 399 | static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 400 | { |
Steven Whitehouse | 0c0834a | 2006-07-03 11:38:01 -0400 | [diff] [blame] | 401 | struct super_block *sb = dentry->d_inode->i_sb; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 402 | struct gfs2_sbd *sdp = sb->s_fs_info; |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 403 | struct gfs2_statfs_change_host sc; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 404 | int error; |
| 405 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 406 | if (gfs2_tune_get(sdp, gt_statfs_slow)) |
| 407 | error = gfs2_statfs_slow(sdp, &sc); |
| 408 | else |
| 409 | error = gfs2_statfs_i(sdp, &sc); |
| 410 | |
| 411 | if (error) |
| 412 | return error; |
| 413 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 414 | buf->f_type = GFS2_MAGIC; |
| 415 | buf->f_bsize = sdp->sd_sb.sb_bsize; |
| 416 | buf->f_blocks = sc.sc_total; |
| 417 | buf->f_bfree = sc.sc_free; |
| 418 | buf->f_bavail = sc.sc_free; |
| 419 | buf->f_files = sc.sc_dinodes + sc.sc_free; |
| 420 | buf->f_ffree = sc.sc_free; |
| 421 | buf->f_namelen = GFS2_FNAMESIZE; |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * gfs2_remount_fs - called when the FS is remounted |
| 428 | * @sb: the filesystem |
| 429 | * @flags: the remount flags |
| 430 | * @data: extra data passed in (not used right now) |
| 431 | * |
| 432 | * Returns: errno |
| 433 | */ |
| 434 | |
| 435 | static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) |
| 436 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 437 | struct gfs2_sbd *sdp = sb->s_fs_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 438 | int error; |
| 439 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 440 | error = gfs2_mount_args(sdp, data, 1); |
| 441 | if (error) |
| 442 | return error; |
| 443 | |
| 444 | if (sdp->sd_args.ar_spectator) |
| 445 | *flags |= MS_RDONLY; |
| 446 | else { |
| 447 | if (*flags & MS_RDONLY) { |
| 448 | if (!(sb->s_flags & MS_RDONLY)) |
| 449 | error = gfs2_make_fs_ro(sdp); |
| 450 | } else if (!(*flags & MS_RDONLY) && |
| 451 | (sb->s_flags & MS_RDONLY)) { |
| 452 | error = gfs2_make_fs_rw(sdp); |
| 453 | } |
| 454 | } |
| 455 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 456 | return error; |
| 457 | } |
| 458 | |
| 459 | /** |
Steven Whitehouse | 3b8249f | 2007-03-16 09:40:31 +0000 | [diff] [blame] | 460 | * gfs2_drop_inode - Drop an inode (test for remote unlink) |
| 461 | * @inode: The inode to drop |
| 462 | * |
| 463 | * If we've received a callback on an iopen lock then its because a |
| 464 | * remote node tried to deallocate the inode but failed due to this node |
| 465 | * still having the inode open. Here we mark the link count zero |
| 466 | * since we know that it must have reached zero if the GLF_DEMOTE flag |
| 467 | * is set on the iopen glock. If we didn't do a disk read since the |
| 468 | * remote node removed the final link then we might otherwise miss |
| 469 | * this event. This check ensures that this node will deallocate the |
| 470 | * inode's blocks, or alternatively pass the baton on to another |
| 471 | * node for later deallocation. |
| 472 | */ |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 473 | |
Steven Whitehouse | 3b8249f | 2007-03-16 09:40:31 +0000 | [diff] [blame] | 474 | static void gfs2_drop_inode(struct inode *inode) |
| 475 | { |
Bob Peterson | 091806ed | 2008-04-29 12:35:48 -0500 | [diff] [blame] | 476 | struct gfs2_inode *ip = GFS2_I(inode); |
| 477 | |
| 478 | if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) { |
Steven Whitehouse | 3b8249f | 2007-03-16 09:40:31 +0000 | [diff] [blame] | 479 | struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl; |
| 480 | if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags)) |
| 481 | clear_nlink(inode); |
| 482 | } |
| 483 | generic_drop_inode(inode); |
| 484 | } |
| 485 | |
| 486 | /** |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 487 | * gfs2_clear_inode - Deallocate an inode when VFS is done with it |
| 488 | * @inode: The VFS inode |
| 489 | * |
| 490 | */ |
| 491 | |
| 492 | static void gfs2_clear_inode(struct inode *inode) |
| 493 | { |
Bob Peterson | 091806ed | 2008-04-29 12:35:48 -0500 | [diff] [blame] | 494 | struct gfs2_inode *ip = GFS2_I(inode); |
| 495 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 496 | /* This tells us its a "real" inode and not one which only |
| 497 | * serves to contain an address space (see rgrp.c, meta_io.c) |
| 498 | * which therefore doesn't have its own glocks. |
| 499 | */ |
Bob Peterson | 091806ed | 2008-04-29 12:35:48 -0500 | [diff] [blame] | 500 | if (test_bit(GIF_USER, &ip->i_flags)) { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 501 | ip->i_gl->gl_object = NULL; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 502 | gfs2_glock_put(ip->i_gl); |
| 503 | ip->i_gl = NULL; |
Abhijith Das | d93cfa9 | 2007-06-11 08:22:32 +0100 | [diff] [blame] | 504 | if (ip->i_iopen_gh.gh_gl) { |
| 505 | ip->i_iopen_gh.gh_gl->gl_object = NULL; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 506 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); |
Abhijith Das | d93cfa9 | 2007-06-11 08:22:32 +0100 | [diff] [blame] | 507 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 511 | static int is_ancestor(const struct dentry *d1, const struct dentry *d2) |
| 512 | { |
| 513 | do { |
| 514 | if (d1 == d2) |
| 515 | return 1; |
| 516 | d1 = d1->d_parent; |
| 517 | } while (!IS_ROOT(d1)); |
| 518 | return 0; |
| 519 | } |
| 520 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 521 | /** |
| 522 | * gfs2_show_options - Show mount options for /proc/mounts |
| 523 | * @s: seq_file structure |
| 524 | * @mnt: vfsmount |
| 525 | * |
| 526 | * Returns: 0 on success or error code |
| 527 | */ |
| 528 | |
| 529 | static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) |
| 530 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 531 | struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 532 | struct gfs2_args *args = &sdp->sd_args; |
| 533 | |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 534 | if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir)) |
| 535 | seq_printf(s, ",meta"); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 536 | if (args->ar_lockproto[0]) |
| 537 | seq_printf(s, ",lockproto=%s", args->ar_lockproto); |
| 538 | if (args->ar_locktable[0]) |
| 539 | seq_printf(s, ",locktable=%s", args->ar_locktable); |
| 540 | if (args->ar_hostdata[0]) |
| 541 | seq_printf(s, ",hostdata=%s", args->ar_hostdata); |
| 542 | if (args->ar_spectator) |
| 543 | seq_printf(s, ",spectator"); |
| 544 | if (args->ar_ignore_local_fs) |
| 545 | seq_printf(s, ",ignore_local_fs"); |
| 546 | if (args->ar_localflocks) |
| 547 | seq_printf(s, ",localflocks"); |
| 548 | if (args->ar_localcaching) |
| 549 | seq_printf(s, ",localcaching"); |
| 550 | if (args->ar_debug) |
| 551 | seq_printf(s, ",debug"); |
| 552 | if (args->ar_upgrade) |
| 553 | seq_printf(s, ",upgrade"); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 554 | if (args->ar_posix_acl) |
| 555 | seq_printf(s, ",acl"); |
| 556 | if (args->ar_quota != GFS2_QUOTA_DEFAULT) { |
| 557 | char *state; |
| 558 | switch (args->ar_quota) { |
| 559 | case GFS2_QUOTA_OFF: |
| 560 | state = "off"; |
| 561 | break; |
| 562 | case GFS2_QUOTA_ACCOUNT: |
| 563 | state = "account"; |
| 564 | break; |
| 565 | case GFS2_QUOTA_ON: |
| 566 | state = "on"; |
| 567 | break; |
| 568 | default: |
| 569 | state = "unknown"; |
| 570 | break; |
| 571 | } |
| 572 | seq_printf(s, ",quota=%s", state); |
| 573 | } |
| 574 | if (args->ar_suiddir) |
| 575 | seq_printf(s, ",suiddir"); |
| 576 | if (args->ar_data != GFS2_DATA_DEFAULT) { |
| 577 | char *state; |
| 578 | switch (args->ar_data) { |
| 579 | case GFS2_DATA_WRITEBACK: |
| 580 | state = "writeback"; |
| 581 | break; |
| 582 | case GFS2_DATA_ORDERED: |
| 583 | state = "ordered"; |
| 584 | break; |
| 585 | default: |
| 586 | state = "unknown"; |
| 587 | break; |
| 588 | } |
| 589 | seq_printf(s, ",data=%s", state); |
| 590 | } |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 595 | /* |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 596 | * We have to (at the moment) hold the inodes main lock to cover |
| 597 | * the gap between unlocking the shared lock on the iopen lock and |
| 598 | * taking the exclusive lock. I'd rather do a shared -> exclusive |
| 599 | * conversion on the iopen lock, but we can change that later. This |
| 600 | * is safe, just less efficient. |
| 601 | */ |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 602 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 603 | static void gfs2_delete_inode(struct inode *inode) |
| 604 | { |
| 605 | struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; |
| 606 | struct gfs2_inode *ip = GFS2_I(inode); |
| 607 | struct gfs2_holder gh; |
| 608 | int error; |
| 609 | |
Bob Peterson | 091806ed | 2008-04-29 12:35:48 -0500 | [diff] [blame] | 610 | if (!test_bit(GIF_USER, &ip->i_flags)) |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 611 | goto out; |
| 612 | |
Abhijith Das | d93cfa9 | 2007-06-11 08:22:32 +0100 | [diff] [blame] | 613 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 614 | if (unlikely(error)) { |
| 615 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); |
| 616 | goto out; |
| 617 | } |
| 618 | |
Abhijith Das | d93cfa9 | 2007-06-11 08:22:32 +0100 | [diff] [blame] | 619 | gfs2_glock_dq_wait(&ip->i_iopen_gh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 620 | gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh); |
| 621 | error = gfs2_glock_nq(&ip->i_iopen_gh); |
| 622 | if (error) |
Steven Whitehouse | 1bb7322 | 2008-10-15 09:46:39 +0100 | [diff] [blame] | 623 | goto out_truncate; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 624 | |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 625 | if (S_ISDIR(inode->i_mode) && |
Steven Whitehouse | 383f01f | 2008-11-04 10:05:22 +0000 | [diff] [blame] | 626 | (ip->i_diskflags & GFS2_DIF_EXHASH)) { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 627 | error = gfs2_dir_exhash_dealloc(ip); |
| 628 | if (error) |
| 629 | goto out_unlock; |
| 630 | } |
| 631 | |
Steven Whitehouse | 3767ac2 | 2008-11-03 14:28:42 +0000 | [diff] [blame] | 632 | if (ip->i_eattr) { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 633 | error = gfs2_ea_dealloc(ip); |
| 634 | if (error) |
| 635 | goto out_unlock; |
| 636 | } |
| 637 | |
| 638 | if (!gfs2_is_stuffed(ip)) { |
| 639 | error = gfs2_file_dealloc(ip); |
| 640 | if (error) |
| 641 | goto out_unlock; |
| 642 | } |
| 643 | |
| 644 | error = gfs2_dinode_dealloc(ip); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 645 | if (error) |
| 646 | goto out_unlock; |
| 647 | |
Steven Whitehouse | 1bb7322 | 2008-10-15 09:46:39 +0100 | [diff] [blame] | 648 | out_truncate: |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 649 | error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); |
| 650 | if (error) |
| 651 | goto out_unlock; |
| 652 | /* Needs to be done before glock release & also in a transaction */ |
Steven Whitehouse | 49686f7 | 2007-01-08 14:31:40 +0000 | [diff] [blame] | 653 | truncate_inode_pages(&inode->i_data, 0); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 654 | gfs2_trans_end(sdp); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 655 | |
| 656 | out_unlock: |
Steven Whitehouse | 1bb7322 | 2008-10-15 09:46:39 +0100 | [diff] [blame] | 657 | if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) |
| 658 | gfs2_glock_dq(&ip->i_iopen_gh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 659 | gfs2_holder_uninit(&ip->i_iopen_gh); |
| 660 | gfs2_glock_dq_uninit(&gh); |
Steven Whitehouse | 3b8249f | 2007-03-16 09:40:31 +0000 | [diff] [blame] | 661 | if (error && error != GLR_TRYFAILED) |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 662 | fs_warn(sdp, "gfs2_delete_inode: %d\n", error); |
| 663 | out: |
| 664 | truncate_inode_pages(&inode->i_data, 0); |
| 665 | clear_inode(inode); |
| 666 | } |
| 667 | |
Steven Whitehouse | 320dd10 | 2006-05-18 16:25:27 -0400 | [diff] [blame] | 668 | static struct inode *gfs2_alloc_inode(struct super_block *sb) |
| 669 | { |
Steven Whitehouse | 320dd10 | 2006-05-18 16:25:27 -0400 | [diff] [blame] | 670 | struct gfs2_inode *ip; |
| 671 | |
| 672 | ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL); |
| 673 | if (ip) { |
| 674 | ip->i_flags = 0; |
| 675 | ip->i_gl = NULL; |
Steven Whitehouse | 320dd10 | 2006-05-18 16:25:27 -0400 | [diff] [blame] | 676 | } |
| 677 | return &ip->i_inode; |
| 678 | } |
| 679 | |
| 680 | static void gfs2_destroy_inode(struct inode *inode) |
| 681 | { |
| 682 | kmem_cache_free(gfs2_inode_cachep, inode); |
| 683 | } |
| 684 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 685 | const struct super_operations gfs2_super_ops = { |
Steven Whitehouse | 4a22195 | 2006-11-01 09:57:57 -0500 | [diff] [blame] | 686 | .alloc_inode = gfs2_alloc_inode, |
| 687 | .destroy_inode = gfs2_destroy_inode, |
| 688 | .write_inode = gfs2_write_inode, |
| 689 | .delete_inode = gfs2_delete_inode, |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame] | 690 | .put_super = gfs2_put_super, |
Steven Whitehouse | 4a22195 | 2006-11-01 09:57:57 -0500 | [diff] [blame] | 691 | .write_super = gfs2_write_super, |
| 692 | .sync_fs = gfs2_sync_fs, |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 693 | .freeze_fs = gfs2_freeze, |
| 694 | .unfreeze_fs = gfs2_unfreeze, |
Steven Whitehouse | 4a22195 | 2006-11-01 09:57:57 -0500 | [diff] [blame] | 695 | .statfs = gfs2_statfs, |
| 696 | .remount_fs = gfs2_remount_fs, |
| 697 | .clear_inode = gfs2_clear_inode, |
Steven Whitehouse | 3b8249f | 2007-03-16 09:40:31 +0000 | [diff] [blame] | 698 | .drop_inode = gfs2_drop_inode, |
Steven Whitehouse | 4a22195 | 2006-11-01 09:57:57 -0500 | [diff] [blame] | 699 | .show_options = gfs2_show_options, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 700 | }; |
| 701 | |