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