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> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 21 | #include <linux/gfs2_ondisk.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 22 | #include <asm/semaphore.h> |
| 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" |
| 33 | #include "page.h" |
| 34 | #include "quota.h" |
| 35 | #include "recovery.h" |
| 36 | #include "rgrp.h" |
| 37 | #include "super.h" |
| 38 | #include "sys.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 39 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * gfs2_write_inode - Make sure the inode is stable on the disk |
| 43 | * @inode: The inode |
| 44 | * @sync: synchronous write flag |
| 45 | * |
| 46 | * Returns: errno |
| 47 | */ |
| 48 | |
| 49 | static int gfs2_write_inode(struct inode *inode, int sync) |
| 50 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 51 | struct gfs2_inode *ip = inode->u.generic_ip; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 52 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 53 | if (current->flags & PF_MEMALLOC) |
| 54 | return 0; |
| 55 | if (ip && sync) |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame^] | 56 | gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * gfs2_put_super - Unmount the filesystem |
| 63 | * @sb: The VFS superblock |
| 64 | * |
| 65 | */ |
| 66 | |
| 67 | static void gfs2_put_super(struct super_block *sb) |
| 68 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 69 | struct gfs2_sbd *sdp = sb->s_fs_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 70 | int error; |
| 71 | |
| 72 | if (!sdp) |
| 73 | return; |
| 74 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 75 | /* Unfreeze the filesystem, if we need to */ |
| 76 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 77 | mutex_lock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 78 | if (sdp->sd_freeze_count) |
| 79 | gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 80 | mutex_unlock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 81 | |
| 82 | kthread_stop(sdp->sd_inoded_process); |
| 83 | kthread_stop(sdp->sd_quotad_process); |
| 84 | kthread_stop(sdp->sd_logd_process); |
| 85 | kthread_stop(sdp->sd_recoverd_process); |
| 86 | while (sdp->sd_glockd_num--) |
| 87 | kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); |
| 88 | kthread_stop(sdp->sd_scand_process); |
| 89 | |
| 90 | if (!(sb->s_flags & MS_RDONLY)) { |
| 91 | error = gfs2_make_fs_ro(sdp); |
| 92 | if (error) |
| 93 | gfs2_io_error(sdp); |
| 94 | } |
| 95 | |
| 96 | /* At this point, we're through modifying the disk */ |
| 97 | |
| 98 | /* Release stuff */ |
| 99 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 100 | iput(sdp->sd_master_dir); |
| 101 | iput(sdp->sd_jindex); |
| 102 | iput(sdp->sd_inum_inode); |
| 103 | iput(sdp->sd_statfs_inode); |
| 104 | iput(sdp->sd_rindex); |
| 105 | iput(sdp->sd_quota_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 106 | |
| 107 | gfs2_glock_put(sdp->sd_rename_gl); |
| 108 | gfs2_glock_put(sdp->sd_trans_gl); |
| 109 | |
| 110 | if (!sdp->sd_args.ar_spectator) { |
| 111 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); |
| 112 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); |
| 113 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); |
| 114 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); |
| 115 | gfs2_glock_dq_uninit(&sdp->sd_ut_gh); |
| 116 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 117 | iput(sdp->sd_ir_inode); |
| 118 | iput(sdp->sd_sc_inode); |
| 119 | iput(sdp->sd_ut_inode); |
| 120 | iput(sdp->sd_qc_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 124 | gfs2_clear_rgrpd(sdp); |
| 125 | gfs2_jindex_free(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 126 | /* Take apart glock structures and buffer lists */ |
| 127 | gfs2_gl_hash_clear(sdp, WAIT); |
| 128 | |
| 129 | /* Unmount the locking protocol */ |
| 130 | gfs2_lm_unmount(sdp); |
| 131 | |
| 132 | /* At this point, we're through participating in the lockspace */ |
| 133 | |
| 134 | gfs2_sys_fs_del(sdp); |
| 135 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 136 | vfree(sdp); |
| 137 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 138 | sb->s_fs_info = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** |
| 142 | * gfs2_write_super - disk commit all incore transactions |
| 143 | * @sb: the filesystem |
| 144 | * |
| 145 | * This function is called every time sync(2) is called. |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame^] | 146 | * After this exits, all dirty buffers are synced. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 147 | */ |
| 148 | |
| 149 | static void gfs2_write_super(struct super_block *sb) |
| 150 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 151 | struct gfs2_sbd *sdp = sb->s_fs_info; |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame^] | 152 | gfs2_log_flush(sdp, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /** |
| 156 | * gfs2_write_super_lockfs - prevent further writes to the filesystem |
| 157 | * @sb: the VFS structure for the filesystem |
| 158 | * |
| 159 | */ |
| 160 | |
| 161 | static void gfs2_write_super_lockfs(struct super_block *sb) |
| 162 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 163 | struct gfs2_sbd *sdp = sb->s_fs_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 164 | int error; |
| 165 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 166 | for (;;) { |
| 167 | error = gfs2_freeze_fs(sdp); |
| 168 | if (!error) |
| 169 | break; |
| 170 | |
| 171 | switch (error) { |
| 172 | case -EBUSY: |
| 173 | fs_err(sdp, "waiting for recovery before freeze\n"); |
| 174 | break; |
| 175 | |
| 176 | default: |
| 177 | fs_err(sdp, "error freezing FS: %d\n", error); |
| 178 | break; |
| 179 | } |
| 180 | |
| 181 | fs_err(sdp, "retrying...\n"); |
| 182 | msleep(1000); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * gfs2_unlockfs - reallow writes to the filesystem |
| 188 | * @sb: the VFS structure for the filesystem |
| 189 | * |
| 190 | */ |
| 191 | |
| 192 | static void gfs2_unlockfs(struct super_block *sb) |
| 193 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 194 | struct gfs2_sbd *sdp = sb->s_fs_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 195 | gfs2_unfreeze_fs(sdp); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * gfs2_statfs - Gather and return stats about the filesystem |
| 200 | * @sb: The superblock |
| 201 | * @statfsbuf: The buffer |
| 202 | * |
| 203 | * Returns: 0 on success or error code |
| 204 | */ |
| 205 | |
| 206 | static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf) |
| 207 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 208 | struct gfs2_sbd *sdp = sb->s_fs_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 209 | struct gfs2_statfs_change sc; |
| 210 | int error; |
| 211 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 212 | if (gfs2_tune_get(sdp, gt_statfs_slow)) |
| 213 | error = gfs2_statfs_slow(sdp, &sc); |
| 214 | else |
| 215 | error = gfs2_statfs_i(sdp, &sc); |
| 216 | |
| 217 | if (error) |
| 218 | return error; |
| 219 | |
| 220 | memset(buf, 0, sizeof(struct kstatfs)); |
| 221 | |
| 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 | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 283 | struct gfs2_inode *ip = inode->u.generic_ip; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 284 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 285 | if (ip) { |
| 286 | spin_lock(&ip->i_spin); |
| 287 | ip->i_vnode = NULL; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 288 | inode->u.generic_ip = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 289 | spin_unlock(&ip->i_spin); |
| 290 | |
| 291 | gfs2_glock_schedule_for_reclaim(ip->i_gl); |
| 292 | gfs2_inode_put(ip); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * gfs2_show_options - Show mount options for /proc/mounts |
| 298 | * @s: seq_file structure |
| 299 | * @mnt: vfsmount |
| 300 | * |
| 301 | * Returns: 0 on success or error code |
| 302 | */ |
| 303 | |
| 304 | static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) |
| 305 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 306 | struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 307 | struct gfs2_args *args = &sdp->sd_args; |
| 308 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 309 | if (args->ar_lockproto[0]) |
| 310 | seq_printf(s, ",lockproto=%s", args->ar_lockproto); |
| 311 | if (args->ar_locktable[0]) |
| 312 | seq_printf(s, ",locktable=%s", args->ar_locktable); |
| 313 | if (args->ar_hostdata[0]) |
| 314 | seq_printf(s, ",hostdata=%s", args->ar_hostdata); |
| 315 | if (args->ar_spectator) |
| 316 | seq_printf(s, ",spectator"); |
| 317 | if (args->ar_ignore_local_fs) |
| 318 | seq_printf(s, ",ignore_local_fs"); |
| 319 | if (args->ar_localflocks) |
| 320 | seq_printf(s, ",localflocks"); |
| 321 | if (args->ar_localcaching) |
| 322 | seq_printf(s, ",localcaching"); |
| 323 | if (args->ar_debug) |
| 324 | seq_printf(s, ",debug"); |
| 325 | if (args->ar_upgrade) |
| 326 | seq_printf(s, ",upgrade"); |
| 327 | if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT) |
| 328 | seq_printf(s, ",num_glockd=%u", args->ar_num_glockd); |
| 329 | if (args->ar_posix_acl) |
| 330 | seq_printf(s, ",acl"); |
| 331 | if (args->ar_quota != GFS2_QUOTA_DEFAULT) { |
| 332 | char *state; |
| 333 | switch (args->ar_quota) { |
| 334 | case GFS2_QUOTA_OFF: |
| 335 | state = "off"; |
| 336 | break; |
| 337 | case GFS2_QUOTA_ACCOUNT: |
| 338 | state = "account"; |
| 339 | break; |
| 340 | case GFS2_QUOTA_ON: |
| 341 | state = "on"; |
| 342 | break; |
| 343 | default: |
| 344 | state = "unknown"; |
| 345 | break; |
| 346 | } |
| 347 | seq_printf(s, ",quota=%s", state); |
| 348 | } |
| 349 | if (args->ar_suiddir) |
| 350 | seq_printf(s, ",suiddir"); |
| 351 | if (args->ar_data != GFS2_DATA_DEFAULT) { |
| 352 | char *state; |
| 353 | switch (args->ar_data) { |
| 354 | case GFS2_DATA_WRITEBACK: |
| 355 | state = "writeback"; |
| 356 | break; |
| 357 | case GFS2_DATA_ORDERED: |
| 358 | state = "ordered"; |
| 359 | break; |
| 360 | default: |
| 361 | state = "unknown"; |
| 362 | break; |
| 363 | } |
| 364 | seq_printf(s, ",data=%s", state); |
| 365 | } |
| 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | struct super_operations gfs2_super_ops = { |
| 371 | .write_inode = gfs2_write_inode, |
| 372 | .put_super = gfs2_put_super, |
| 373 | .write_super = gfs2_write_super, |
| 374 | .write_super_lockfs = gfs2_write_super_lockfs, |
| 375 | .unlockfs = gfs2_unlockfs, |
| 376 | .statfs = gfs2_statfs, |
| 377 | .remount_fs = gfs2_remount_fs, |
| 378 | .clear_inode = gfs2_clear_inode, |
| 379 | .show_options = gfs2_show_options, |
| 380 | }; |
| 381 | |