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