David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
| 3 | * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. |
| 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 |
| 7 | * of the GNU General Public License v.2. |
| 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> |
| 21 | #include <asm/semaphore.h> |
| 22 | |
| 23 | #include "gfs2.h" |
| 24 | #include "glock.h" |
| 25 | #include "inode.h" |
| 26 | #include "lm.h" |
| 27 | #include "log.h" |
| 28 | #include "mount.h" |
| 29 | #include "ops_super.h" |
| 30 | #include "page.h" |
| 31 | #include "quota.h" |
| 32 | #include "recovery.h" |
| 33 | #include "rgrp.h" |
| 34 | #include "super.h" |
| 35 | #include "sys.h" |
| 36 | |
| 37 | /** |
| 38 | * gfs2_write_inode - Make sure the inode is stable on the disk |
| 39 | * @inode: The inode |
| 40 | * @sync: synchronous write flag |
| 41 | * |
| 42 | * Returns: errno |
| 43 | */ |
| 44 | |
| 45 | static int gfs2_write_inode(struct inode *inode, int sync) |
| 46 | { |
| 47 | struct gfs2_inode *ip = get_v2ip(inode); |
| 48 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 49 | if (current->flags & PF_MEMALLOC) |
| 50 | return 0; |
| 51 | if (ip && sync) |
| 52 | gfs2_log_flush_glock(ip->i_gl); |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * gfs2_put_super - Unmount the filesystem |
| 59 | * @sb: The VFS superblock |
| 60 | * |
| 61 | */ |
| 62 | |
| 63 | static void gfs2_put_super(struct super_block *sb) |
| 64 | { |
| 65 | struct gfs2_sbd *sdp = get_v2sdp(sb); |
| 66 | int error; |
| 67 | |
| 68 | if (!sdp) |
| 69 | return; |
| 70 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 71 | /* Unfreeze the filesystem, if we need to */ |
| 72 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 73 | mutex_lock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 74 | if (sdp->sd_freeze_count) |
| 75 | gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 76 | mutex_unlock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 77 | |
| 78 | kthread_stop(sdp->sd_inoded_process); |
| 79 | kthread_stop(sdp->sd_quotad_process); |
| 80 | kthread_stop(sdp->sd_logd_process); |
| 81 | kthread_stop(sdp->sd_recoverd_process); |
| 82 | while (sdp->sd_glockd_num--) |
| 83 | kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); |
| 84 | kthread_stop(sdp->sd_scand_process); |
| 85 | |
| 86 | if (!(sb->s_flags & MS_RDONLY)) { |
| 87 | error = gfs2_make_fs_ro(sdp); |
| 88 | if (error) |
| 89 | gfs2_io_error(sdp); |
| 90 | } |
| 91 | |
| 92 | /* At this point, we're through modifying the disk */ |
| 93 | |
| 94 | /* Release stuff */ |
| 95 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 96 | iput(sdp->sd_master_dir); |
| 97 | iput(sdp->sd_jindex); |
| 98 | iput(sdp->sd_inum_inode); |
| 99 | iput(sdp->sd_statfs_inode); |
| 100 | iput(sdp->sd_rindex); |
| 101 | iput(sdp->sd_quota_inode); |
| 102 | iput(sdp->sd_root_dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 103 | |
| 104 | gfs2_glock_put(sdp->sd_rename_gl); |
| 105 | gfs2_glock_put(sdp->sd_trans_gl); |
| 106 | |
| 107 | if (!sdp->sd_args.ar_spectator) { |
| 108 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); |
| 109 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); |
| 110 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); |
| 111 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); |
| 112 | gfs2_glock_dq_uninit(&sdp->sd_ut_gh); |
| 113 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 114 | iput(sdp->sd_ir_inode); |
| 115 | iput(sdp->sd_sc_inode); |
| 116 | iput(sdp->sd_ut_inode); |
| 117 | iput(sdp->sd_qc_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); |
| 121 | |
| 122 | gfs2_clear_rgrpd(sdp); |
| 123 | gfs2_jindex_free(sdp); |
| 124 | |
| 125 | /* Take apart glock structures and buffer lists */ |
| 126 | gfs2_gl_hash_clear(sdp, WAIT); |
| 127 | |
| 128 | /* Unmount the locking protocol */ |
| 129 | gfs2_lm_unmount(sdp); |
| 130 | |
| 131 | /* At this point, we're through participating in the lockspace */ |
| 132 | |
| 133 | gfs2_sys_fs_del(sdp); |
| 134 | |
| 135 | /* Get rid of any extra inodes */ |
| 136 | while (invalidate_inodes(sb)) |
| 137 | yield(); |
| 138 | |
| 139 | vfree(sdp); |
| 140 | |
| 141 | set_v2sdp(sb, NULL); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * gfs2_write_super - disk commit all incore transactions |
| 146 | * @sb: the filesystem |
| 147 | * |
| 148 | * This function is called every time sync(2) is called. |
| 149 | * After this exits, all dirty buffers and synced. |
| 150 | */ |
| 151 | |
| 152 | static void gfs2_write_super(struct super_block *sb) |
| 153 | { |
| 154 | struct gfs2_sbd *sdp = get_v2sdp(sb); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 155 | gfs2_log_flush(sdp); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * gfs2_write_super_lockfs - prevent further writes to the filesystem |
| 160 | * @sb: the VFS structure for the filesystem |
| 161 | * |
| 162 | */ |
| 163 | |
| 164 | static void gfs2_write_super_lockfs(struct super_block *sb) |
| 165 | { |
| 166 | struct gfs2_sbd *sdp = get_v2sdp(sb); |
| 167 | int error; |
| 168 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 169 | for (;;) { |
| 170 | error = gfs2_freeze_fs(sdp); |
| 171 | if (!error) |
| 172 | break; |
| 173 | |
| 174 | switch (error) { |
| 175 | case -EBUSY: |
| 176 | fs_err(sdp, "waiting for recovery before freeze\n"); |
| 177 | break; |
| 178 | |
| 179 | default: |
| 180 | fs_err(sdp, "error freezing FS: %d\n", error); |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | fs_err(sdp, "retrying...\n"); |
| 185 | msleep(1000); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * gfs2_unlockfs - reallow writes to the filesystem |
| 191 | * @sb: the VFS structure for the filesystem |
| 192 | * |
| 193 | */ |
| 194 | |
| 195 | static void gfs2_unlockfs(struct super_block *sb) |
| 196 | { |
| 197 | struct gfs2_sbd *sdp = get_v2sdp(sb); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 198 | gfs2_unfreeze_fs(sdp); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * gfs2_statfs - Gather and return stats about the filesystem |
| 203 | * @sb: The superblock |
| 204 | * @statfsbuf: The buffer |
| 205 | * |
| 206 | * Returns: 0 on success or error code |
| 207 | */ |
| 208 | |
| 209 | static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf) |
| 210 | { |
| 211 | struct gfs2_sbd *sdp = get_v2sdp(sb); |
| 212 | struct gfs2_statfs_change sc; |
| 213 | int error; |
| 214 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 215 | if (gfs2_tune_get(sdp, gt_statfs_slow)) |
| 216 | error = gfs2_statfs_slow(sdp, &sc); |
| 217 | else |
| 218 | error = gfs2_statfs_i(sdp, &sc); |
| 219 | |
| 220 | if (error) |
| 221 | return error; |
| 222 | |
| 223 | memset(buf, 0, sizeof(struct kstatfs)); |
| 224 | |
| 225 | buf->f_type = GFS2_MAGIC; |
| 226 | buf->f_bsize = sdp->sd_sb.sb_bsize; |
| 227 | buf->f_blocks = sc.sc_total; |
| 228 | buf->f_bfree = sc.sc_free; |
| 229 | buf->f_bavail = sc.sc_free; |
| 230 | buf->f_files = sc.sc_dinodes + sc.sc_free; |
| 231 | buf->f_ffree = sc.sc_free; |
| 232 | buf->f_namelen = GFS2_FNAMESIZE; |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * gfs2_remount_fs - called when the FS is remounted |
| 239 | * @sb: the filesystem |
| 240 | * @flags: the remount flags |
| 241 | * @data: extra data passed in (not used right now) |
| 242 | * |
| 243 | * Returns: errno |
| 244 | */ |
| 245 | |
| 246 | static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) |
| 247 | { |
| 248 | struct gfs2_sbd *sdp = get_v2sdp(sb); |
| 249 | int error; |
| 250 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 251 | error = gfs2_mount_args(sdp, data, 1); |
| 252 | if (error) |
| 253 | return error; |
| 254 | |
| 255 | if (sdp->sd_args.ar_spectator) |
| 256 | *flags |= MS_RDONLY; |
| 257 | else { |
| 258 | if (*flags & MS_RDONLY) { |
| 259 | if (!(sb->s_flags & MS_RDONLY)) |
| 260 | error = gfs2_make_fs_ro(sdp); |
| 261 | } else if (!(*flags & MS_RDONLY) && |
| 262 | (sb->s_flags & MS_RDONLY)) { |
| 263 | error = gfs2_make_fs_rw(sdp); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | if (*flags & (MS_NOATIME | MS_NODIRATIME)) |
| 268 | set_bit(SDF_NOATIME, &sdp->sd_flags); |
| 269 | else |
| 270 | clear_bit(SDF_NOATIME, &sdp->sd_flags); |
| 271 | |
| 272 | /* Don't let the VFS update atimes. GFS2 handles this itself. */ |
| 273 | *flags |= MS_NOATIME | MS_NODIRATIME; |
| 274 | |
| 275 | return error; |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * gfs2_clear_inode - Deallocate an inode when VFS is done with it |
| 280 | * @inode: The VFS inode |
| 281 | * |
| 282 | */ |
| 283 | |
| 284 | static void gfs2_clear_inode(struct inode *inode) |
| 285 | { |
| 286 | struct gfs2_inode *ip = get_v2ip(inode); |
| 287 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 288 | if (ip) { |
| 289 | spin_lock(&ip->i_spin); |
| 290 | ip->i_vnode = NULL; |
| 291 | set_v2ip(inode, NULL); |
| 292 | spin_unlock(&ip->i_spin); |
| 293 | |
| 294 | gfs2_glock_schedule_for_reclaim(ip->i_gl); |
| 295 | gfs2_inode_put(ip); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * gfs2_show_options - Show mount options for /proc/mounts |
| 301 | * @s: seq_file structure |
| 302 | * @mnt: vfsmount |
| 303 | * |
| 304 | * Returns: 0 on success or error code |
| 305 | */ |
| 306 | |
| 307 | static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) |
| 308 | { |
| 309 | struct gfs2_sbd *sdp = get_v2sdp(mnt->mnt_sb); |
| 310 | struct gfs2_args *args = &sdp->sd_args; |
| 311 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 312 | if (args->ar_lockproto[0]) |
| 313 | seq_printf(s, ",lockproto=%s", args->ar_lockproto); |
| 314 | if (args->ar_locktable[0]) |
| 315 | seq_printf(s, ",locktable=%s", args->ar_locktable); |
| 316 | if (args->ar_hostdata[0]) |
| 317 | seq_printf(s, ",hostdata=%s", args->ar_hostdata); |
| 318 | if (args->ar_spectator) |
| 319 | seq_printf(s, ",spectator"); |
| 320 | if (args->ar_ignore_local_fs) |
| 321 | seq_printf(s, ",ignore_local_fs"); |
| 322 | if (args->ar_localflocks) |
| 323 | seq_printf(s, ",localflocks"); |
| 324 | if (args->ar_localcaching) |
| 325 | seq_printf(s, ",localcaching"); |
| 326 | if (args->ar_debug) |
| 327 | seq_printf(s, ",debug"); |
| 328 | if (args->ar_upgrade) |
| 329 | seq_printf(s, ",upgrade"); |
| 330 | if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT) |
| 331 | seq_printf(s, ",num_glockd=%u", args->ar_num_glockd); |
| 332 | if (args->ar_posix_acl) |
| 333 | seq_printf(s, ",acl"); |
| 334 | if (args->ar_quota != GFS2_QUOTA_DEFAULT) { |
| 335 | char *state; |
| 336 | switch (args->ar_quota) { |
| 337 | case GFS2_QUOTA_OFF: |
| 338 | state = "off"; |
| 339 | break; |
| 340 | case GFS2_QUOTA_ACCOUNT: |
| 341 | state = "account"; |
| 342 | break; |
| 343 | case GFS2_QUOTA_ON: |
| 344 | state = "on"; |
| 345 | break; |
| 346 | default: |
| 347 | state = "unknown"; |
| 348 | break; |
| 349 | } |
| 350 | seq_printf(s, ",quota=%s", state); |
| 351 | } |
| 352 | if (args->ar_suiddir) |
| 353 | seq_printf(s, ",suiddir"); |
| 354 | if (args->ar_data != GFS2_DATA_DEFAULT) { |
| 355 | char *state; |
| 356 | switch (args->ar_data) { |
| 357 | case GFS2_DATA_WRITEBACK: |
| 358 | state = "writeback"; |
| 359 | break; |
| 360 | case GFS2_DATA_ORDERED: |
| 361 | state = "ordered"; |
| 362 | break; |
| 363 | default: |
| 364 | state = "unknown"; |
| 365 | break; |
| 366 | } |
| 367 | seq_printf(s, ",data=%s", state); |
| 368 | } |
| 369 | |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | struct super_operations gfs2_super_ops = { |
| 374 | .write_inode = gfs2_write_inode, |
| 375 | .put_super = gfs2_put_super, |
| 376 | .write_super = gfs2_write_super, |
| 377 | .write_super_lockfs = gfs2_write_super_lockfs, |
| 378 | .unlockfs = gfs2_unlockfs, |
| 379 | .statfs = gfs2_statfs, |
| 380 | .remount_fs = gfs2_remount_fs, |
| 381 | .clear_inode = gfs2_clear_inode, |
| 382 | .show_options = gfs2_show_options, |
| 383 | }; |
| 384 | |