David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 3 | * Copyright (C) 2004-2007 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/blkdev.h> |
| 16 | #include <linux/kthread.h> |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 17 | #include <linux/namei.h> |
| 18 | #include <linux/mount.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 19 | #include <linux/gfs2_ondisk.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 20 | #include <linux/lm_interface.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 21 | |
| 22 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 23 | #include "incore.h" |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 24 | #include "bmap.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 25 | #include "daemon.h" |
| 26 | #include "glock.h" |
| 27 | #include "glops.h" |
| 28 | #include "inode.h" |
| 29 | #include "lm.h" |
| 30 | #include "mount.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 31 | #include "ops_fstype.h" |
Denis Cheng | ca5a939 | 2007-07-31 18:31:12 +0800 | [diff] [blame] | 32 | #include "ops_dentry.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 33 | #include "ops_super.h" |
| 34 | #include "recovery.h" |
| 35 | #include "rgrp.h" |
| 36 | #include "super.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 37 | #include "sys.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 38 | #include "util.h" |
Steven Whitehouse | bb3b0e3 | 2007-08-16 16:03:57 +0100 | [diff] [blame] | 39 | #include "log.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 40 | |
| 41 | #define DO 0 |
| 42 | #define UNDO 1 |
| 43 | |
| 44 | static struct gfs2_sbd *init_sbd(struct super_block *sb) |
| 45 | { |
| 46 | struct gfs2_sbd *sdp; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 47 | |
Steven Whitehouse | 85d1da6 | 2006-09-07 14:40:21 -0400 | [diff] [blame] | 48 | sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 49 | if (!sdp) |
| 50 | return NULL; |
| 51 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 52 | sb->s_fs_info = sdp; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 53 | sdp->sd_vfs = sb; |
| 54 | |
| 55 | gfs2_tune_init(&sdp->sd_tune); |
| 56 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 57 | INIT_LIST_HEAD(&sdp->sd_reclaim_list); |
| 58 | spin_lock_init(&sdp->sd_reclaim_lock); |
| 59 | init_waitqueue_head(&sdp->sd_reclaim_wq); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 60 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 61 | mutex_init(&sdp->sd_inum_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 62 | spin_lock_init(&sdp->sd_statfs_spin); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 63 | |
| 64 | spin_lock_init(&sdp->sd_rindex_spin); |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 65 | mutex_init(&sdp->sd_rindex_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 66 | INIT_LIST_HEAD(&sdp->sd_rindex_list); |
| 67 | INIT_LIST_HEAD(&sdp->sd_rindex_mru_list); |
| 68 | INIT_LIST_HEAD(&sdp->sd_rindex_recent_list); |
| 69 | |
| 70 | INIT_LIST_HEAD(&sdp->sd_jindex_list); |
| 71 | spin_lock_init(&sdp->sd_jindex_spin); |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 72 | mutex_init(&sdp->sd_jindex_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 73 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 74 | INIT_LIST_HEAD(&sdp->sd_quota_list); |
| 75 | spin_lock_init(&sdp->sd_quota_spin); |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 76 | mutex_init(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 77 | |
| 78 | spin_lock_init(&sdp->sd_log_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 79 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 80 | INIT_LIST_HEAD(&sdp->sd_log_le_buf); |
| 81 | INIT_LIST_HEAD(&sdp->sd_log_le_revoke); |
| 82 | INIT_LIST_HEAD(&sdp->sd_log_le_rg); |
| 83 | INIT_LIST_HEAD(&sdp->sd_log_le_databuf); |
Steven Whitehouse | d7b616e | 2007-09-02 10:48:13 +0100 | [diff] [blame] | 84 | INIT_LIST_HEAD(&sdp->sd_log_le_ordered); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 85 | |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 86 | mutex_init(&sdp->sd_log_reserve_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 87 | INIT_LIST_HEAD(&sdp->sd_ail1_list); |
| 88 | INIT_LIST_HEAD(&sdp->sd_ail2_list); |
| 89 | |
Steven Whitehouse | 484adff | 2006-03-29 09:12:12 -0500 | [diff] [blame] | 90 | init_rwsem(&sdp->sd_log_flush_lock); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 91 | atomic_set(&sdp->sd_log_in_flight, 0); |
| 92 | init_waitqueue_head(&sdp->sd_log_flush_wait); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 93 | |
| 94 | INIT_LIST_HEAD(&sdp->sd_revoke_list); |
| 95 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 96 | mutex_init(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 97 | |
| 98 | return sdp; |
| 99 | } |
| 100 | |
Steven Whitehouse | 419c93e0 | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 101 | static void init_vfs(struct super_block *sb, unsigned noatime) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 102 | { |
Steven Whitehouse | 419c93e0 | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 103 | struct gfs2_sbd *sdp = sb->s_fs_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 104 | |
| 105 | sb->s_magic = GFS2_MAGIC; |
| 106 | sb->s_op = &gfs2_super_ops; |
| 107 | sb->s_export_op = &gfs2_export_ops; |
Steven Whitehouse | 4bd91ba | 2007-06-05 09:39:18 +0100 | [diff] [blame] | 108 | sb->s_time_gran = 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 109 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
| 110 | |
| 111 | if (sb->s_flags & (MS_NOATIME | MS_NODIRATIME)) |
Steven Whitehouse | 419c93e0 | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 112 | set_bit(noatime, &sdp->sd_flags); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 113 | |
| 114 | /* Don't let the VFS update atimes. GFS2 handles this itself. */ |
| 115 | sb->s_flags |= MS_NOATIME | MS_NODIRATIME; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static int init_names(struct gfs2_sbd *sdp, int silent) |
| 119 | { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 120 | char *proto, *table; |
| 121 | int error = 0; |
| 122 | |
| 123 | proto = sdp->sd_args.ar_lockproto; |
| 124 | table = sdp->sd_args.ar_locktable; |
| 125 | |
| 126 | /* Try to autodetect */ |
| 127 | |
| 128 | if (!proto[0] || !table[0]) { |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 129 | error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); |
| 130 | if (error) |
| 131 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 132 | |
Steven Whitehouse | 3cf1e7b | 2006-10-02 11:49:41 -0400 | [diff] [blame] | 133 | error = gfs2_check_sb(sdp, &sdp->sd_sb, silent); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 134 | if (error) |
| 135 | goto out; |
| 136 | |
| 137 | if (!proto[0]) |
Steven Whitehouse | 3cf1e7b | 2006-10-02 11:49:41 -0400 | [diff] [blame] | 138 | proto = sdp->sd_sb.sb_lockproto; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 139 | if (!table[0]) |
Steven Whitehouse | 3cf1e7b | 2006-10-02 11:49:41 -0400 | [diff] [blame] | 140 | table = sdp->sd_sb.sb_locktable; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | if (!table[0]) |
| 144 | table = sdp->sd_vfs->s_id; |
| 145 | |
| 146 | snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto); |
| 147 | snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table); |
| 148 | |
Denis Cheng | 5d35e31 | 2007-08-13 11:01:58 +0800 | [diff] [blame] | 149 | table = sdp->sd_table_name; |
| 150 | while ((table = strchr(table, '/'))) |
Robert Peterson | b35997d | 2007-06-07 09:10:01 -0500 | [diff] [blame] | 151 | *table = '_'; |
| 152 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 153 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 154 | return error; |
| 155 | } |
| 156 | |
| 157 | static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh, |
| 158 | int undo) |
| 159 | { |
| 160 | struct task_struct *p; |
| 161 | int error = 0; |
| 162 | |
| 163 | if (undo) |
| 164 | goto fail_trans; |
| 165 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 166 | for (sdp->sd_glockd_num = 0; |
| 167 | sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd; |
| 168 | sdp->sd_glockd_num++) { |
| 169 | p = kthread_run(gfs2_glockd, sdp, "gfs2_glockd"); |
| 170 | error = IS_ERR(p); |
| 171 | if (error) { |
| 172 | fs_err(sdp, "can't start glockd thread: %d\n", error); |
| 173 | goto fail; |
| 174 | } |
| 175 | sdp->sd_glockd_process[sdp->sd_glockd_num] = p; |
| 176 | } |
| 177 | |
| 178 | error = gfs2_glock_nq_num(sdp, |
| 179 | GFS2_MOUNT_LOCK, &gfs2_nondisk_glops, |
| 180 | LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE, |
| 181 | mount_gh); |
| 182 | if (error) { |
| 183 | fs_err(sdp, "can't acquire mount glock: %d\n", error); |
| 184 | goto fail; |
| 185 | } |
| 186 | |
| 187 | error = gfs2_glock_nq_num(sdp, |
| 188 | GFS2_LIVE_LOCK, &gfs2_nondisk_glops, |
| 189 | LM_ST_SHARED, |
Steven Whitehouse | 579b78a | 2006-04-26 14:58:26 -0400 | [diff] [blame] | 190 | LM_FLAG_NOEXP | GL_EXACT, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 191 | &sdp->sd_live_gh); |
| 192 | if (error) { |
| 193 | fs_err(sdp, "can't acquire live glock: %d\n", error); |
| 194 | goto fail_mount; |
| 195 | } |
| 196 | |
| 197 | error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops, |
| 198 | CREATE, &sdp->sd_rename_gl); |
| 199 | if (error) { |
| 200 | fs_err(sdp, "can't create rename glock: %d\n", error); |
| 201 | goto fail_live; |
| 202 | } |
| 203 | |
| 204 | error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops, |
| 205 | CREATE, &sdp->sd_trans_gl); |
| 206 | if (error) { |
| 207 | fs_err(sdp, "can't create transaction glock: %d\n", error); |
| 208 | goto fail_rename; |
| 209 | } |
| 210 | set_bit(GLF_STICKY, &sdp->sd_trans_gl->gl_flags); |
| 211 | |
| 212 | return 0; |
| 213 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 214 | fail_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 215 | gfs2_glock_put(sdp->sd_trans_gl); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 216 | fail_rename: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 217 | gfs2_glock_put(sdp->sd_rename_gl); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 218 | fail_live: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 219 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 220 | fail_mount: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 221 | gfs2_glock_dq_uninit(mount_gh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 222 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 223 | while (sdp->sd_glockd_num--) |
| 224 | kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); |
| 225 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 226 | return error; |
| 227 | } |
| 228 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 229 | static inline struct inode *gfs2_lookup_root(struct super_block *sb, |
| 230 | u64 no_addr) |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 231 | { |
Benjamin Marzinski | 7a9f53b | 2007-09-18 13:33:18 -0500 | [diff] [blame] | 232 | return gfs2_inode_lookup(sb, DT_DIR, no_addr, 0, 0); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 233 | } |
| 234 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 235 | static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) |
| 236 | { |
| 237 | struct super_block *sb = sdp->sd_vfs; |
| 238 | struct gfs2_holder sb_gh; |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 239 | u64 no_addr; |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 240 | struct inode *inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 241 | int error = 0; |
| 242 | |
| 243 | if (undo) { |
Russell Cattelan | 8872187 | 2006-08-10 11:08:40 -0500 | [diff] [blame] | 244 | if (sb->s_root) { |
| 245 | dput(sb->s_root); |
| 246 | sb->s_root = NULL; |
| 247 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 248 | return 0; |
| 249 | } |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 250 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 251 | error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 252 | LM_ST_SHARED, 0, &sb_gh); |
| 253 | if (error) { |
| 254 | fs_err(sdp, "can't acquire superblock glock: %d\n", error); |
| 255 | return error; |
| 256 | } |
| 257 | |
| 258 | error = gfs2_read_sb(sdp, sb_gh.gh_gl, silent); |
| 259 | if (error) { |
| 260 | fs_err(sdp, "can't read superblock: %d\n", error); |
| 261 | goto out; |
| 262 | } |
| 263 | |
| 264 | /* Set up the buffer cache and SB for real */ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 265 | if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) { |
Steven Whitehouse | 419c93e0 | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 266 | error = -EINVAL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 267 | fs_err(sdp, "FS block size (%u) is too small for device " |
| 268 | "block size (%u)\n", |
| 269 | sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev)); |
| 270 | goto out; |
| 271 | } |
| 272 | if (sdp->sd_sb.sb_bsize > PAGE_SIZE) { |
Steven Whitehouse | 419c93e0 | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 273 | error = -EINVAL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 274 | fs_err(sdp, "FS block size (%u) is too big for machine " |
| 275 | "page size (%u)\n", |
| 276 | sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE); |
| 277 | goto out; |
| 278 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 279 | sb_set_blocksize(sb, sdp->sd_sb.sb_bsize); |
| 280 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 281 | /* Get the root inode */ |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 282 | no_addr = sdp->sd_sb.sb_root_dir.no_addr; |
Steven Whitehouse | 419c93e0 | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 283 | if (sb->s_type == &gfs2meta_fs_type) |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 284 | no_addr = sdp->sd_sb.sb_master_dir.no_addr; |
| 285 | inode = gfs2_lookup_root(sb, no_addr); |
Steven Whitehouse | c9fd430 | 2006-03-01 15:31:02 -0500 | [diff] [blame] | 286 | if (IS_ERR(inode)) { |
| 287 | error = PTR_ERR(inode); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 288 | fs_err(sdp, "can't read in root inode: %d\n", error); |
| 289 | goto out; |
| 290 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 291 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 292 | sb->s_root = d_alloc_root(inode); |
| 293 | if (!sb->s_root) { |
| 294 | fs_err(sdp, "can't get root dentry\n"); |
| 295 | error = -ENOMEM; |
Steven Whitehouse | c9fd430 | 2006-03-01 15:31:02 -0500 | [diff] [blame] | 296 | iput(inode); |
Denis Cheng | 34eaae3 | 2007-08-15 23:54:44 +0800 | [diff] [blame] | 297 | } else |
| 298 | sb->s_root->d_op = &gfs2_dops; |
| 299 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 300 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 301 | gfs2_glock_dq_uninit(&sb_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 302 | return error; |
| 303 | } |
| 304 | |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 305 | /** |
| 306 | * map_journal_extents - create a reusable "extent" mapping from all logical |
| 307 | * blocks to all physical blocks for the given journal. This will save |
| 308 | * us time when writing journal blocks. Most journals will have only one |
| 309 | * extent that maps all their logical blocks. That's because gfs2.mkfs |
| 310 | * arranges the journal blocks sequentially to maximize performance. |
| 311 | * So the extent would map the first block for the entire file length. |
| 312 | * However, gfs2_jadd can happen while file activity is happening, so |
| 313 | * those journals may not be sequential. Less likely is the case where |
| 314 | * the users created their own journals by mounting the metafs and |
| 315 | * laying it out. But it's still possible. These journals might have |
| 316 | * several extents. |
| 317 | * |
| 318 | * TODO: This should be done in bigger chunks rather than one block at a time, |
| 319 | * but since it's only done at mount time, I'm not worried about the |
| 320 | * time it takes. |
| 321 | */ |
| 322 | static int map_journal_extents(struct gfs2_sbd *sdp) |
| 323 | { |
| 324 | struct gfs2_jdesc *jd = sdp->sd_jdesc; |
| 325 | unsigned int lb; |
| 326 | u64 db, prev_db; /* logical block, disk block, prev disk block */ |
| 327 | struct gfs2_inode *ip = GFS2_I(jd->jd_inode); |
| 328 | struct gfs2_journal_extent *jext = NULL; |
| 329 | struct buffer_head bh; |
| 330 | int rc = 0; |
| 331 | |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 332 | prev_db = 0; |
| 333 | |
Bob Peterson | fa3742f | 2007-12-12 17:52:13 -0600 | [diff] [blame] | 334 | for (lb = 0; lb < ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; lb++) { |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 335 | bh.b_state = 0; |
| 336 | bh.b_blocknr = 0; |
| 337 | bh.b_size = 1 << ip->i_inode.i_blkbits; |
| 338 | rc = gfs2_block_map(jd->jd_inode, lb, &bh, 0); |
| 339 | db = bh.b_blocknr; |
| 340 | if (rc || !db) { |
| 341 | printk(KERN_INFO "GFS2 journal mapping error %d: lb=" |
| 342 | "%u db=%llu\n", rc, lb, (unsigned long long)db); |
| 343 | break; |
| 344 | } |
| 345 | if (!prev_db || db != prev_db + 1) { |
| 346 | jext = kzalloc(sizeof(struct gfs2_journal_extent), |
| 347 | GFP_KERNEL); |
| 348 | if (!jext) { |
| 349 | printk(KERN_INFO "GFS2 error: out of memory " |
| 350 | "mapping journal extents.\n"); |
| 351 | rc = -ENOMEM; |
| 352 | break; |
| 353 | } |
| 354 | jext->dblock = db; |
| 355 | jext->lblock = lb; |
| 356 | jext->blocks = 1; |
| 357 | list_add_tail(&jext->extent_list, &jd->extent_list); |
| 358 | } else { |
| 359 | jext->blocks++; |
| 360 | } |
| 361 | prev_db = db; |
| 362 | } |
| 363 | return rc; |
| 364 | } |
| 365 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 366 | static int init_journal(struct gfs2_sbd *sdp, int undo) |
| 367 | { |
| 368 | struct gfs2_holder ji_gh; |
| 369 | struct task_struct *p; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 370 | struct gfs2_inode *ip; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 371 | int jindex = 1; |
| 372 | int error = 0; |
| 373 | |
| 374 | if (undo) { |
| 375 | jindex = 0; |
| 376 | goto fail_recoverd; |
| 377 | } |
| 378 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 379 | sdp->sd_jindex = gfs2_lookup_simple(sdp->sd_master_dir, "jindex"); |
| 380 | if (IS_ERR(sdp->sd_jindex)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 381 | fs_err(sdp, "can't lookup journal index: %d\n", error); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 382 | return PTR_ERR(sdp->sd_jindex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 383 | } |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 384 | ip = GFS2_I(sdp->sd_jindex); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 385 | set_bit(GLF_STICKY, &ip->i_gl->gl_flags); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 386 | |
| 387 | /* Load in the journal index special file */ |
| 388 | |
| 389 | error = gfs2_jindex_hold(sdp, &ji_gh); |
| 390 | if (error) { |
| 391 | fs_err(sdp, "can't read journal index: %d\n", error); |
| 392 | goto fail; |
| 393 | } |
| 394 | |
| 395 | error = -EINVAL; |
| 396 | if (!gfs2_jindex_size(sdp)) { |
| 397 | fs_err(sdp, "no journals!\n"); |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 398 | goto fail_jindex; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | if (sdp->sd_args.ar_spectator) { |
| 402 | sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0); |
Steven Whitehouse | fd041f0 | 2007-11-08 14:55:03 +0000 | [diff] [blame] | 403 | atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 404 | } else { |
| 405 | if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) { |
| 406 | fs_err(sdp, "can't mount journal #%u\n", |
| 407 | sdp->sd_lockstruct.ls_jid); |
| 408 | fs_err(sdp, "there are only %u journals (0 - %u)\n", |
| 409 | gfs2_jindex_size(sdp), |
| 410 | gfs2_jindex_size(sdp) - 1); |
| 411 | goto fail_jindex; |
| 412 | } |
| 413 | sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid); |
| 414 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 415 | error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 416 | &gfs2_journal_glops, |
| 417 | LM_ST_EXCLUSIVE, LM_FLAG_NOEXP, |
| 418 | &sdp->sd_journal_gh); |
| 419 | if (error) { |
| 420 | fs_err(sdp, "can't acquire journal glock: %d\n", error); |
| 421 | goto fail_jindex; |
| 422 | } |
| 423 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 424 | ip = GFS2_I(sdp->sd_jdesc->jd_inode); |
| 425 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, |
Bob Peterson | 75be73a | 2007-08-08 17:08:14 -0500 | [diff] [blame] | 426 | LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 427 | &sdp->sd_jinode_gh); |
| 428 | if (error) { |
| 429 | fs_err(sdp, "can't acquire journal inode glock: %d\n", |
| 430 | error); |
| 431 | goto fail_journal_gh; |
| 432 | } |
| 433 | |
| 434 | error = gfs2_jdesc_check(sdp->sd_jdesc); |
| 435 | if (error) { |
| 436 | fs_err(sdp, "my journal (%u) is bad: %d\n", |
| 437 | sdp->sd_jdesc->jd_jid, error); |
| 438 | goto fail_jinode_gh; |
| 439 | } |
Steven Whitehouse | fd041f0 | 2007-11-08 14:55:03 +0000 | [diff] [blame] | 440 | atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks); |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 441 | |
| 442 | /* Map the extents for this journal's blocks */ |
| 443 | map_journal_extents(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | if (sdp->sd_lockstruct.ls_first) { |
| 447 | unsigned int x; |
| 448 | for (x = 0; x < sdp->sd_journals; x++) { |
David Teigland | c63e31c | 2006-04-20 17:03:48 -0400 | [diff] [blame] | 449 | error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 450 | if (error) { |
| 451 | fs_err(sdp, "error recovering journal %u: %d\n", |
| 452 | x, error); |
| 453 | goto fail_jinode_gh; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | gfs2_lm_others_may_mount(sdp); |
| 458 | } else if (!sdp->sd_args.ar_spectator) { |
David Teigland | c63e31c | 2006-04-20 17:03:48 -0400 | [diff] [blame] | 459 | error = gfs2_recover_journal(sdp->sd_jdesc); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 460 | if (error) { |
| 461 | fs_err(sdp, "error recovering my journal: %d\n", error); |
| 462 | goto fail_jinode_gh; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags); |
| 467 | gfs2_glock_dq_uninit(&ji_gh); |
| 468 | jindex = 0; |
| 469 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 470 | p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd"); |
| 471 | error = IS_ERR(p); |
| 472 | if (error) { |
| 473 | fs_err(sdp, "can't start recoverd thread: %d\n", error); |
| 474 | goto fail_jinode_gh; |
| 475 | } |
| 476 | sdp->sd_recoverd_process = p; |
| 477 | |
| 478 | return 0; |
| 479 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 480 | fail_recoverd: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 481 | kthread_stop(sdp->sd_recoverd_process); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 482 | fail_jinode_gh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 483 | if (!sdp->sd_args.ar_spectator) |
| 484 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 485 | fail_journal_gh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 486 | if (!sdp->sd_args.ar_spectator) |
| 487 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 488 | fail_jindex: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 489 | gfs2_jindex_free(sdp); |
| 490 | if (jindex) |
| 491 | gfs2_glock_dq_uninit(&ji_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 492 | fail: |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 493 | iput(sdp->sd_jindex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 494 | return error; |
| 495 | } |
| 496 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 497 | |
| 498 | static int init_inodes(struct gfs2_sbd *sdp, int undo) |
| 499 | { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 500 | int error = 0; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 501 | struct gfs2_inode *ip; |
Steven Whitehouse | c9fd430 | 2006-03-01 15:31:02 -0500 | [diff] [blame] | 502 | struct inode *inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 503 | |
| 504 | if (undo) |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 505 | goto fail_qinode; |
| 506 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 507 | inode = gfs2_lookup_root(sdp->sd_vfs, sdp->sd_sb.sb_master_dir.no_addr); |
Steven Whitehouse | c9fd430 | 2006-03-01 15:31:02 -0500 | [diff] [blame] | 508 | if (IS_ERR(inode)) { |
| 509 | error = PTR_ERR(inode); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 510 | fs_err(sdp, "can't read in master directory: %d\n", error); |
| 511 | goto fail; |
| 512 | } |
Steven Whitehouse | c9fd430 | 2006-03-01 15:31:02 -0500 | [diff] [blame] | 513 | sdp->sd_master_dir = inode; |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 514 | |
| 515 | error = init_journal(sdp, undo); |
| 516 | if (error) |
| 517 | goto fail_master; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 518 | |
| 519 | /* Read in the master inode number inode */ |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 520 | sdp->sd_inum_inode = gfs2_lookup_simple(sdp->sd_master_dir, "inum"); |
| 521 | if (IS_ERR(sdp->sd_inum_inode)) { |
| 522 | error = PTR_ERR(sdp->sd_inum_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 523 | fs_err(sdp, "can't read in inum inode: %d\n", error); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 524 | goto fail_journal; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 527 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 528 | /* Read in the master statfs inode */ |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 529 | sdp->sd_statfs_inode = gfs2_lookup_simple(sdp->sd_master_dir, "statfs"); |
| 530 | if (IS_ERR(sdp->sd_statfs_inode)) { |
| 531 | error = PTR_ERR(sdp->sd_statfs_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 532 | fs_err(sdp, "can't read in statfs inode: %d\n", error); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 533 | goto fail_inum; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /* Read in the resource index inode */ |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 537 | sdp->sd_rindex = gfs2_lookup_simple(sdp->sd_master_dir, "rindex"); |
| 538 | if (IS_ERR(sdp->sd_rindex)) { |
| 539 | error = PTR_ERR(sdp->sd_rindex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 540 | fs_err(sdp, "can't get resource index inode: %d\n", error); |
| 541 | goto fail_statfs; |
| 542 | } |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 543 | ip = GFS2_I(sdp->sd_rindex); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 544 | set_bit(GLF_STICKY, &ip->i_gl->gl_flags); |
| 545 | sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 546 | |
| 547 | /* Read in the quota inode */ |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 548 | sdp->sd_quota_inode = gfs2_lookup_simple(sdp->sd_master_dir, "quota"); |
| 549 | if (IS_ERR(sdp->sd_quota_inode)) { |
| 550 | error = PTR_ERR(sdp->sd_quota_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 551 | fs_err(sdp, "can't get quota file inode: %d\n", error); |
| 552 | goto fail_rindex; |
| 553 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 554 | return 0; |
| 555 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 556 | fail_qinode: |
| 557 | iput(sdp->sd_quota_inode); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 558 | fail_rindex: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 559 | gfs2_clear_rgrpd(sdp); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 560 | iput(sdp->sd_rindex); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 561 | fail_statfs: |
| 562 | iput(sdp->sd_statfs_inode); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 563 | fail_inum: |
| 564 | iput(sdp->sd_inum_inode); |
| 565 | fail_journal: |
| 566 | init_journal(sdp, UNDO); |
| 567 | fail_master: |
| 568 | iput(sdp->sd_master_dir); |
| 569 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 570 | return error; |
| 571 | } |
| 572 | |
| 573 | static int init_per_node(struct gfs2_sbd *sdp, int undo) |
| 574 | { |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 575 | struct inode *pn = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 576 | char buf[30]; |
| 577 | int error = 0; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 578 | struct gfs2_inode *ip; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 579 | |
| 580 | if (sdp->sd_args.ar_spectator) |
| 581 | return 0; |
| 582 | |
| 583 | if (undo) |
| 584 | goto fail_qc_gh; |
| 585 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 586 | pn = gfs2_lookup_simple(sdp->sd_master_dir, "per_node"); |
| 587 | if (IS_ERR(pn)) { |
| 588 | error = PTR_ERR(pn); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 589 | fs_err(sdp, "can't find per_node directory: %d\n", error); |
| 590 | return error; |
| 591 | } |
| 592 | |
| 593 | sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 594 | sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf); |
| 595 | if (IS_ERR(sdp->sd_ir_inode)) { |
| 596 | error = PTR_ERR(sdp->sd_ir_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 597 | fs_err(sdp, "can't find local \"ir\" file: %d\n", error); |
| 598 | goto fail; |
| 599 | } |
| 600 | |
| 601 | sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 602 | sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf); |
| 603 | if (IS_ERR(sdp->sd_sc_inode)) { |
| 604 | error = PTR_ERR(sdp->sd_sc_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 605 | fs_err(sdp, "can't find local \"sc\" file: %d\n", error); |
| 606 | goto fail_ir_i; |
| 607 | } |
| 608 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 609 | sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 610 | sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf); |
| 611 | if (IS_ERR(sdp->sd_qc_inode)) { |
| 612 | error = PTR_ERR(sdp->sd_qc_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 613 | fs_err(sdp, "can't find local \"qc\" file: %d\n", error); |
| 614 | goto fail_ut_i; |
| 615 | } |
| 616 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 617 | iput(pn); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 618 | pn = NULL; |
| 619 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 620 | ip = GFS2_I(sdp->sd_ir_inode); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 621 | error = gfs2_glock_nq_init(ip->i_gl, |
Steven Whitehouse | 579b78a | 2006-04-26 14:58:26 -0400 | [diff] [blame] | 622 | LM_ST_EXCLUSIVE, 0, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 623 | &sdp->sd_ir_gh); |
| 624 | if (error) { |
| 625 | fs_err(sdp, "can't lock local \"ir\" file: %d\n", error); |
| 626 | goto fail_qc_i; |
| 627 | } |
| 628 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 629 | ip = GFS2_I(sdp->sd_sc_inode); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 630 | error = gfs2_glock_nq_init(ip->i_gl, |
Steven Whitehouse | 579b78a | 2006-04-26 14:58:26 -0400 | [diff] [blame] | 631 | LM_ST_EXCLUSIVE, 0, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 632 | &sdp->sd_sc_gh); |
| 633 | if (error) { |
| 634 | fs_err(sdp, "can't lock local \"sc\" file: %d\n", error); |
| 635 | goto fail_ir_gh; |
| 636 | } |
| 637 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 638 | ip = GFS2_I(sdp->sd_qc_inode); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 639 | error = gfs2_glock_nq_init(ip->i_gl, |
Steven Whitehouse | 579b78a | 2006-04-26 14:58:26 -0400 | [diff] [blame] | 640 | LM_ST_EXCLUSIVE, 0, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 641 | &sdp->sd_qc_gh); |
| 642 | if (error) { |
| 643 | fs_err(sdp, "can't lock local \"qc\" file: %d\n", error); |
| 644 | goto fail_ut_gh; |
| 645 | } |
| 646 | |
| 647 | return 0; |
| 648 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 649 | fail_qc_gh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 650 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 651 | fail_ut_gh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 652 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 653 | fail_ir_gh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 654 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 655 | fail_qc_i: |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 656 | iput(sdp->sd_qc_inode); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 657 | fail_ut_i: |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 658 | iput(sdp->sd_sc_inode); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 659 | fail_ir_i: |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 660 | iput(sdp->sd_ir_inode); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 661 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 662 | if (pn) |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 663 | iput(pn); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 664 | return error; |
| 665 | } |
| 666 | |
| 667 | static int init_threads(struct gfs2_sbd *sdp, int undo) |
| 668 | { |
| 669 | struct task_struct *p; |
| 670 | int error = 0; |
| 671 | |
| 672 | if (undo) |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 673 | goto fail_quotad; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 674 | |
| 675 | sdp->sd_log_flush_time = jiffies; |
| 676 | sdp->sd_jindex_refresh_time = jiffies; |
| 677 | |
| 678 | p = kthread_run(gfs2_logd, sdp, "gfs2_logd"); |
| 679 | error = IS_ERR(p); |
| 680 | if (error) { |
| 681 | fs_err(sdp, "can't start logd thread: %d\n", error); |
| 682 | return error; |
| 683 | } |
| 684 | sdp->sd_logd_process = p; |
| 685 | |
| 686 | sdp->sd_statfs_sync_time = jiffies; |
| 687 | sdp->sd_quota_sync_time = jiffies; |
| 688 | |
| 689 | p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad"); |
| 690 | error = IS_ERR(p); |
| 691 | if (error) { |
| 692 | fs_err(sdp, "can't start quotad thread: %d\n", error); |
| 693 | goto fail; |
| 694 | } |
| 695 | sdp->sd_quotad_process = p; |
| 696 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 697 | return 0; |
| 698 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 699 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 700 | fail_quotad: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 701 | kthread_stop(sdp->sd_quotad_process); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 702 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 703 | kthread_stop(sdp->sd_logd_process); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 704 | return error; |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * fill_super - Read in superblock |
| 709 | * @sb: The VFS superblock |
| 710 | * @data: Mount options |
| 711 | * @silent: Don't complain if it's not a GFS2 filesystem |
| 712 | * |
| 713 | * Returns: errno |
| 714 | */ |
| 715 | |
| 716 | static int fill_super(struct super_block *sb, void *data, int silent) |
| 717 | { |
| 718 | struct gfs2_sbd *sdp; |
| 719 | struct gfs2_holder mount_gh; |
| 720 | int error; |
| 721 | |
| 722 | sdp = init_sbd(sb); |
| 723 | if (!sdp) { |
Steven Whitehouse | d92a8d4 | 2006-02-27 10:57:14 -0500 | [diff] [blame] | 724 | printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n"); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 725 | return -ENOMEM; |
| 726 | } |
| 727 | |
| 728 | error = gfs2_mount_args(sdp, (char *)data, 0); |
| 729 | if (error) { |
Steven Whitehouse | d92a8d4 | 2006-02-27 10:57:14 -0500 | [diff] [blame] | 730 | printk(KERN_WARNING "GFS2: can't parse mount arguments\n"); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 731 | goto fail; |
| 732 | } |
| 733 | |
Steven Whitehouse | 419c93e0 | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 734 | init_vfs(sb, SDF_NOATIME); |
| 735 | |
| 736 | /* Set up the buffer cache and fill in some fake block size values |
| 737 | to allow us to read-in the on-disk superblock. */ |
| 738 | sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK); |
| 739 | sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits; |
| 740 | sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - |
| 741 | GFS2_BASIC_BLOCK_SHIFT; |
| 742 | sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 743 | |
| 744 | error = init_names(sdp, silent); |
| 745 | if (error) |
| 746 | goto fail; |
| 747 | |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 748 | gfs2_create_debugfs_file(sdp); |
| 749 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 750 | error = gfs2_sys_fs_add(sdp); |
| 751 | if (error) |
| 752 | goto fail; |
| 753 | |
| 754 | error = gfs2_lm_mount(sdp, silent); |
| 755 | if (error) |
| 756 | goto fail_sys; |
| 757 | |
| 758 | error = init_locking(sdp, &mount_gh, DO); |
| 759 | if (error) |
| 760 | goto fail_lm; |
| 761 | |
| 762 | error = init_sb(sdp, silent, DO); |
| 763 | if (error) |
| 764 | goto fail_locking; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 765 | |
| 766 | error = init_inodes(sdp, DO); |
| 767 | if (error) |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 768 | goto fail_sb; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 769 | |
| 770 | error = init_per_node(sdp, DO); |
| 771 | if (error) |
| 772 | goto fail_inodes; |
| 773 | |
| 774 | error = gfs2_statfs_init(sdp); |
| 775 | if (error) { |
| 776 | fs_err(sdp, "can't initialize statfs subsystem: %d\n", error); |
| 777 | goto fail_per_node; |
| 778 | } |
| 779 | |
| 780 | error = init_threads(sdp, DO); |
| 781 | if (error) |
| 782 | goto fail_per_node; |
| 783 | |
| 784 | if (!(sb->s_flags & MS_RDONLY)) { |
| 785 | error = gfs2_make_fs_rw(sdp); |
| 786 | if (error) { |
| 787 | fs_err(sdp, "can't make FS RW: %d\n", error); |
| 788 | goto fail_threads; |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | gfs2_glock_dq_uninit(&mount_gh); |
| 793 | |
| 794 | return 0; |
| 795 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 796 | fail_threads: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 797 | init_threads(sdp, UNDO); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 798 | fail_per_node: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 799 | init_per_node(sdp, UNDO); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 800 | fail_inodes: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 801 | init_inodes(sdp, UNDO); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 802 | fail_sb: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 803 | init_sb(sdp, 0, UNDO); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 804 | fail_locking: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 805 | init_locking(sdp, &mount_gh, UNDO); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 806 | fail_lm: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 807 | gfs2_gl_hash_clear(sdp, WAIT); |
| 808 | gfs2_lm_unmount(sdp); |
| 809 | while (invalidate_inodes(sb)) |
| 810 | yield(); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 811 | fail_sys: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 812 | gfs2_sys_fs_del(sdp); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 813 | fail: |
Robert Peterson | 5f88209 | 2007-04-18 11:41:11 -0500 | [diff] [blame] | 814 | gfs2_delete_debugfs_file(sdp); |
Steven Whitehouse | a2c4580 | 2006-09-08 10:13:03 -0400 | [diff] [blame] | 815 | kfree(sdp); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 816 | sb->s_fs_info = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 817 | return error; |
| 818 | } |
| 819 | |
Andrew Morton | ccd6efd | 2006-06-30 02:16:34 -0700 | [diff] [blame] | 820 | static int gfs2_get_sb(struct file_system_type *fs_type, int flags, |
| 821 | const char *dev_name, void *data, struct vfsmount *mnt) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 822 | { |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 823 | struct super_block *sb; |
| 824 | struct gfs2_sbd *sdp; |
| 825 | int error = get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt); |
| 826 | if (error) |
| 827 | goto out; |
| 828 | sb = mnt->mnt_sb; |
Steven Whitehouse | 26c1a57 | 2006-09-04 15:32:10 -0400 | [diff] [blame] | 829 | sdp = sb->s_fs_info; |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 830 | sdp->sd_gfs2mnt = mnt; |
| 831 | out: |
| 832 | return error; |
| 833 | } |
| 834 | |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 835 | static int fill_super_meta(struct super_block *sb, struct super_block *new, |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 836 | void *data, int silent) |
| 837 | { |
| 838 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 839 | struct inode *inode; |
| 840 | int error = 0; |
| 841 | |
| 842 | new->s_fs_info = sdp; |
| 843 | sdp->sd_vfs_meta = sb; |
| 844 | |
| 845 | init_vfs(new, SDF_NOATIME); |
| 846 | |
| 847 | /* Get the master inode */ |
| 848 | inode = igrab(sdp->sd_master_dir); |
| 849 | |
| 850 | new->s_root = d_alloc_root(inode); |
| 851 | if (!new->s_root) { |
| 852 | fs_err(sdp, "can't get root dentry\n"); |
| 853 | error = -ENOMEM; |
| 854 | iput(inode); |
Adrian Bunk | bbbe451 | 2006-10-19 15:27:00 +0200 | [diff] [blame] | 855 | } else |
| 856 | new->s_root->d_op = &gfs2_dops; |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 857 | |
| 858 | return error; |
| 859 | } |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 860 | |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 861 | static int set_bdev_super(struct super_block *s, void *data) |
| 862 | { |
| 863 | s->s_bdev = data; |
| 864 | s->s_dev = s->s_bdev->bd_dev; |
| 865 | return 0; |
| 866 | } |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 867 | |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 868 | static int test_bdev_super(struct super_block *s, void *data) |
| 869 | { |
Steven Whitehouse | 26c1a57 | 2006-09-04 15:32:10 -0400 | [diff] [blame] | 870 | return s->s_bdev == data; |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | static struct super_block* get_gfs2_sb(const char *dev_name) |
| 874 | { |
| 875 | struct kstat stat; |
| 876 | struct nameidata nd; |
| 877 | struct file_system_type *fstype; |
| 878 | struct super_block *sb = NULL, *s; |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 879 | int error; |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 880 | |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 881 | error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd); |
| 882 | if (error) { |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 883 | printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n", |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 884 | dev_name); |
| 885 | goto out; |
| 886 | } |
| 887 | error = vfs_getattr(nd.mnt, nd.dentry, &stat); |
| 888 | |
| 889 | fstype = get_fs_type("gfs2"); |
Denis Cheng | adb4ec1 | 2007-08-11 10:27:07 +0800 | [diff] [blame] | 890 | list_for_each_entry(s, &fstype->fs_supers, s_instances) { |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 891 | if ((S_ISBLK(stat.mode) && s->s_dev == stat.rdev) || |
| 892 | (S_ISDIR(stat.mode) && s == nd.dentry->d_inode->i_sb)) { |
| 893 | sb = s; |
| 894 | goto free_nd; |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | printk(KERN_WARNING "GFS2: Unrecognized block device or " |
Richard Fearn | d5a6751 | 2007-02-17 17:29:15 +0000 | [diff] [blame] | 899 | "mount point %s\n", dev_name); |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 900 | |
| 901 | free_nd: |
| 902 | path_release(&nd); |
| 903 | out: |
| 904 | return sb; |
| 905 | } |
| 906 | |
| 907 | static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags, |
| 908 | const char *dev_name, void *data, struct vfsmount *mnt) |
| 909 | { |
| 910 | int error = 0; |
| 911 | struct super_block *sb = NULL, *new; |
| 912 | struct gfs2_sbd *sdp; |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 913 | |
| 914 | sb = get_gfs2_sb(dev_name); |
| 915 | if (!sb) { |
| 916 | printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n"); |
| 917 | error = -ENOENT; |
| 918 | goto error; |
| 919 | } |
Denis Cheng | 2d3ba1e | 2007-08-11 10:27:08 +0800 | [diff] [blame] | 920 | sdp = sb->s_fs_info; |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 921 | if (sdp->sd_vfs_meta) { |
| 922 | printk(KERN_WARNING "GFS2: gfs2meta mount already exists\n"); |
| 923 | error = -EBUSY; |
| 924 | goto error; |
| 925 | } |
David Chinner | f73ca1b | 2007-01-10 23:15:41 -0800 | [diff] [blame] | 926 | down(&sb->s_bdev->bd_mount_sem); |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 927 | new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev); |
David Chinner | f73ca1b | 2007-01-10 23:15:41 -0800 | [diff] [blame] | 928 | up(&sb->s_bdev->bd_mount_sem); |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 929 | if (IS_ERR(new)) { |
| 930 | error = PTR_ERR(new); |
| 931 | goto error; |
| 932 | } |
| 933 | module_put(fs_type->owner); |
| 934 | new->s_flags = flags; |
| 935 | strlcpy(new->s_id, sb->s_id, sizeof(new->s_id)); |
| 936 | sb_set_blocksize(new, sb->s_blocksize); |
| 937 | error = fill_super_meta(sb, new, data, flags & MS_SILENT ? 1 : 0); |
| 938 | if (error) { |
| 939 | up_write(&new->s_umount); |
| 940 | deactivate_super(new); |
| 941 | goto error; |
| 942 | } |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 943 | |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 944 | new->s_flags |= MS_ACTIVE; |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 945 | |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 946 | /* Grab a reference to the gfs2 mount point */ |
| 947 | atomic_inc(&sdp->sd_gfs2mnt->mnt_count); |
| 948 | return simple_set_mnt(mnt, new); |
| 949 | error: |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 950 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Steven Whitehouse | 419c93e0 | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 953 | static void gfs2_kill_sb(struct super_block *sb) |
| 954 | { |
Abhijith Das | d1e2777 | 2007-08-23 13:33:01 -0500 | [diff] [blame] | 955 | if (sb->s_fs_info) { |
| 956 | gfs2_delete_debugfs_file(sb->s_fs_info); |
| 957 | gfs2_meta_syncfs(sb->s_fs_info); |
| 958 | } |
Steven Whitehouse | 419c93e0 | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 959 | kill_block_super(sb); |
| 960 | } |
| 961 | |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 962 | static void gfs2_kill_sb_meta(struct super_block *sb) |
| 963 | { |
| 964 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 965 | generic_shutdown_super(sb); |
| 966 | sdp->sd_vfs_meta = NULL; |
| 967 | atomic_dec(&sdp->sd_gfs2mnt->mnt_count); |
| 968 | } |
| 969 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 970 | struct file_system_type gfs2_fs_type = { |
| 971 | .name = "gfs2", |
| 972 | .fs_flags = FS_REQUIRES_DEV, |
| 973 | .get_sb = gfs2_get_sb, |
Steven Whitehouse | 419c93e0 | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 974 | .kill_sb = gfs2_kill_sb, |
| 975 | .owner = THIS_MODULE, |
| 976 | }; |
| 977 | |
| 978 | struct file_system_type gfs2meta_fs_type = { |
| 979 | .name = "gfs2meta", |
| 980 | .fs_flags = FS_REQUIRES_DEV, |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 981 | .get_sb = gfs2_get_sb_meta, |
| 982 | .kill_sb = gfs2_kill_sb_meta, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 983 | .owner = THIS_MODULE, |
| 984 | }; |
| 985 | |