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 | cf45b75 | 2008-01-31 10:31:39 -0600 | [diff] [blame] | 3 | * Copyright (C) 2004-2008 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 "glock.h" |
| 26 | #include "glops.h" |
| 27 | #include "inode.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 28 | #include "mount.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 29 | #include "recovery.h" |
| 30 | #include "rgrp.h" |
| 31 | #include "super.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 32 | #include "sys.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 33 | #include "util.h" |
Steven Whitehouse | bb3b0e3 | 2007-08-16 16:03:57 +0100 | [diff] [blame] | 34 | #include "log.h" |
Steven Whitehouse | 9ac1b4d | 2008-11-19 10:08:22 +0000 | [diff] [blame] | 35 | #include "quota.h" |
Steven Whitehouse | b528968 | 2008-11-26 12:49:26 +0000 | [diff] [blame] | 36 | #include "dir.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 37 | |
| 38 | #define DO 0 |
| 39 | #define UNDO 1 |
| 40 | |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 41 | static const u32 gfs2_old_fs_formats[] = { |
| 42 | 0 |
| 43 | }; |
| 44 | |
| 45 | static const u32 gfs2_old_multihost_formats[] = { |
| 46 | 0 |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * gfs2_tune_init - Fill a gfs2_tune structure with default values |
| 51 | * @gt: tune |
| 52 | * |
| 53 | */ |
| 54 | |
| 55 | static void gfs2_tune_init(struct gfs2_tune *gt) |
| 56 | { |
| 57 | spin_lock_init(>->gt_spin); |
| 58 | |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 59 | gt->gt_incore_log_blocks = 1024; |
| 60 | gt->gt_log_flush_secs = 60; |
| 61 | gt->gt_recoverd_secs = 60; |
| 62 | gt->gt_logd_secs = 1; |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 63 | gt->gt_quota_simul_sync = 64; |
| 64 | gt->gt_quota_warn_period = 10; |
| 65 | gt->gt_quota_scale_num = 1; |
| 66 | gt->gt_quota_scale_den = 1; |
| 67 | gt->gt_quota_cache_secs = 300; |
| 68 | gt->gt_quota_quantum = 60; |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 69 | gt->gt_new_files_jdata = 0; |
| 70 | gt->gt_max_readahead = 1 << 18; |
| 71 | gt->gt_stall_secs = 600; |
| 72 | gt->gt_complain_secs = 10; |
| 73 | gt->gt_statfs_quantum = 30; |
| 74 | gt->gt_statfs_slow = 0; |
| 75 | } |
| 76 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 77 | static struct gfs2_sbd *init_sbd(struct super_block *sb) |
| 78 | { |
| 79 | struct gfs2_sbd *sdp; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 80 | |
Steven Whitehouse | 85d1da6 | 2006-09-07 14:40:21 -0400 | [diff] [blame] | 81 | sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 82 | if (!sdp) |
| 83 | return NULL; |
| 84 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 85 | sb->s_fs_info = sdp; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 86 | sdp->sd_vfs = sb; |
| 87 | |
| 88 | gfs2_tune_init(&sdp->sd_tune); |
| 89 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 90 | mutex_init(&sdp->sd_inum_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 91 | spin_lock_init(&sdp->sd_statfs_spin); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 92 | |
| 93 | spin_lock_init(&sdp->sd_rindex_spin); |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 94 | mutex_init(&sdp->sd_rindex_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 95 | INIT_LIST_HEAD(&sdp->sd_rindex_list); |
| 96 | INIT_LIST_HEAD(&sdp->sd_rindex_mru_list); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 97 | |
| 98 | INIT_LIST_HEAD(&sdp->sd_jindex_list); |
| 99 | spin_lock_init(&sdp->sd_jindex_spin); |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 100 | mutex_init(&sdp->sd_jindex_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 101 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 102 | INIT_LIST_HEAD(&sdp->sd_quota_list); |
| 103 | spin_lock_init(&sdp->sd_quota_spin); |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 104 | mutex_init(&sdp->sd_quota_mutex); |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 105 | init_waitqueue_head(&sdp->sd_quota_wait); |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 106 | INIT_LIST_HEAD(&sdp->sd_trunc_list); |
| 107 | spin_lock_init(&sdp->sd_trunc_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 108 | |
| 109 | spin_lock_init(&sdp->sd_log_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 110 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 111 | INIT_LIST_HEAD(&sdp->sd_log_le_buf); |
| 112 | INIT_LIST_HEAD(&sdp->sd_log_le_revoke); |
| 113 | INIT_LIST_HEAD(&sdp->sd_log_le_rg); |
| 114 | INIT_LIST_HEAD(&sdp->sd_log_le_databuf); |
Steven Whitehouse | d7b616e | 2007-09-02 10:48:13 +0100 | [diff] [blame] | 115 | INIT_LIST_HEAD(&sdp->sd_log_le_ordered); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 116 | |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 117 | mutex_init(&sdp->sd_log_reserve_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 118 | INIT_LIST_HEAD(&sdp->sd_ail1_list); |
| 119 | INIT_LIST_HEAD(&sdp->sd_ail2_list); |
| 120 | |
Steven Whitehouse | 484adff | 2006-03-29 09:12:12 -0500 | [diff] [blame] | 121 | init_rwsem(&sdp->sd_log_flush_lock); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 122 | atomic_set(&sdp->sd_log_in_flight, 0); |
| 123 | init_waitqueue_head(&sdp->sd_log_flush_wait); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 124 | |
| 125 | INIT_LIST_HEAD(&sdp->sd_revoke_list); |
| 126 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 127 | mutex_init(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 128 | |
| 129 | return sdp; |
| 130 | } |
| 131 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 132 | |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 133 | /** |
| 134 | * gfs2_check_sb - Check superblock |
| 135 | * @sdp: the filesystem |
| 136 | * @sb: The superblock |
| 137 | * @silent: Don't print a message if the check fails |
| 138 | * |
| 139 | * Checks the version code of the FS is one that we understand how to |
| 140 | * read and that the sizes of the various on-disk structures have not |
| 141 | * changed. |
| 142 | */ |
| 143 | |
| 144 | static int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb_host *sb, int silent) |
| 145 | { |
| 146 | unsigned int x; |
| 147 | |
| 148 | if (sb->sb_magic != GFS2_MAGIC || |
| 149 | sb->sb_type != GFS2_METATYPE_SB) { |
| 150 | if (!silent) |
| 151 | printk(KERN_WARNING "GFS2: not a GFS2 filesystem\n"); |
| 152 | return -EINVAL; |
| 153 | } |
| 154 | |
| 155 | /* If format numbers match exactly, we're done. */ |
| 156 | |
| 157 | if (sb->sb_fs_format == GFS2_FORMAT_FS && |
| 158 | sb->sb_multihost_format == GFS2_FORMAT_MULTI) |
| 159 | return 0; |
| 160 | |
| 161 | if (sb->sb_fs_format != GFS2_FORMAT_FS) { |
| 162 | for (x = 0; gfs2_old_fs_formats[x]; x++) |
| 163 | if (gfs2_old_fs_formats[x] == sb->sb_fs_format) |
| 164 | break; |
| 165 | |
| 166 | if (!gfs2_old_fs_formats[x]) { |
| 167 | printk(KERN_WARNING |
| 168 | "GFS2: code version (%u, %u) is incompatible " |
| 169 | "with ondisk format (%u, %u)\n", |
| 170 | GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, |
| 171 | sb->sb_fs_format, sb->sb_multihost_format); |
| 172 | printk(KERN_WARNING |
| 173 | "GFS2: I don't know how to upgrade this FS\n"); |
| 174 | return -EINVAL; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | if (sb->sb_multihost_format != GFS2_FORMAT_MULTI) { |
| 179 | for (x = 0; gfs2_old_multihost_formats[x]; x++) |
| 180 | if (gfs2_old_multihost_formats[x] == |
| 181 | sb->sb_multihost_format) |
| 182 | break; |
| 183 | |
| 184 | if (!gfs2_old_multihost_formats[x]) { |
| 185 | printk(KERN_WARNING |
| 186 | "GFS2: code version (%u, %u) is incompatible " |
| 187 | "with ondisk format (%u, %u)\n", |
| 188 | GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, |
| 189 | sb->sb_fs_format, sb->sb_multihost_format); |
| 190 | printk(KERN_WARNING |
| 191 | "GFS2: I don't know how to upgrade this FS\n"); |
| 192 | return -EINVAL; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if (!sdp->sd_args.ar_upgrade) { |
| 197 | printk(KERN_WARNING |
| 198 | "GFS2: code version (%u, %u) is incompatible " |
| 199 | "with ondisk format (%u, %u)\n", |
| 200 | GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, |
| 201 | sb->sb_fs_format, sb->sb_multihost_format); |
| 202 | printk(KERN_INFO |
| 203 | "GFS2: Use the \"upgrade\" mount option to upgrade " |
| 204 | "the FS\n"); |
| 205 | printk(KERN_INFO "GFS2: See the manual for more details\n"); |
| 206 | return -EINVAL; |
| 207 | } |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static void end_bio_io_page(struct bio *bio, int error) |
| 213 | { |
| 214 | struct page *page = bio->bi_private; |
| 215 | |
| 216 | if (!error) |
| 217 | SetPageUptodate(page); |
| 218 | else |
| 219 | printk(KERN_WARNING "gfs2: error %d reading superblock\n", error); |
| 220 | unlock_page(page); |
| 221 | } |
| 222 | |
| 223 | static void gfs2_sb_in(struct gfs2_sb_host *sb, const void *buf) |
| 224 | { |
| 225 | const struct gfs2_sb *str = buf; |
| 226 | |
| 227 | sb->sb_magic = be32_to_cpu(str->sb_header.mh_magic); |
| 228 | sb->sb_type = be32_to_cpu(str->sb_header.mh_type); |
| 229 | sb->sb_format = be32_to_cpu(str->sb_header.mh_format); |
| 230 | sb->sb_fs_format = be32_to_cpu(str->sb_fs_format); |
| 231 | sb->sb_multihost_format = be32_to_cpu(str->sb_multihost_format); |
| 232 | sb->sb_bsize = be32_to_cpu(str->sb_bsize); |
| 233 | sb->sb_bsize_shift = be32_to_cpu(str->sb_bsize_shift); |
| 234 | sb->sb_master_dir.no_addr = be64_to_cpu(str->sb_master_dir.no_addr); |
| 235 | sb->sb_master_dir.no_formal_ino = be64_to_cpu(str->sb_master_dir.no_formal_ino); |
| 236 | sb->sb_root_dir.no_addr = be64_to_cpu(str->sb_root_dir.no_addr); |
| 237 | sb->sb_root_dir.no_formal_ino = be64_to_cpu(str->sb_root_dir.no_formal_ino); |
| 238 | |
| 239 | memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN); |
| 240 | memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN); |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * gfs2_read_super - Read the gfs2 super block from disk |
| 245 | * @sdp: The GFS2 super block |
| 246 | * @sector: The location of the super block |
| 247 | * @error: The error code to return |
| 248 | * |
| 249 | * This uses the bio functions to read the super block from disk |
| 250 | * because we want to be 100% sure that we never read cached data. |
| 251 | * A super block is read twice only during each GFS2 mount and is |
| 252 | * never written to by the filesystem. The first time its read no |
| 253 | * locks are held, and the only details which are looked at are those |
| 254 | * relating to the locking protocol. Once locking is up and working, |
| 255 | * the sb is read again under the lock to establish the location of |
| 256 | * the master directory (contains pointers to journals etc) and the |
| 257 | * root directory. |
| 258 | * |
| 259 | * Returns: 0 on success or error |
| 260 | */ |
| 261 | |
| 262 | static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector) |
| 263 | { |
| 264 | struct super_block *sb = sdp->sd_vfs; |
| 265 | struct gfs2_sb *p; |
| 266 | struct page *page; |
| 267 | struct bio *bio; |
| 268 | |
| 269 | page = alloc_page(GFP_NOFS); |
| 270 | if (unlikely(!page)) |
| 271 | return -ENOBUFS; |
| 272 | |
| 273 | ClearPageUptodate(page); |
| 274 | ClearPageDirty(page); |
| 275 | lock_page(page); |
| 276 | |
| 277 | bio = bio_alloc(GFP_NOFS, 1); |
| 278 | if (unlikely(!bio)) { |
| 279 | __free_page(page); |
| 280 | return -ENOBUFS; |
| 281 | } |
| 282 | |
| 283 | bio->bi_sector = sector * (sb->s_blocksize >> 9); |
| 284 | bio->bi_bdev = sb->s_bdev; |
| 285 | bio_add_page(bio, page, PAGE_SIZE, 0); |
| 286 | |
| 287 | bio->bi_end_io = end_bio_io_page; |
| 288 | bio->bi_private = page; |
| 289 | submit_bio(READ_SYNC | (1 << BIO_RW_META), bio); |
| 290 | wait_on_page_locked(page); |
| 291 | bio_put(bio); |
| 292 | if (!PageUptodate(page)) { |
| 293 | __free_page(page); |
| 294 | return -EIO; |
| 295 | } |
| 296 | p = kmap(page); |
| 297 | gfs2_sb_in(&sdp->sd_sb, p); |
| 298 | kunmap(page); |
| 299 | __free_page(page); |
| 300 | return 0; |
| 301 | } |
| 302 | /** |
| 303 | * gfs2_read_sb - Read super block |
| 304 | * @sdp: The GFS2 superblock |
| 305 | * @gl: the glock for the superblock (assumed to be held) |
| 306 | * @silent: Don't print message if mount fails |
| 307 | * |
| 308 | */ |
| 309 | |
| 310 | static int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) |
| 311 | { |
| 312 | u32 hash_blocks, ind_blocks, leaf_blocks; |
| 313 | u32 tmp_blocks; |
| 314 | unsigned int x; |
| 315 | int error; |
| 316 | |
| 317 | error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); |
| 318 | if (error) { |
| 319 | if (!silent) |
| 320 | fs_err(sdp, "can't read superblock\n"); |
| 321 | return error; |
| 322 | } |
| 323 | |
| 324 | error = gfs2_check_sb(sdp, &sdp->sd_sb, silent); |
| 325 | if (error) |
| 326 | return error; |
| 327 | |
| 328 | sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - |
| 329 | GFS2_BASIC_BLOCK_SHIFT; |
| 330 | sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; |
| 331 | sdp->sd_diptrs = (sdp->sd_sb.sb_bsize - |
| 332 | sizeof(struct gfs2_dinode)) / sizeof(u64); |
| 333 | sdp->sd_inptrs = (sdp->sd_sb.sb_bsize - |
| 334 | sizeof(struct gfs2_meta_header)) / sizeof(u64); |
| 335 | sdp->sd_jbsize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header); |
| 336 | sdp->sd_hash_bsize = sdp->sd_sb.sb_bsize / 2; |
| 337 | sdp->sd_hash_bsize_shift = sdp->sd_sb.sb_bsize_shift - 1; |
| 338 | sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(u64); |
| 339 | sdp->sd_qc_per_block = (sdp->sd_sb.sb_bsize - |
| 340 | sizeof(struct gfs2_meta_header)) / |
| 341 | sizeof(struct gfs2_quota_change); |
| 342 | |
| 343 | /* Compute maximum reservation required to add a entry to a directory */ |
| 344 | |
| 345 | hash_blocks = DIV_ROUND_UP(sizeof(u64) * (1 << GFS2_DIR_MAX_DEPTH), |
| 346 | sdp->sd_jbsize); |
| 347 | |
| 348 | ind_blocks = 0; |
| 349 | for (tmp_blocks = hash_blocks; tmp_blocks > sdp->sd_diptrs;) { |
| 350 | tmp_blocks = DIV_ROUND_UP(tmp_blocks, sdp->sd_inptrs); |
| 351 | ind_blocks += tmp_blocks; |
| 352 | } |
| 353 | |
| 354 | leaf_blocks = 2 + GFS2_DIR_MAX_DEPTH; |
| 355 | |
| 356 | sdp->sd_max_dirres = hash_blocks + ind_blocks + leaf_blocks; |
| 357 | |
| 358 | sdp->sd_heightsize[0] = sdp->sd_sb.sb_bsize - |
| 359 | sizeof(struct gfs2_dinode); |
| 360 | sdp->sd_heightsize[1] = sdp->sd_sb.sb_bsize * sdp->sd_diptrs; |
| 361 | for (x = 2;; x++) { |
| 362 | u64 space, d; |
| 363 | u32 m; |
| 364 | |
| 365 | space = sdp->sd_heightsize[x - 1] * sdp->sd_inptrs; |
| 366 | d = space; |
| 367 | m = do_div(d, sdp->sd_inptrs); |
| 368 | |
| 369 | if (d != sdp->sd_heightsize[x - 1] || m) |
| 370 | break; |
| 371 | sdp->sd_heightsize[x] = space; |
| 372 | } |
| 373 | sdp->sd_max_height = x; |
| 374 | sdp->sd_heightsize[x] = ~0; |
| 375 | gfs2_assert(sdp, sdp->sd_max_height <= GFS2_MAX_META_HEIGHT); |
| 376 | |
| 377 | sdp->sd_jheightsize[0] = sdp->sd_sb.sb_bsize - |
| 378 | sizeof(struct gfs2_dinode); |
| 379 | sdp->sd_jheightsize[1] = sdp->sd_jbsize * sdp->sd_diptrs; |
| 380 | for (x = 2;; x++) { |
| 381 | u64 space, d; |
| 382 | u32 m; |
| 383 | |
| 384 | space = sdp->sd_jheightsize[x - 1] * sdp->sd_inptrs; |
| 385 | d = space; |
| 386 | m = do_div(d, sdp->sd_inptrs); |
| 387 | |
| 388 | if (d != sdp->sd_jheightsize[x - 1] || m) |
| 389 | break; |
| 390 | sdp->sd_jheightsize[x] = space; |
| 391 | } |
| 392 | sdp->sd_max_jheight = x; |
| 393 | sdp->sd_jheightsize[x] = ~0; |
| 394 | gfs2_assert(sdp, sdp->sd_max_jheight <= GFS2_MAX_META_HEIGHT); |
| 395 | |
| 396 | return 0; |
| 397 | } |
| 398 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 399 | static int init_names(struct gfs2_sbd *sdp, int silent) |
| 400 | { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 401 | char *proto, *table; |
| 402 | int error = 0; |
| 403 | |
| 404 | proto = sdp->sd_args.ar_lockproto; |
| 405 | table = sdp->sd_args.ar_locktable; |
| 406 | |
| 407 | /* Try to autodetect */ |
| 408 | |
| 409 | if (!proto[0] || !table[0]) { |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 410 | error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); |
| 411 | if (error) |
| 412 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 413 | |
Steven Whitehouse | 3cf1e7b | 2006-10-02 11:49:41 -0400 | [diff] [blame] | 414 | error = gfs2_check_sb(sdp, &sdp->sd_sb, silent); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 415 | if (error) |
| 416 | goto out; |
| 417 | |
| 418 | if (!proto[0]) |
Steven Whitehouse | 3cf1e7b | 2006-10-02 11:49:41 -0400 | [diff] [blame] | 419 | proto = sdp->sd_sb.sb_lockproto; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 420 | if (!table[0]) |
Steven Whitehouse | 3cf1e7b | 2006-10-02 11:49:41 -0400 | [diff] [blame] | 421 | table = sdp->sd_sb.sb_locktable; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | if (!table[0]) |
| 425 | table = sdp->sd_vfs->s_id; |
| 426 | |
Jean Delvare | 00377d8 | 2008-05-09 17:59:51 +0200 | [diff] [blame] | 427 | strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN); |
| 428 | strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 429 | |
Denis Cheng | 5d35e31 | 2007-08-13 11:01:58 +0800 | [diff] [blame] | 430 | table = sdp->sd_table_name; |
| 431 | while ((table = strchr(table, '/'))) |
Robert Peterson | b35997d | 2007-06-07 09:10:01 -0500 | [diff] [blame] | 432 | *table = '_'; |
| 433 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 434 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 435 | return error; |
| 436 | } |
| 437 | |
| 438 | static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh, |
| 439 | int undo) |
| 440 | { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 441 | int error = 0; |
| 442 | |
| 443 | if (undo) |
| 444 | goto fail_trans; |
| 445 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 446 | error = gfs2_glock_nq_num(sdp, |
| 447 | GFS2_MOUNT_LOCK, &gfs2_nondisk_glops, |
| 448 | LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE, |
| 449 | mount_gh); |
| 450 | if (error) { |
| 451 | fs_err(sdp, "can't acquire mount glock: %d\n", error); |
| 452 | goto fail; |
| 453 | } |
| 454 | |
| 455 | error = gfs2_glock_nq_num(sdp, |
| 456 | GFS2_LIVE_LOCK, &gfs2_nondisk_glops, |
| 457 | LM_ST_SHARED, |
Steven Whitehouse | 579b78a | 2006-04-26 14:58:26 -0400 | [diff] [blame] | 458 | LM_FLAG_NOEXP | GL_EXACT, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 459 | &sdp->sd_live_gh); |
| 460 | if (error) { |
| 461 | fs_err(sdp, "can't acquire live glock: %d\n", error); |
| 462 | goto fail_mount; |
| 463 | } |
| 464 | |
| 465 | error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops, |
| 466 | CREATE, &sdp->sd_rename_gl); |
| 467 | if (error) { |
| 468 | fs_err(sdp, "can't create rename glock: %d\n", error); |
| 469 | goto fail_live; |
| 470 | } |
| 471 | |
| 472 | error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops, |
| 473 | CREATE, &sdp->sd_trans_gl); |
| 474 | if (error) { |
| 475 | fs_err(sdp, "can't create transaction glock: %d\n", error); |
| 476 | goto fail_rename; |
| 477 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 478 | |
| 479 | return 0; |
| 480 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 481 | fail_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 482 | gfs2_glock_put(sdp->sd_trans_gl); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 483 | fail_rename: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 484 | gfs2_glock_put(sdp->sd_rename_gl); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 485 | fail_live: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 486 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 487 | fail_mount: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 488 | gfs2_glock_dq_uninit(mount_gh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 489 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 490 | return error; |
| 491 | } |
| 492 | |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 493 | static int gfs2_lookup_root(struct super_block *sb, struct dentry **dptr, |
| 494 | u64 no_addr, const char *name) |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 495 | { |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 496 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 497 | struct dentry *dentry; |
| 498 | struct inode *inode; |
| 499 | |
| 500 | inode = gfs2_inode_lookup(sb, DT_DIR, no_addr, 0, 0); |
| 501 | if (IS_ERR(inode)) { |
| 502 | fs_err(sdp, "can't read in %s inode: %ld\n", name, PTR_ERR(inode)); |
| 503 | return PTR_ERR(inode); |
| 504 | } |
| 505 | dentry = d_alloc_root(inode); |
| 506 | if (!dentry) { |
| 507 | fs_err(sdp, "can't alloc %s dentry\n", name); |
| 508 | iput(inode); |
| 509 | return -ENOMEM; |
| 510 | } |
| 511 | dentry->d_op = &gfs2_dops; |
| 512 | *dptr = dentry; |
| 513 | return 0; |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 516 | static int init_sb(struct gfs2_sbd *sdp, int silent) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 517 | { |
| 518 | struct super_block *sb = sdp->sd_vfs; |
| 519 | struct gfs2_holder sb_gh; |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 520 | u64 no_addr; |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 521 | int ret; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 522 | |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 523 | ret = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops, |
| 524 | LM_ST_SHARED, 0, &sb_gh); |
| 525 | if (ret) { |
| 526 | fs_err(sdp, "can't acquire superblock glock: %d\n", ret); |
| 527 | return ret; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 528 | } |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 529 | |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 530 | ret = gfs2_read_sb(sdp, sb_gh.gh_gl, silent); |
| 531 | if (ret) { |
| 532 | fs_err(sdp, "can't read superblock: %d\n", ret); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 533 | goto out; |
| 534 | } |
| 535 | |
| 536 | /* Set up the buffer cache and SB for real */ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 537 | if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) { |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 538 | ret = -EINVAL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 539 | fs_err(sdp, "FS block size (%u) is too small for device " |
| 540 | "block size (%u)\n", |
| 541 | sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev)); |
| 542 | goto out; |
| 543 | } |
| 544 | if (sdp->sd_sb.sb_bsize > PAGE_SIZE) { |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 545 | ret = -EINVAL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 546 | fs_err(sdp, "FS block size (%u) is too big for machine " |
| 547 | "page size (%u)\n", |
| 548 | sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE); |
| 549 | goto out; |
| 550 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 551 | sb_set_blocksize(sb, sdp->sd_sb.sb_bsize); |
| 552 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 553 | /* Get the root inode */ |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 554 | no_addr = sdp->sd_sb.sb_root_dir.no_addr; |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 555 | ret = gfs2_lookup_root(sb, &sdp->sd_root_dir, no_addr, "root"); |
| 556 | if (ret) |
| 557 | goto out; |
| 558 | |
| 559 | /* Get the master inode */ |
| 560 | no_addr = sdp->sd_sb.sb_master_dir.no_addr; |
| 561 | ret = gfs2_lookup_root(sb, &sdp->sd_master_dir, no_addr, "master"); |
| 562 | if (ret) { |
| 563 | dput(sdp->sd_root_dir); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 564 | goto out; |
| 565 | } |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 566 | sb->s_root = dget(sdp->sd_args.ar_meta ? sdp->sd_master_dir : sdp->sd_root_dir); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 567 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 568 | gfs2_glock_dq_uninit(&sb_gh); |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 569 | return ret; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 572 | /** |
| 573 | * map_journal_extents - create a reusable "extent" mapping from all logical |
| 574 | * blocks to all physical blocks for the given journal. This will save |
| 575 | * us time when writing journal blocks. Most journals will have only one |
| 576 | * extent that maps all their logical blocks. That's because gfs2.mkfs |
| 577 | * arranges the journal blocks sequentially to maximize performance. |
| 578 | * So the extent would map the first block for the entire file length. |
| 579 | * However, gfs2_jadd can happen while file activity is happening, so |
| 580 | * those journals may not be sequential. Less likely is the case where |
| 581 | * the users created their own journals by mounting the metafs and |
| 582 | * laying it out. But it's still possible. These journals might have |
| 583 | * several extents. |
| 584 | * |
| 585 | * TODO: This should be done in bigger chunks rather than one block at a time, |
| 586 | * but since it's only done at mount time, I'm not worried about the |
| 587 | * time it takes. |
| 588 | */ |
| 589 | static int map_journal_extents(struct gfs2_sbd *sdp) |
| 590 | { |
| 591 | struct gfs2_jdesc *jd = sdp->sd_jdesc; |
| 592 | unsigned int lb; |
| 593 | u64 db, prev_db; /* logical block, disk block, prev disk block */ |
| 594 | struct gfs2_inode *ip = GFS2_I(jd->jd_inode); |
| 595 | struct gfs2_journal_extent *jext = NULL; |
| 596 | struct buffer_head bh; |
| 597 | int rc = 0; |
| 598 | |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 599 | prev_db = 0; |
| 600 | |
Steven Whitehouse | c9e9888 | 2008-11-04 09:47:33 +0000 | [diff] [blame] | 601 | for (lb = 0; lb < ip->i_disksize >> sdp->sd_sb.sb_bsize_shift; lb++) { |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 602 | bh.b_state = 0; |
| 603 | bh.b_blocknr = 0; |
| 604 | bh.b_size = 1 << ip->i_inode.i_blkbits; |
| 605 | rc = gfs2_block_map(jd->jd_inode, lb, &bh, 0); |
| 606 | db = bh.b_blocknr; |
| 607 | if (rc || !db) { |
| 608 | printk(KERN_INFO "GFS2 journal mapping error %d: lb=" |
| 609 | "%u db=%llu\n", rc, lb, (unsigned long long)db); |
| 610 | break; |
| 611 | } |
| 612 | if (!prev_db || db != prev_db + 1) { |
| 613 | jext = kzalloc(sizeof(struct gfs2_journal_extent), |
| 614 | GFP_KERNEL); |
| 615 | if (!jext) { |
| 616 | printk(KERN_INFO "GFS2 error: out of memory " |
| 617 | "mapping journal extents.\n"); |
| 618 | rc = -ENOMEM; |
| 619 | break; |
| 620 | } |
| 621 | jext->dblock = db; |
| 622 | jext->lblock = lb; |
| 623 | jext->blocks = 1; |
| 624 | list_add_tail(&jext->extent_list, &jd->extent_list); |
| 625 | } else { |
| 626 | jext->blocks++; |
| 627 | } |
| 628 | prev_db = db; |
| 629 | } |
| 630 | return rc; |
| 631 | } |
| 632 | |
Steven Whitehouse | da755fd | 2008-01-30 15:34:04 +0000 | [diff] [blame] | 633 | static void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp) |
| 634 | { |
Steven Whitehouse | 048bca2 | 2008-05-23 14:46:04 +0100 | [diff] [blame] | 635 | if (!sdp->sd_lockstruct.ls_ops->lm_others_may_mount) |
| 636 | return; |
Steven Whitehouse | da755fd | 2008-01-30 15:34:04 +0000 | [diff] [blame] | 637 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 638 | sdp->sd_lockstruct.ls_ops->lm_others_may_mount( |
| 639 | sdp->sd_lockstruct.ls_lockspace); |
| 640 | } |
| 641 | |
Steven Whitehouse | b528968 | 2008-11-26 12:49:26 +0000 | [diff] [blame] | 642 | /** |
| 643 | * gfs2_jindex_hold - Grab a lock on the jindex |
| 644 | * @sdp: The GFS2 superblock |
| 645 | * @ji_gh: the holder for the jindex glock |
| 646 | * |
| 647 | * Returns: errno |
| 648 | */ |
| 649 | |
| 650 | static int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) |
| 651 | { |
| 652 | struct gfs2_inode *dip = GFS2_I(sdp->sd_jindex); |
| 653 | struct qstr name; |
| 654 | char buf[20]; |
| 655 | struct gfs2_jdesc *jd; |
| 656 | int error; |
| 657 | |
| 658 | name.name = buf; |
| 659 | |
| 660 | mutex_lock(&sdp->sd_jindex_mutex); |
| 661 | |
| 662 | for (;;) { |
| 663 | error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, ji_gh); |
| 664 | if (error) |
| 665 | break; |
| 666 | |
| 667 | name.len = sprintf(buf, "journal%u", sdp->sd_journals); |
| 668 | name.hash = gfs2_disk_hash(name.name, name.len); |
| 669 | |
| 670 | error = gfs2_dir_check(sdp->sd_jindex, &name, NULL); |
| 671 | if (error == -ENOENT) { |
| 672 | error = 0; |
| 673 | break; |
| 674 | } |
| 675 | |
| 676 | gfs2_glock_dq_uninit(ji_gh); |
| 677 | |
| 678 | if (error) |
| 679 | break; |
| 680 | |
| 681 | error = -ENOMEM; |
| 682 | jd = kzalloc(sizeof(struct gfs2_jdesc), GFP_KERNEL); |
| 683 | if (!jd) |
| 684 | break; |
| 685 | |
| 686 | INIT_LIST_HEAD(&jd->extent_list); |
| 687 | jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1); |
| 688 | if (!jd->jd_inode || IS_ERR(jd->jd_inode)) { |
| 689 | if (!jd->jd_inode) |
| 690 | error = -ENOENT; |
| 691 | else |
| 692 | error = PTR_ERR(jd->jd_inode); |
| 693 | kfree(jd); |
| 694 | break; |
| 695 | } |
| 696 | |
| 697 | spin_lock(&sdp->sd_jindex_spin); |
| 698 | jd->jd_jid = sdp->sd_journals++; |
| 699 | list_add_tail(&jd->jd_list, &sdp->sd_jindex_list); |
| 700 | spin_unlock(&sdp->sd_jindex_spin); |
| 701 | } |
| 702 | |
| 703 | mutex_unlock(&sdp->sd_jindex_mutex); |
| 704 | |
| 705 | return error; |
| 706 | } |
| 707 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 708 | static int init_journal(struct gfs2_sbd *sdp, int undo) |
| 709 | { |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 710 | struct inode *master = sdp->sd_master_dir->d_inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 711 | struct gfs2_holder ji_gh; |
| 712 | struct task_struct *p; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 713 | struct gfs2_inode *ip; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 714 | int jindex = 1; |
| 715 | int error = 0; |
| 716 | |
| 717 | if (undo) { |
| 718 | jindex = 0; |
| 719 | goto fail_recoverd; |
| 720 | } |
| 721 | |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 722 | sdp->sd_jindex = gfs2_lookup_simple(master, "jindex"); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 723 | if (IS_ERR(sdp->sd_jindex)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 724 | fs_err(sdp, "can't lookup journal index: %d\n", error); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 725 | return PTR_ERR(sdp->sd_jindex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 726 | } |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 727 | ip = GFS2_I(sdp->sd_jindex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 728 | |
| 729 | /* Load in the journal index special file */ |
| 730 | |
| 731 | error = gfs2_jindex_hold(sdp, &ji_gh); |
| 732 | if (error) { |
| 733 | fs_err(sdp, "can't read journal index: %d\n", error); |
| 734 | goto fail; |
| 735 | } |
| 736 | |
| 737 | error = -EINVAL; |
| 738 | if (!gfs2_jindex_size(sdp)) { |
| 739 | fs_err(sdp, "no journals!\n"); |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 740 | goto fail_jindex; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | if (sdp->sd_args.ar_spectator) { |
| 744 | sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0); |
Steven Whitehouse | fd041f0 | 2007-11-08 14:55:03 +0000 | [diff] [blame] | 745 | atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 746 | } else { |
| 747 | if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) { |
| 748 | fs_err(sdp, "can't mount journal #%u\n", |
| 749 | sdp->sd_lockstruct.ls_jid); |
| 750 | fs_err(sdp, "there are only %u journals (0 - %u)\n", |
| 751 | gfs2_jindex_size(sdp), |
| 752 | gfs2_jindex_size(sdp) - 1); |
| 753 | goto fail_jindex; |
| 754 | } |
| 755 | sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid); |
| 756 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 757 | error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 758 | &gfs2_journal_glops, |
| 759 | LM_ST_EXCLUSIVE, LM_FLAG_NOEXP, |
| 760 | &sdp->sd_journal_gh); |
| 761 | if (error) { |
| 762 | fs_err(sdp, "can't acquire journal glock: %d\n", error); |
| 763 | goto fail_jindex; |
| 764 | } |
| 765 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 766 | ip = GFS2_I(sdp->sd_jdesc->jd_inode); |
| 767 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, |
Bob Peterson | 75be73a | 2007-08-08 17:08:14 -0500 | [diff] [blame] | 768 | LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 769 | &sdp->sd_jinode_gh); |
| 770 | if (error) { |
| 771 | fs_err(sdp, "can't acquire journal inode glock: %d\n", |
| 772 | error); |
| 773 | goto fail_journal_gh; |
| 774 | } |
| 775 | |
| 776 | error = gfs2_jdesc_check(sdp->sd_jdesc); |
| 777 | if (error) { |
| 778 | fs_err(sdp, "my journal (%u) is bad: %d\n", |
| 779 | sdp->sd_jdesc->jd_jid, error); |
| 780 | goto fail_jinode_gh; |
| 781 | } |
Steven Whitehouse | fd041f0 | 2007-11-08 14:55:03 +0000 | [diff] [blame] | 782 | atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks); |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 783 | |
| 784 | /* Map the extents for this journal's blocks */ |
| 785 | map_journal_extents(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | if (sdp->sd_lockstruct.ls_first) { |
| 789 | unsigned int x; |
| 790 | for (x = 0; x < sdp->sd_journals; x++) { |
David Teigland | c63e31c | 2006-04-20 17:03:48 -0400 | [diff] [blame] | 791 | error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 792 | if (error) { |
| 793 | fs_err(sdp, "error recovering journal %u: %d\n", |
| 794 | x, error); |
| 795 | goto fail_jinode_gh; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | gfs2_lm_others_may_mount(sdp); |
| 800 | } else if (!sdp->sd_args.ar_spectator) { |
David Teigland | c63e31c | 2006-04-20 17:03:48 -0400 | [diff] [blame] | 801 | error = gfs2_recover_journal(sdp->sd_jdesc); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 802 | if (error) { |
| 803 | fs_err(sdp, "error recovering my journal: %d\n", error); |
| 804 | goto fail_jinode_gh; |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags); |
| 809 | gfs2_glock_dq_uninit(&ji_gh); |
| 810 | jindex = 0; |
| 811 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 812 | p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd"); |
| 813 | error = IS_ERR(p); |
| 814 | if (error) { |
| 815 | fs_err(sdp, "can't start recoverd thread: %d\n", error); |
| 816 | goto fail_jinode_gh; |
| 817 | } |
| 818 | sdp->sd_recoverd_process = p; |
| 819 | |
| 820 | return 0; |
| 821 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 822 | fail_recoverd: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 823 | kthread_stop(sdp->sd_recoverd_process); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 824 | fail_jinode_gh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 825 | if (!sdp->sd_args.ar_spectator) |
| 826 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 827 | fail_journal_gh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 828 | if (!sdp->sd_args.ar_spectator) |
| 829 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 830 | fail_jindex: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 831 | gfs2_jindex_free(sdp); |
| 832 | if (jindex) |
| 833 | gfs2_glock_dq_uninit(&ji_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 834 | fail: |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 835 | iput(sdp->sd_jindex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 836 | return error; |
| 837 | } |
| 838 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 839 | |
| 840 | static int init_inodes(struct gfs2_sbd *sdp, int undo) |
| 841 | { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 842 | int error = 0; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 843 | struct gfs2_inode *ip; |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 844 | struct inode *master = sdp->sd_master_dir->d_inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 845 | |
| 846 | if (undo) |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 847 | goto fail_qinode; |
| 848 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 849 | error = init_journal(sdp, undo); |
| 850 | if (error) |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 851 | goto fail; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 852 | |
| 853 | /* Read in the master inode number inode */ |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 854 | sdp->sd_inum_inode = gfs2_lookup_simple(master, "inum"); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 855 | if (IS_ERR(sdp->sd_inum_inode)) { |
| 856 | error = PTR_ERR(sdp->sd_inum_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 857 | fs_err(sdp, "can't read in inum inode: %d\n", error); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 858 | goto fail_journal; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 861 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 862 | /* Read in the master statfs inode */ |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 863 | sdp->sd_statfs_inode = gfs2_lookup_simple(master, "statfs"); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 864 | if (IS_ERR(sdp->sd_statfs_inode)) { |
| 865 | error = PTR_ERR(sdp->sd_statfs_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 866 | fs_err(sdp, "can't read in statfs inode: %d\n", error); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 867 | goto fail_inum; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | /* Read in the resource index inode */ |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 871 | sdp->sd_rindex = gfs2_lookup_simple(master, "rindex"); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 872 | if (IS_ERR(sdp->sd_rindex)) { |
| 873 | error = PTR_ERR(sdp->sd_rindex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 874 | fs_err(sdp, "can't get resource index inode: %d\n", error); |
| 875 | goto fail_statfs; |
| 876 | } |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 877 | ip = GFS2_I(sdp->sd_rindex); |
Bob Peterson | cf45b75 | 2008-01-31 10:31:39 -0600 | [diff] [blame] | 878 | sdp->sd_rindex_uptodate = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 879 | |
| 880 | /* Read in the quota inode */ |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 881 | sdp->sd_quota_inode = gfs2_lookup_simple(master, "quota"); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 882 | if (IS_ERR(sdp->sd_quota_inode)) { |
| 883 | error = PTR_ERR(sdp->sd_quota_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 884 | fs_err(sdp, "can't get quota file inode: %d\n", error); |
| 885 | goto fail_rindex; |
| 886 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 887 | return 0; |
| 888 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 889 | fail_qinode: |
| 890 | iput(sdp->sd_quota_inode); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 891 | fail_rindex: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 892 | gfs2_clear_rgrpd(sdp); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 893 | iput(sdp->sd_rindex); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 894 | fail_statfs: |
| 895 | iput(sdp->sd_statfs_inode); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 896 | fail_inum: |
| 897 | iput(sdp->sd_inum_inode); |
| 898 | fail_journal: |
| 899 | init_journal(sdp, UNDO); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 900 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 901 | return error; |
| 902 | } |
| 903 | |
| 904 | static int init_per_node(struct gfs2_sbd *sdp, int undo) |
| 905 | { |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 906 | struct inode *pn = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 907 | char buf[30]; |
| 908 | int error = 0; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 909 | struct gfs2_inode *ip; |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 910 | struct inode *master = sdp->sd_master_dir->d_inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 911 | |
| 912 | if (sdp->sd_args.ar_spectator) |
| 913 | return 0; |
| 914 | |
| 915 | if (undo) |
| 916 | goto fail_qc_gh; |
| 917 | |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 918 | pn = gfs2_lookup_simple(master, "per_node"); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 919 | if (IS_ERR(pn)) { |
| 920 | error = PTR_ERR(pn); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 921 | fs_err(sdp, "can't find per_node directory: %d\n", error); |
| 922 | return error; |
| 923 | } |
| 924 | |
| 925 | sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 926 | sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf); |
| 927 | if (IS_ERR(sdp->sd_ir_inode)) { |
| 928 | error = PTR_ERR(sdp->sd_ir_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 929 | fs_err(sdp, "can't find local \"ir\" file: %d\n", error); |
| 930 | goto fail; |
| 931 | } |
| 932 | |
| 933 | sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 934 | sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf); |
| 935 | if (IS_ERR(sdp->sd_sc_inode)) { |
| 936 | error = PTR_ERR(sdp->sd_sc_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 937 | fs_err(sdp, "can't find local \"sc\" file: %d\n", error); |
| 938 | goto fail_ir_i; |
| 939 | } |
| 940 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 941 | sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 942 | sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf); |
| 943 | if (IS_ERR(sdp->sd_qc_inode)) { |
| 944 | error = PTR_ERR(sdp->sd_qc_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 945 | fs_err(sdp, "can't find local \"qc\" file: %d\n", error); |
| 946 | goto fail_ut_i; |
| 947 | } |
| 948 | |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 949 | iput(pn); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 950 | pn = NULL; |
| 951 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 952 | ip = GFS2_I(sdp->sd_ir_inode); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 953 | error = gfs2_glock_nq_init(ip->i_gl, |
Steven Whitehouse | 579b78a | 2006-04-26 14:58:26 -0400 | [diff] [blame] | 954 | LM_ST_EXCLUSIVE, 0, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 955 | &sdp->sd_ir_gh); |
| 956 | if (error) { |
| 957 | fs_err(sdp, "can't lock local \"ir\" file: %d\n", error); |
| 958 | goto fail_qc_i; |
| 959 | } |
| 960 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 961 | ip = GFS2_I(sdp->sd_sc_inode); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 962 | error = gfs2_glock_nq_init(ip->i_gl, |
Steven Whitehouse | 579b78a | 2006-04-26 14:58:26 -0400 | [diff] [blame] | 963 | LM_ST_EXCLUSIVE, 0, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 964 | &sdp->sd_sc_gh); |
| 965 | if (error) { |
| 966 | fs_err(sdp, "can't lock local \"sc\" file: %d\n", error); |
| 967 | goto fail_ir_gh; |
| 968 | } |
| 969 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 970 | ip = GFS2_I(sdp->sd_qc_inode); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 971 | error = gfs2_glock_nq_init(ip->i_gl, |
Steven Whitehouse | 579b78a | 2006-04-26 14:58:26 -0400 | [diff] [blame] | 972 | LM_ST_EXCLUSIVE, 0, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 973 | &sdp->sd_qc_gh); |
| 974 | if (error) { |
| 975 | fs_err(sdp, "can't lock local \"qc\" file: %d\n", error); |
| 976 | goto fail_ut_gh; |
| 977 | } |
| 978 | |
| 979 | return 0; |
| 980 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 981 | fail_qc_gh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 982 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 983 | fail_ut_gh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 984 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 985 | fail_ir_gh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 986 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 987 | fail_qc_i: |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 988 | iput(sdp->sd_qc_inode); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 989 | fail_ut_i: |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 990 | iput(sdp->sd_sc_inode); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 991 | fail_ir_i: |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 992 | iput(sdp->sd_ir_inode); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 993 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 994 | if (pn) |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 995 | iput(pn); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 996 | return error; |
| 997 | } |
| 998 | |
| 999 | static int init_threads(struct gfs2_sbd *sdp, int undo) |
| 1000 | { |
| 1001 | struct task_struct *p; |
| 1002 | int error = 0; |
| 1003 | |
| 1004 | if (undo) |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1005 | goto fail_quotad; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1006 | |
| 1007 | sdp->sd_log_flush_time = jiffies; |
| 1008 | sdp->sd_jindex_refresh_time = jiffies; |
| 1009 | |
| 1010 | p = kthread_run(gfs2_logd, sdp, "gfs2_logd"); |
| 1011 | error = IS_ERR(p); |
| 1012 | if (error) { |
| 1013 | fs_err(sdp, "can't start logd thread: %d\n", error); |
| 1014 | return error; |
| 1015 | } |
| 1016 | sdp->sd_logd_process = p; |
| 1017 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1018 | p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad"); |
| 1019 | error = IS_ERR(p); |
| 1020 | if (error) { |
| 1021 | fs_err(sdp, "can't start quotad thread: %d\n", error); |
| 1022 | goto fail; |
| 1023 | } |
| 1024 | sdp->sd_quotad_process = p; |
| 1025 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1026 | return 0; |
| 1027 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1028 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1029 | fail_quotad: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1030 | kthread_stop(sdp->sd_quotad_process); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1031 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1032 | kthread_stop(sdp->sd_logd_process); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1033 | return error; |
| 1034 | } |
| 1035 | |
| 1036 | /** |
Steven Whitehouse | da755fd | 2008-01-30 15:34:04 +0000 | [diff] [blame] | 1037 | * gfs2_lm_mount - mount a locking protocol |
| 1038 | * @sdp: the filesystem |
| 1039 | * @args: mount arguements |
| 1040 | * @silent: if 1, don't complain if the FS isn't a GFS2 fs |
| 1041 | * |
| 1042 | * Returns: errno |
| 1043 | */ |
| 1044 | |
| 1045 | static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent) |
| 1046 | { |
| 1047 | char *proto = sdp->sd_proto_name; |
| 1048 | char *table = sdp->sd_table_name; |
Benjamin Marzinski | 58e9fee | 2008-03-14 13:52:52 -0500 | [diff] [blame] | 1049 | int flags = LM_MFLAG_CONV_NODROP; |
Steven Whitehouse | da755fd | 2008-01-30 15:34:04 +0000 | [diff] [blame] | 1050 | int error; |
| 1051 | |
| 1052 | if (sdp->sd_args.ar_spectator) |
| 1053 | flags |= LM_MFLAG_SPECTATOR; |
| 1054 | |
| 1055 | fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table); |
| 1056 | |
| 1057 | error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata, |
| 1058 | gfs2_glock_cb, sdp, |
| 1059 | GFS2_MIN_LVB_SIZE, flags, |
| 1060 | &sdp->sd_lockstruct, &sdp->sd_kobj); |
| 1061 | if (error) { |
| 1062 | fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n", |
| 1063 | proto, table, sdp->sd_args.ar_hostdata); |
| 1064 | goto out; |
| 1065 | } |
| 1066 | |
Steven Whitehouse | 048bca2 | 2008-05-23 14:46:04 +0100 | [diff] [blame] | 1067 | if (gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_ops) || |
Steven Whitehouse | da755fd | 2008-01-30 15:34:04 +0000 | [diff] [blame] | 1068 | gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lvb_size >= |
| 1069 | GFS2_MIN_LVB_SIZE)) { |
| 1070 | gfs2_unmount_lockproto(&sdp->sd_lockstruct); |
| 1071 | goto out; |
| 1072 | } |
| 1073 | |
| 1074 | if (sdp->sd_args.ar_spectator) |
| 1075 | snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table); |
| 1076 | else |
| 1077 | snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table, |
| 1078 | sdp->sd_lockstruct.ls_jid); |
| 1079 | |
| 1080 | fs_info(sdp, "Joined cluster. Now mounting FS...\n"); |
| 1081 | |
| 1082 | if ((sdp->sd_lockstruct.ls_flags & LM_LSFLAG_LOCAL) && |
| 1083 | !sdp->sd_args.ar_ignore_local_fs) { |
| 1084 | sdp->sd_args.ar_localflocks = 1; |
| 1085 | sdp->sd_args.ar_localcaching = 1; |
| 1086 | } |
| 1087 | |
| 1088 | out: |
| 1089 | return error; |
| 1090 | } |
| 1091 | |
| 1092 | void gfs2_lm_unmount(struct gfs2_sbd *sdp) |
| 1093 | { |
| 1094 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
| 1095 | gfs2_unmount_lockproto(&sdp->sd_lockstruct); |
| 1096 | } |
| 1097 | |
| 1098 | /** |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1099 | * fill_super - Read in superblock |
| 1100 | * @sb: The VFS superblock |
| 1101 | * @data: Mount options |
| 1102 | * @silent: Don't complain if it's not a GFS2 filesystem |
| 1103 | * |
| 1104 | * Returns: errno |
| 1105 | */ |
| 1106 | |
| 1107 | static int fill_super(struct super_block *sb, void *data, int silent) |
| 1108 | { |
| 1109 | struct gfs2_sbd *sdp; |
| 1110 | struct gfs2_holder mount_gh; |
| 1111 | int error; |
| 1112 | |
| 1113 | sdp = init_sbd(sb); |
| 1114 | if (!sdp) { |
Steven Whitehouse | d92a8d4 | 2006-02-27 10:57:14 -0500 | [diff] [blame] | 1115 | printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n"); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1116 | return -ENOMEM; |
| 1117 | } |
| 1118 | |
| 1119 | error = gfs2_mount_args(sdp, (char *)data, 0); |
| 1120 | if (error) { |
Steven Whitehouse | d92a8d4 | 2006-02-27 10:57:14 -0500 | [diff] [blame] | 1121 | printk(KERN_WARNING "GFS2: can't parse mount arguments\n"); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1122 | goto fail; |
| 1123 | } |
| 1124 | |
Steven Whitehouse | 719ee34 | 2008-09-18 13:53:59 +0100 | [diff] [blame] | 1125 | sb->s_magic = GFS2_MAGIC; |
| 1126 | sb->s_op = &gfs2_super_ops; |
| 1127 | sb->s_export_op = &gfs2_export_ops; |
| 1128 | sb->s_time_gran = 1; |
| 1129 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
Steven Whitehouse | 419c93e | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 1130 | |
| 1131 | /* Set up the buffer cache and fill in some fake block size values |
| 1132 | to allow us to read-in the on-disk superblock. */ |
| 1133 | sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK); |
| 1134 | sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits; |
| 1135 | sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - |
| 1136 | GFS2_BASIC_BLOCK_SHIFT; |
| 1137 | sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1138 | |
| 1139 | error = init_names(sdp, silent); |
| 1140 | if (error) |
| 1141 | goto fail; |
| 1142 | |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 1143 | gfs2_create_debugfs_file(sdp); |
| 1144 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1145 | error = gfs2_sys_fs_add(sdp); |
| 1146 | if (error) |
| 1147 | goto fail; |
| 1148 | |
| 1149 | error = gfs2_lm_mount(sdp, silent); |
| 1150 | if (error) |
| 1151 | goto fail_sys; |
| 1152 | |
| 1153 | error = init_locking(sdp, &mount_gh, DO); |
| 1154 | if (error) |
| 1155 | goto fail_lm; |
| 1156 | |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 1157 | error = init_sb(sdp, silent); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1158 | if (error) |
| 1159 | goto fail_locking; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1160 | |
| 1161 | error = init_inodes(sdp, DO); |
| 1162 | if (error) |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 1163 | goto fail_sb; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1164 | |
| 1165 | error = init_per_node(sdp, DO); |
| 1166 | if (error) |
| 1167 | goto fail_inodes; |
| 1168 | |
| 1169 | error = gfs2_statfs_init(sdp); |
| 1170 | if (error) { |
| 1171 | fs_err(sdp, "can't initialize statfs subsystem: %d\n", error); |
| 1172 | goto fail_per_node; |
| 1173 | } |
| 1174 | |
| 1175 | error = init_threads(sdp, DO); |
| 1176 | if (error) |
| 1177 | goto fail_per_node; |
| 1178 | |
| 1179 | if (!(sb->s_flags & MS_RDONLY)) { |
| 1180 | error = gfs2_make_fs_rw(sdp); |
| 1181 | if (error) { |
| 1182 | fs_err(sdp, "can't make FS RW: %d\n", error); |
| 1183 | goto fail_threads; |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | gfs2_glock_dq_uninit(&mount_gh); |
| 1188 | |
| 1189 | return 0; |
| 1190 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1191 | fail_threads: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1192 | init_threads(sdp, UNDO); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1193 | fail_per_node: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1194 | init_per_node(sdp, UNDO); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1195 | fail_inodes: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1196 | init_inodes(sdp, UNDO); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1197 | fail_sb: |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 1198 | if (sdp->sd_root_dir) |
| 1199 | dput(sdp->sd_root_dir); |
| 1200 | if (sdp->sd_master_dir) |
| 1201 | dput(sdp->sd_master_dir); |
| 1202 | sb->s_root = NULL; |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1203 | fail_locking: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1204 | init_locking(sdp, &mount_gh, UNDO); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1205 | fail_lm: |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame] | 1206 | gfs2_gl_hash_clear(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1207 | gfs2_lm_unmount(sdp); |
| 1208 | while (invalidate_inodes(sb)) |
| 1209 | yield(); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1210 | fail_sys: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1211 | gfs2_sys_fs_del(sdp); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1212 | fail: |
Robert Peterson | 5f88209 | 2007-04-18 11:41:11 -0500 | [diff] [blame] | 1213 | gfs2_delete_debugfs_file(sdp); |
Steven Whitehouse | a2c4580 | 2006-09-08 10:13:03 -0400 | [diff] [blame] | 1214 | kfree(sdp); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 1215 | sb->s_fs_info = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1216 | return error; |
| 1217 | } |
| 1218 | |
Andrew Morton | ccd6efd | 2006-06-30 02:16:34 -0700 | [diff] [blame] | 1219 | static int gfs2_get_sb(struct file_system_type *fs_type, int flags, |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 1220 | const char *dev_name, void *data, struct vfsmount *mnt) |
| 1221 | { |
| 1222 | return get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt); |
| 1223 | } |
| 1224 | |
| 1225 | static struct super_block *get_gfs2_sb(const char *dev_name) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1226 | { |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 1227 | struct super_block *sb; |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 1228 | struct nameidata nd; |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 1229 | int error; |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 1230 | |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 1231 | error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd); |
| 1232 | if (error) { |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 1233 | printk(KERN_WARNING "GFS2: path_lookup on %s returned error %d\n", |
| 1234 | dev_name, error); |
| 1235 | return NULL; |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 1236 | } |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 1237 | sb = nd.path.dentry->d_inode->i_sb; |
| 1238 | if (sb && (sb->s_type == &gfs2_fs_type)) |
| 1239 | atomic_inc(&sb->s_active); |
| 1240 | else |
| 1241 | sb = NULL; |
Jan Blunck | 1d957f9 | 2008-02-14 19:34:35 -0800 | [diff] [blame] | 1242 | path_put(&nd.path); |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 1243 | return sb; |
| 1244 | } |
| 1245 | |
| 1246 | static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags, |
| 1247 | const char *dev_name, void *data, struct vfsmount *mnt) |
| 1248 | { |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 1249 | struct super_block *sb = NULL; |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 1250 | struct gfs2_sbd *sdp; |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 1251 | |
| 1252 | sb = get_gfs2_sb(dev_name); |
| 1253 | if (!sb) { |
| 1254 | printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n"); |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 1255 | return -ENOENT; |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 1256 | } |
Denis Cheng | 2d3ba1e | 2007-08-11 10:27:08 +0800 | [diff] [blame] | 1257 | sdp = sb->s_fs_info; |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 1258 | mnt->mnt_sb = sb; |
| 1259 | mnt->mnt_root = dget(sdp->sd_master_dir); |
| 1260 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
Steven Whitehouse | 419c93e | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 1263 | static void gfs2_kill_sb(struct super_block *sb) |
| 1264 | { |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 1265 | struct gfs2_sbd *sdp = sb->s_fs_info; |
Steven Whitehouse | 88a19ad | 2008-12-19 15:43:05 +0000 | [diff] [blame] | 1266 | |
| 1267 | if (sdp == NULL) { |
| 1268 | kill_block_super(sb); |
| 1269 | return; |
Abhijith Das | acd2c8a | 2008-09-15 08:54:06 -0500 | [diff] [blame] | 1270 | } |
Steven Whitehouse | 88a19ad | 2008-12-19 15:43:05 +0000 | [diff] [blame] | 1271 | |
| 1272 | gfs2_meta_syncfs(sdp); |
| 1273 | dput(sdp->sd_root_dir); |
| 1274 | dput(sdp->sd_master_dir); |
| 1275 | sdp->sd_root_dir = NULL; |
| 1276 | sdp->sd_master_dir = NULL; |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame] | 1277 | shrink_dcache_sb(sb); |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 1278 | kill_block_super(sb); |
Steven Whitehouse | 88a19ad | 2008-12-19 15:43:05 +0000 | [diff] [blame] | 1279 | gfs2_delete_debugfs_file(sdp); |
| 1280 | kfree(sdp); |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 1281 | } |
| 1282 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1283 | struct file_system_type gfs2_fs_type = { |
| 1284 | .name = "gfs2", |
| 1285 | .fs_flags = FS_REQUIRES_DEV, |
| 1286 | .get_sb = gfs2_get_sb, |
Steven Whitehouse | 419c93e | 2006-03-02 16:33:41 -0500 | [diff] [blame] | 1287 | .kill_sb = gfs2_kill_sb, |
| 1288 | .owner = THIS_MODULE, |
| 1289 | }; |
| 1290 | |
| 1291 | struct file_system_type gfs2meta_fs_type = { |
| 1292 | .name = "gfs2meta", |
| 1293 | .fs_flags = FS_REQUIRES_DEV, |
Abhijith Das | 8638460 | 2006-08-25 11:13:37 -0500 | [diff] [blame] | 1294 | .get_sb = gfs2_get_sb_meta, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1295 | .owner = THIS_MODULE, |
| 1296 | }; |
| 1297 | |