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