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