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