Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1 | /* |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2 | * linux/fs/ext4/super.c |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1992, 1993, 1994, 1995 |
| 5 | * Remy Card (card@masi.ibp.fr) |
| 6 | * Laboratoire MASI - Institut Blaise Pascal |
| 7 | * Universite Pierre et Marie Curie (Paris VI) |
| 8 | * |
| 9 | * from |
| 10 | * |
| 11 | * linux/fs/minix/inode.c |
| 12 | * |
| 13 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 14 | * |
| 15 | * Big-endian to little-endian byte-swapping/bitmaps by |
| 16 | * David S. Miller (davem@caip.rutgers.edu), 1995 |
| 17 | */ |
| 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/string.h> |
| 21 | #include <linux/fs.h> |
| 22 | #include <linux/time.h> |
Theodore Ts'o | c5ca7c7 | 2009-04-27 22:48:48 -0400 | [diff] [blame] | 23 | #include <linux/vmalloc.h> |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 24 | #include <linux/jbd2.h> |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 25 | #include <linux/slab.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/blkdev.h> |
| 28 | #include <linux/parser.h> |
| 29 | #include <linux/smp_lock.h> |
| 30 | #include <linux/buffer_head.h> |
Christoph Hellwig | a569425 | 2007-07-17 04:04:28 -0700 | [diff] [blame] | 31 | #include <linux/exportfs.h> |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 32 | #include <linux/vfs.h> |
| 33 | #include <linux/random.h> |
| 34 | #include <linux/mount.h> |
| 35 | #include <linux/namei.h> |
| 36 | #include <linux/quotaops.h> |
| 37 | #include <linux/seq_file.h> |
Theodore Ts'o | 9f6200b | 2008-09-23 09:18:24 -0400 | [diff] [blame] | 38 | #include <linux/proc_fs.h> |
Theodore Ts'o | 3197ebd | 2009-03-31 09:10:09 -0400 | [diff] [blame] | 39 | #include <linux/ctype.h> |
Theodore Ts'o | ede86cc | 2008-10-05 20:50:06 -0400 | [diff] [blame] | 40 | #include <linux/marker.h> |
Vignesh Babu | 1330593 | 2007-07-18 09:11:02 -0400 | [diff] [blame] | 41 | #include <linux/log2.h> |
Andreas Dilger | 717d50e | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 42 | #include <linux/crc16.h> |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 43 | #include <asm/uaccess.h> |
| 44 | |
Christoph Hellwig | 3dcf545 | 2008-04-29 18:13:32 -0400 | [diff] [blame] | 45 | #include "ext4.h" |
| 46 | #include "ext4_jbd2.h" |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 47 | #include "xattr.h" |
| 48 | #include "acl.h" |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 49 | |
Curt Wohlgemuth | f403390 | 2009-05-01 20:27:20 -0400 | [diff] [blame] | 50 | static int default_mb_history_length = 1000; |
| 51 | |
| 52 | module_param_named(default_mb_history_length, default_mb_history_length, |
| 53 | int, 0644); |
| 54 | MODULE_PARM_DESC(default_mb_history_length, |
| 55 | "Default number of entries saved for mb_history"); |
| 56 | |
Theodore Ts'o | 9f6200b | 2008-09-23 09:18:24 -0400 | [diff] [blame] | 57 | struct proc_dir_entry *ext4_proc_root; |
Theodore Ts'o | 3197ebd | 2009-03-31 09:10:09 -0400 | [diff] [blame] | 58 | static struct kset *ext4_kset; |
Theodore Ts'o | 9f6200b | 2008-09-23 09:18:24 -0400 | [diff] [blame] | 59 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 60 | static int ext4_load_journal(struct super_block *, struct ext4_super_block *, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 61 | unsigned long journal_devnum); |
Theodore Ts'o | e2d6705 | 2009-05-01 00:33:44 -0400 | [diff] [blame] | 62 | static int ext4_commit_super(struct super_block *sb, int sync); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 63 | static void ext4_mark_recovery_complete(struct super_block *sb, |
| 64 | struct ext4_super_block *es); |
| 65 | static void ext4_clear_journal_err(struct super_block *sb, |
| 66 | struct ext4_super_block *es); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 67 | static int ext4_sync_fs(struct super_block *sb, int wait); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 68 | static const char *ext4_decode_error(struct super_block *sb, int errno, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 69 | char nbuf[16]); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 70 | static int ext4_remount(struct super_block *sb, int *flags, char *data); |
| 71 | static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf); |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 72 | static int ext4_unfreeze(struct super_block *sb); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 73 | static void ext4_write_super(struct super_block *sb); |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 74 | static int ext4_freeze(struct super_block *sb); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 75 | |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 76 | |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 77 | ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, |
| 78 | struct ext4_group_desc *bg) |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 79 | { |
Aneesh Kumar K.V | 3a14589 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 80 | return le32_to_cpu(bg->bg_block_bitmap_lo) | |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 81 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? |
Aneesh Kumar K.V | 3a14589 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 82 | (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0); |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 85 | ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, |
| 86 | struct ext4_group_desc *bg) |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 87 | { |
Aneesh Kumar K.V | 5272f83 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 88 | return le32_to_cpu(bg->bg_inode_bitmap_lo) | |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 89 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? |
Aneesh Kumar K.V | 5272f83 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 90 | (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0); |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 93 | ext4_fsblk_t ext4_inode_table(struct super_block *sb, |
| 94 | struct ext4_group_desc *bg) |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 95 | { |
Aneesh Kumar K.V | 5272f83 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 96 | return le32_to_cpu(bg->bg_inode_table_lo) | |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 97 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? |
Aneesh Kumar K.V | 5272f83 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 98 | (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0); |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Aneesh Kumar K.V | 560671a | 2009-01-05 22:20:24 -0500 | [diff] [blame] | 101 | __u32 ext4_free_blks_count(struct super_block *sb, |
| 102 | struct ext4_group_desc *bg) |
| 103 | { |
| 104 | return le16_to_cpu(bg->bg_free_blocks_count_lo) | |
| 105 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? |
| 106 | (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0); |
| 107 | } |
| 108 | |
| 109 | __u32 ext4_free_inodes_count(struct super_block *sb, |
| 110 | struct ext4_group_desc *bg) |
| 111 | { |
| 112 | return le16_to_cpu(bg->bg_free_inodes_count_lo) | |
| 113 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? |
| 114 | (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0); |
| 115 | } |
| 116 | |
| 117 | __u32 ext4_used_dirs_count(struct super_block *sb, |
| 118 | struct ext4_group_desc *bg) |
| 119 | { |
| 120 | return le16_to_cpu(bg->bg_used_dirs_count_lo) | |
| 121 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? |
| 122 | (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0); |
| 123 | } |
| 124 | |
| 125 | __u32 ext4_itable_unused_count(struct super_block *sb, |
| 126 | struct ext4_group_desc *bg) |
| 127 | { |
| 128 | return le16_to_cpu(bg->bg_itable_unused_lo) | |
| 129 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? |
| 130 | (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0); |
| 131 | } |
| 132 | |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 133 | void ext4_block_bitmap_set(struct super_block *sb, |
| 134 | struct ext4_group_desc *bg, ext4_fsblk_t blk) |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 135 | { |
Aneesh Kumar K.V | 3a14589 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 136 | bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk); |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 137 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) |
| 138 | bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32); |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 141 | void ext4_inode_bitmap_set(struct super_block *sb, |
| 142 | struct ext4_group_desc *bg, ext4_fsblk_t blk) |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 143 | { |
Aneesh Kumar K.V | 5272f83 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 144 | bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk); |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 145 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) |
| 146 | bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32); |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 149 | void ext4_inode_table_set(struct super_block *sb, |
| 150 | struct ext4_group_desc *bg, ext4_fsblk_t blk) |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 151 | { |
Aneesh Kumar K.V | 5272f83 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 152 | bg->bg_inode_table_lo = cpu_to_le32((u32)blk); |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 153 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) |
| 154 | bg->bg_inode_table_hi = cpu_to_le32(blk >> 32); |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Aneesh Kumar K.V | 560671a | 2009-01-05 22:20:24 -0500 | [diff] [blame] | 157 | void ext4_free_blks_set(struct super_block *sb, |
| 158 | struct ext4_group_desc *bg, __u32 count) |
| 159 | { |
| 160 | bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count); |
| 161 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) |
| 162 | bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16); |
| 163 | } |
| 164 | |
| 165 | void ext4_free_inodes_set(struct super_block *sb, |
| 166 | struct ext4_group_desc *bg, __u32 count) |
| 167 | { |
| 168 | bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count); |
| 169 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) |
| 170 | bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16); |
| 171 | } |
| 172 | |
| 173 | void ext4_used_dirs_set(struct super_block *sb, |
| 174 | struct ext4_group_desc *bg, __u32 count) |
| 175 | { |
| 176 | bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count); |
| 177 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) |
| 178 | bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16); |
| 179 | } |
| 180 | |
| 181 | void ext4_itable_unused_set(struct super_block *sb, |
| 182 | struct ext4_group_desc *bg, __u32 count) |
| 183 | { |
| 184 | bg->bg_itable_unused_lo = cpu_to_le16((__u16)count); |
| 185 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) |
| 186 | bg->bg_itable_unused_hi = cpu_to_le16(count >> 16); |
| 187 | } |
| 188 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 189 | /* |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 190 | * Wrappers for jbd2_journal_start/end. |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 191 | * |
| 192 | * The only special thing we need to do here is to make sure that all |
| 193 | * journal_end calls result in the superblock being marked dirty, so |
| 194 | * that sync() will call the filesystem's write_super callback if |
| 195 | * appropriate. |
| 196 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 197 | handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 198 | { |
| 199 | journal_t *journal; |
| 200 | |
| 201 | if (sb->s_flags & MS_RDONLY) |
| 202 | return ERR_PTR(-EROFS); |
| 203 | |
| 204 | /* Special case here: if the journal has aborted behind our |
| 205 | * backs (eg. EIO in the commit thread), then we still need to |
| 206 | * take the FS itself readonly cleanly. */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 207 | journal = EXT4_SB(sb)->s_journal; |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 208 | if (journal) { |
| 209 | if (is_journal_aborted(journal)) { |
| 210 | ext4_abort(sb, __func__, |
| 211 | "Detected aborted journal"); |
| 212 | return ERR_PTR(-EROFS); |
| 213 | } |
| 214 | return jbd2_journal_start(journal, nblocks); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 215 | } |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 216 | /* |
| 217 | * We're not journaling, return the appropriate indication. |
| 218 | */ |
| 219 | current->journal_info = EXT4_NOJOURNAL_HANDLE; |
| 220 | return current->journal_info; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /* |
| 224 | * The only special thing we need to do here is to make sure that all |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 225 | * jbd2_journal_stop calls result in the superblock being marked dirty, so |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 226 | * that sync() will call the filesystem's write_super callback if |
| 227 | * appropriate. |
| 228 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 229 | int __ext4_journal_stop(const char *where, handle_t *handle) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 230 | { |
| 231 | struct super_block *sb; |
| 232 | int err; |
| 233 | int rc; |
| 234 | |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 235 | if (!ext4_handle_valid(handle)) { |
| 236 | /* |
| 237 | * Do this here since we don't call jbd2_journal_stop() in |
| 238 | * no-journal mode. |
| 239 | */ |
| 240 | current->journal_info = NULL; |
| 241 | return 0; |
| 242 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 243 | sb = handle->h_transaction->t_journal->j_private; |
| 244 | err = handle->h_err; |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 245 | rc = jbd2_journal_stop(handle); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 246 | |
| 247 | if (!err) |
| 248 | err = rc; |
| 249 | if (err) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 250 | __ext4_std_error(sb, where, err); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 251 | return err; |
| 252 | } |
| 253 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 254 | void ext4_journal_abort_handle(const char *caller, const char *err_fn, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 255 | struct buffer_head *bh, handle_t *handle, int err) |
| 256 | { |
| 257 | char nbuf[16]; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 258 | const char *errstr = ext4_decode_error(NULL, err, nbuf); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 259 | |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 260 | BUG_ON(!ext4_handle_valid(handle)); |
| 261 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 262 | if (bh) |
| 263 | BUFFER_TRACE(bh, "abort"); |
| 264 | |
| 265 | if (!handle->h_err) |
| 266 | handle->h_err = err; |
| 267 | |
| 268 | if (is_handle_aborted(handle)) |
| 269 | return; |
| 270 | |
| 271 | printk(KERN_ERR "%s: aborting transaction: %s in %s\n", |
| 272 | caller, errstr, err_fn); |
| 273 | |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 274 | jbd2_journal_abort_handle(handle); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /* Deal with the reporting of failure conditions on a filesystem such as |
| 278 | * inconsistencies detected or read IO failures. |
| 279 | * |
| 280 | * On ext2, we can store the error state of the filesystem in the |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 281 | * superblock. That is not possible on ext4, because we may have other |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 282 | * write ordering constraints on the superblock which prevent us from |
| 283 | * writing it out straight away; and given that the journal is about to |
| 284 | * be aborted, we can't rely on the current, or future, transactions to |
| 285 | * write out the superblock safely. |
| 286 | * |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 287 | * We'll just use the jbd2_journal_abort() error code to record an error in |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 288 | * the journal instead. On recovery, the journal will compain about |
| 289 | * that error until we've noted it down and cleared it. |
| 290 | */ |
| 291 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 292 | static void ext4_handle_error(struct super_block *sb) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 293 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 294 | struct ext4_super_block *es = EXT4_SB(sb)->s_es; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 295 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 296 | EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; |
| 297 | es->s_state |= cpu_to_le16(EXT4_ERROR_FS); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 298 | |
| 299 | if (sb->s_flags & MS_RDONLY) |
| 300 | return; |
| 301 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 302 | if (!test_opt(sb, ERRORS_CONT)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 303 | journal_t *journal = EXT4_SB(sb)->s_journal; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 304 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 305 | EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 306 | if (journal) |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 307 | jbd2_journal_abort(journal, -EIO); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 308 | } |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 309 | if (test_opt(sb, ERRORS_RO)) { |
| 310 | printk(KERN_CRIT "Remounting filesystem read-only\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 311 | sb->s_flags |= MS_RDONLY; |
| 312 | } |
Theodore Ts'o | e2d6705 | 2009-05-01 00:33:44 -0400 | [diff] [blame] | 313 | ext4_commit_super(sb, 1); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 314 | if (test_opt(sb, ERRORS_PANIC)) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 315 | panic("EXT4-fs (device %s): panic forced after error\n", |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 316 | sb->s_id); |
| 317 | } |
| 318 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 319 | void ext4_error(struct super_block *sb, const char *function, |
| 320 | const char *fmt, ...) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 321 | { |
| 322 | va_list args; |
| 323 | |
| 324 | va_start(args, fmt); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 325 | printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 326 | vprintk(fmt, args); |
| 327 | printk("\n"); |
| 328 | va_end(args); |
| 329 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 330 | ext4_handle_error(sb); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 333 | static const char *ext4_decode_error(struct super_block *sb, int errno, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 334 | char nbuf[16]) |
| 335 | { |
| 336 | char *errstr = NULL; |
| 337 | |
| 338 | switch (errno) { |
| 339 | case -EIO: |
| 340 | errstr = "IO failure"; |
| 341 | break; |
| 342 | case -ENOMEM: |
| 343 | errstr = "Out of memory"; |
| 344 | break; |
| 345 | case -EROFS: |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 346 | if (!sb || EXT4_SB(sb)->s_journal->j_flags & JBD2_ABORT) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 347 | errstr = "Journal has aborted"; |
| 348 | else |
| 349 | errstr = "Readonly filesystem"; |
| 350 | break; |
| 351 | default: |
| 352 | /* If the caller passed in an extra buffer for unknown |
| 353 | * errors, textualise them now. Else we just return |
| 354 | * NULL. */ |
| 355 | if (nbuf) { |
| 356 | /* Check for truncated error codes... */ |
| 357 | if (snprintf(nbuf, 16, "error %d", -errno) >= 0) |
| 358 | errstr = nbuf; |
| 359 | } |
| 360 | break; |
| 361 | } |
| 362 | |
| 363 | return errstr; |
| 364 | } |
| 365 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 366 | /* __ext4_std_error decodes expected errors from journaling functions |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 367 | * automatically and invokes the appropriate error response. */ |
| 368 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 369 | void __ext4_std_error(struct super_block *sb, const char *function, int errno) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 370 | { |
| 371 | char nbuf[16]; |
| 372 | const char *errstr; |
| 373 | |
| 374 | /* Special case: if the error is EROFS, and we're not already |
| 375 | * inside a transaction, then there's really no point in logging |
| 376 | * an error. */ |
| 377 | if (errno == -EROFS && journal_current_handle() == NULL && |
| 378 | (sb->s_flags & MS_RDONLY)) |
| 379 | return; |
| 380 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 381 | errstr = ext4_decode_error(sb, errno, nbuf); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 382 | printk(KERN_CRIT "EXT4-fs error (device %s) in %s: %s\n", |
| 383 | sb->s_id, function, errstr); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 384 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 385 | ext4_handle_error(sb); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | /* |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 389 | * ext4_abort is a much stronger failure handler than ext4_error. The |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 390 | * abort function may be used to deal with unrecoverable failures such |
| 391 | * as journal IO errors or ENOMEM at a critical moment in log management. |
| 392 | * |
| 393 | * We unconditionally force the filesystem into an ABORT|READONLY state, |
| 394 | * unless the error response on the fs has been set to panic in which |
| 395 | * case we take the easy way out and panic immediately. |
| 396 | */ |
| 397 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 398 | void ext4_abort(struct super_block *sb, const char *function, |
| 399 | const char *fmt, ...) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 400 | { |
| 401 | va_list args; |
| 402 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 403 | printk(KERN_CRIT "ext4_abort called.\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 404 | |
| 405 | va_start(args, fmt); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 406 | printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 407 | vprintk(fmt, args); |
| 408 | printk("\n"); |
| 409 | va_end(args); |
| 410 | |
| 411 | if (test_opt(sb, ERRORS_PANIC)) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 412 | panic("EXT4-fs panic from previous error\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 413 | |
| 414 | if (sb->s_flags & MS_RDONLY) |
| 415 | return; |
| 416 | |
| 417 | printk(KERN_CRIT "Remounting filesystem read-only\n"); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 418 | EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 419 | sb->s_flags |= MS_RDONLY; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 420 | EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT; |
Hidehiro Kawai | ef2cabf | 2008-10-27 22:53:05 -0400 | [diff] [blame] | 421 | if (EXT4_SB(sb)->s_journal) |
| 422 | jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 425 | void ext4_warning(struct super_block *sb, const char *function, |
| 426 | const char *fmt, ...) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 427 | { |
| 428 | va_list args; |
| 429 | |
| 430 | va_start(args, fmt); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 431 | printk(KERN_WARNING "EXT4-fs warning (device %s): %s: ", |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 432 | sb->s_id, function); |
| 433 | vprintk(fmt, args); |
| 434 | printk("\n"); |
| 435 | va_end(args); |
| 436 | } |
| 437 | |
Aneesh Kumar K.V | 5d1b1b3 | 2009-01-05 22:19:52 -0500 | [diff] [blame] | 438 | void ext4_grp_locked_error(struct super_block *sb, ext4_group_t grp, |
| 439 | const char *function, const char *fmt, ...) |
| 440 | __releases(bitlock) |
| 441 | __acquires(bitlock) |
| 442 | { |
| 443 | va_list args; |
| 444 | struct ext4_super_block *es = EXT4_SB(sb)->s_es; |
| 445 | |
| 446 | va_start(args, fmt); |
| 447 | printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); |
| 448 | vprintk(fmt, args); |
| 449 | printk("\n"); |
| 450 | va_end(args); |
| 451 | |
| 452 | if (test_opt(sb, ERRORS_CONT)) { |
| 453 | EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; |
| 454 | es->s_state |= cpu_to_le16(EXT4_ERROR_FS); |
Theodore Ts'o | e2d6705 | 2009-05-01 00:33:44 -0400 | [diff] [blame] | 455 | ext4_commit_super(sb, 0); |
Aneesh Kumar K.V | 5d1b1b3 | 2009-01-05 22:19:52 -0500 | [diff] [blame] | 456 | return; |
| 457 | } |
| 458 | ext4_unlock_group(sb, grp); |
| 459 | ext4_handle_error(sb); |
| 460 | /* |
| 461 | * We only get here in the ERRORS_RO case; relocking the group |
| 462 | * may be dangerous, but nothing bad will happen since the |
| 463 | * filesystem will have already been marked read/only and the |
| 464 | * journal has been aborted. We return 1 as a hint to callers |
| 465 | * who might what to use the return value from |
| 466 | * ext4_grp_locked_error() to distinguish beween the |
| 467 | * ERRORS_CONT and ERRORS_RO case, and perhaps return more |
| 468 | * aggressively from the ext4 function in question, with a |
| 469 | * more appropriate error code. |
| 470 | */ |
| 471 | ext4_lock_group(sb, grp); |
| 472 | return; |
| 473 | } |
| 474 | |
| 475 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 476 | void ext4_update_dynamic_rev(struct super_block *sb) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 477 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 478 | struct ext4_super_block *es = EXT4_SB(sb)->s_es; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 479 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 480 | if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 481 | return; |
| 482 | |
Harvey Harrison | 46e665e | 2008-04-17 10:38:59 -0400 | [diff] [blame] | 483 | ext4_warning(sb, __func__, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 484 | "updating to rev %d because of new feature flag, " |
| 485 | "running e2fsck is recommended", |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 486 | EXT4_DYNAMIC_REV); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 487 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 488 | es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO); |
| 489 | es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE); |
| 490 | es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 491 | /* leave es->s_feature_*compat flags alone */ |
| 492 | /* es->s_uuid will be set by e2fsck if empty */ |
| 493 | |
| 494 | /* |
| 495 | * The rest of the superblock fields should be zero, and if not it |
| 496 | * means they are likely already in use, so leave them alone. We |
| 497 | * can leave it up to e2fsck to clean up any inconsistencies there. |
| 498 | */ |
| 499 | } |
| 500 | |
| 501 | /* |
| 502 | * Open the external journal device |
| 503 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 504 | static struct block_device *ext4_blkdev_get(dev_t dev) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 505 | { |
| 506 | struct block_device *bdev; |
| 507 | char b[BDEVNAME_SIZE]; |
| 508 | |
| 509 | bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); |
| 510 | if (IS_ERR(bdev)) |
| 511 | goto fail; |
| 512 | return bdev; |
| 513 | |
| 514 | fail: |
Theodore Ts'o | abda141 | 2009-01-06 00:20:32 -0500 | [diff] [blame] | 515 | printk(KERN_ERR "EXT4-fs: failed to open journal device %s: %ld\n", |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 516 | __bdevname(dev, b), PTR_ERR(bdev)); |
| 517 | return NULL; |
| 518 | } |
| 519 | |
| 520 | /* |
| 521 | * Release the journal device |
| 522 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 523 | static int ext4_blkdev_put(struct block_device *bdev) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 524 | { |
| 525 | bd_release(bdev); |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 526 | return blkdev_put(bdev, FMODE_READ|FMODE_WRITE); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 529 | static int ext4_blkdev_remove(struct ext4_sb_info *sbi) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 530 | { |
| 531 | struct block_device *bdev; |
| 532 | int ret = -ENODEV; |
| 533 | |
| 534 | bdev = sbi->journal_bdev; |
| 535 | if (bdev) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 536 | ret = ext4_blkdev_put(bdev); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 537 | sbi->journal_bdev = NULL; |
| 538 | } |
| 539 | return ret; |
| 540 | } |
| 541 | |
| 542 | static inline struct inode *orphan_list_entry(struct list_head *l) |
| 543 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 544 | return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 547 | static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 548 | { |
| 549 | struct list_head *l; |
| 550 | |
| 551 | printk(KERN_ERR "sb orphan head is %d\n", |
| 552 | le32_to_cpu(sbi->s_es->s_last_orphan)); |
| 553 | |
| 554 | printk(KERN_ERR "sb_info orphan list:\n"); |
| 555 | list_for_each(l, &sbi->s_orphan) { |
| 556 | struct inode *inode = orphan_list_entry(l); |
| 557 | printk(KERN_ERR " " |
| 558 | "inode %s:%lu at %p: mode %o, nlink %d, next %d\n", |
| 559 | inode->i_sb->s_id, inode->i_ino, inode, |
| 560 | inode->i_mode, inode->i_nlink, |
| 561 | NEXT_ORPHAN(inode)); |
| 562 | } |
| 563 | } |
| 564 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 565 | static void ext4_put_super(struct super_block *sb) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 566 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 567 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
| 568 | struct ext4_super_block *es = sbi->s_es; |
Hidehiro Kawai | ef2cabf | 2008-10-27 22:53:05 -0400 | [diff] [blame] | 569 | int i, err; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 570 | |
Theodore Ts'o | 6fd058f | 2009-05-17 15:38:01 -0400 | [diff] [blame] | 571 | ext4_release_system_zone(sb); |
Alex Tomas | c9de560 | 2008-01-29 00:19:52 -0500 | [diff] [blame] | 572 | ext4_mb_release(sb); |
Alex Tomas | a86c618 | 2006-10-11 01:21:03 -0700 | [diff] [blame] | 573 | ext4_ext_release(sb); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 574 | ext4_xattr_put_super(sb); |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 575 | if (sbi->s_journal) { |
| 576 | err = jbd2_journal_destroy(sbi->s_journal); |
| 577 | sbi->s_journal = NULL; |
| 578 | if (err < 0) |
| 579 | ext4_abort(sb, __func__, |
| 580 | "Couldn't clean up the journal"); |
| 581 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 582 | if (!(sb->s_flags & MS_RDONLY)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 583 | EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 584 | es->s_state = cpu_to_le16(sbi->s_mount_state); |
Theodore Ts'o | e2d6705 | 2009-05-01 00:33:44 -0400 | [diff] [blame] | 585 | ext4_commit_super(sb, 1); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 586 | } |
Theodore Ts'o | 240799c | 2008-10-09 23:53:47 -0400 | [diff] [blame] | 587 | if (sbi->s_proc) { |
Theodore Ts'o | 9f6200b | 2008-09-23 09:18:24 -0400 | [diff] [blame] | 588 | remove_proc_entry(sb->s_id, ext4_proc_root); |
Theodore Ts'o | 240799c | 2008-10-09 23:53:47 -0400 | [diff] [blame] | 589 | } |
Theodore Ts'o | 3197ebd | 2009-03-31 09:10:09 -0400 | [diff] [blame] | 590 | kobject_del(&sbi->s_kobj); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 591 | |
| 592 | for (i = 0; i < sbi->s_gdb_count; i++) |
| 593 | brelse(sbi->s_group_desc[i]); |
| 594 | kfree(sbi->s_group_desc); |
Theodore Ts'o | c5ca7c7 | 2009-04-27 22:48:48 -0400 | [diff] [blame] | 595 | if (is_vmalloc_addr(sbi->s_flex_groups)) |
| 596 | vfree(sbi->s_flex_groups); |
| 597 | else |
| 598 | kfree(sbi->s_flex_groups); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 599 | percpu_counter_destroy(&sbi->s_freeblocks_counter); |
| 600 | percpu_counter_destroy(&sbi->s_freeinodes_counter); |
| 601 | percpu_counter_destroy(&sbi->s_dirs_counter); |
Aneesh Kumar K.V | 6bc6e63 | 2008-10-10 09:39:00 -0400 | [diff] [blame] | 602 | percpu_counter_destroy(&sbi->s_dirtyblocks_counter); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 603 | brelse(sbi->s_sbh); |
| 604 | #ifdef CONFIG_QUOTA |
| 605 | for (i = 0; i < MAXQUOTAS; i++) |
| 606 | kfree(sbi->s_qf_names[i]); |
| 607 | #endif |
| 608 | |
| 609 | /* Debugging code just in case the in-memory inode orphan list |
| 610 | * isn't empty. The on-disk one can be non-empty if we've |
| 611 | * detected an error and taken the fs readonly, but the |
| 612 | * in-memory list had better be clean by this point. */ |
| 613 | if (!list_empty(&sbi->s_orphan)) |
| 614 | dump_orphan_list(sb, sbi); |
| 615 | J_ASSERT(list_empty(&sbi->s_orphan)); |
| 616 | |
Peter Zijlstra | f98393a | 2007-05-06 14:49:54 -0700 | [diff] [blame] | 617 | invalidate_bdev(sb->s_bdev); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 618 | if (sbi->journal_bdev && sbi->journal_bdev != sb->s_bdev) { |
| 619 | /* |
| 620 | * Invalidate the journal device's buffers. We don't want them |
| 621 | * floating about in memory - the physical journal device may |
| 622 | * hotswapped, and it breaks the `ro-after' testing code. |
| 623 | */ |
| 624 | sync_blockdev(sbi->journal_bdev); |
Peter Zijlstra | f98393a | 2007-05-06 14:49:54 -0700 | [diff] [blame] | 625 | invalidate_bdev(sbi->journal_bdev); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 626 | ext4_blkdev_remove(sbi); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 627 | } |
| 628 | sb->s_fs_info = NULL; |
Theodore Ts'o | 3197ebd | 2009-03-31 09:10:09 -0400 | [diff] [blame] | 629 | /* |
| 630 | * Now that we are completely done shutting down the |
| 631 | * superblock, we need to actually destroy the kobject. |
| 632 | */ |
| 633 | unlock_kernel(); |
| 634 | unlock_super(sb); |
| 635 | kobject_put(&sbi->s_kobj); |
| 636 | wait_for_completion(&sbi->s_kobj_unregister); |
| 637 | lock_super(sb); |
| 638 | lock_kernel(); |
Pekka Enberg | 705895b | 2009-02-15 18:07:52 -0500 | [diff] [blame] | 639 | kfree(sbi->s_blockgroup_lock); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 640 | kfree(sbi); |
| 641 | return; |
| 642 | } |
| 643 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 644 | static struct kmem_cache *ext4_inode_cachep; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 645 | |
| 646 | /* |
| 647 | * Called inside transaction, so use GFP_NOFS |
| 648 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 649 | static struct inode *ext4_alloc_inode(struct super_block *sb) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 650 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 651 | struct ext4_inode_info *ei; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 652 | |
Christoph Lameter | e6b4f8d | 2006-12-06 20:33:14 -0800 | [diff] [blame] | 653 | ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 654 | if (!ei) |
| 655 | return NULL; |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 656 | #ifdef CONFIG_EXT4_FS_POSIX_ACL |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 657 | ei->i_acl = EXT4_ACL_NOT_CACHED; |
| 658 | ei->i_default_acl = EXT4_ACL_NOT_CACHED; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 659 | #endif |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 660 | ei->vfs_inode.i_version = 1; |
Aneesh Kumar K.V | 91246c0 | 2008-08-19 21:14:52 -0400 | [diff] [blame] | 661 | ei->vfs_inode.i_data.writeback_index = 0; |
Alex Tomas | a86c618 | 2006-10-11 01:21:03 -0700 | [diff] [blame] | 662 | memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache)); |
Alex Tomas | c9de560 | 2008-01-29 00:19:52 -0500 | [diff] [blame] | 663 | INIT_LIST_HEAD(&ei->i_prealloc_list); |
| 664 | spin_lock_init(&ei->i_prealloc_lock); |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 665 | /* |
| 666 | * Note: We can be called before EXT4_SB(sb)->s_journal is set, |
| 667 | * therefore it can be null here. Don't check it, just initialize |
| 668 | * jinode. |
| 669 | */ |
Jan Kara | 678aaf4 | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 670 | jbd2_journal_init_jbd_inode(&ei->jinode, &ei->vfs_inode); |
Mingming Cao | d2a1763 | 2008-07-14 17:52:37 -0400 | [diff] [blame] | 671 | ei->i_reserved_data_blocks = 0; |
| 672 | ei->i_reserved_meta_blocks = 0; |
| 673 | ei->i_allocated_meta_blocks = 0; |
| 674 | ei->i_delalloc_reserved_flag = 0; |
| 675 | spin_lock_init(&(ei->i_block_reservation_lock)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 676 | return &ei->vfs_inode; |
| 677 | } |
| 678 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 679 | static void ext4_destroy_inode(struct inode *inode) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 680 | { |
Vasily Averin | 9f7dd93 | 2007-07-15 23:40:45 -0700 | [diff] [blame] | 681 | if (!list_empty(&(EXT4_I(inode)->i_orphan))) { |
| 682 | printk("EXT4 Inode %p: orphan list check failed!\n", |
| 683 | EXT4_I(inode)); |
| 684 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4, |
| 685 | EXT4_I(inode), sizeof(struct ext4_inode_info), |
| 686 | true); |
| 687 | dump_stack(); |
| 688 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 689 | kmem_cache_free(ext4_inode_cachep, EXT4_I(inode)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 692 | static void init_once(void *foo) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 693 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 694 | struct ext4_inode_info *ei = (struct ext4_inode_info *) foo; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 695 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 696 | INIT_LIST_HEAD(&ei->i_orphan); |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 697 | #ifdef CONFIG_EXT4_FS_XATTR |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 698 | init_rwsem(&ei->xattr_sem); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 699 | #endif |
Aneesh Kumar K.V | 0e855ac | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 700 | init_rwsem(&ei->i_data_sem); |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 701 | inode_init_once(&ei->vfs_inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | static int init_inodecache(void) |
| 705 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 706 | ext4_inode_cachep = kmem_cache_create("ext4_inode_cache", |
| 707 | sizeof(struct ext4_inode_info), |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 708 | 0, (SLAB_RECLAIM_ACCOUNT| |
| 709 | SLAB_MEM_SPREAD), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 710 | init_once); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 711 | if (ext4_inode_cachep == NULL) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 712 | return -ENOMEM; |
| 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | static void destroy_inodecache(void) |
| 717 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 718 | kmem_cache_destroy(ext4_inode_cachep); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 721 | static void ext4_clear_inode(struct inode *inode) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 722 | { |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 723 | #ifdef CONFIG_EXT4_FS_POSIX_ACL |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 724 | if (EXT4_I(inode)->i_acl && |
| 725 | EXT4_I(inode)->i_acl != EXT4_ACL_NOT_CACHED) { |
| 726 | posix_acl_release(EXT4_I(inode)->i_acl); |
| 727 | EXT4_I(inode)->i_acl = EXT4_ACL_NOT_CACHED; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 728 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 729 | if (EXT4_I(inode)->i_default_acl && |
| 730 | EXT4_I(inode)->i_default_acl != EXT4_ACL_NOT_CACHED) { |
| 731 | posix_acl_release(EXT4_I(inode)->i_default_acl); |
| 732 | EXT4_I(inode)->i_default_acl = EXT4_ACL_NOT_CACHED; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 733 | } |
| 734 | #endif |
Theodore Ts'o | c2ea3fd | 2008-10-10 09:40:52 -0400 | [diff] [blame] | 735 | ext4_discard_preallocations(inode); |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 736 | if (EXT4_JOURNAL(inode)) |
| 737 | jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal, |
Jan Kara | 678aaf4 | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 738 | &EXT4_I(inode)->jinode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 741 | static inline void ext4_show_quota_options(struct seq_file *seq, |
| 742 | struct super_block *sb) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 743 | { |
| 744 | #if defined(CONFIG_QUOTA) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 745 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 746 | |
| 747 | if (sbi->s_jquota_fmt) |
| 748 | seq_printf(seq, ",jqfmt=%s", |
Theodore Ts'o | af5bc92 | 2008-09-08 22:25:24 -0400 | [diff] [blame] | 749 | (sbi->s_jquota_fmt == QFMT_VFS_OLD) ? "vfsold" : "vfsv0"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 750 | |
| 751 | if (sbi->s_qf_names[USRQUOTA]) |
| 752 | seq_printf(seq, ",usrjquota=%s", sbi->s_qf_names[USRQUOTA]); |
| 753 | |
| 754 | if (sbi->s_qf_names[GRPQUOTA]) |
| 755 | seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]); |
| 756 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 757 | if (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 758 | seq_puts(seq, ",usrquota"); |
| 759 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 760 | if (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 761 | seq_puts(seq, ",grpquota"); |
| 762 | #endif |
| 763 | } |
| 764 | |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 765 | /* |
| 766 | * Show an option if |
| 767 | * - it's set to a non-default value OR |
| 768 | * - if the per-sb default is different from the global default |
| 769 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 770 | static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 771 | { |
Aneesh Kumar K.V | aa22df2 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 772 | int def_errors; |
| 773 | unsigned long def_mount_opts; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 774 | struct super_block *sb = vfs->mnt_sb; |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 775 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
| 776 | struct ext4_super_block *es = sbi->s_es; |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 777 | |
| 778 | def_mount_opts = le32_to_cpu(es->s_default_mount_opts); |
Aneesh Kumar K.V | aa22df2 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 779 | def_errors = le16_to_cpu(es->s_errors); |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 780 | |
| 781 | if (sbi->s_sb_block != 1) |
| 782 | seq_printf(seq, ",sb=%llu", sbi->s_sb_block); |
| 783 | if (test_opt(sb, MINIX_DF)) |
| 784 | seq_puts(seq, ",minixdf"); |
Aneesh Kumar K.V | aa22df2 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 785 | if (test_opt(sb, GRPID) && !(def_mount_opts & EXT4_DEFM_BSDGROUPS)) |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 786 | seq_puts(seq, ",grpid"); |
| 787 | if (!test_opt(sb, GRPID) && (def_mount_opts & EXT4_DEFM_BSDGROUPS)) |
| 788 | seq_puts(seq, ",nogrpid"); |
| 789 | if (sbi->s_resuid != EXT4_DEF_RESUID || |
| 790 | le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID) { |
| 791 | seq_printf(seq, ",resuid=%u", sbi->s_resuid); |
| 792 | } |
| 793 | if (sbi->s_resgid != EXT4_DEF_RESGID || |
| 794 | le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID) { |
| 795 | seq_printf(seq, ",resgid=%u", sbi->s_resgid); |
| 796 | } |
Aneesh Kumar K.V | bb4f397 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 797 | if (test_opt(sb, ERRORS_RO)) { |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 798 | if (def_errors == EXT4_ERRORS_PANIC || |
Aneesh Kumar K.V | bb4f397 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 799 | def_errors == EXT4_ERRORS_CONTINUE) { |
| 800 | seq_puts(seq, ",errors=remount-ro"); |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 801 | } |
| 802 | } |
Aneesh Kumar K.V | aa22df2 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 803 | if (test_opt(sb, ERRORS_CONT) && def_errors != EXT4_ERRORS_CONTINUE) |
Aneesh Kumar K.V | bb4f397 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 804 | seq_puts(seq, ",errors=continue"); |
Aneesh Kumar K.V | aa22df2 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 805 | if (test_opt(sb, ERRORS_PANIC) && def_errors != EXT4_ERRORS_PANIC) |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 806 | seq_puts(seq, ",errors=panic"); |
Aneesh Kumar K.V | aa22df2 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 807 | if (test_opt(sb, NO_UID32) && !(def_mount_opts & EXT4_DEFM_UID16)) |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 808 | seq_puts(seq, ",nouid32"); |
Aneesh Kumar K.V | aa22df2 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 809 | if (test_opt(sb, DEBUG) && !(def_mount_opts & EXT4_DEFM_DEBUG)) |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 810 | seq_puts(seq, ",debug"); |
| 811 | if (test_opt(sb, OLDALLOC)) |
| 812 | seq_puts(seq, ",oldalloc"); |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 813 | #ifdef CONFIG_EXT4_FS_XATTR |
Aneesh Kumar K.V | aa22df2 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 814 | if (test_opt(sb, XATTR_USER) && |
| 815 | !(def_mount_opts & EXT4_DEFM_XATTR_USER)) |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 816 | seq_puts(seq, ",user_xattr"); |
| 817 | if (!test_opt(sb, XATTR_USER) && |
| 818 | (def_mount_opts & EXT4_DEFM_XATTR_USER)) { |
| 819 | seq_puts(seq, ",nouser_xattr"); |
| 820 | } |
| 821 | #endif |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 822 | #ifdef CONFIG_EXT4_FS_POSIX_ACL |
Aneesh Kumar K.V | aa22df2 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 823 | if (test_opt(sb, POSIX_ACL) && !(def_mount_opts & EXT4_DEFM_ACL)) |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 824 | seq_puts(seq, ",acl"); |
| 825 | if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT4_DEFM_ACL)) |
| 826 | seq_puts(seq, ",noacl"); |
| 827 | #endif |
Theodore Ts'o | 3077384 | 2009-01-03 20:27:38 -0500 | [diff] [blame] | 828 | if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) { |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 829 | seq_printf(seq, ",commit=%u", |
| 830 | (unsigned) (sbi->s_commit_interval / HZ)); |
| 831 | } |
Theodore Ts'o | 3077384 | 2009-01-03 20:27:38 -0500 | [diff] [blame] | 832 | if (sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME) { |
| 833 | seq_printf(seq, ",min_batch_time=%u", |
| 834 | (unsigned) sbi->s_min_batch_time); |
| 835 | } |
| 836 | if (sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME) { |
| 837 | seq_printf(seq, ",max_batch_time=%u", |
| 838 | (unsigned) sbi->s_min_batch_time); |
| 839 | } |
| 840 | |
Eric Sandeen | 571640c | 2008-05-26 12:29:46 -0400 | [diff] [blame] | 841 | /* |
| 842 | * We're changing the default of barrier mount option, so |
| 843 | * let's always display its mount state so it's clear what its |
| 844 | * status is. |
| 845 | */ |
| 846 | seq_puts(seq, ",barrier="); |
| 847 | seq_puts(seq, test_opt(sb, BARRIER) ? "1" : "0"); |
Theodore Ts'o | cd0b6a3 | 2008-05-26 10:28:28 -0400 | [diff] [blame] | 848 | if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) |
| 849 | seq_puts(seq, ",journal_async_commit"); |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 850 | if (test_opt(sb, NOBH)) |
| 851 | seq_puts(seq, ",nobh"); |
Jean Noel Cordenner | 25ec56b | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 852 | if (test_opt(sb, I_VERSION)) |
| 853 | seq_puts(seq, ",i_version"); |
Aneesh Kumar K.V | dd919b9 | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 854 | if (!test_opt(sb, DELALLOC)) |
| 855 | seq_puts(seq, ",nodelalloc"); |
| 856 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 857 | |
Miklos Szeredi | cb45bbe | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 858 | if (sbi->s_stripe) |
| 859 | seq_printf(seq, ",stripe=%lu", sbi->s_stripe); |
Aneesh Kumar K.V | aa22df2 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 860 | /* |
| 861 | * journal mode get enabled in different ways |
| 862 | * So just print the value even if we didn't specify it |
| 863 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 864 | if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 865 | seq_puts(seq, ",data=journal"); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 866 | else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 867 | seq_puts(seq, ",data=ordered"); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 868 | else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 869 | seq_puts(seq, ",data=writeback"); |
| 870 | |
Theodore Ts'o | 240799c | 2008-10-09 23:53:47 -0400 | [diff] [blame] | 871 | if (sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS) |
| 872 | seq_printf(seq, ",inode_readahead_blks=%u", |
| 873 | sbi->s_inode_readahead_blks); |
| 874 | |
Hidehiro Kawai | 5bf5683 | 2008-10-10 22:12:43 -0400 | [diff] [blame] | 875 | if (test_opt(sb, DATA_ERR_ABORT)) |
| 876 | seq_puts(seq, ",data_err=abort"); |
| 877 | |
Theodore Ts'o | afd4672 | 2009-03-16 23:12:23 -0400 | [diff] [blame] | 878 | if (test_opt(sb, NO_AUTO_DA_ALLOC)) |
Theodore Ts'o | 06705bf | 2009-03-28 10:59:57 -0400 | [diff] [blame] | 879 | seq_puts(seq, ",noauto_da_alloc"); |
Theodore Ts'o | afd4672 | 2009-03-16 23:12:23 -0400 | [diff] [blame] | 880 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 881 | ext4_show_quota_options(seq, sb); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 882 | return 0; |
| 883 | } |
| 884 | |
| 885 | |
Christoph Hellwig | 1b961ac | 2007-10-21 16:42:08 -0700 | [diff] [blame] | 886 | static struct inode *ext4_nfs_get_inode(struct super_block *sb, |
| 887 | u64 ino, u32 generation) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 888 | { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 889 | struct inode *inode; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 890 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 891 | if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 892 | return ERR_PTR(-ESTALE); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 893 | if (ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 894 | return ERR_PTR(-ESTALE); |
| 895 | |
| 896 | /* iget isn't really right if the inode is currently unallocated!! |
| 897 | * |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 898 | * ext4_read_inode will return a bad_inode if the inode had been |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 899 | * deleted, so we should be safe. |
| 900 | * |
| 901 | * Currently we don't know the generation for parent directory, so |
| 902 | * a generation of 0 means "accept any" |
| 903 | */ |
David Howells | 1d1fe1e | 2008-02-07 00:15:37 -0800 | [diff] [blame] | 904 | inode = ext4_iget(sb, ino); |
| 905 | if (IS_ERR(inode)) |
| 906 | return ERR_CAST(inode); |
| 907 | if (generation && inode->i_generation != generation) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 908 | iput(inode); |
| 909 | return ERR_PTR(-ESTALE); |
| 910 | } |
Christoph Hellwig | 1b961ac | 2007-10-21 16:42:08 -0700 | [diff] [blame] | 911 | |
| 912 | return inode; |
| 913 | } |
| 914 | |
| 915 | static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid, |
| 916 | int fh_len, int fh_type) |
| 917 | { |
| 918 | return generic_fh_to_dentry(sb, fid, fh_len, fh_type, |
| 919 | ext4_nfs_get_inode); |
| 920 | } |
| 921 | |
| 922 | static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid, |
| 923 | int fh_len, int fh_type) |
| 924 | { |
| 925 | return generic_fh_to_parent(sb, fid, fh_len, fh_type, |
| 926 | ext4_nfs_get_inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Toshiyuki Okajima | c39a7f8 | 2009-01-05 22:38:48 -0500 | [diff] [blame] | 929 | /* |
| 930 | * Try to release metadata pages (indirect blocks, directories) which are |
| 931 | * mapped via the block device. Since these pages could have journal heads |
| 932 | * which would prevent try_to_free_buffers() from freeing them, we must use |
| 933 | * jbd2 layer's try_to_free_buffers() function to release them. |
| 934 | */ |
| 935 | static int bdev_try_to_free_page(struct super_block *sb, struct page *page, gfp_t wait) |
| 936 | { |
| 937 | journal_t *journal = EXT4_SB(sb)->s_journal; |
| 938 | |
| 939 | WARN_ON(PageChecked(page)); |
| 940 | if (!page_has_buffers(page)) |
| 941 | return 0; |
| 942 | if (journal) |
| 943 | return jbd2_journal_try_to_free_buffers(journal, page, |
| 944 | wait & ~__GFP_WAIT); |
| 945 | return try_to_free_buffers(page); |
| 946 | } |
| 947 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 948 | #ifdef CONFIG_QUOTA |
Theodore Ts'o | af5bc92 | 2008-09-08 22:25:24 -0400 | [diff] [blame] | 949 | #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group") |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 950 | #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 951 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 952 | static int ext4_write_dquot(struct dquot *dquot); |
| 953 | static int ext4_acquire_dquot(struct dquot *dquot); |
| 954 | static int ext4_release_dquot(struct dquot *dquot); |
| 955 | static int ext4_mark_dquot_dirty(struct dquot *dquot); |
| 956 | static int ext4_write_info(struct super_block *sb, int type); |
Jan Kara | 6f28e08 | 2008-04-28 02:14:34 -0700 | [diff] [blame] | 957 | static int ext4_quota_on(struct super_block *sb, int type, int format_id, |
| 958 | char *path, int remount); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 959 | static int ext4_quota_on_mount(struct super_block *sb, int type); |
| 960 | static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 961 | size_t len, loff_t off); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 962 | static ssize_t ext4_quota_write(struct super_block *sb, int type, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 963 | const char *data, size_t len, loff_t off); |
| 964 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 965 | static struct dquot_operations ext4_quota_operations = { |
Jan Kara | edf7245 | 2009-01-12 19:05:26 +0100 | [diff] [blame] | 966 | .initialize = dquot_initialize, |
| 967 | .drop = dquot_drop, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 968 | .alloc_space = dquot_alloc_space, |
Mingming Cao | 60e58e0 | 2009-01-22 18:13:05 +0100 | [diff] [blame] | 969 | .reserve_space = dquot_reserve_space, |
| 970 | .claim_space = dquot_claim_space, |
| 971 | .release_rsv = dquot_release_reserved_space, |
| 972 | .get_reserved_space = ext4_get_reserved_space, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 973 | .alloc_inode = dquot_alloc_inode, |
| 974 | .free_space = dquot_free_space, |
| 975 | .free_inode = dquot_free_inode, |
| 976 | .transfer = dquot_transfer, |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 977 | .write_dquot = ext4_write_dquot, |
| 978 | .acquire_dquot = ext4_acquire_dquot, |
| 979 | .release_dquot = ext4_release_dquot, |
| 980 | .mark_dirty = ext4_mark_dquot_dirty, |
Jan Kara | a5b5ee3 | 2008-11-25 15:31:35 +0100 | [diff] [blame] | 981 | .write_info = ext4_write_info, |
| 982 | .alloc_dquot = dquot_alloc, |
| 983 | .destroy_dquot = dquot_destroy, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 984 | }; |
| 985 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 986 | static struct quotactl_ops ext4_qctl_operations = { |
| 987 | .quota_on = ext4_quota_on, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 988 | .quota_off = vfs_quota_off, |
| 989 | .quota_sync = vfs_quota_sync, |
| 990 | .get_info = vfs_get_dqinfo, |
| 991 | .set_info = vfs_set_dqinfo, |
| 992 | .get_dqblk = vfs_get_dqblk, |
| 993 | .set_dqblk = vfs_set_dqblk |
| 994 | }; |
| 995 | #endif |
| 996 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 997 | static const struct super_operations ext4_sops = { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 998 | .alloc_inode = ext4_alloc_inode, |
| 999 | .destroy_inode = ext4_destroy_inode, |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1000 | .write_inode = ext4_write_inode, |
| 1001 | .dirty_inode = ext4_dirty_inode, |
| 1002 | .delete_inode = ext4_delete_inode, |
| 1003 | .put_super = ext4_put_super, |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1004 | .sync_fs = ext4_sync_fs, |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 1005 | .freeze_fs = ext4_freeze, |
| 1006 | .unfreeze_fs = ext4_unfreeze, |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1007 | .statfs = ext4_statfs, |
| 1008 | .remount_fs = ext4_remount, |
| 1009 | .clear_inode = ext4_clear_inode, |
| 1010 | .show_options = ext4_show_options, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1011 | #ifdef CONFIG_QUOTA |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1012 | .quota_read = ext4_quota_read, |
| 1013 | .quota_write = ext4_quota_write, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1014 | #endif |
Toshiyuki Okajima | c39a7f8 | 2009-01-05 22:38:48 -0500 | [diff] [blame] | 1015 | .bdev_try_to_free_page = bdev_try_to_free_page, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1016 | }; |
| 1017 | |
Theodore Ts'o | 9ca9238 | 2009-05-01 12:52:25 -0400 | [diff] [blame] | 1018 | static const struct super_operations ext4_nojournal_sops = { |
| 1019 | .alloc_inode = ext4_alloc_inode, |
| 1020 | .destroy_inode = ext4_destroy_inode, |
| 1021 | .write_inode = ext4_write_inode, |
| 1022 | .dirty_inode = ext4_dirty_inode, |
| 1023 | .delete_inode = ext4_delete_inode, |
| 1024 | .write_super = ext4_write_super, |
| 1025 | .put_super = ext4_put_super, |
| 1026 | .statfs = ext4_statfs, |
| 1027 | .remount_fs = ext4_remount, |
| 1028 | .clear_inode = ext4_clear_inode, |
| 1029 | .show_options = ext4_show_options, |
| 1030 | #ifdef CONFIG_QUOTA |
| 1031 | .quota_read = ext4_quota_read, |
| 1032 | .quota_write = ext4_quota_write, |
| 1033 | #endif |
| 1034 | .bdev_try_to_free_page = bdev_try_to_free_page, |
| 1035 | }; |
| 1036 | |
Christoph Hellwig | 3965516 | 2007-10-21 16:42:17 -0700 | [diff] [blame] | 1037 | static const struct export_operations ext4_export_ops = { |
Christoph Hellwig | 1b961ac | 2007-10-21 16:42:08 -0700 | [diff] [blame] | 1038 | .fh_to_dentry = ext4_fh_to_dentry, |
| 1039 | .fh_to_parent = ext4_fh_to_parent, |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1040 | .get_parent = ext4_get_parent, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1041 | }; |
| 1042 | |
| 1043 | enum { |
| 1044 | Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid, |
| 1045 | Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro, |
Theodore Ts'o | 01436ef | 2008-10-17 07:22:35 -0400 | [diff] [blame] | 1046 | Opt_nouid32, Opt_debug, Opt_oldalloc, Opt_orlov, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1047 | Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, |
Theodore Ts'o | 06705bf | 2009-03-28 10:59:57 -0400 | [diff] [blame] | 1048 | Opt_auto_da_alloc, Opt_noauto_da_alloc, Opt_noload, Opt_nobh, Opt_bh, |
Theodore Ts'o | 3077384 | 2009-01-03 20:27:38 -0500 | [diff] [blame] | 1049 | Opt_commit, Opt_min_batch_time, Opt_max_batch_time, |
Theodore Ts'o | c319106 | 2009-01-06 11:14:25 -0500 | [diff] [blame] | 1050 | Opt_journal_update, Opt_journal_dev, |
Girish Shilamkar | 818d276 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1051 | Opt_journal_checksum, Opt_journal_async_commit, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1052 | Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, |
Curt Wohlgemuth | f403390 | 2009-05-01 20:27:20 -0400 | [diff] [blame] | 1053 | Opt_data_err_abort, Opt_data_err_ignore, Opt_mb_history_length, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1054 | Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, |
| 1055 | Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, |
Theodore Ts'o | 06705bf | 2009-03-28 10:59:57 -0400 | [diff] [blame] | 1056 | Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, Opt_resize, |
| 1057 | Opt_usrquota, Opt_grpquota, Opt_i_version, |
Theodore Ts'o | 01436ef | 2008-10-17 07:22:35 -0400 | [diff] [blame] | 1058 | Opt_stripe, Opt_delalloc, Opt_nodelalloc, |
Theodore Ts'o | 6fd058f | 2009-05-17 15:38:01 -0400 | [diff] [blame] | 1059 | Opt_block_validity, Opt_noblock_validity, |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 1060 | Opt_inode_readahead_blks, Opt_journal_ioprio |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1061 | }; |
| 1062 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 1063 | static const match_table_t tokens = { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1064 | {Opt_bsd_df, "bsddf"}, |
| 1065 | {Opt_minix_df, "minixdf"}, |
| 1066 | {Opt_grpid, "grpid"}, |
| 1067 | {Opt_grpid, "bsdgroups"}, |
| 1068 | {Opt_nogrpid, "nogrpid"}, |
| 1069 | {Opt_nogrpid, "sysvgroups"}, |
| 1070 | {Opt_resgid, "resgid=%u"}, |
| 1071 | {Opt_resuid, "resuid=%u"}, |
| 1072 | {Opt_sb, "sb=%u"}, |
| 1073 | {Opt_err_cont, "errors=continue"}, |
| 1074 | {Opt_err_panic, "errors=panic"}, |
| 1075 | {Opt_err_ro, "errors=remount-ro"}, |
| 1076 | {Opt_nouid32, "nouid32"}, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1077 | {Opt_debug, "debug"}, |
| 1078 | {Opt_oldalloc, "oldalloc"}, |
| 1079 | {Opt_orlov, "orlov"}, |
| 1080 | {Opt_user_xattr, "user_xattr"}, |
| 1081 | {Opt_nouser_xattr, "nouser_xattr"}, |
| 1082 | {Opt_acl, "acl"}, |
| 1083 | {Opt_noacl, "noacl"}, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1084 | {Opt_noload, "noload"}, |
| 1085 | {Opt_nobh, "nobh"}, |
| 1086 | {Opt_bh, "bh"}, |
| 1087 | {Opt_commit, "commit=%u"}, |
Theodore Ts'o | 3077384 | 2009-01-03 20:27:38 -0500 | [diff] [blame] | 1088 | {Opt_min_batch_time, "min_batch_time=%u"}, |
| 1089 | {Opt_max_batch_time, "max_batch_time=%u"}, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1090 | {Opt_journal_update, "journal=update"}, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1091 | {Opt_journal_dev, "journal_dev=%u"}, |
Girish Shilamkar | 818d276 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1092 | {Opt_journal_checksum, "journal_checksum"}, |
| 1093 | {Opt_journal_async_commit, "journal_async_commit"}, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1094 | {Opt_abort, "abort"}, |
| 1095 | {Opt_data_journal, "data=journal"}, |
| 1096 | {Opt_data_ordered, "data=ordered"}, |
| 1097 | {Opt_data_writeback, "data=writeback"}, |
Hidehiro Kawai | 5bf5683 | 2008-10-10 22:12:43 -0400 | [diff] [blame] | 1098 | {Opt_data_err_abort, "data_err=abort"}, |
| 1099 | {Opt_data_err_ignore, "data_err=ignore"}, |
Curt Wohlgemuth | f403390 | 2009-05-01 20:27:20 -0400 | [diff] [blame] | 1100 | {Opt_mb_history_length, "mb_history_length=%u"}, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1101 | {Opt_offusrjquota, "usrjquota="}, |
| 1102 | {Opt_usrjquota, "usrjquota=%s"}, |
| 1103 | {Opt_offgrpjquota, "grpjquota="}, |
| 1104 | {Opt_grpjquota, "grpjquota=%s"}, |
| 1105 | {Opt_jqfmt_vfsold, "jqfmt=vfsold"}, |
| 1106 | {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, |
| 1107 | {Opt_grpquota, "grpquota"}, |
| 1108 | {Opt_noquota, "noquota"}, |
| 1109 | {Opt_quota, "quota"}, |
| 1110 | {Opt_usrquota, "usrquota"}, |
| 1111 | {Opt_barrier, "barrier=%u"}, |
Theodore Ts'o | 06705bf | 2009-03-28 10:59:57 -0400 | [diff] [blame] | 1112 | {Opt_barrier, "barrier"}, |
| 1113 | {Opt_nobarrier, "nobarrier"}, |
Jean Noel Cordenner | 25ec56b | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1114 | {Opt_i_version, "i_version"}, |
Alex Tomas | c9de560 | 2008-01-29 00:19:52 -0500 | [diff] [blame] | 1115 | {Opt_stripe, "stripe=%u"}, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1116 | {Opt_resize, "resize"}, |
Alex Tomas | 6476924 | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1117 | {Opt_delalloc, "delalloc"}, |
Aneesh Kumar K.V | dd919b9 | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1118 | {Opt_nodelalloc, "nodelalloc"}, |
Theodore Ts'o | 6fd058f | 2009-05-17 15:38:01 -0400 | [diff] [blame] | 1119 | {Opt_block_validity, "block_validity"}, |
| 1120 | {Opt_noblock_validity, "noblock_validity"}, |
Theodore Ts'o | 240799c | 2008-10-09 23:53:47 -0400 | [diff] [blame] | 1121 | {Opt_inode_readahead_blks, "inode_readahead_blks=%u"}, |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 1122 | {Opt_journal_ioprio, "journal_ioprio=%u"}, |
Theodore Ts'o | afd4672 | 2009-03-16 23:12:23 -0400 | [diff] [blame] | 1123 | {Opt_auto_da_alloc, "auto_da_alloc=%u"}, |
Theodore Ts'o | 06705bf | 2009-03-28 10:59:57 -0400 | [diff] [blame] | 1124 | {Opt_auto_da_alloc, "auto_da_alloc"}, |
| 1125 | {Opt_noauto_da_alloc, "noauto_da_alloc"}, |
Josef Bacik | f3f12fa | 2008-04-29 22:05:28 -0400 | [diff] [blame] | 1126 | {Opt_err, NULL}, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1127 | }; |
| 1128 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1129 | static ext4_fsblk_t get_sb_block(void **data) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1130 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1131 | ext4_fsblk_t sb_block; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1132 | char *options = (char *) *data; |
| 1133 | |
| 1134 | if (!options || strncmp(options, "sb=", 3) != 0) |
| 1135 | return 1; /* Default location */ |
| 1136 | options += 3; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1137 | /*todo: use simple_strtoll with >32bit ext4 */ |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1138 | sb_block = simple_strtoul(options, &options, 0); |
| 1139 | if (*options && *options != ',') { |
Theodore Ts'o | 4776004 | 2008-09-08 23:00:52 -0400 | [diff] [blame] | 1140 | printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n", |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1141 | (char *) *data); |
| 1142 | return 1; |
| 1143 | } |
| 1144 | if (*options == ',') |
| 1145 | options++; |
| 1146 | *data = (void *) options; |
| 1147 | return sb_block; |
| 1148 | } |
| 1149 | |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 1150 | #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3)) |
| 1151 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1152 | static int parse_options(char *options, struct super_block *sb, |
Theodore Ts'o | c319106 | 2009-01-06 11:14:25 -0500 | [diff] [blame] | 1153 | unsigned long *journal_devnum, |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 1154 | unsigned int *journal_ioprio, |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1155 | ext4_fsblk_t *n_blocks_count, int is_remount) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1156 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1157 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1158 | char *p; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1159 | substring_t args[MAX_OPT_ARGS]; |
| 1160 | int data_opt = 0; |
| 1161 | int option; |
| 1162 | #ifdef CONFIG_QUOTA |
Jan Kara | dfc5d03 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 1163 | int qtype, qfmt; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1164 | char *qname; |
| 1165 | #endif |
| 1166 | |
| 1167 | if (!options) |
| 1168 | return 1; |
| 1169 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1170 | while ((p = strsep(&options, ",")) != NULL) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1171 | int token; |
| 1172 | if (!*p) |
| 1173 | continue; |
| 1174 | |
| 1175 | token = match_token(p, tokens, args); |
| 1176 | switch (token) { |
| 1177 | case Opt_bsd_df: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1178 | clear_opt(sbi->s_mount_opt, MINIX_DF); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1179 | break; |
| 1180 | case Opt_minix_df: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1181 | set_opt(sbi->s_mount_opt, MINIX_DF); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1182 | break; |
| 1183 | case Opt_grpid: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1184 | set_opt(sbi->s_mount_opt, GRPID); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1185 | break; |
| 1186 | case Opt_nogrpid: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1187 | clear_opt(sbi->s_mount_opt, GRPID); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1188 | break; |
| 1189 | case Opt_resuid: |
| 1190 | if (match_int(&args[0], &option)) |
| 1191 | return 0; |
| 1192 | sbi->s_resuid = option; |
| 1193 | break; |
| 1194 | case Opt_resgid: |
| 1195 | if (match_int(&args[0], &option)) |
| 1196 | return 0; |
| 1197 | sbi->s_resgid = option; |
| 1198 | break; |
| 1199 | case Opt_sb: |
| 1200 | /* handled by get_sb_block() instead of here */ |
| 1201 | /* *sb_block = match_int(&args[0]); */ |
| 1202 | break; |
| 1203 | case Opt_err_panic: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1204 | clear_opt(sbi->s_mount_opt, ERRORS_CONT); |
| 1205 | clear_opt(sbi->s_mount_opt, ERRORS_RO); |
| 1206 | set_opt(sbi->s_mount_opt, ERRORS_PANIC); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1207 | break; |
| 1208 | case Opt_err_ro: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1209 | clear_opt(sbi->s_mount_opt, ERRORS_CONT); |
| 1210 | clear_opt(sbi->s_mount_opt, ERRORS_PANIC); |
| 1211 | set_opt(sbi->s_mount_opt, ERRORS_RO); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1212 | break; |
| 1213 | case Opt_err_cont: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1214 | clear_opt(sbi->s_mount_opt, ERRORS_RO); |
| 1215 | clear_opt(sbi->s_mount_opt, ERRORS_PANIC); |
| 1216 | set_opt(sbi->s_mount_opt, ERRORS_CONT); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1217 | break; |
| 1218 | case Opt_nouid32: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1219 | set_opt(sbi->s_mount_opt, NO_UID32); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1220 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1221 | case Opt_debug: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1222 | set_opt(sbi->s_mount_opt, DEBUG); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1223 | break; |
| 1224 | case Opt_oldalloc: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1225 | set_opt(sbi->s_mount_opt, OLDALLOC); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1226 | break; |
| 1227 | case Opt_orlov: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1228 | clear_opt(sbi->s_mount_opt, OLDALLOC); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1229 | break; |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 1230 | #ifdef CONFIG_EXT4_FS_XATTR |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1231 | case Opt_user_xattr: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1232 | set_opt(sbi->s_mount_opt, XATTR_USER); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1233 | break; |
| 1234 | case Opt_nouser_xattr: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1235 | clear_opt(sbi->s_mount_opt, XATTR_USER); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1236 | break; |
| 1237 | #else |
| 1238 | case Opt_user_xattr: |
| 1239 | case Opt_nouser_xattr: |
Theodore Ts'o | 4776004 | 2008-09-08 23:00:52 -0400 | [diff] [blame] | 1240 | printk(KERN_ERR "EXT4 (no)user_xattr options " |
| 1241 | "not supported\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1242 | break; |
| 1243 | #endif |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 1244 | #ifdef CONFIG_EXT4_FS_POSIX_ACL |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1245 | case Opt_acl: |
| 1246 | set_opt(sbi->s_mount_opt, POSIX_ACL); |
| 1247 | break; |
| 1248 | case Opt_noacl: |
| 1249 | clear_opt(sbi->s_mount_opt, POSIX_ACL); |
| 1250 | break; |
| 1251 | #else |
| 1252 | case Opt_acl: |
| 1253 | case Opt_noacl: |
Theodore Ts'o | 4776004 | 2008-09-08 23:00:52 -0400 | [diff] [blame] | 1254 | printk(KERN_ERR "EXT4 (no)acl options " |
| 1255 | "not supported\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1256 | break; |
| 1257 | #endif |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1258 | case Opt_journal_update: |
| 1259 | /* @@@ FIXME */ |
| 1260 | /* Eventually we will want to be able to create |
| 1261 | a journal file here. For now, only allow the |
| 1262 | user to specify an existing inode to be the |
| 1263 | journal file. */ |
| 1264 | if (is_remount) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1265 | printk(KERN_ERR "EXT4-fs: cannot specify " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1266 | "journal on remount\n"); |
| 1267 | return 0; |
| 1268 | } |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1269 | set_opt(sbi->s_mount_opt, UPDATE_JOURNAL); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1270 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1271 | case Opt_journal_dev: |
| 1272 | if (is_remount) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1273 | printk(KERN_ERR "EXT4-fs: cannot specify " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1274 | "journal on remount\n"); |
| 1275 | return 0; |
| 1276 | } |
| 1277 | if (match_int(&args[0], &option)) |
| 1278 | return 0; |
| 1279 | *journal_devnum = option; |
| 1280 | break; |
Girish Shilamkar | 818d276 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1281 | case Opt_journal_checksum: |
| 1282 | set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM); |
| 1283 | break; |
| 1284 | case Opt_journal_async_commit: |
| 1285 | set_opt(sbi->s_mount_opt, JOURNAL_ASYNC_COMMIT); |
| 1286 | set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM); |
| 1287 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1288 | case Opt_noload: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1289 | set_opt(sbi->s_mount_opt, NOLOAD); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1290 | break; |
| 1291 | case Opt_commit: |
| 1292 | if (match_int(&args[0], &option)) |
| 1293 | return 0; |
| 1294 | if (option < 0) |
| 1295 | return 0; |
| 1296 | if (option == 0) |
Mingming Cao | cd02ff0 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 1297 | option = JBD2_DEFAULT_MAX_COMMIT_AGE; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1298 | sbi->s_commit_interval = HZ * option; |
| 1299 | break; |
Theodore Ts'o | 3077384 | 2009-01-03 20:27:38 -0500 | [diff] [blame] | 1300 | case Opt_max_batch_time: |
| 1301 | if (match_int(&args[0], &option)) |
| 1302 | return 0; |
| 1303 | if (option < 0) |
| 1304 | return 0; |
| 1305 | if (option == 0) |
| 1306 | option = EXT4_DEF_MAX_BATCH_TIME; |
| 1307 | sbi->s_max_batch_time = option; |
| 1308 | break; |
| 1309 | case Opt_min_batch_time: |
| 1310 | if (match_int(&args[0], &option)) |
| 1311 | return 0; |
| 1312 | if (option < 0) |
| 1313 | return 0; |
| 1314 | sbi->s_min_batch_time = option; |
| 1315 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1316 | case Opt_data_journal: |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1317 | data_opt = EXT4_MOUNT_JOURNAL_DATA; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1318 | goto datacheck; |
| 1319 | case Opt_data_ordered: |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1320 | data_opt = EXT4_MOUNT_ORDERED_DATA; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1321 | goto datacheck; |
| 1322 | case Opt_data_writeback: |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1323 | data_opt = EXT4_MOUNT_WRITEBACK_DATA; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1324 | datacheck: |
| 1325 | if (is_remount) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1326 | if ((sbi->s_mount_opt & EXT4_MOUNT_DATA_FLAGS) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1327 | != data_opt) { |
| 1328 | printk(KERN_ERR |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1329 | "EXT4-fs: cannot change data " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1330 | "mode on remount\n"); |
| 1331 | return 0; |
| 1332 | } |
| 1333 | } else { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1334 | sbi->s_mount_opt &= ~EXT4_MOUNT_DATA_FLAGS; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1335 | sbi->s_mount_opt |= data_opt; |
| 1336 | } |
| 1337 | break; |
Hidehiro Kawai | 5bf5683 | 2008-10-10 22:12:43 -0400 | [diff] [blame] | 1338 | case Opt_data_err_abort: |
| 1339 | set_opt(sbi->s_mount_opt, DATA_ERR_ABORT); |
| 1340 | break; |
| 1341 | case Opt_data_err_ignore: |
| 1342 | clear_opt(sbi->s_mount_opt, DATA_ERR_ABORT); |
| 1343 | break; |
Curt Wohlgemuth | f403390 | 2009-05-01 20:27:20 -0400 | [diff] [blame] | 1344 | case Opt_mb_history_length: |
| 1345 | if (match_int(&args[0], &option)) |
| 1346 | return 0; |
| 1347 | if (option < 0) |
| 1348 | return 0; |
| 1349 | sbi->s_mb_history_max = option; |
| 1350 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1351 | #ifdef CONFIG_QUOTA |
| 1352 | case Opt_usrjquota: |
| 1353 | qtype = USRQUOTA; |
| 1354 | goto set_qf_name; |
| 1355 | case Opt_grpjquota: |
| 1356 | qtype = GRPQUOTA; |
| 1357 | set_qf_name: |
Jan Kara | 17bd13b | 2008-08-20 18:14:35 +0200 | [diff] [blame] | 1358 | if (sb_any_quota_loaded(sb) && |
Jan Kara | dfc5d03 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 1359 | !sbi->s_qf_names[qtype]) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1360 | printk(KERN_ERR |
Theodore Ts'o | 4776004 | 2008-09-08 23:00:52 -0400 | [diff] [blame] | 1361 | "EXT4-fs: Cannot change journaled " |
| 1362 | "quota options when quota turned on.\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1363 | return 0; |
| 1364 | } |
| 1365 | qname = match_strdup(&args[0]); |
| 1366 | if (!qname) { |
| 1367 | printk(KERN_ERR |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1368 | "EXT4-fs: not enough memory for " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1369 | "storing quotafile name.\n"); |
| 1370 | return 0; |
| 1371 | } |
| 1372 | if (sbi->s_qf_names[qtype] && |
| 1373 | strcmp(sbi->s_qf_names[qtype], qname)) { |
| 1374 | printk(KERN_ERR |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1375 | "EXT4-fs: %s quota file already " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1376 | "specified.\n", QTYPE2NAME(qtype)); |
| 1377 | kfree(qname); |
| 1378 | return 0; |
| 1379 | } |
| 1380 | sbi->s_qf_names[qtype] = qname; |
| 1381 | if (strchr(sbi->s_qf_names[qtype], '/')) { |
| 1382 | printk(KERN_ERR |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1383 | "EXT4-fs: quotafile must be on " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1384 | "filesystem root.\n"); |
| 1385 | kfree(sbi->s_qf_names[qtype]); |
| 1386 | sbi->s_qf_names[qtype] = NULL; |
| 1387 | return 0; |
| 1388 | } |
| 1389 | set_opt(sbi->s_mount_opt, QUOTA); |
| 1390 | break; |
| 1391 | case Opt_offusrjquota: |
| 1392 | qtype = USRQUOTA; |
| 1393 | goto clear_qf_name; |
| 1394 | case Opt_offgrpjquota: |
| 1395 | qtype = GRPQUOTA; |
| 1396 | clear_qf_name: |
Jan Kara | 17bd13b | 2008-08-20 18:14:35 +0200 | [diff] [blame] | 1397 | if (sb_any_quota_loaded(sb) && |
Jan Kara | dfc5d03 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 1398 | sbi->s_qf_names[qtype]) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1399 | printk(KERN_ERR "EXT4-fs: Cannot change " |
Jan Kara | 2c8be6b | 2008-05-13 21:27:55 -0400 | [diff] [blame] | 1400 | "journaled quota options when " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1401 | "quota turned on.\n"); |
| 1402 | return 0; |
| 1403 | } |
| 1404 | /* |
| 1405 | * The space will be released later when all options |
| 1406 | * are confirmed to be correct |
| 1407 | */ |
| 1408 | sbi->s_qf_names[qtype] = NULL; |
| 1409 | break; |
| 1410 | case Opt_jqfmt_vfsold: |
Jan Kara | dfc5d03 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 1411 | qfmt = QFMT_VFS_OLD; |
| 1412 | goto set_qf_format; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1413 | case Opt_jqfmt_vfsv0: |
Jan Kara | dfc5d03 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 1414 | qfmt = QFMT_VFS_V0; |
| 1415 | set_qf_format: |
Jan Kara | 17bd13b | 2008-08-20 18:14:35 +0200 | [diff] [blame] | 1416 | if (sb_any_quota_loaded(sb) && |
Jan Kara | dfc5d03 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 1417 | sbi->s_jquota_fmt != qfmt) { |
| 1418 | printk(KERN_ERR "EXT4-fs: Cannot change " |
| 1419 | "journaled quota options when " |
| 1420 | "quota turned on.\n"); |
| 1421 | return 0; |
| 1422 | } |
| 1423 | sbi->s_jquota_fmt = qfmt; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1424 | break; |
| 1425 | case Opt_quota: |
| 1426 | case Opt_usrquota: |
| 1427 | set_opt(sbi->s_mount_opt, QUOTA); |
| 1428 | set_opt(sbi->s_mount_opt, USRQUOTA); |
| 1429 | break; |
| 1430 | case Opt_grpquota: |
| 1431 | set_opt(sbi->s_mount_opt, QUOTA); |
| 1432 | set_opt(sbi->s_mount_opt, GRPQUOTA); |
| 1433 | break; |
| 1434 | case Opt_noquota: |
Jan Kara | 17bd13b | 2008-08-20 18:14:35 +0200 | [diff] [blame] | 1435 | if (sb_any_quota_loaded(sb)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1436 | printk(KERN_ERR "EXT4-fs: Cannot change quota " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1437 | "options when quota turned on.\n"); |
| 1438 | return 0; |
| 1439 | } |
| 1440 | clear_opt(sbi->s_mount_opt, QUOTA); |
| 1441 | clear_opt(sbi->s_mount_opt, USRQUOTA); |
| 1442 | clear_opt(sbi->s_mount_opt, GRPQUOTA); |
| 1443 | break; |
| 1444 | #else |
| 1445 | case Opt_quota: |
| 1446 | case Opt_usrquota: |
| 1447 | case Opt_grpquota: |
Jan Kara | cd59e7b | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 1448 | printk(KERN_ERR |
| 1449 | "EXT4-fs: quota options not supported.\n"); |
| 1450 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1451 | case Opt_usrjquota: |
| 1452 | case Opt_grpjquota: |
| 1453 | case Opt_offusrjquota: |
| 1454 | case Opt_offgrpjquota: |
| 1455 | case Opt_jqfmt_vfsold: |
| 1456 | case Opt_jqfmt_vfsv0: |
| 1457 | printk(KERN_ERR |
Jan Kara | cd59e7b | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 1458 | "EXT4-fs: journaled quota options not " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1459 | "supported.\n"); |
| 1460 | break; |
| 1461 | case Opt_noquota: |
| 1462 | break; |
| 1463 | #endif |
| 1464 | case Opt_abort: |
| 1465 | set_opt(sbi->s_mount_opt, ABORT); |
| 1466 | break; |
Theodore Ts'o | 06705bf | 2009-03-28 10:59:57 -0400 | [diff] [blame] | 1467 | case Opt_nobarrier: |
| 1468 | clear_opt(sbi->s_mount_opt, BARRIER); |
| 1469 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1470 | case Opt_barrier: |
Theodore Ts'o | 06705bf | 2009-03-28 10:59:57 -0400 | [diff] [blame] | 1471 | if (match_int(&args[0], &option)) { |
| 1472 | set_opt(sbi->s_mount_opt, BARRIER); |
| 1473 | break; |
| 1474 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1475 | if (option) |
| 1476 | set_opt(sbi->s_mount_opt, BARRIER); |
| 1477 | else |
| 1478 | clear_opt(sbi->s_mount_opt, BARRIER); |
| 1479 | break; |
| 1480 | case Opt_ignore: |
| 1481 | break; |
| 1482 | case Opt_resize: |
| 1483 | if (!is_remount) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1484 | printk("EXT4-fs: resize option only available " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1485 | "for remount\n"); |
| 1486 | return 0; |
| 1487 | } |
| 1488 | if (match_int(&args[0], &option) != 0) |
| 1489 | return 0; |
| 1490 | *n_blocks_count = option; |
| 1491 | break; |
| 1492 | case Opt_nobh: |
| 1493 | set_opt(sbi->s_mount_opt, NOBH); |
| 1494 | break; |
| 1495 | case Opt_bh: |
| 1496 | clear_opt(sbi->s_mount_opt, NOBH); |
| 1497 | break; |
Jean Noel Cordenner | 25ec56b | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1498 | case Opt_i_version: |
| 1499 | set_opt(sbi->s_mount_opt, I_VERSION); |
| 1500 | sb->s_flags |= MS_I_VERSION; |
| 1501 | break; |
Aneesh Kumar K.V | dd919b9 | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1502 | case Opt_nodelalloc: |
| 1503 | clear_opt(sbi->s_mount_opt, DELALLOC); |
| 1504 | break; |
Alex Tomas | c9de560 | 2008-01-29 00:19:52 -0500 | [diff] [blame] | 1505 | case Opt_stripe: |
| 1506 | if (match_int(&args[0], &option)) |
| 1507 | return 0; |
| 1508 | if (option < 0) |
| 1509 | return 0; |
| 1510 | sbi->s_stripe = option; |
| 1511 | break; |
Alex Tomas | 6476924 | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1512 | case Opt_delalloc: |
| 1513 | set_opt(sbi->s_mount_opt, DELALLOC); |
| 1514 | break; |
Theodore Ts'o | 6fd058f | 2009-05-17 15:38:01 -0400 | [diff] [blame] | 1515 | case Opt_block_validity: |
| 1516 | set_opt(sbi->s_mount_opt, BLOCK_VALIDITY); |
| 1517 | break; |
| 1518 | case Opt_noblock_validity: |
| 1519 | clear_opt(sbi->s_mount_opt, BLOCK_VALIDITY); |
| 1520 | break; |
Theodore Ts'o | 240799c | 2008-10-09 23:53:47 -0400 | [diff] [blame] | 1521 | case Opt_inode_readahead_blks: |
| 1522 | if (match_int(&args[0], &option)) |
| 1523 | return 0; |
| 1524 | if (option < 0 || option > (1 << 30)) |
| 1525 | return 0; |
Theodore Ts'o | f7c4395 | 2009-04-24 23:31:59 -0400 | [diff] [blame] | 1526 | if (!is_power_of_2(option)) { |
Theodore Ts'o | 3197ebd | 2009-03-31 09:10:09 -0400 | [diff] [blame] | 1527 | printk(KERN_ERR "EXT4-fs: inode_readahead_blks" |
| 1528 | " must be a power of 2\n"); |
| 1529 | return 0; |
| 1530 | } |
Theodore Ts'o | 240799c | 2008-10-09 23:53:47 -0400 | [diff] [blame] | 1531 | sbi->s_inode_readahead_blks = option; |
| 1532 | break; |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 1533 | case Opt_journal_ioprio: |
| 1534 | if (match_int(&args[0], &option)) |
| 1535 | return 0; |
| 1536 | if (option < 0 || option > 7) |
| 1537 | break; |
| 1538 | *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, |
| 1539 | option); |
| 1540 | break; |
Theodore Ts'o | 06705bf | 2009-03-28 10:59:57 -0400 | [diff] [blame] | 1541 | case Opt_noauto_da_alloc: |
| 1542 | set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC); |
| 1543 | break; |
Theodore Ts'o | afd4672 | 2009-03-16 23:12:23 -0400 | [diff] [blame] | 1544 | case Opt_auto_da_alloc: |
Theodore Ts'o | 06705bf | 2009-03-28 10:59:57 -0400 | [diff] [blame] | 1545 | if (match_int(&args[0], &option)) { |
| 1546 | clear_opt(sbi->s_mount_opt, NO_AUTO_DA_ALLOC); |
| 1547 | break; |
| 1548 | } |
Theodore Ts'o | afd4672 | 2009-03-16 23:12:23 -0400 | [diff] [blame] | 1549 | if (option) |
| 1550 | clear_opt(sbi->s_mount_opt, NO_AUTO_DA_ALLOC); |
| 1551 | else |
| 1552 | set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC); |
| 1553 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1554 | default: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1555 | printk(KERN_ERR |
| 1556 | "EXT4-fs: Unrecognized mount option \"%s\" " |
| 1557 | "or missing value\n", p); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1558 | return 0; |
| 1559 | } |
| 1560 | } |
| 1561 | #ifdef CONFIG_QUOTA |
| 1562 | if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1563 | if ((sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA) && |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1564 | sbi->s_qf_names[USRQUOTA]) |
| 1565 | clear_opt(sbi->s_mount_opt, USRQUOTA); |
| 1566 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1567 | if ((sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA) && |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1568 | sbi->s_qf_names[GRPQUOTA]) |
| 1569 | clear_opt(sbi->s_mount_opt, GRPQUOTA); |
| 1570 | |
| 1571 | if ((sbi->s_qf_names[USRQUOTA] && |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1572 | (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)) || |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1573 | (sbi->s_qf_names[GRPQUOTA] && |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1574 | (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA))) { |
| 1575 | printk(KERN_ERR "EXT4-fs: old and new quota " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1576 | "format mixing.\n"); |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
| 1580 | if (!sbi->s_jquota_fmt) { |
Jan Kara | 2c8be6b | 2008-05-13 21:27:55 -0400 | [diff] [blame] | 1581 | printk(KERN_ERR "EXT4-fs: journaled quota format " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1582 | "not specified.\n"); |
| 1583 | return 0; |
| 1584 | } |
| 1585 | } else { |
| 1586 | if (sbi->s_jquota_fmt) { |
Jan Kara | 2c8be6b | 2008-05-13 21:27:55 -0400 | [diff] [blame] | 1587 | printk(KERN_ERR "EXT4-fs: journaled quota format " |
| 1588 | "specified with no journaling " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1589 | "enabled.\n"); |
| 1590 | return 0; |
| 1591 | } |
| 1592 | } |
| 1593 | #endif |
| 1594 | return 1; |
| 1595 | } |
| 1596 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1597 | static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1598 | int read_only) |
| 1599 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1600 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1601 | int res = 0; |
| 1602 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1603 | if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1604 | printk(KERN_ERR "EXT4-fs warning: revision level too high, " |
| 1605 | "forcing read-only mode\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1606 | res = MS_RDONLY; |
| 1607 | } |
| 1608 | if (read_only) |
| 1609 | return res; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1610 | if (!(sbi->s_mount_state & EXT4_VALID_FS)) |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1611 | printk(KERN_WARNING "EXT4-fs warning: mounting unchecked fs, " |
| 1612 | "running e2fsck is recommended\n"); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1613 | else if ((sbi->s_mount_state & EXT4_ERROR_FS)) |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1614 | printk(KERN_WARNING |
| 1615 | "EXT4-fs warning: mounting fs with errors, " |
| 1616 | "running e2fsck is recommended\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1617 | else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 && |
| 1618 | le16_to_cpu(es->s_mnt_count) >= |
| 1619 | (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count)) |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1620 | printk(KERN_WARNING |
| 1621 | "EXT4-fs warning: maximal mount count reached, " |
| 1622 | "running e2fsck is recommended\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1623 | else if (le32_to_cpu(es->s_checkinterval) && |
| 1624 | (le32_to_cpu(es->s_lastcheck) + |
| 1625 | le32_to_cpu(es->s_checkinterval) <= get_seconds())) |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1626 | printk(KERN_WARNING |
| 1627 | "EXT4-fs warning: checktime reached, " |
| 1628 | "running e2fsck is recommended\n"); |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 1629 | if (!sbi->s_journal) |
| 1630 | es->s_state &= cpu_to_le16(~EXT4_VALID_FS); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1631 | if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1632 | es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); |
Marcin Slusarz | e8546d0 | 2008-04-17 10:38:59 -0400 | [diff] [blame] | 1633 | le16_add_cpu(&es->s_mnt_count, 1); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1634 | es->s_mtime = cpu_to_le32(get_seconds()); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1635 | ext4_update_dynamic_rev(sb); |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 1636 | if (sbi->s_journal) |
| 1637 | EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1638 | |
Theodore Ts'o | e2d6705 | 2009-05-01 00:33:44 -0400 | [diff] [blame] | 1639 | ext4_commit_super(sb, 1); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1640 | if (test_opt(sb, DEBUG)) |
Theodore Ts'o | a9df9a4 | 2009-01-05 22:18:16 -0500 | [diff] [blame] | 1641 | printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1642 | "bpg=%lu, ipg=%lu, mo=%04lx]\n", |
| 1643 | sb->s_blocksize, |
| 1644 | sbi->s_groups_count, |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1645 | EXT4_BLOCKS_PER_GROUP(sb), |
| 1646 | EXT4_INODES_PER_GROUP(sb), |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1647 | sbi->s_mount_opt); |
| 1648 | |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 1649 | if (EXT4_SB(sb)->s_journal) { |
| 1650 | printk(KERN_INFO "EXT4 FS on %s, %s journal on %s\n", |
| 1651 | sb->s_id, EXT4_SB(sb)->s_journal->j_inode ? "internal" : |
| 1652 | "external", EXT4_SB(sb)->s_journal->j_devname); |
| 1653 | } else { |
| 1654 | printk(KERN_INFO "EXT4 FS on %s, no journal\n", sb->s_id); |
| 1655 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1656 | return res; |
| 1657 | } |
| 1658 | |
Jose R. Santos | 772cb7c | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1659 | static int ext4_fill_flex_info(struct super_block *sb) |
| 1660 | { |
| 1661 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
| 1662 | struct ext4_group_desc *gdp = NULL; |
Jose R. Santos | 772cb7c | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1663 | ext4_group_t flex_group_count; |
| 1664 | ext4_group_t flex_group; |
| 1665 | int groups_per_flex = 0; |
Theodore Ts'o | c5ca7c7 | 2009-04-27 22:48:48 -0400 | [diff] [blame] | 1666 | size_t size; |
Jose R. Santos | 772cb7c | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1667 | int i; |
| 1668 | |
| 1669 | if (!sbi->s_es->s_log_groups_per_flex) { |
| 1670 | sbi->s_log_groups_per_flex = 0; |
| 1671 | return 1; |
| 1672 | } |
| 1673 | |
| 1674 | sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex; |
| 1675 | groups_per_flex = 1 << sbi->s_log_groups_per_flex; |
| 1676 | |
Frederic Bohe | c62a11f | 2008-09-08 10:20:24 -0400 | [diff] [blame] | 1677 | /* We allocate both existing and potentially added groups */ |
| 1678 | flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) + |
Aneesh Kumar K.V | d94e99a | 2008-11-04 09:11:26 -0500 | [diff] [blame] | 1679 | ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) << |
| 1680 | EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex; |
Theodore Ts'o | c5ca7c7 | 2009-04-27 22:48:48 -0400 | [diff] [blame] | 1681 | size = flex_group_count * sizeof(struct flex_groups); |
| 1682 | sbi->s_flex_groups = kzalloc(size, GFP_KERNEL); |
| 1683 | if (sbi->s_flex_groups == NULL) { |
| 1684 | sbi->s_flex_groups = vmalloc(size); |
| 1685 | if (sbi->s_flex_groups) |
| 1686 | memset(sbi->s_flex_groups, 0, size); |
| 1687 | } |
Jose R. Santos | 772cb7c | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1688 | if (sbi->s_flex_groups == NULL) { |
Li Zefan | ec05e86 | 2008-07-24 12:49:59 -0400 | [diff] [blame] | 1689 | printk(KERN_ERR "EXT4-fs: not enough memory for " |
Theodore Ts'o | a9df9a4 | 2009-01-05 22:18:16 -0500 | [diff] [blame] | 1690 | "%u flex groups\n", flex_group_count); |
Jose R. Santos | 772cb7c | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1691 | goto failed; |
| 1692 | } |
Jose R. Santos | 772cb7c | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1693 | |
Jose R. Santos | 772cb7c | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1694 | for (i = 0; i < sbi->s_groups_count; i++) { |
Theodore Ts'o | 88b6edd | 2009-05-25 11:50:39 -0400 | [diff] [blame^] | 1695 | gdp = ext4_get_group_desc(sb, i, NULL); |
Jose R. Santos | 772cb7c | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1696 | |
| 1697 | flex_group = ext4_flex_group(sbi, i); |
Theodore Ts'o | 9f24e42 | 2009-03-04 19:09:10 -0500 | [diff] [blame] | 1698 | atomic_set(&sbi->s_flex_groups[flex_group].free_inodes, |
| 1699 | ext4_free_inodes_count(sb, gdp)); |
| 1700 | atomic_set(&sbi->s_flex_groups[flex_group].free_blocks, |
| 1701 | ext4_free_blks_count(sb, gdp)); |
Theodore Ts'o | 7d39db1 | 2009-03-04 19:31:53 -0500 | [diff] [blame] | 1702 | atomic_set(&sbi->s_flex_groups[flex_group].used_dirs, |
| 1703 | ext4_used_dirs_count(sb, gdp)); |
Jose R. Santos | 772cb7c | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | return 1; |
| 1707 | failed: |
| 1708 | return 0; |
| 1709 | } |
| 1710 | |
Andreas Dilger | 717d50e | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 1711 | __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group, |
| 1712 | struct ext4_group_desc *gdp) |
| 1713 | { |
| 1714 | __u16 crc = 0; |
| 1715 | |
| 1716 | if (sbi->s_es->s_feature_ro_compat & |
| 1717 | cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { |
| 1718 | int offset = offsetof(struct ext4_group_desc, bg_checksum); |
| 1719 | __le32 le_group = cpu_to_le32(block_group); |
| 1720 | |
| 1721 | crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid)); |
| 1722 | crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group)); |
| 1723 | crc = crc16(crc, (__u8 *)gdp, offset); |
| 1724 | offset += sizeof(gdp->bg_checksum); /* skip checksum */ |
| 1725 | /* for checksum of struct ext4_group_desc do the rest...*/ |
| 1726 | if ((sbi->s_es->s_feature_incompat & |
| 1727 | cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) && |
| 1728 | offset < le16_to_cpu(sbi->s_es->s_desc_size)) |
| 1729 | crc = crc16(crc, (__u8 *)gdp + offset, |
| 1730 | le16_to_cpu(sbi->s_es->s_desc_size) - |
| 1731 | offset); |
| 1732 | } |
| 1733 | |
| 1734 | return cpu_to_le16(crc); |
| 1735 | } |
| 1736 | |
| 1737 | int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group, |
| 1738 | struct ext4_group_desc *gdp) |
| 1739 | { |
| 1740 | if ((sbi->s_es->s_feature_ro_compat & |
| 1741 | cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) && |
| 1742 | (gdp->bg_checksum != ext4_group_desc_csum(sbi, block_group, gdp))) |
| 1743 | return 0; |
| 1744 | |
| 1745 | return 1; |
| 1746 | } |
| 1747 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1748 | /* Called at mount-time, super-block is locked */ |
Akinobu Mita | 197cd65a | 2008-02-06 01:40:16 -0800 | [diff] [blame] | 1749 | static int ext4_check_descriptors(struct super_block *sb) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1750 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1751 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
| 1752 | ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block); |
| 1753 | ext4_fsblk_t last_block; |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 1754 | ext4_fsblk_t block_bitmap; |
| 1755 | ext4_fsblk_t inode_bitmap; |
| 1756 | ext4_fsblk_t inode_table; |
Jose R. Santos | ce42158 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 1757 | int flexbg_flag = 0; |
Avantika Mathur | fd2d429 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1758 | ext4_group_t i; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1759 | |
Jose R. Santos | ce42158 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 1760 | if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) |
| 1761 | flexbg_flag = 1; |
| 1762 | |
Theodore Ts'o | af5bc92 | 2008-09-08 22:25:24 -0400 | [diff] [blame] | 1763 | ext4_debug("Checking group descriptors"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1764 | |
Akinobu Mita | 197cd65a | 2008-02-06 01:40:16 -0800 | [diff] [blame] | 1765 | for (i = 0; i < sbi->s_groups_count; i++) { |
| 1766 | struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL); |
| 1767 | |
Jose R. Santos | ce42158 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 1768 | if (i == sbi->s_groups_count - 1 || flexbg_flag) |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 1769 | last_block = ext4_blocks_count(sbi->s_es) - 1; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1770 | else |
| 1771 | last_block = first_block + |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1772 | (EXT4_BLOCKS_PER_GROUP(sb) - 1); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1773 | |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 1774 | block_bitmap = ext4_block_bitmap(sb, gdp); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1775 | if (block_bitmap < first_block || block_bitmap > last_block) { |
Josef Bacik | c19204b | 2008-04-29 22:00:28 -0400 | [diff] [blame] | 1776 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " |
Theodore Ts'o | a9df9a4 | 2009-01-05 22:18:16 -0500 | [diff] [blame] | 1777 | "Block bitmap for group %u not in group " |
Eric Sesterhenn | 5128273 | 2008-10-17 09:16:19 -0400 | [diff] [blame] | 1778 | "(block %llu)!\n", i, block_bitmap); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1779 | return 0; |
| 1780 | } |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 1781 | inode_bitmap = ext4_inode_bitmap(sb, gdp); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1782 | if (inode_bitmap < first_block || inode_bitmap > last_block) { |
Josef Bacik | c19204b | 2008-04-29 22:00:28 -0400 | [diff] [blame] | 1783 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " |
Theodore Ts'o | a9df9a4 | 2009-01-05 22:18:16 -0500 | [diff] [blame] | 1784 | "Inode bitmap for group %u not in group " |
Eric Sesterhenn | 5128273 | 2008-10-17 09:16:19 -0400 | [diff] [blame] | 1785 | "(block %llu)!\n", i, inode_bitmap); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1786 | return 0; |
| 1787 | } |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 1788 | inode_table = ext4_inode_table(sb, gdp); |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 1789 | if (inode_table < first_block || |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1790 | inode_table + sbi->s_itb_per_group - 1 > last_block) { |
Josef Bacik | c19204b | 2008-04-29 22:00:28 -0400 | [diff] [blame] | 1791 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " |
Theodore Ts'o | a9df9a4 | 2009-01-05 22:18:16 -0500 | [diff] [blame] | 1792 | "Inode table for group %u not in group " |
Eric Sesterhenn | 5128273 | 2008-10-17 09:16:19 -0400 | [diff] [blame] | 1793 | "(block %llu)!\n", i, inode_table); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1794 | return 0; |
| 1795 | } |
Aneesh Kumar K.V | 955ce5f | 2009-05-02 20:35:09 -0400 | [diff] [blame] | 1796 | ext4_lock_group(sb, i); |
Andreas Dilger | 717d50e | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 1797 | if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { |
Josef Bacik | c19204b | 2008-04-29 22:00:28 -0400 | [diff] [blame] | 1798 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " |
Theodore Ts'o | a9df9a4 | 2009-01-05 22:18:16 -0500 | [diff] [blame] | 1799 | "Checksum for group %u failed (%u!=%u)\n", |
Josef Bacik | c19204b | 2008-04-29 22:00:28 -0400 | [diff] [blame] | 1800 | i, le16_to_cpu(ext4_group_desc_csum(sbi, i, |
| 1801 | gdp)), le16_to_cpu(gdp->bg_checksum)); |
Li Zefan | 7ee1ec4 | 2008-09-08 10:47:19 -0400 | [diff] [blame] | 1802 | if (!(sb->s_flags & MS_RDONLY)) { |
Aneesh Kumar K.V | 955ce5f | 2009-05-02 20:35:09 -0400 | [diff] [blame] | 1803 | ext4_unlock_group(sb, i); |
Theodore Ts'o | 8a26646 | 2008-07-26 14:34:21 -0400 | [diff] [blame] | 1804 | return 0; |
Li Zefan | 7ee1ec4 | 2008-09-08 10:47:19 -0400 | [diff] [blame] | 1805 | } |
Andreas Dilger | 717d50e | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 1806 | } |
Aneesh Kumar K.V | 955ce5f | 2009-05-02 20:35:09 -0400 | [diff] [blame] | 1807 | ext4_unlock_group(sb, i); |
Jose R. Santos | ce42158 | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 1808 | if (!flexbg_flag) |
| 1809 | first_block += EXT4_BLOCKS_PER_GROUP(sb); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 1812 | ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb)); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1813 | sbi->s_es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1814 | return 1; |
| 1815 | } |
| 1816 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1817 | /* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1818 | * the superblock) which were deleted from all directories, but held open by |
| 1819 | * a process at the time of a crash. We walk the list and try to delete these |
| 1820 | * inodes at recovery time (only with a read-write filesystem). |
| 1821 | * |
| 1822 | * In order to keep the orphan inode chain consistent during traversal (in |
| 1823 | * case of crash during recovery), we link each inode into the superblock |
| 1824 | * orphan list_head and handle it the same way as an inode deletion during |
| 1825 | * normal operation (which journals the operations for us). |
| 1826 | * |
| 1827 | * We only do an iget() and an iput() on each inode, which is very safe if we |
| 1828 | * accidentally point at an in-use or already deleted inode. The worst that |
| 1829 | * can happen in this case is that we get a "bit already cleared" message from |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1830 | * ext4_free_inode(). The only reason we would point at a wrong inode is if |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1831 | * e2fsck was run on this filesystem, and it must have already done the orphan |
| 1832 | * inode cleanup for us, so we can safely abort without any further action. |
| 1833 | */ |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1834 | static void ext4_orphan_cleanup(struct super_block *sb, |
| 1835 | struct ext4_super_block *es) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1836 | { |
| 1837 | unsigned int s_flags = sb->s_flags; |
| 1838 | int nr_orphans = 0, nr_truncates = 0; |
| 1839 | #ifdef CONFIG_QUOTA |
| 1840 | int i; |
| 1841 | #endif |
| 1842 | if (!es->s_last_orphan) { |
| 1843 | jbd_debug(4, "no orphan inodes to clean up\n"); |
| 1844 | return; |
| 1845 | } |
| 1846 | |
Eric Sandeen | a8f48a9 | 2006-12-06 20:40:13 -0800 | [diff] [blame] | 1847 | if (bdev_read_only(sb->s_bdev)) { |
| 1848 | printk(KERN_ERR "EXT4-fs: write access " |
| 1849 | "unavailable, skipping orphan cleanup.\n"); |
| 1850 | return; |
| 1851 | } |
| 1852 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1853 | if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1854 | if (es->s_last_orphan) |
| 1855 | jbd_debug(1, "Errors on filesystem, " |
| 1856 | "clearing orphan list.\n"); |
| 1857 | es->s_last_orphan = 0; |
| 1858 | jbd_debug(1, "Skipping orphan recovery on fs with errors.\n"); |
| 1859 | return; |
| 1860 | } |
| 1861 | |
| 1862 | if (s_flags & MS_RDONLY) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1863 | printk(KERN_INFO "EXT4-fs: %s: orphan cleanup on readonly fs\n", |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1864 | sb->s_id); |
| 1865 | sb->s_flags &= ~MS_RDONLY; |
| 1866 | } |
| 1867 | #ifdef CONFIG_QUOTA |
| 1868 | /* Needed for iput() to work correctly and not trash data */ |
| 1869 | sb->s_flags |= MS_ACTIVE; |
| 1870 | /* Turn on quotas so that they are updated correctly */ |
| 1871 | for (i = 0; i < MAXQUOTAS; i++) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1872 | if (EXT4_SB(sb)->s_qf_names[i]) { |
| 1873 | int ret = ext4_quota_on_mount(sb, i); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1874 | if (ret < 0) |
| 1875 | printk(KERN_ERR |
Jan Kara | 2c8be6b | 2008-05-13 21:27:55 -0400 | [diff] [blame] | 1876 | "EXT4-fs: Cannot turn on journaled " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1877 | "quota: error %d\n", ret); |
| 1878 | } |
| 1879 | } |
| 1880 | #endif |
| 1881 | |
| 1882 | while (es->s_last_orphan) { |
| 1883 | struct inode *inode; |
| 1884 | |
Josef Bacik | 97bd42b | 2008-04-29 22:04:56 -0400 | [diff] [blame] | 1885 | inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan)); |
| 1886 | if (IS_ERR(inode)) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1887 | es->s_last_orphan = 0; |
| 1888 | break; |
| 1889 | } |
| 1890 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1891 | list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan); |
Jan Kara | a269eb1 | 2009-01-26 17:04:39 +0100 | [diff] [blame] | 1892 | vfs_dq_init(inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1893 | if (inode->i_nlink) { |
| 1894 | printk(KERN_DEBUG |
Theodore Ts'o | e5f8eab | 2008-09-08 22:25:04 -0400 | [diff] [blame] | 1895 | "%s: truncating inode %lu to %lld bytes\n", |
Harvey Harrison | 46e665e | 2008-04-17 10:38:59 -0400 | [diff] [blame] | 1896 | __func__, inode->i_ino, inode->i_size); |
Theodore Ts'o | e5f8eab | 2008-09-08 22:25:04 -0400 | [diff] [blame] | 1897 | jbd_debug(2, "truncating inode %lu to %lld bytes\n", |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1898 | inode->i_ino, inode->i_size); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1899 | ext4_truncate(inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1900 | nr_truncates++; |
| 1901 | } else { |
| 1902 | printk(KERN_DEBUG |
| 1903 | "%s: deleting unreferenced inode %lu\n", |
Harvey Harrison | 46e665e | 2008-04-17 10:38:59 -0400 | [diff] [blame] | 1904 | __func__, inode->i_ino); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1905 | jbd_debug(2, "deleting unreferenced inode %lu\n", |
| 1906 | inode->i_ino); |
| 1907 | nr_orphans++; |
| 1908 | } |
| 1909 | iput(inode); /* The delete magic happens here! */ |
| 1910 | } |
| 1911 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 1912 | #define PLURAL(x) (x), ((x) == 1) ? "" : "s" |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1913 | |
| 1914 | if (nr_orphans) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1915 | printk(KERN_INFO "EXT4-fs: %s: %d orphan inode%s deleted\n", |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1916 | sb->s_id, PLURAL(nr_orphans)); |
| 1917 | if (nr_truncates) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1918 | printk(KERN_INFO "EXT4-fs: %s: %d truncate%s cleaned up\n", |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1919 | sb->s_id, PLURAL(nr_truncates)); |
| 1920 | #ifdef CONFIG_QUOTA |
| 1921 | /* Turn quotas off */ |
| 1922 | for (i = 0; i < MAXQUOTAS; i++) { |
| 1923 | if (sb_dqopt(sb)->files[i]) |
Jan Kara | 6f28e08 | 2008-04-28 02:14:34 -0700 | [diff] [blame] | 1924 | vfs_quota_off(sb, i, 0); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1925 | } |
| 1926 | #endif |
| 1927 | sb->s_flags = s_flags; /* Restore MS_RDONLY status */ |
| 1928 | } |
Eric Sandeen | cd2291a | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1929 | /* |
| 1930 | * Maximal extent format file size. |
| 1931 | * Resulting logical blkno at s_maxbytes must fit in our on-disk |
| 1932 | * extent format containers, within a sector_t, and within i_blocks |
| 1933 | * in the vfs. ext4 inode has 48 bits of i_block in fsblock units, |
| 1934 | * so that won't be a limiting factor. |
| 1935 | * |
| 1936 | * Note, this does *not* consider any metadata overhead for vfs i_blocks. |
| 1937 | */ |
Theodore Ts'o | f287a1a | 2008-10-16 22:50:48 -0400 | [diff] [blame] | 1938 | static loff_t ext4_max_size(int blkbits, int has_huge_files) |
Eric Sandeen | cd2291a | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1939 | { |
| 1940 | loff_t res; |
| 1941 | loff_t upper_limit = MAX_LFS_FILESIZE; |
| 1942 | |
| 1943 | /* small i_blocks in vfs inode? */ |
Theodore Ts'o | f287a1a | 2008-10-16 22:50:48 -0400 | [diff] [blame] | 1944 | if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) { |
Eric Sandeen | cd2291a | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1945 | /* |
Jens Axboe | b3a6ffe | 2008-12-12 09:51:16 +0100 | [diff] [blame] | 1946 | * CONFIG_LBD is not enabled implies the inode |
Eric Sandeen | cd2291a | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1947 | * i_block represent total blocks in 512 bytes |
| 1948 | * 32 == size of vfs inode i_blocks * 8 |
| 1949 | */ |
| 1950 | upper_limit = (1LL << 32) - 1; |
| 1951 | |
| 1952 | /* total blocks in file system block size */ |
| 1953 | upper_limit >>= (blkbits - 9); |
| 1954 | upper_limit <<= blkbits; |
| 1955 | } |
| 1956 | |
| 1957 | /* 32-bit extent-start container, ee_block */ |
| 1958 | res = 1LL << 32; |
| 1959 | res <<= blkbits; |
| 1960 | res -= 1; |
| 1961 | |
| 1962 | /* Sanity check against vm- & vfs- imposed limits */ |
| 1963 | if (res > upper_limit) |
| 1964 | res = upper_limit; |
| 1965 | |
| 1966 | return res; |
| 1967 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1968 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1969 | /* |
Eric Sandeen | cd2291a | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1970 | * Maximal bitmap file size. There is a direct, and {,double-,triple-}indirect |
Aneesh Kumar K.V | 0fc1b45 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 1971 | * block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks. |
| 1972 | * We need to be 1 filesystem block less than the 2^48 sector limit. |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1973 | */ |
Theodore Ts'o | f287a1a | 2008-10-16 22:50:48 -0400 | [diff] [blame] | 1974 | static loff_t ext4_max_bitmap_size(int bits, int has_huge_files) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1975 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 1976 | loff_t res = EXT4_NDIR_BLOCKS; |
Aneesh Kumar K.V | 0fc1b45 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 1977 | int meta_blocks; |
| 1978 | loff_t upper_limit; |
| 1979 | /* This is calculated to be the largest file size for a |
Eric Sandeen | cd2291a | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1980 | * dense, bitmapped file such that the total number of |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1981 | * sectors in the file, including data and all indirect blocks, |
Aneesh Kumar K.V | 0fc1b45 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 1982 | * does not exceed 2^48 -1 |
| 1983 | * __u32 i_blocks_lo and _u16 i_blocks_high representing the |
| 1984 | * total number of 512 bytes blocks of the file |
| 1985 | */ |
| 1986 | |
Theodore Ts'o | f287a1a | 2008-10-16 22:50:48 -0400 | [diff] [blame] | 1987 | if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) { |
Aneesh Kumar K.V | 0fc1b45 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 1988 | /* |
Jens Axboe | b3a6ffe | 2008-12-12 09:51:16 +0100 | [diff] [blame] | 1989 | * !has_huge_files or CONFIG_LBD is not enabled |
Theodore Ts'o | f287a1a | 2008-10-16 22:50:48 -0400 | [diff] [blame] | 1990 | * implies the inode i_block represent total blocks in |
| 1991 | * 512 bytes 32 == size of vfs inode i_blocks * 8 |
Aneesh Kumar K.V | 0fc1b45 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 1992 | */ |
| 1993 | upper_limit = (1LL << 32) - 1; |
| 1994 | |
| 1995 | /* total blocks in file system block size */ |
| 1996 | upper_limit >>= (bits - 9); |
| 1997 | |
| 1998 | } else { |
Aneesh Kumar K.V | 8180a56 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 1999 | /* |
| 2000 | * We use 48 bit ext4_inode i_blocks |
| 2001 | * With EXT4_HUGE_FILE_FL set the i_blocks |
| 2002 | * represent total number of blocks in |
| 2003 | * file system block size |
| 2004 | */ |
Aneesh Kumar K.V | 0fc1b45 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 2005 | upper_limit = (1LL << 48) - 1; |
| 2006 | |
Aneesh Kumar K.V | 0fc1b45 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | /* indirect blocks */ |
| 2010 | meta_blocks = 1; |
| 2011 | /* double indirect blocks */ |
| 2012 | meta_blocks += 1 + (1LL << (bits-2)); |
| 2013 | /* tripple indirect blocks */ |
| 2014 | meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2))); |
| 2015 | |
| 2016 | upper_limit -= meta_blocks; |
| 2017 | upper_limit <<= bits; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2018 | |
| 2019 | res += 1LL << (bits-2); |
| 2020 | res += 1LL << (2*(bits-2)); |
| 2021 | res += 1LL << (3*(bits-2)); |
| 2022 | res <<= bits; |
| 2023 | if (res > upper_limit) |
| 2024 | res = upper_limit; |
Aneesh Kumar K.V | 0fc1b45 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 2025 | |
| 2026 | if (res > MAX_LFS_FILESIZE) |
| 2027 | res = MAX_LFS_FILESIZE; |
| 2028 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2029 | return res; |
| 2030 | } |
| 2031 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2032 | static ext4_fsblk_t descriptor_loc(struct super_block *sb, |
Andrew Morton | 70bbb3e | 2006-10-11 01:21:20 -0700 | [diff] [blame] | 2033 | ext4_fsblk_t logical_sb_block, int nr) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2034 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2035 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
Avantika Mathur | fd2d429 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 2036 | ext4_group_t bg, first_meta_bg; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2037 | int has_super = 0; |
| 2038 | |
| 2039 | first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg); |
| 2040 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2041 | if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) || |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2042 | nr < first_meta_bg) |
Andrew Morton | 70bbb3e | 2006-10-11 01:21:20 -0700 | [diff] [blame] | 2043 | return logical_sb_block + nr + 1; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2044 | bg = sbi->s_desc_per_block * nr; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2045 | if (ext4_bg_has_super(sb, bg)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2046 | has_super = 1; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2047 | return (has_super + ext4_group_first_block_no(sb, bg)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
Alex Tomas | c9de560 | 2008-01-29 00:19:52 -0500 | [diff] [blame] | 2050 | /** |
| 2051 | * ext4_get_stripe_size: Get the stripe size. |
| 2052 | * @sbi: In memory super block info |
| 2053 | * |
| 2054 | * If we have specified it via mount option, then |
| 2055 | * use the mount option value. If the value specified at mount time is |
| 2056 | * greater than the blocks per group use the super block value. |
| 2057 | * If the super block value is greater than blocks per group return 0. |
| 2058 | * Allocator needs it be less than blocks per group. |
| 2059 | * |
| 2060 | */ |
| 2061 | static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi) |
| 2062 | { |
| 2063 | unsigned long stride = le16_to_cpu(sbi->s_es->s_raid_stride); |
| 2064 | unsigned long stripe_width = |
| 2065 | le32_to_cpu(sbi->s_es->s_raid_stripe_width); |
| 2066 | |
| 2067 | if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group) |
| 2068 | return sbi->s_stripe; |
| 2069 | |
| 2070 | if (stripe_width <= sbi->s_blocks_per_group) |
| 2071 | return stripe_width; |
| 2072 | |
| 2073 | if (stride <= sbi->s_blocks_per_group) |
| 2074 | return stride; |
| 2075 | |
| 2076 | return 0; |
| 2077 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2078 | |
Theodore Ts'o | 3197ebd | 2009-03-31 09:10:09 -0400 | [diff] [blame] | 2079 | /* sysfs supprt */ |
| 2080 | |
| 2081 | struct ext4_attr { |
| 2082 | struct attribute attr; |
| 2083 | ssize_t (*show)(struct ext4_attr *, struct ext4_sb_info *, char *); |
| 2084 | ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *, |
| 2085 | const char *, size_t); |
| 2086 | int offset; |
| 2087 | }; |
| 2088 | |
| 2089 | static int parse_strtoul(const char *buf, |
| 2090 | unsigned long max, unsigned long *value) |
| 2091 | { |
| 2092 | char *endp; |
| 2093 | |
| 2094 | while (*buf && isspace(*buf)) |
| 2095 | buf++; |
| 2096 | *value = simple_strtoul(buf, &endp, 0); |
| 2097 | while (*endp && isspace(*endp)) |
| 2098 | endp++; |
| 2099 | if (*endp || *value > max) |
| 2100 | return -EINVAL; |
| 2101 | |
| 2102 | return 0; |
| 2103 | } |
| 2104 | |
| 2105 | static ssize_t delayed_allocation_blocks_show(struct ext4_attr *a, |
| 2106 | struct ext4_sb_info *sbi, |
| 2107 | char *buf) |
| 2108 | { |
| 2109 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
| 2110 | (s64) percpu_counter_sum(&sbi->s_dirtyblocks_counter)); |
| 2111 | } |
| 2112 | |
| 2113 | static ssize_t session_write_kbytes_show(struct ext4_attr *a, |
| 2114 | struct ext4_sb_info *sbi, char *buf) |
| 2115 | { |
| 2116 | struct super_block *sb = sbi->s_buddy_cache->i_sb; |
| 2117 | |
| 2118 | return snprintf(buf, PAGE_SIZE, "%lu\n", |
| 2119 | (part_stat_read(sb->s_bdev->bd_part, sectors[1]) - |
| 2120 | sbi->s_sectors_written_start) >> 1); |
| 2121 | } |
| 2122 | |
| 2123 | static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a, |
| 2124 | struct ext4_sb_info *sbi, char *buf) |
| 2125 | { |
| 2126 | struct super_block *sb = sbi->s_buddy_cache->i_sb; |
| 2127 | |
| 2128 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
| 2129 | sbi->s_kbytes_written + |
| 2130 | ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - |
| 2131 | EXT4_SB(sb)->s_sectors_written_start) >> 1)); |
| 2132 | } |
| 2133 | |
| 2134 | static ssize_t inode_readahead_blks_store(struct ext4_attr *a, |
| 2135 | struct ext4_sb_info *sbi, |
| 2136 | const char *buf, size_t count) |
| 2137 | { |
| 2138 | unsigned long t; |
| 2139 | |
| 2140 | if (parse_strtoul(buf, 0x40000000, &t)) |
| 2141 | return -EINVAL; |
| 2142 | |
Theodore Ts'o | f7c4395 | 2009-04-24 23:31:59 -0400 | [diff] [blame] | 2143 | if (!is_power_of_2(t)) |
Theodore Ts'o | 3197ebd | 2009-03-31 09:10:09 -0400 | [diff] [blame] | 2144 | return -EINVAL; |
| 2145 | |
| 2146 | sbi->s_inode_readahead_blks = t; |
| 2147 | return count; |
| 2148 | } |
| 2149 | |
| 2150 | static ssize_t sbi_ui_show(struct ext4_attr *a, |
| 2151 | struct ext4_sb_info *sbi, char *buf) |
| 2152 | { |
| 2153 | unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset); |
| 2154 | |
| 2155 | return snprintf(buf, PAGE_SIZE, "%u\n", *ui); |
| 2156 | } |
| 2157 | |
| 2158 | static ssize_t sbi_ui_store(struct ext4_attr *a, |
| 2159 | struct ext4_sb_info *sbi, |
| 2160 | const char *buf, size_t count) |
| 2161 | { |
| 2162 | unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset); |
| 2163 | unsigned long t; |
| 2164 | |
| 2165 | if (parse_strtoul(buf, 0xffffffff, &t)) |
| 2166 | return -EINVAL; |
| 2167 | *ui = t; |
| 2168 | return count; |
| 2169 | } |
| 2170 | |
| 2171 | #define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \ |
| 2172 | static struct ext4_attr ext4_attr_##_name = { \ |
| 2173 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 2174 | .show = _show, \ |
| 2175 | .store = _store, \ |
| 2176 | .offset = offsetof(struct ext4_sb_info, _elname), \ |
| 2177 | } |
| 2178 | #define EXT4_ATTR(name, mode, show, store) \ |
| 2179 | static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store) |
| 2180 | |
| 2181 | #define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL) |
| 2182 | #define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store) |
| 2183 | #define EXT4_RW_ATTR_SBI_UI(name, elname) \ |
| 2184 | EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname) |
| 2185 | #define ATTR_LIST(name) &ext4_attr_##name.attr |
| 2186 | |
| 2187 | EXT4_RO_ATTR(delayed_allocation_blocks); |
| 2188 | EXT4_RO_ATTR(session_write_kbytes); |
| 2189 | EXT4_RO_ATTR(lifetime_write_kbytes); |
| 2190 | EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show, |
| 2191 | inode_readahead_blks_store, s_inode_readahead_blks); |
| 2192 | EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats); |
| 2193 | EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan); |
| 2194 | EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan); |
| 2195 | EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs); |
| 2196 | EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request); |
| 2197 | EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc); |
| 2198 | |
| 2199 | static struct attribute *ext4_attrs[] = { |
| 2200 | ATTR_LIST(delayed_allocation_blocks), |
| 2201 | ATTR_LIST(session_write_kbytes), |
| 2202 | ATTR_LIST(lifetime_write_kbytes), |
| 2203 | ATTR_LIST(inode_readahead_blks), |
| 2204 | ATTR_LIST(mb_stats), |
| 2205 | ATTR_LIST(mb_max_to_scan), |
| 2206 | ATTR_LIST(mb_min_to_scan), |
| 2207 | ATTR_LIST(mb_order2_req), |
| 2208 | ATTR_LIST(mb_stream_req), |
| 2209 | ATTR_LIST(mb_group_prealloc), |
| 2210 | NULL, |
| 2211 | }; |
| 2212 | |
| 2213 | static ssize_t ext4_attr_show(struct kobject *kobj, |
| 2214 | struct attribute *attr, char *buf) |
| 2215 | { |
| 2216 | struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, |
| 2217 | s_kobj); |
| 2218 | struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); |
| 2219 | |
| 2220 | return a->show ? a->show(a, sbi, buf) : 0; |
| 2221 | } |
| 2222 | |
| 2223 | static ssize_t ext4_attr_store(struct kobject *kobj, |
| 2224 | struct attribute *attr, |
| 2225 | const char *buf, size_t len) |
| 2226 | { |
| 2227 | struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, |
| 2228 | s_kobj); |
| 2229 | struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); |
| 2230 | |
| 2231 | return a->store ? a->store(a, sbi, buf, len) : 0; |
| 2232 | } |
| 2233 | |
| 2234 | static void ext4_sb_release(struct kobject *kobj) |
| 2235 | { |
| 2236 | struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, |
| 2237 | s_kobj); |
| 2238 | complete(&sbi->s_kobj_unregister); |
| 2239 | } |
| 2240 | |
| 2241 | |
| 2242 | static struct sysfs_ops ext4_attr_ops = { |
| 2243 | .show = ext4_attr_show, |
| 2244 | .store = ext4_attr_store, |
| 2245 | }; |
| 2246 | |
| 2247 | static struct kobj_type ext4_ktype = { |
| 2248 | .default_attrs = ext4_attrs, |
| 2249 | .sysfs_ops = &ext4_attr_ops, |
| 2250 | .release = ext4_sb_release, |
| 2251 | }; |
| 2252 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2253 | static int ext4_fill_super(struct super_block *sb, void *data, int silent) |
Aneesh Kumar K.V | 7477827 | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 2254 | __releases(kernel_lock) |
| 2255 | __acquires(kernel_lock) |
Aneesh Kumar K.V | 1d03ec9 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 2256 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2257 | { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2258 | struct buffer_head *bh; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2259 | struct ext4_super_block *es = NULL; |
| 2260 | struct ext4_sb_info *sbi; |
| 2261 | ext4_fsblk_t block; |
| 2262 | ext4_fsblk_t sb_block = get_sb_block(&data); |
Andrew Morton | 70bbb3e | 2006-10-11 01:21:20 -0700 | [diff] [blame] | 2263 | ext4_fsblk_t logical_sb_block; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2264 | unsigned long offset = 0; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2265 | unsigned long journal_devnum = 0; |
| 2266 | unsigned long def_mount_opts; |
| 2267 | struct inode *root; |
Theodore Ts'o | 9f6200b | 2008-09-23 09:18:24 -0400 | [diff] [blame] | 2268 | char *cp; |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 2269 | const char *descr; |
David Howells | 1d1fe1e | 2008-02-07 00:15:37 -0800 | [diff] [blame] | 2270 | int ret = -EINVAL; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2271 | int blocksize; |
Theodore Ts'o | 4ec1102 | 2009-01-06 14:53:26 -0500 | [diff] [blame] | 2272 | unsigned int db_count; |
| 2273 | unsigned int i; |
Theodore Ts'o | f287a1a | 2008-10-16 22:50:48 -0400 | [diff] [blame] | 2274 | int needs_recovery, has_huge_files; |
Aneesh Kumar K.V | 3a06d77 | 2008-11-22 15:04:59 -0500 | [diff] [blame] | 2275 | int features; |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 2276 | __u64 blocks_count; |
Peter Zijlstra | 833f407 | 2007-10-16 23:25:45 -0700 | [diff] [blame] | 2277 | int err; |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 2278 | unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2279 | |
| 2280 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); |
| 2281 | if (!sbi) |
| 2282 | return -ENOMEM; |
Pekka Enberg | 705895b | 2009-02-15 18:07:52 -0500 | [diff] [blame] | 2283 | |
| 2284 | sbi->s_blockgroup_lock = |
| 2285 | kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); |
| 2286 | if (!sbi->s_blockgroup_lock) { |
| 2287 | kfree(sbi); |
| 2288 | return -ENOMEM; |
| 2289 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2290 | sb->s_fs_info = sbi; |
| 2291 | sbi->s_mount_opt = 0; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2292 | sbi->s_resuid = EXT4_DEF_RESUID; |
| 2293 | sbi->s_resgid = EXT4_DEF_RESGID; |
Theodore Ts'o | 240799c | 2008-10-09 23:53:47 -0400 | [diff] [blame] | 2294 | sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; |
Miklos Szeredi | d9c9bef1 | 2007-10-16 23:26:27 -0700 | [diff] [blame] | 2295 | sbi->s_sb_block = sb_block; |
Theodore Ts'o | afc32f7 | 2009-02-28 19:39:58 -0500 | [diff] [blame] | 2296 | sbi->s_sectors_written_start = part_stat_read(sb->s_bdev->bd_part, |
| 2297 | sectors[1]); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2298 | |
| 2299 | unlock_kernel(); |
| 2300 | |
Theodore Ts'o | 9f6200b | 2008-09-23 09:18:24 -0400 | [diff] [blame] | 2301 | /* Cleanup superblock name */ |
| 2302 | for (cp = sb->s_id; (cp = strchr(cp, '/'));) |
| 2303 | *cp = '!'; |
| 2304 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2305 | blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2306 | if (!blocksize) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2307 | printk(KERN_ERR "EXT4-fs: unable to set blocksize\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2308 | goto out_fail; |
| 2309 | } |
| 2310 | |
| 2311 | /* |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2312 | * The ext4 superblock will not be buffer aligned for other than 1kB |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2313 | * block sizes. We need to calculate the offset from buffer start. |
| 2314 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2315 | if (blocksize != EXT4_MIN_BLOCK_SIZE) { |
Andrew Morton | 70bbb3e | 2006-10-11 01:21:20 -0700 | [diff] [blame] | 2316 | logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; |
| 2317 | offset = do_div(logical_sb_block, blocksize); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2318 | } else { |
Andrew Morton | 70bbb3e | 2006-10-11 01:21:20 -0700 | [diff] [blame] | 2319 | logical_sb_block = sb_block; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
Andrew Morton | 70bbb3e | 2006-10-11 01:21:20 -0700 | [diff] [blame] | 2322 | if (!(bh = sb_bread(sb, logical_sb_block))) { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2323 | printk(KERN_ERR "EXT4-fs: unable to read superblock\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2324 | goto out_fail; |
| 2325 | } |
| 2326 | /* |
| 2327 | * Note: s_es must be initialized as soon as possible because |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2328 | * some ext4 macro-instructions depend on its value |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2329 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2330 | es = (struct ext4_super_block *) (((char *)bh->b_data) + offset); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2331 | sbi->s_es = es; |
| 2332 | sb->s_magic = le16_to_cpu(es->s_magic); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2333 | if (sb->s_magic != EXT4_SUPER_MAGIC) |
| 2334 | goto cantfind_ext4; |
Theodore Ts'o | afc32f7 | 2009-02-28 19:39:58 -0500 | [diff] [blame] | 2335 | sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2336 | |
| 2337 | /* Set defaults before we parse the mount options */ |
| 2338 | def_mount_opts = le32_to_cpu(es->s_default_mount_opts); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2339 | if (def_mount_opts & EXT4_DEFM_DEBUG) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2340 | set_opt(sbi->s_mount_opt, DEBUG); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2341 | if (def_mount_opts & EXT4_DEFM_BSDGROUPS) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2342 | set_opt(sbi->s_mount_opt, GRPID); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2343 | if (def_mount_opts & EXT4_DEFM_UID16) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2344 | set_opt(sbi->s_mount_opt, NO_UID32); |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 2345 | #ifdef CONFIG_EXT4_FS_XATTR |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2346 | if (def_mount_opts & EXT4_DEFM_XATTR_USER) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2347 | set_opt(sbi->s_mount_opt, XATTR_USER); |
Hugh Dickins | 2e7842b | 2007-02-10 01:46:13 -0800 | [diff] [blame] | 2348 | #endif |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 2349 | #ifdef CONFIG_EXT4_FS_POSIX_ACL |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2350 | if (def_mount_opts & EXT4_DEFM_ACL) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2351 | set_opt(sbi->s_mount_opt, POSIX_ACL); |
Hugh Dickins | 2e7842b | 2007-02-10 01:46:13 -0800 | [diff] [blame] | 2352 | #endif |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2353 | if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA) |
| 2354 | sbi->s_mount_opt |= EXT4_MOUNT_JOURNAL_DATA; |
| 2355 | else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED) |
| 2356 | sbi->s_mount_opt |= EXT4_MOUNT_ORDERED_DATA; |
| 2357 | else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK) |
| 2358 | sbi->s_mount_opt |= EXT4_MOUNT_WRITEBACK_DATA; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2359 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2360 | if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2361 | set_opt(sbi->s_mount_opt, ERRORS_PANIC); |
Aneesh Kumar K.V | bb4f397 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 2362 | else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE) |
Dmitry Mishin | ceea16b | 2006-10-11 01:21:21 -0700 | [diff] [blame] | 2363 | set_opt(sbi->s_mount_opt, ERRORS_CONT); |
Aneesh Kumar K.V | bb4f397 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 2364 | else |
| 2365 | set_opt(sbi->s_mount_opt, ERRORS_RO); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2366 | |
| 2367 | sbi->s_resuid = le16_to_cpu(es->s_def_resuid); |
| 2368 | sbi->s_resgid = le16_to_cpu(es->s_def_resgid); |
Theodore Ts'o | 3077384 | 2009-01-03 20:27:38 -0500 | [diff] [blame] | 2369 | sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ; |
| 2370 | sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME; |
| 2371 | sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME; |
Curt Wohlgemuth | f403390 | 2009-05-01 20:27:20 -0400 | [diff] [blame] | 2372 | sbi->s_mb_history_max = default_mb_history_length; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2373 | |
Eric Sandeen | 571640c | 2008-05-26 12:29:46 -0400 | [diff] [blame] | 2374 | set_opt(sbi->s_mount_opt, BARRIER); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2375 | |
Mingming Cao | 1e2462f | 2007-07-18 09:00:55 -0400 | [diff] [blame] | 2376 | /* |
Aneesh Kumar K.V | dd919b9 | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 2377 | * enable delayed allocation by default |
| 2378 | * Use -o nodelalloc to turn it off |
| 2379 | */ |
| 2380 | set_opt(sbi->s_mount_opt, DELALLOC); |
| 2381 | |
| 2382 | |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 2383 | if (!parse_options((char *) data, sb, &journal_devnum, |
| 2384 | &journal_ioprio, NULL, 0)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2385 | goto failed_mount; |
| 2386 | |
| 2387 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2388 | ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2389 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2390 | if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV && |
| 2391 | (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) || |
| 2392 | EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) || |
| 2393 | EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U))) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2394 | printk(KERN_WARNING |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2395 | "EXT4-fs warning: feature flags set on rev 0 fs, " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2396 | "running e2fsck is recommended\n"); |
Theodore Tso | 469108f | 2008-02-10 01:11:44 -0500 | [diff] [blame] | 2397 | |
| 2398 | /* |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2399 | * Check feature flags regardless of the revision level, since we |
| 2400 | * previously didn't change the revision level when setting the flags, |
| 2401 | * so there is a chance incompat flags are set on a rev 0 filesystem. |
| 2402 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2403 | features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2404 | if (features) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2405 | printk(KERN_ERR "EXT4-fs: %s: couldn't mount because of " |
Aneesh Kumar K.V | 3a06d77 | 2008-11-22 15:04:59 -0500 | [diff] [blame] | 2406 | "unsupported optional features (%x).\n", sb->s_id, |
| 2407 | (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) & |
| 2408 | ~EXT4_FEATURE_INCOMPAT_SUPP)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2409 | goto failed_mount; |
| 2410 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2411 | features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2412 | if (!(sb->s_flags & MS_RDONLY) && features) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2413 | printk(KERN_ERR "EXT4-fs: %s: couldn't mount RDWR because of " |
Aneesh Kumar K.V | 3a06d77 | 2008-11-22 15:04:59 -0500 | [diff] [blame] | 2414 | "unsupported optional features (%x).\n", sb->s_id, |
| 2415 | (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) & |
| 2416 | ~EXT4_FEATURE_RO_COMPAT_SUPP)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2417 | goto failed_mount; |
| 2418 | } |
Theodore Ts'o | f287a1a | 2008-10-16 22:50:48 -0400 | [diff] [blame] | 2419 | has_huge_files = EXT4_HAS_RO_COMPAT_FEATURE(sb, |
| 2420 | EXT4_FEATURE_RO_COMPAT_HUGE_FILE); |
| 2421 | if (has_huge_files) { |
Aneesh Kumar K.V | 0fc1b45 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 2422 | /* |
| 2423 | * Large file size enabled file system can only be |
Jens Axboe | b3a6ffe | 2008-12-12 09:51:16 +0100 | [diff] [blame] | 2424 | * mount if kernel is build with CONFIG_LBD |
Aneesh Kumar K.V | 0fc1b45 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 2425 | */ |
| 2426 | if (sizeof(root->i_blocks) < sizeof(u64) && |
| 2427 | !(sb->s_flags & MS_RDONLY)) { |
| 2428 | printk(KERN_ERR "EXT4-fs: %s: Filesystem with huge " |
| 2429 | "files cannot be mounted read-write " |
Jens Axboe | b3a6ffe | 2008-12-12 09:51:16 +0100 | [diff] [blame] | 2430 | "without CONFIG_LBD.\n", sb->s_id); |
Aneesh Kumar K.V | 0fc1b45 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 2431 | goto failed_mount; |
| 2432 | } |
| 2433 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2434 | blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size); |
| 2435 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2436 | if (blocksize < EXT4_MIN_BLOCK_SIZE || |
| 2437 | blocksize > EXT4_MAX_BLOCK_SIZE) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2438 | printk(KERN_ERR |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2439 | "EXT4-fs: Unsupported filesystem blocksize %d on %s.\n", |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2440 | blocksize, sb->s_id); |
| 2441 | goto failed_mount; |
| 2442 | } |
| 2443 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2444 | if (sb->s_blocksize != blocksize) { |
Aneesh Kumar K.V | ce40733 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 2445 | |
| 2446 | /* Validate the filesystem blocksize */ |
| 2447 | if (!sb_set_blocksize(sb, blocksize)) { |
| 2448 | printk(KERN_ERR "EXT4-fs: bad block size %d.\n", |
| 2449 | blocksize); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2450 | goto failed_mount; |
| 2451 | } |
| 2452 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2453 | brelse(bh); |
Andrew Morton | 70bbb3e | 2006-10-11 01:21:20 -0700 | [diff] [blame] | 2454 | logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; |
| 2455 | offset = do_div(logical_sb_block, blocksize); |
| 2456 | bh = sb_bread(sb, logical_sb_block); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2457 | if (!bh) { |
| 2458 | printk(KERN_ERR |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2459 | "EXT4-fs: Can't read superblock on 2nd try.\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2460 | goto failed_mount; |
| 2461 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2462 | es = (struct ext4_super_block *)(((char *)bh->b_data) + offset); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2463 | sbi->s_es = es; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2464 | if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2465 | printk(KERN_ERR |
| 2466 | "EXT4-fs: Magic mismatch, very weird !\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2467 | goto failed_mount; |
| 2468 | } |
| 2469 | } |
| 2470 | |
Theodore Ts'o | f287a1a | 2008-10-16 22:50:48 -0400 | [diff] [blame] | 2471 | sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits, |
| 2472 | has_huge_files); |
| 2473 | sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2474 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2475 | if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) { |
| 2476 | sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE; |
| 2477 | sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2478 | } else { |
| 2479 | sbi->s_inode_size = le16_to_cpu(es->s_inode_size); |
| 2480 | sbi->s_first_ino = le32_to_cpu(es->s_first_ino); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2481 | if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) || |
Vignesh Babu | 1330593 | 2007-07-18 09:11:02 -0400 | [diff] [blame] | 2482 | (!is_power_of_2(sbi->s_inode_size)) || |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2483 | (sbi->s_inode_size > blocksize)) { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2484 | printk(KERN_ERR |
| 2485 | "EXT4-fs: unsupported inode size: %d\n", |
| 2486 | sbi->s_inode_size); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2487 | goto failed_mount; |
| 2488 | } |
Kalpak Shah | ef7f383 | 2007-07-18 09:15:20 -0400 | [diff] [blame] | 2489 | if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) |
| 2490 | sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2491 | } |
Alexandre Ratchov | 0d1ee42 | 2006-10-11 01:21:14 -0700 | [diff] [blame] | 2492 | sbi->s_desc_size = le16_to_cpu(es->s_desc_size); |
| 2493 | if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) { |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 2494 | if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT || |
Alexandre Ratchov | 0d1ee42 | 2006-10-11 01:21:14 -0700 | [diff] [blame] | 2495 | sbi->s_desc_size > EXT4_MAX_DESC_SIZE || |
vignesh babu | d8ea6cf | 2007-10-16 23:27:14 -0700 | [diff] [blame] | 2496 | !is_power_of_2(sbi->s_desc_size)) { |
Alexandre Ratchov | 0d1ee42 | 2006-10-11 01:21:14 -0700 | [diff] [blame] | 2497 | printk(KERN_ERR |
Alexandre Ratchov | 8fadc14 | 2006-10-11 01:21:15 -0700 | [diff] [blame] | 2498 | "EXT4-fs: unsupported descriptor size %lu\n", |
Alexandre Ratchov | 0d1ee42 | 2006-10-11 01:21:14 -0700 | [diff] [blame] | 2499 | sbi->s_desc_size); |
| 2500 | goto failed_mount; |
| 2501 | } |
| 2502 | } else |
| 2503 | sbi->s_desc_size = EXT4_MIN_DESC_SIZE; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2504 | sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2505 | sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); |
Andries E. Brouwer | b47b6f3 | 2007-12-17 16:19:55 -0800 | [diff] [blame] | 2506 | if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2507 | goto cantfind_ext4; |
| 2508 | sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2509 | if (sbi->s_inodes_per_block == 0) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2510 | goto cantfind_ext4; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2511 | sbi->s_itb_per_group = sbi->s_inodes_per_group / |
| 2512 | sbi->s_inodes_per_block; |
Alexandre Ratchov | 0d1ee42 | 2006-10-11 01:21:14 -0700 | [diff] [blame] | 2513 | sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2514 | sbi->s_sbh = bh; |
| 2515 | sbi->s_mount_state = le16_to_cpu(es->s_state); |
Fengguang Wu | e57aa83 | 2007-10-16 23:26:25 -0700 | [diff] [blame] | 2516 | sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb)); |
| 2517 | sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb)); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2518 | for (i = 0; i < 4; i++) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2519 | sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); |
| 2520 | sbi->s_def_hash_version = es->s_def_hash_version; |
Theodore Ts'o | f99b258 | 2008-10-28 13:21:44 -0400 | [diff] [blame] | 2521 | i = le32_to_cpu(es->s_flags); |
| 2522 | if (i & EXT2_FLAGS_UNSIGNED_HASH) |
| 2523 | sbi->s_hash_unsigned = 3; |
| 2524 | else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) { |
| 2525 | #ifdef __CHAR_UNSIGNED__ |
| 2526 | es->s_flags |= cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH); |
| 2527 | sbi->s_hash_unsigned = 3; |
| 2528 | #else |
| 2529 | es->s_flags |= cpu_to_le32(EXT2_FLAGS_SIGNED_HASH); |
| 2530 | #endif |
| 2531 | sb->s_dirt = 1; |
| 2532 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2533 | |
| 2534 | if (sbi->s_blocks_per_group > blocksize * 8) { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2535 | printk(KERN_ERR |
| 2536 | "EXT4-fs: #blocks per group too big: %lu\n", |
| 2537 | sbi->s_blocks_per_group); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2538 | goto failed_mount; |
| 2539 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2540 | if (sbi->s_inodes_per_group > blocksize * 8) { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2541 | printk(KERN_ERR |
| 2542 | "EXT4-fs: #inodes per group too big: %lu\n", |
| 2543 | sbi->s_inodes_per_group); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2544 | goto failed_mount; |
| 2545 | } |
| 2546 | |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 2547 | if (ext4_blocks_count(es) > |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2548 | (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2549 | printk(KERN_ERR "EXT4-fs: filesystem on %s:" |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2550 | " too large to mount safely\n", sb->s_id); |
| 2551 | if (sizeof(sector_t) < 8) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2552 | printk(KERN_WARNING "EXT4-fs: CONFIG_LBD not " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2553 | "enabled\n"); |
| 2554 | goto failed_mount; |
| 2555 | } |
| 2556 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2557 | if (EXT4_BLOCKS_PER_GROUP(sb) == 0) |
| 2558 | goto cantfind_ext4; |
Eric Sandeen | e7c9559 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 2559 | |
From: Thiemo Nagel | 0f2ddca | 2009-04-07 14:07:47 -0400 | [diff] [blame] | 2560 | /* check blocks count against device size */ |
| 2561 | blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits; |
| 2562 | if (blocks_count && ext4_blocks_count(es) > blocks_count) { |
| 2563 | printk(KERN_WARNING "EXT4-fs: bad geometry: block count %llu " |
| 2564 | "exceeds size of device (%llu blocks)\n", |
| 2565 | ext4_blocks_count(es), blocks_count); |
| 2566 | goto failed_mount; |
| 2567 | } |
| 2568 | |
Theodore Ts'o | 4ec1102 | 2009-01-06 14:53:26 -0500 | [diff] [blame] | 2569 | /* |
| 2570 | * It makes no sense for the first data block to be beyond the end |
| 2571 | * of the filesystem. |
| 2572 | */ |
| 2573 | if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) { |
| 2574 | printk(KERN_WARNING "EXT4-fs: bad geometry: first data" |
| 2575 | "block %u is beyond end of filesystem (%llu)\n", |
| 2576 | le32_to_cpu(es->s_first_data_block), |
| 2577 | ext4_blocks_count(es)); |
Eric Sandeen | e7c9559 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 2578 | goto failed_mount; |
| 2579 | } |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 2580 | blocks_count = (ext4_blocks_count(es) - |
| 2581 | le32_to_cpu(es->s_first_data_block) + |
| 2582 | EXT4_BLOCKS_PER_GROUP(sb) - 1); |
| 2583 | do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb)); |
Theodore Ts'o | 4ec1102 | 2009-01-06 14:53:26 -0500 | [diff] [blame] | 2584 | if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) { |
| 2585 | printk(KERN_WARNING "EXT4-fs: groups count too large: %u " |
| 2586 | "(block count %llu, first data block %u, " |
| 2587 | "blocks per group %lu)\n", sbi->s_groups_count, |
| 2588 | ext4_blocks_count(es), |
| 2589 | le32_to_cpu(es->s_first_data_block), |
| 2590 | EXT4_BLOCKS_PER_GROUP(sb)); |
| 2591 | goto failed_mount; |
| 2592 | } |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 2593 | sbi->s_groups_count = blocks_count; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2594 | db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) / |
| 2595 | EXT4_DESC_PER_BLOCK(sb); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2596 | sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *), |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2597 | GFP_KERNEL); |
| 2598 | if (sbi->s_group_desc == NULL) { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2599 | printk(KERN_ERR "EXT4-fs: not enough memory\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2600 | goto failed_mount; |
| 2601 | } |
| 2602 | |
Alexander Beregalov | 3244fcb | 2008-10-12 17:27:49 -0400 | [diff] [blame] | 2603 | #ifdef CONFIG_PROC_FS |
Theodore Ts'o | 9f6200b | 2008-09-23 09:18:24 -0400 | [diff] [blame] | 2604 | if (ext4_proc_root) |
| 2605 | sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); |
Alexander Beregalov | 3244fcb | 2008-10-12 17:27:49 -0400 | [diff] [blame] | 2606 | #endif |
Theodore Ts'o | 240799c | 2008-10-09 23:53:47 -0400 | [diff] [blame] | 2607 | |
Pekka Enberg | 705895b | 2009-02-15 18:07:52 -0500 | [diff] [blame] | 2608 | bgl_lock_init(sbi->s_blockgroup_lock); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2609 | |
| 2610 | for (i = 0; i < db_count; i++) { |
Andrew Morton | 70bbb3e | 2006-10-11 01:21:20 -0700 | [diff] [blame] | 2611 | block = descriptor_loc(sb, logical_sb_block, i); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2612 | sbi->s_group_desc[i] = sb_bread(sb, block); |
| 2613 | if (!sbi->s_group_desc[i]) { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2614 | printk(KERN_ERR "EXT4-fs: " |
| 2615 | "can't read group descriptor %d\n", i); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2616 | db_count = i; |
| 2617 | goto failed_mount2; |
| 2618 | } |
| 2619 | } |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2620 | if (!ext4_check_descriptors(sb)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2621 | printk(KERN_ERR "EXT4-fs: group descriptors corrupted!\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2622 | goto failed_mount2; |
| 2623 | } |
Jose R. Santos | 772cb7c | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 2624 | if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) |
| 2625 | if (!ext4_fill_flex_info(sb)) { |
| 2626 | printk(KERN_ERR |
| 2627 | "EXT4-fs: unable to initialize " |
| 2628 | "flex_bg meta info!\n"); |
| 2629 | goto failed_mount2; |
| 2630 | } |
| 2631 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2632 | sbi->s_gdb_count = db_count; |
| 2633 | get_random_bytes(&sbi->s_next_generation, sizeof(u32)); |
| 2634 | spin_lock_init(&sbi->s_next_gen_lock); |
| 2635 | |
Peter Zijlstra | 833f407 | 2007-10-16 23:25:45 -0700 | [diff] [blame] | 2636 | err = percpu_counter_init(&sbi->s_freeblocks_counter, |
| 2637 | ext4_count_free_blocks(sb)); |
| 2638 | if (!err) { |
| 2639 | err = percpu_counter_init(&sbi->s_freeinodes_counter, |
| 2640 | ext4_count_free_inodes(sb)); |
| 2641 | } |
| 2642 | if (!err) { |
| 2643 | err = percpu_counter_init(&sbi->s_dirs_counter, |
| 2644 | ext4_count_dirs(sb)); |
| 2645 | } |
Aneesh Kumar K.V | 6bc6e63 | 2008-10-10 09:39:00 -0400 | [diff] [blame] | 2646 | if (!err) { |
| 2647 | err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0); |
| 2648 | } |
Peter Zijlstra | 833f407 | 2007-10-16 23:25:45 -0700 | [diff] [blame] | 2649 | if (err) { |
| 2650 | printk(KERN_ERR "EXT4-fs: insufficient memory\n"); |
| 2651 | goto failed_mount3; |
| 2652 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2653 | |
Alex Tomas | c9de560 | 2008-01-29 00:19:52 -0500 | [diff] [blame] | 2654 | sbi->s_stripe = ext4_get_stripe_size(sbi); |
| 2655 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2656 | /* |
| 2657 | * set up enough so that it can read an inode |
| 2658 | */ |
Theodore Ts'o | 9ca9238 | 2009-05-01 12:52:25 -0400 | [diff] [blame] | 2659 | if (!test_opt(sb, NOLOAD) && |
| 2660 | EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) |
| 2661 | sb->s_op = &ext4_sops; |
| 2662 | else |
| 2663 | sb->s_op = &ext4_nojournal_sops; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2664 | sb->s_export_op = &ext4_export_ops; |
| 2665 | sb->s_xattr = ext4_xattr_handlers; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2666 | #ifdef CONFIG_QUOTA |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2667 | sb->s_qcop = &ext4_qctl_operations; |
| 2668 | sb->dq_op = &ext4_quota_operations; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2669 | #endif |
| 2670 | INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ |
Theodore Ts'o | 3b9d4ed | 2009-04-25 22:54:04 -0400 | [diff] [blame] | 2671 | mutex_init(&sbi->s_orphan_lock); |
Theodore Ts'o | 32ed505 | 2009-04-25 22:53:39 -0400 | [diff] [blame] | 2672 | mutex_init(&sbi->s_resize_lock); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2673 | |
| 2674 | sb->s_root = NULL; |
| 2675 | |
| 2676 | needs_recovery = (es->s_last_orphan != 0 || |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2677 | EXT4_HAS_INCOMPAT_FEATURE(sb, |
| 2678 | EXT4_FEATURE_INCOMPAT_RECOVER)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2679 | |
| 2680 | /* |
| 2681 | * The first inode we look at is the journal inode. Don't try |
| 2682 | * root first: it may be modified in the journal! |
| 2683 | */ |
| 2684 | if (!test_opt(sb, NOLOAD) && |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2685 | EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) { |
| 2686 | if (ext4_load_journal(sb, es, journal_devnum)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2687 | goto failed_mount3; |
Theodore Ts'o | 624080e | 2008-06-06 17:50:40 -0400 | [diff] [blame] | 2688 | if (!(sb->s_flags & MS_RDONLY) && |
| 2689 | EXT4_SB(sb)->s_journal->j_failed_commit) { |
| 2690 | printk(KERN_CRIT "EXT4-fs error (device %s): " |
| 2691 | "ext4_fill_super: Journal transaction " |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2692 | "%u is corrupt\n", sb->s_id, |
Theodore Ts'o | 624080e | 2008-06-06 17:50:40 -0400 | [diff] [blame] | 2693 | EXT4_SB(sb)->s_journal->j_failed_commit); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2694 | if (test_opt(sb, ERRORS_RO)) { |
| 2695 | printk(KERN_CRIT |
| 2696 | "Mounting filesystem read-only\n"); |
Theodore Ts'o | 624080e | 2008-06-06 17:50:40 -0400 | [diff] [blame] | 2697 | sb->s_flags |= MS_RDONLY; |
| 2698 | EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; |
| 2699 | es->s_state |= cpu_to_le16(EXT4_ERROR_FS); |
| 2700 | } |
| 2701 | if (test_opt(sb, ERRORS_PANIC)) { |
| 2702 | EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; |
| 2703 | es->s_state |= cpu_to_le16(EXT4_ERROR_FS); |
Theodore Ts'o | e2d6705 | 2009-05-01 00:33:44 -0400 | [diff] [blame] | 2704 | ext4_commit_super(sb, 1); |
Theodore Ts'o | 624080e | 2008-06-06 17:50:40 -0400 | [diff] [blame] | 2705 | goto failed_mount4; |
| 2706 | } |
| 2707 | } |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 2708 | } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) && |
| 2709 | EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { |
| 2710 | printk(KERN_ERR "EXT4-fs: required journal recovery " |
| 2711 | "suppressed and not mounted read-only\n"); |
| 2712 | goto failed_mount4; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2713 | } else { |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 2714 | clear_opt(sbi->s_mount_opt, DATA_FLAGS); |
| 2715 | set_opt(sbi->s_mount_opt, WRITEBACK_DATA); |
| 2716 | sbi->s_journal = NULL; |
| 2717 | needs_recovery = 0; |
| 2718 | goto no_journal; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2719 | } |
| 2720 | |
Jose R. Santos | eb40a09 | 2007-07-18 08:37:25 -0400 | [diff] [blame] | 2721 | if (ext4_blocks_count(es) > 0xffffffffULL && |
| 2722 | !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0, |
| 2723 | JBD2_FEATURE_INCOMPAT_64BIT)) { |
Theodore Ts'o | abda141 | 2009-01-06 00:20:32 -0500 | [diff] [blame] | 2724 | printk(KERN_ERR "EXT4-fs: Failed to set 64-bit journal feature\n"); |
Jose R. Santos | eb40a09 | 2007-07-18 08:37:25 -0400 | [diff] [blame] | 2725 | goto failed_mount4; |
| 2726 | } |
| 2727 | |
Girish Shilamkar | 818d276 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 2728 | if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) { |
| 2729 | jbd2_journal_set_features(sbi->s_journal, |
| 2730 | JBD2_FEATURE_COMPAT_CHECKSUM, 0, |
| 2731 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); |
| 2732 | } else if (test_opt(sb, JOURNAL_CHECKSUM)) { |
| 2733 | jbd2_journal_set_features(sbi->s_journal, |
| 2734 | JBD2_FEATURE_COMPAT_CHECKSUM, 0, 0); |
| 2735 | jbd2_journal_clear_features(sbi->s_journal, 0, 0, |
| 2736 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); |
| 2737 | } else { |
| 2738 | jbd2_journal_clear_features(sbi->s_journal, |
| 2739 | JBD2_FEATURE_COMPAT_CHECKSUM, 0, |
| 2740 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); |
| 2741 | } |
| 2742 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2743 | /* We have now updated the journal if required, so we can |
| 2744 | * validate the data journaling mode. */ |
| 2745 | switch (test_opt(sb, DATA_FLAGS)) { |
| 2746 | case 0: |
| 2747 | /* No mode set, assume a default based on the journal |
Andrew Morton | 63f5793 | 2006-10-11 01:21:24 -0700 | [diff] [blame] | 2748 | * capabilities: ORDERED_DATA if the journal can |
| 2749 | * cope, else JOURNAL_DATA |
| 2750 | */ |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 2751 | if (jbd2_journal_check_available_features |
| 2752 | (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2753 | set_opt(sbi->s_mount_opt, ORDERED_DATA); |
| 2754 | else |
| 2755 | set_opt(sbi->s_mount_opt, JOURNAL_DATA); |
| 2756 | break; |
| 2757 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2758 | case EXT4_MOUNT_ORDERED_DATA: |
| 2759 | case EXT4_MOUNT_WRITEBACK_DATA: |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 2760 | if (!jbd2_journal_check_available_features |
| 2761 | (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2762 | printk(KERN_ERR "EXT4-fs: Journal does not support " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2763 | "requested data journaling mode\n"); |
| 2764 | goto failed_mount4; |
| 2765 | } |
| 2766 | default: |
| 2767 | break; |
| 2768 | } |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 2769 | set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2770 | |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 2771 | no_journal: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2772 | |
| 2773 | if (test_opt(sb, NOBH)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2774 | if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) { |
| 2775 | printk(KERN_WARNING "EXT4-fs: Ignoring nobh option - " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2776 | "its supported only with writeback mode\n"); |
| 2777 | clear_opt(sbi->s_mount_opt, NOBH); |
| 2778 | } |
| 2779 | } |
| 2780 | /* |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 2781 | * The jbd2_journal_load will have done any necessary log recovery, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2782 | * so we can safely mount the rest of the filesystem now. |
| 2783 | */ |
| 2784 | |
David Howells | 1d1fe1e | 2008-02-07 00:15:37 -0800 | [diff] [blame] | 2785 | root = ext4_iget(sb, EXT4_ROOT_INO); |
| 2786 | if (IS_ERR(root)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2787 | printk(KERN_ERR "EXT4-fs: get root inode failed\n"); |
David Howells | 1d1fe1e | 2008-02-07 00:15:37 -0800 | [diff] [blame] | 2788 | ret = PTR_ERR(root); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2789 | goto failed_mount4; |
| 2790 | } |
| 2791 | if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { |
David Howells | 1d1fe1e | 2008-02-07 00:15:37 -0800 | [diff] [blame] | 2792 | iput(root); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2793 | printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2794 | goto failed_mount4; |
| 2795 | } |
David Howells | 1d1fe1e | 2008-02-07 00:15:37 -0800 | [diff] [blame] | 2796 | sb->s_root = d_alloc_root(root); |
| 2797 | if (!sb->s_root) { |
| 2798 | printk(KERN_ERR "EXT4-fs: get root dentry failed\n"); |
| 2799 | iput(root); |
| 2800 | ret = -ENOMEM; |
| 2801 | goto failed_mount4; |
| 2802 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2803 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2804 | ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY); |
Kalpak Shah | ef7f383 | 2007-07-18 09:15:20 -0400 | [diff] [blame] | 2805 | |
| 2806 | /* determine the minimum size of new large inodes, if present */ |
| 2807 | if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) { |
| 2808 | sbi->s_want_extra_isize = sizeof(struct ext4_inode) - |
| 2809 | EXT4_GOOD_OLD_INODE_SIZE; |
| 2810 | if (EXT4_HAS_RO_COMPAT_FEATURE(sb, |
| 2811 | EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)) { |
| 2812 | if (sbi->s_want_extra_isize < |
| 2813 | le16_to_cpu(es->s_want_extra_isize)) |
| 2814 | sbi->s_want_extra_isize = |
| 2815 | le16_to_cpu(es->s_want_extra_isize); |
| 2816 | if (sbi->s_want_extra_isize < |
| 2817 | le16_to_cpu(es->s_min_extra_isize)) |
| 2818 | sbi->s_want_extra_isize = |
| 2819 | le16_to_cpu(es->s_min_extra_isize); |
| 2820 | } |
| 2821 | } |
| 2822 | /* Check if enough inode space is available */ |
| 2823 | if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize > |
| 2824 | sbi->s_inode_size) { |
| 2825 | sbi->s_want_extra_isize = sizeof(struct ext4_inode) - |
| 2826 | EXT4_GOOD_OLD_INODE_SIZE; |
| 2827 | printk(KERN_INFO "EXT4-fs: required extra inode space not" |
| 2828 | "available.\n"); |
| 2829 | } |
| 2830 | |
Aneesh Kumar K.V | c2774d8 | 2008-10-10 20:07:20 -0400 | [diff] [blame] | 2831 | if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) { |
| 2832 | printk(KERN_WARNING "EXT4-fs: Ignoring delalloc option - " |
| 2833 | "requested data journaling mode\n"); |
| 2834 | clear_opt(sbi->s_mount_opt, DELALLOC); |
| 2835 | } else if (test_opt(sb, DELALLOC)) |
| 2836 | printk(KERN_INFO "EXT4-fs: delayed allocation enabled\n"); |
| 2837 | |
Theodore Ts'o | 6fd058f | 2009-05-17 15:38:01 -0400 | [diff] [blame] | 2838 | err = ext4_setup_system_zone(sb); |
| 2839 | if (err) { |
| 2840 | printk(KERN_ERR "EXT4-fs: failed to initialize system " |
| 2841 | "zone (%d)\n", err); |
| 2842 | goto failed_mount4; |
| 2843 | } |
| 2844 | |
Aneesh Kumar K.V | c2774d8 | 2008-10-10 20:07:20 -0400 | [diff] [blame] | 2845 | ext4_ext_init(sb); |
| 2846 | err = ext4_mb_init(sb, needs_recovery); |
| 2847 | if (err) { |
| 2848 | printk(KERN_ERR "EXT4-fs: failed to initalize mballoc (%d)\n", |
| 2849 | err); |
| 2850 | goto failed_mount4; |
| 2851 | } |
| 2852 | |
Theodore Ts'o | 3197ebd | 2009-03-31 09:10:09 -0400 | [diff] [blame] | 2853 | sbi->s_kobj.kset = ext4_kset; |
| 2854 | init_completion(&sbi->s_kobj_unregister); |
| 2855 | err = kobject_init_and_add(&sbi->s_kobj, &ext4_ktype, NULL, |
| 2856 | "%s", sb->s_id); |
| 2857 | if (err) { |
| 2858 | ext4_mb_release(sb); |
| 2859 | ext4_ext_release(sb); |
| 2860 | goto failed_mount4; |
| 2861 | }; |
| 2862 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2863 | EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; |
| 2864 | ext4_orphan_cleanup(sb, es); |
| 2865 | EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS; |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 2866 | if (needs_recovery) { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 2867 | printk(KERN_INFO "EXT4-fs: recovery complete.\n"); |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 2868 | ext4_mark_recovery_complete(sb, es); |
| 2869 | } |
| 2870 | if (EXT4_SB(sb)->s_journal) { |
| 2871 | if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) |
| 2872 | descr = " journalled data mode"; |
| 2873 | else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) |
| 2874 | descr = " ordered data mode"; |
| 2875 | else |
| 2876 | descr = " writeback data mode"; |
| 2877 | } else |
| 2878 | descr = "out journal"; |
| 2879 | |
| 2880 | printk(KERN_INFO "EXT4-fs: mounted filesystem %s with%s\n", |
| 2881 | sb->s_id, descr); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2882 | |
| 2883 | lock_kernel(); |
| 2884 | return 0; |
| 2885 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2886 | cantfind_ext4: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2887 | if (!silent) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2888 | printk(KERN_ERR "VFS: Can't find ext4 filesystem on dev %s.\n", |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2889 | sb->s_id); |
| 2890 | goto failed_mount; |
| 2891 | |
| 2892 | failed_mount4: |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 2893 | printk(KERN_ERR "EXT4-fs (device %s): mount failed\n", sb->s_id); |
Theodore Ts'o | 6fd058f | 2009-05-17 15:38:01 -0400 | [diff] [blame] | 2894 | ext4_release_system_zone(sb); |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 2895 | if (sbi->s_journal) { |
| 2896 | jbd2_journal_destroy(sbi->s_journal); |
| 2897 | sbi->s_journal = NULL; |
| 2898 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2899 | failed_mount3: |
Theodore Ts'o | c5ca7c7 | 2009-04-27 22:48:48 -0400 | [diff] [blame] | 2900 | if (sbi->s_flex_groups) { |
| 2901 | if (is_vmalloc_addr(sbi->s_flex_groups)) |
| 2902 | vfree(sbi->s_flex_groups); |
| 2903 | else |
| 2904 | kfree(sbi->s_flex_groups); |
| 2905 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2906 | percpu_counter_destroy(&sbi->s_freeblocks_counter); |
| 2907 | percpu_counter_destroy(&sbi->s_freeinodes_counter); |
| 2908 | percpu_counter_destroy(&sbi->s_dirs_counter); |
Aneesh Kumar K.V | 6bc6e63 | 2008-10-10 09:39:00 -0400 | [diff] [blame] | 2909 | percpu_counter_destroy(&sbi->s_dirtyblocks_counter); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2910 | failed_mount2: |
| 2911 | for (i = 0; i < db_count; i++) |
| 2912 | brelse(sbi->s_group_desc[i]); |
| 2913 | kfree(sbi->s_group_desc); |
| 2914 | failed_mount: |
Theodore Ts'o | 240799c | 2008-10-09 23:53:47 -0400 | [diff] [blame] | 2915 | if (sbi->s_proc) { |
Theodore Ts'o | 9f6200b | 2008-09-23 09:18:24 -0400 | [diff] [blame] | 2916 | remove_proc_entry(sb->s_id, ext4_proc_root); |
Theodore Ts'o | 240799c | 2008-10-09 23:53:47 -0400 | [diff] [blame] | 2917 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2918 | #ifdef CONFIG_QUOTA |
| 2919 | for (i = 0; i < MAXQUOTAS; i++) |
| 2920 | kfree(sbi->s_qf_names[i]); |
| 2921 | #endif |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2922 | ext4_blkdev_remove(sbi); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2923 | brelse(bh); |
| 2924 | out_fail: |
| 2925 | sb->s_fs_info = NULL; |
Manish Katiyar | f683016 | 2009-05-17 23:52:44 -0400 | [diff] [blame] | 2926 | kfree(sbi->s_blockgroup_lock); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2927 | kfree(sbi); |
| 2928 | lock_kernel(); |
David Howells | 1d1fe1e | 2008-02-07 00:15:37 -0800 | [diff] [blame] | 2929 | return ret; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | /* |
| 2933 | * Setup any per-fs journal parameters now. We'll do this both on |
| 2934 | * initial mount, once the journal has been initialised but before we've |
| 2935 | * done any recovery; and again on any subsequent remount. |
| 2936 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2937 | static void ext4_init_journal_params(struct super_block *sb, journal_t *journal) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2938 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2939 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2940 | |
Theodore Ts'o | 3077384 | 2009-01-03 20:27:38 -0500 | [diff] [blame] | 2941 | journal->j_commit_interval = sbi->s_commit_interval; |
| 2942 | journal->j_min_batch_time = sbi->s_min_batch_time; |
| 2943 | journal->j_max_batch_time = sbi->s_max_batch_time; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2944 | |
| 2945 | spin_lock(&journal->j_state_lock); |
| 2946 | if (test_opt(sb, BARRIER)) |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 2947 | journal->j_flags |= JBD2_BARRIER; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2948 | else |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 2949 | journal->j_flags &= ~JBD2_BARRIER; |
Hidehiro Kawai | 5bf5683 | 2008-10-10 22:12:43 -0400 | [diff] [blame] | 2950 | if (test_opt(sb, DATA_ERR_ABORT)) |
| 2951 | journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR; |
| 2952 | else |
| 2953 | journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2954 | spin_unlock(&journal->j_state_lock); |
| 2955 | } |
| 2956 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2957 | static journal_t *ext4_get_journal(struct super_block *sb, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2958 | unsigned int journal_inum) |
| 2959 | { |
| 2960 | struct inode *journal_inode; |
| 2961 | journal_t *journal; |
| 2962 | |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 2963 | BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); |
| 2964 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2965 | /* First, test for the existence of a valid inode on disk. Bad |
| 2966 | * things happen if we iget() an unused inode, as the subsequent |
| 2967 | * iput() will try to delete it. */ |
| 2968 | |
David Howells | 1d1fe1e | 2008-02-07 00:15:37 -0800 | [diff] [blame] | 2969 | journal_inode = ext4_iget(sb, journal_inum); |
| 2970 | if (IS_ERR(journal_inode)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2971 | printk(KERN_ERR "EXT4-fs: no journal found.\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2972 | return NULL; |
| 2973 | } |
| 2974 | if (!journal_inode->i_nlink) { |
| 2975 | make_bad_inode(journal_inode); |
| 2976 | iput(journal_inode); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2977 | printk(KERN_ERR "EXT4-fs: journal inode is deleted.\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2978 | return NULL; |
| 2979 | } |
| 2980 | |
Theodore Ts'o | e5f8eab | 2008-09-08 22:25:04 -0400 | [diff] [blame] | 2981 | jbd_debug(2, "Journal inode found at %p: %lld bytes\n", |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2982 | journal_inode, journal_inode->i_size); |
David Howells | 1d1fe1e | 2008-02-07 00:15:37 -0800 | [diff] [blame] | 2983 | if (!S_ISREG(journal_inode->i_mode)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2984 | printk(KERN_ERR "EXT4-fs: invalid journal inode.\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2985 | iput(journal_inode); |
| 2986 | return NULL; |
| 2987 | } |
| 2988 | |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 2989 | journal = jbd2_journal_init_inode(journal_inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2990 | if (!journal) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2991 | printk(KERN_ERR "EXT4-fs: Could not load journal inode\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2992 | iput(journal_inode); |
| 2993 | return NULL; |
| 2994 | } |
| 2995 | journal->j_private = sb; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2996 | ext4_init_journal_params(sb, journal); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2997 | return journal; |
| 2998 | } |
| 2999 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3000 | static journal_t *ext4_get_dev_journal(struct super_block *sb, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3001 | dev_t j_dev) |
| 3002 | { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 3003 | struct buffer_head *bh; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3004 | journal_t *journal; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3005 | ext4_fsblk_t start; |
| 3006 | ext4_fsblk_t len; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3007 | int hblock, blocksize; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3008 | ext4_fsblk_t sb_block; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3009 | unsigned long offset; |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 3010 | struct ext4_super_block *es; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3011 | struct block_device *bdev; |
| 3012 | |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3013 | BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); |
| 3014 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3015 | bdev = ext4_blkdev_get(j_dev); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3016 | if (bdev == NULL) |
| 3017 | return NULL; |
| 3018 | |
| 3019 | if (bd_claim(bdev, sb)) { |
| 3020 | printk(KERN_ERR |
Theodore Ts'o | abda141 | 2009-01-06 00:20:32 -0500 | [diff] [blame] | 3021 | "EXT4-fs: failed to claim external journal device.\n"); |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 3022 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3023 | return NULL; |
| 3024 | } |
| 3025 | |
| 3026 | blocksize = sb->s_blocksize; |
| 3027 | hblock = bdev_hardsect_size(bdev); |
| 3028 | if (blocksize < hblock) { |
| 3029 | printk(KERN_ERR |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3030 | "EXT4-fs: blocksize too small for journal device.\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3031 | goto out_bdev; |
| 3032 | } |
| 3033 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3034 | sb_block = EXT4_MIN_BLOCK_SIZE / blocksize; |
| 3035 | offset = EXT4_MIN_BLOCK_SIZE % blocksize; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3036 | set_blocksize(bdev, blocksize); |
| 3037 | if (!(bh = __bread(bdev, sb_block, blocksize))) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3038 | printk(KERN_ERR "EXT4-fs: couldn't read superblock of " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3039 | "external journal\n"); |
| 3040 | goto out_bdev; |
| 3041 | } |
| 3042 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3043 | es = (struct ext4_super_block *) (((char *)bh->b_data) + offset); |
| 3044 | if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) || |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3045 | !(le32_to_cpu(es->s_feature_incompat) & |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3046 | EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) { |
| 3047 | printk(KERN_ERR "EXT4-fs: external journal has " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3048 | "bad superblock\n"); |
| 3049 | brelse(bh); |
| 3050 | goto out_bdev; |
| 3051 | } |
| 3052 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3053 | if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { |
| 3054 | printk(KERN_ERR "EXT4-fs: journal UUID does not match\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3055 | brelse(bh); |
| 3056 | goto out_bdev; |
| 3057 | } |
| 3058 | |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 3059 | len = ext4_blocks_count(es); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3060 | start = sb_block + 1; |
| 3061 | brelse(bh); /* we're done with the superblock */ |
| 3062 | |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 3063 | journal = jbd2_journal_init_dev(bdev, sb->s_bdev, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3064 | start, len, blocksize); |
| 3065 | if (!journal) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3066 | printk(KERN_ERR "EXT4-fs: failed to create device journal\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3067 | goto out_bdev; |
| 3068 | } |
| 3069 | journal->j_private = sb; |
| 3070 | ll_rw_block(READ, 1, &journal->j_sb_buffer); |
| 3071 | wait_on_buffer(journal->j_sb_buffer); |
| 3072 | if (!buffer_uptodate(journal->j_sb_buffer)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3073 | printk(KERN_ERR "EXT4-fs: I/O error on journal device\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3074 | goto out_journal; |
| 3075 | } |
| 3076 | if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3077 | printk(KERN_ERR "EXT4-fs: External journal has more than one " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3078 | "user (unsupported) - %d\n", |
| 3079 | be32_to_cpu(journal->j_superblock->s_nr_users)); |
| 3080 | goto out_journal; |
| 3081 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3082 | EXT4_SB(sb)->journal_bdev = bdev; |
| 3083 | ext4_init_journal_params(sb, journal); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3084 | return journal; |
| 3085 | out_journal: |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 3086 | jbd2_journal_destroy(journal); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3087 | out_bdev: |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3088 | ext4_blkdev_put(bdev); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3089 | return NULL; |
| 3090 | } |
| 3091 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3092 | static int ext4_load_journal(struct super_block *sb, |
| 3093 | struct ext4_super_block *es, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3094 | unsigned long journal_devnum) |
| 3095 | { |
| 3096 | journal_t *journal; |
| 3097 | unsigned int journal_inum = le32_to_cpu(es->s_journal_inum); |
| 3098 | dev_t journal_dev; |
| 3099 | int err = 0; |
| 3100 | int really_read_only; |
| 3101 | |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3102 | BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); |
| 3103 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3104 | if (journal_devnum && |
| 3105 | journal_devnum != le32_to_cpu(es->s_journal_dev)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3106 | printk(KERN_INFO "EXT4-fs: external journal device major/minor " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3107 | "numbers have changed\n"); |
| 3108 | journal_dev = new_decode_dev(journal_devnum); |
| 3109 | } else |
| 3110 | journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev)); |
| 3111 | |
| 3112 | really_read_only = bdev_read_only(sb->s_bdev); |
| 3113 | |
| 3114 | /* |
| 3115 | * Are we loading a blank journal or performing recovery after a |
| 3116 | * crash? For recovery, we need to check in advance whether we |
| 3117 | * can get read-write access to the device. |
| 3118 | */ |
| 3119 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3120 | if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3121 | if (sb->s_flags & MS_RDONLY) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3122 | printk(KERN_INFO "EXT4-fs: INFO: recovery " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3123 | "required on readonly filesystem.\n"); |
| 3124 | if (really_read_only) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3125 | printk(KERN_ERR "EXT4-fs: write access " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3126 | "unavailable, cannot proceed.\n"); |
| 3127 | return -EROFS; |
| 3128 | } |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 3129 | printk(KERN_INFO "EXT4-fs: write access will " |
| 3130 | "be enabled during recovery.\n"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3131 | } |
| 3132 | } |
| 3133 | |
| 3134 | if (journal_inum && journal_dev) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3135 | printk(KERN_ERR "EXT4-fs: filesystem has both journal " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3136 | "and inode journals!\n"); |
| 3137 | return -EINVAL; |
| 3138 | } |
| 3139 | |
| 3140 | if (journal_inum) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3141 | if (!(journal = ext4_get_journal(sb, journal_inum))) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3142 | return -EINVAL; |
| 3143 | } else { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3144 | if (!(journal = ext4_get_dev_journal(sb, journal_dev))) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3145 | return -EINVAL; |
| 3146 | } |
| 3147 | |
Theodore Ts'o | 4776004 | 2008-09-08 23:00:52 -0400 | [diff] [blame] | 3148 | if (journal->j_flags & JBD2_BARRIER) |
| 3149 | printk(KERN_INFO "EXT4-fs: barriers enabled\n"); |
| 3150 | else |
| 3151 | printk(KERN_INFO "EXT4-fs: barriers disabled\n"); |
| 3152 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3153 | if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) { |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 3154 | err = jbd2_journal_update_format(journal); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3155 | if (err) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3156 | printk(KERN_ERR "EXT4-fs: error updating journal.\n"); |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 3157 | jbd2_journal_destroy(journal); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3158 | return err; |
| 3159 | } |
| 3160 | } |
| 3161 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3162 | if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 3163 | err = jbd2_journal_wipe(journal, !really_read_only); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3164 | if (!err) |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 3165 | err = jbd2_journal_load(journal); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3166 | |
| 3167 | if (err) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3168 | printk(KERN_ERR "EXT4-fs: error loading journal.\n"); |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 3169 | jbd2_journal_destroy(journal); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3170 | return err; |
| 3171 | } |
| 3172 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3173 | EXT4_SB(sb)->s_journal = journal; |
| 3174 | ext4_clear_journal_err(sb, es); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3175 | |
| 3176 | if (journal_devnum && |
| 3177 | journal_devnum != le32_to_cpu(es->s_journal_dev)) { |
| 3178 | es->s_journal_dev = cpu_to_le32(journal_devnum); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3179 | |
| 3180 | /* Make sure we flush the recovery flag to disk. */ |
Theodore Ts'o | e2d6705 | 2009-05-01 00:33:44 -0400 | [diff] [blame] | 3181 | ext4_commit_super(sb, 1); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | return 0; |
| 3185 | } |
| 3186 | |
Theodore Ts'o | e2d6705 | 2009-05-01 00:33:44 -0400 | [diff] [blame] | 3187 | static int ext4_commit_super(struct super_block *sb, int sync) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3188 | { |
Theodore Ts'o | e2d6705 | 2009-05-01 00:33:44 -0400 | [diff] [blame] | 3189 | struct ext4_super_block *es = EXT4_SB(sb)->s_es; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3190 | struct buffer_head *sbh = EXT4_SB(sb)->s_sbh; |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 3191 | int error = 0; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3192 | |
| 3193 | if (!sbh) |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 3194 | return error; |
Theodore Ts'o | 914258b | 2008-10-06 21:35:40 -0400 | [diff] [blame] | 3195 | if (buffer_write_io_error(sbh)) { |
| 3196 | /* |
| 3197 | * Oh, dear. A previous attempt to write the |
| 3198 | * superblock failed. This could happen because the |
| 3199 | * USB device was yanked out. Or it could happen to |
| 3200 | * be a transient write error and maybe the block will |
| 3201 | * be remapped. Nothing we can do but to retry the |
| 3202 | * write and hope for the best. |
| 3203 | */ |
Theodore Ts'o | abda141 | 2009-01-06 00:20:32 -0500 | [diff] [blame] | 3204 | printk(KERN_ERR "EXT4-fs: previous I/O error to " |
Theodore Ts'o | 914258b | 2008-10-06 21:35:40 -0400 | [diff] [blame] | 3205 | "superblock detected for %s.\n", sb->s_id); |
| 3206 | clear_buffer_write_io_error(sbh); |
| 3207 | set_buffer_uptodate(sbh); |
| 3208 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3209 | es->s_wtime = cpu_to_le32(get_seconds()); |
Theodore Ts'o | afc32f7 | 2009-02-28 19:39:58 -0500 | [diff] [blame] | 3210 | es->s_kbytes_written = |
| 3211 | cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + |
| 3212 | ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - |
| 3213 | EXT4_SB(sb)->s_sectors_written_start) >> 1)); |
Aneesh Kumar K.V | 5d1b1b3 | 2009-01-05 22:19:52 -0500 | [diff] [blame] | 3214 | ext4_free_blocks_count_set(es, percpu_counter_sum_positive( |
| 3215 | &EXT4_SB(sb)->s_freeblocks_counter)); |
| 3216 | es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive( |
| 3217 | &EXT4_SB(sb)->s_freeinodes_counter)); |
Theodore Ts'o | 7234ab2 | 2009-04-30 21:24:04 -0400 | [diff] [blame] | 3218 | sb->s_dirt = 0; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3219 | BUFFER_TRACE(sbh, "marking dirty"); |
| 3220 | mark_buffer_dirty(sbh); |
Theodore Ts'o | 914258b | 2008-10-06 21:35:40 -0400 | [diff] [blame] | 3221 | if (sync) { |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 3222 | error = sync_dirty_buffer(sbh); |
| 3223 | if (error) |
| 3224 | return error; |
| 3225 | |
| 3226 | error = buffer_write_io_error(sbh); |
| 3227 | if (error) { |
Theodore Ts'o | abda141 | 2009-01-06 00:20:32 -0500 | [diff] [blame] | 3228 | printk(KERN_ERR "EXT4-fs: I/O error while writing " |
Theodore Ts'o | 914258b | 2008-10-06 21:35:40 -0400 | [diff] [blame] | 3229 | "superblock for %s.\n", sb->s_id); |
| 3230 | clear_buffer_write_io_error(sbh); |
| 3231 | set_buffer_uptodate(sbh); |
| 3232 | } |
| 3233 | } |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 3234 | return error; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
| 3237 | |
| 3238 | /* |
| 3239 | * Have we just finished recovery? If so, and if we are mounting (or |
| 3240 | * remounting) the filesystem readonly, then we will end up with a |
| 3241 | * consistent fs on disk. Record that fact. |
| 3242 | */ |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 3243 | static void ext4_mark_recovery_complete(struct super_block *sb, |
| 3244 | struct ext4_super_block *es) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3245 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3246 | journal_t *journal = EXT4_SB(sb)->s_journal; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3247 | |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3248 | if (!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) { |
| 3249 | BUG_ON(journal != NULL); |
| 3250 | return; |
| 3251 | } |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 3252 | jbd2_journal_lock_updates(journal); |
Hidehiro Kawai | 7ffe1ea | 2008-10-10 20:29:21 -0400 | [diff] [blame] | 3253 | if (jbd2_journal_flush(journal) < 0) |
| 3254 | goto out; |
| 3255 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3256 | if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) && |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3257 | sb->s_flags & MS_RDONLY) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3258 | EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); |
Theodore Ts'o | e2d6705 | 2009-05-01 00:33:44 -0400 | [diff] [blame] | 3259 | ext4_commit_super(sb, 1); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3260 | } |
Hidehiro Kawai | 7ffe1ea | 2008-10-10 20:29:21 -0400 | [diff] [blame] | 3261 | |
| 3262 | out: |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 3263 | jbd2_journal_unlock_updates(journal); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | /* |
| 3267 | * If we are mounting (or read-write remounting) a filesystem whose journal |
| 3268 | * has recorded an error from a previous lifetime, move that error to the |
| 3269 | * main filesystem now. |
| 3270 | */ |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 3271 | static void ext4_clear_journal_err(struct super_block *sb, |
| 3272 | struct ext4_super_block *es) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3273 | { |
| 3274 | journal_t *journal; |
| 3275 | int j_errno; |
| 3276 | const char *errstr; |
| 3277 | |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3278 | BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); |
| 3279 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3280 | journal = EXT4_SB(sb)->s_journal; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3281 | |
| 3282 | /* |
| 3283 | * Now check for any error status which may have been recorded in the |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3284 | * journal by a prior ext4_error() or ext4_abort() |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3285 | */ |
| 3286 | |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 3287 | j_errno = jbd2_journal_errno(journal); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3288 | if (j_errno) { |
| 3289 | char nbuf[16]; |
| 3290 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3291 | errstr = ext4_decode_error(sb, j_errno, nbuf); |
Harvey Harrison | 46e665e | 2008-04-17 10:38:59 -0400 | [diff] [blame] | 3292 | ext4_warning(sb, __func__, "Filesystem error recorded " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3293 | "from previous mount: %s", errstr); |
Harvey Harrison | 46e665e | 2008-04-17 10:38:59 -0400 | [diff] [blame] | 3294 | ext4_warning(sb, __func__, "Marking fs in need of " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3295 | "filesystem check."); |
| 3296 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3297 | EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; |
| 3298 | es->s_state |= cpu_to_le16(EXT4_ERROR_FS); |
Theodore Ts'o | e2d6705 | 2009-05-01 00:33:44 -0400 | [diff] [blame] | 3299 | ext4_commit_super(sb, 1); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3300 | |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 3301 | jbd2_journal_clear_err(journal); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3302 | } |
| 3303 | } |
| 3304 | |
| 3305 | /* |
| 3306 | * Force the running and committing transactions to commit, |
| 3307 | * and wait on the commit. |
| 3308 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3309 | int ext4_force_commit(struct super_block *sb) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3310 | { |
| 3311 | journal_t *journal; |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3312 | int ret = 0; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3313 | |
| 3314 | if (sb->s_flags & MS_RDONLY) |
| 3315 | return 0; |
| 3316 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3317 | journal = EXT4_SB(sb)->s_journal; |
Theodore Ts'o | 7234ab2 | 2009-04-30 21:24:04 -0400 | [diff] [blame] | 3318 | if (journal) |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3319 | ret = ext4_journal_force_commit(journal); |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3320 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3321 | return ret; |
| 3322 | } |
| 3323 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 3324 | static void ext4_write_super(struct super_block *sb) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3325 | { |
Theodore Ts'o | 9ca9238 | 2009-05-01 12:52:25 -0400 | [diff] [blame] | 3326 | ext4_commit_super(sb, 1); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3327 | } |
| 3328 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3329 | static int ext4_sync_fs(struct super_block *sb, int wait) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3330 | { |
Theodore Ts'o | 14ce0cb | 2008-11-03 18:10:55 -0500 | [diff] [blame] | 3331 | int ret = 0; |
Jan Kara | 9eddacf | 2009-02-10 06:46:05 -0500 | [diff] [blame] | 3332 | tid_t target; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3333 | |
Theodore Ts'o | ede86cc | 2008-10-05 20:50:06 -0400 | [diff] [blame] | 3334 | trace_mark(ext4_sync_fs, "dev %s wait %d", sb->s_id, wait); |
Theodore Ts'o | 9ca9238 | 2009-05-01 12:52:25 -0400 | [diff] [blame] | 3335 | if (jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, &target)) { |
| 3336 | if (wait) |
| 3337 | jbd2_log_wait_commit(EXT4_SB(sb)->s_journal, target); |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3338 | } |
Theodore Ts'o | 14ce0cb | 2008-11-03 18:10:55 -0500 | [diff] [blame] | 3339 | return ret; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | /* |
| 3343 | * LVM calls this function before a (read-only) snapshot is created. This |
| 3344 | * gives us a chance to flush the journal completely and mark the fs clean. |
| 3345 | */ |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 3346 | static int ext4_freeze(struct super_block *sb) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3347 | { |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 3348 | int error = 0; |
| 3349 | journal_t *journal; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3350 | |
Theodore Ts'o | 9ca9238 | 2009-05-01 12:52:25 -0400 | [diff] [blame] | 3351 | if (sb->s_flags & MS_RDONLY) |
| 3352 | return 0; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3353 | |
Theodore Ts'o | 9ca9238 | 2009-05-01 12:52:25 -0400 | [diff] [blame] | 3354 | journal = EXT4_SB(sb)->s_journal; |
Hidehiro Kawai | 7ffe1ea | 2008-10-10 20:29:21 -0400 | [diff] [blame] | 3355 | |
Theodore Ts'o | 9ca9238 | 2009-05-01 12:52:25 -0400 | [diff] [blame] | 3356 | /* Now we set up the journal barrier. */ |
| 3357 | jbd2_journal_lock_updates(journal); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3358 | |
Theodore Ts'o | 9ca9238 | 2009-05-01 12:52:25 -0400 | [diff] [blame] | 3359 | /* |
| 3360 | * Don't clear the needs_recovery flag if we failed to flush |
| 3361 | * the journal. |
| 3362 | */ |
| 3363 | error = jbd2_journal_flush(journal); |
| 3364 | if (error < 0) { |
| 3365 | out: |
| 3366 | jbd2_journal_unlock_updates(journal); |
| 3367 | return error; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3368 | } |
Theodore Ts'o | 9ca9238 | 2009-05-01 12:52:25 -0400 | [diff] [blame] | 3369 | |
| 3370 | /* Journal blocked and flushed, clear needs_recovery flag. */ |
| 3371 | EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); |
| 3372 | error = ext4_commit_super(sb, 1); |
| 3373 | if (error) |
| 3374 | goto out; |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 3375 | return 0; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | /* |
| 3379 | * Called by LVM after the snapshot is done. We need to reset the RECOVER |
| 3380 | * flag here, even though the filesystem is not technically dirty yet. |
| 3381 | */ |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 3382 | static int ext4_unfreeze(struct super_block *sb) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3383 | { |
Theodore Ts'o | 9ca9238 | 2009-05-01 12:52:25 -0400 | [diff] [blame] | 3384 | if (sb->s_flags & MS_RDONLY) |
| 3385 | return 0; |
| 3386 | |
| 3387 | lock_super(sb); |
| 3388 | /* Reset the needs_recovery flag before the fs is unlocked. */ |
| 3389 | EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); |
| 3390 | ext4_commit_super(sb, 1); |
| 3391 | unlock_super(sb); |
| 3392 | jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 3393 | return 0; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3394 | } |
| 3395 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 3396 | static int ext4_remount(struct super_block *sb, int *flags, char *data) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3397 | { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 3398 | struct ext4_super_block *es; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3399 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
| 3400 | ext4_fsblk_t n_blocks_count = 0; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3401 | unsigned long old_sb_flags; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3402 | struct ext4_mount_options old_opts; |
Theodore Ts'o | 8a26646 | 2008-07-26 14:34:21 -0400 | [diff] [blame] | 3403 | ext4_group_t g; |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 3404 | unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3405 | int err; |
| 3406 | #ifdef CONFIG_QUOTA |
| 3407 | int i; |
| 3408 | #endif |
| 3409 | |
| 3410 | /* Store the original options */ |
| 3411 | old_sb_flags = sb->s_flags; |
| 3412 | old_opts.s_mount_opt = sbi->s_mount_opt; |
| 3413 | old_opts.s_resuid = sbi->s_resuid; |
| 3414 | old_opts.s_resgid = sbi->s_resgid; |
| 3415 | old_opts.s_commit_interval = sbi->s_commit_interval; |
Theodore Ts'o | 3077384 | 2009-01-03 20:27:38 -0500 | [diff] [blame] | 3416 | old_opts.s_min_batch_time = sbi->s_min_batch_time; |
| 3417 | old_opts.s_max_batch_time = sbi->s_max_batch_time; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3418 | #ifdef CONFIG_QUOTA |
| 3419 | old_opts.s_jquota_fmt = sbi->s_jquota_fmt; |
| 3420 | for (i = 0; i < MAXQUOTAS; i++) |
| 3421 | old_opts.s_qf_names[i] = sbi->s_qf_names[i]; |
| 3422 | #endif |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 3423 | if (sbi->s_journal && sbi->s_journal->j_task->io_context) |
| 3424 | journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3425 | |
| 3426 | /* |
| 3427 | * Allow the "check" option to be passed as a remount option. |
| 3428 | */ |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 3429 | if (!parse_options(data, sb, NULL, &journal_ioprio, |
| 3430 | &n_blocks_count, 1)) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3431 | err = -EINVAL; |
| 3432 | goto restore_opts; |
| 3433 | } |
| 3434 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3435 | if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) |
Harvey Harrison | 46e665e | 2008-04-17 10:38:59 -0400 | [diff] [blame] | 3436 | ext4_abort(sb, __func__, "Abort forced by user"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3437 | |
| 3438 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3439 | ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3440 | |
| 3441 | es = sbi->s_es; |
| 3442 | |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 3443 | if (sbi->s_journal) { |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3444 | ext4_init_journal_params(sb, sbi->s_journal); |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 3445 | set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); |
| 3446 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3447 | |
| 3448 | if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) || |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 3449 | n_blocks_count > ext4_blocks_count(es)) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3450 | if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3451 | err = -EROFS; |
| 3452 | goto restore_opts; |
| 3453 | } |
| 3454 | |
| 3455 | if (*flags & MS_RDONLY) { |
| 3456 | /* |
| 3457 | * First of all, the unconditional stuff we have to do |
| 3458 | * to disable replay of the journal when we next remount |
| 3459 | */ |
| 3460 | sb->s_flags |= MS_RDONLY; |
| 3461 | |
| 3462 | /* |
| 3463 | * OK, test if we are remounting a valid rw partition |
| 3464 | * readonly, and if so set the rdonly flag and then |
| 3465 | * mark the partition as valid again. |
| 3466 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3467 | if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) && |
| 3468 | (sbi->s_mount_state & EXT4_VALID_FS)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3469 | es->s_state = cpu_to_le16(sbi->s_mount_state); |
| 3470 | |
Theodore Ts'o | a63c9eb | 2009-05-01 01:59:42 -0400 | [diff] [blame] | 3471 | if (sbi->s_journal) |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3472 | ext4_mark_recovery_complete(sb, es); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3473 | } else { |
Aneesh Kumar K.V | 3a06d77 | 2008-11-22 15:04:59 -0500 | [diff] [blame] | 3474 | int ret; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3475 | if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb, |
| 3476 | ~EXT4_FEATURE_RO_COMPAT_SUPP))) { |
| 3477 | printk(KERN_WARNING "EXT4-fs: %s: couldn't " |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3478 | "remount RDWR because of unsupported " |
Aneesh Kumar K.V | 3a06d77 | 2008-11-22 15:04:59 -0500 | [diff] [blame] | 3479 | "optional features (%x).\n", sb->s_id, |
| 3480 | (le32_to_cpu(sbi->s_es->s_feature_ro_compat) & |
| 3481 | ~EXT4_FEATURE_RO_COMPAT_SUPP)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3482 | err = -EROFS; |
| 3483 | goto restore_opts; |
| 3484 | } |
Eric Sandeen | ead6596 | 2007-02-10 01:46:08 -0800 | [diff] [blame] | 3485 | |
| 3486 | /* |
Theodore Ts'o | 8a26646 | 2008-07-26 14:34:21 -0400 | [diff] [blame] | 3487 | * Make sure the group descriptor checksums |
| 3488 | * are sane. If they aren't, refuse to |
| 3489 | * remount r/w. |
| 3490 | */ |
| 3491 | for (g = 0; g < sbi->s_groups_count; g++) { |
| 3492 | struct ext4_group_desc *gdp = |
| 3493 | ext4_get_group_desc(sb, g, NULL); |
| 3494 | |
| 3495 | if (!ext4_group_desc_csum_verify(sbi, g, gdp)) { |
| 3496 | printk(KERN_ERR |
| 3497 | "EXT4-fs: ext4_remount: " |
Theodore Ts'o | a9df9a4 | 2009-01-05 22:18:16 -0500 | [diff] [blame] | 3498 | "Checksum for group %u failed (%u!=%u)\n", |
Theodore Ts'o | 8a26646 | 2008-07-26 14:34:21 -0400 | [diff] [blame] | 3499 | g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)), |
| 3500 | le16_to_cpu(gdp->bg_checksum)); |
| 3501 | err = -EINVAL; |
| 3502 | goto restore_opts; |
| 3503 | } |
| 3504 | } |
| 3505 | |
| 3506 | /* |
Eric Sandeen | ead6596 | 2007-02-10 01:46:08 -0800 | [diff] [blame] | 3507 | * If we have an unprocessed orphan list hanging |
| 3508 | * around from a previously readonly bdev mount, |
| 3509 | * require a full umount/remount for now. |
| 3510 | */ |
| 3511 | if (es->s_last_orphan) { |
| 3512 | printk(KERN_WARNING "EXT4-fs: %s: couldn't " |
| 3513 | "remount RDWR because of unprocessed " |
| 3514 | "orphan inode list. Please " |
| 3515 | "umount/remount instead.\n", |
| 3516 | sb->s_id); |
| 3517 | err = -EINVAL; |
| 3518 | goto restore_opts; |
| 3519 | } |
| 3520 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3521 | /* |
| 3522 | * Mounting a RDONLY partition read-write, so reread |
| 3523 | * and store the current valid flag. (It may have |
| 3524 | * been changed by e2fsck since we originally mounted |
| 3525 | * the partition.) |
| 3526 | */ |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3527 | if (sbi->s_journal) |
| 3528 | ext4_clear_journal_err(sb, es); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3529 | sbi->s_mount_state = le16_to_cpu(es->s_state); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3530 | if ((err = ext4_group_extend(sb, es, n_blocks_count))) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3531 | goto restore_opts; |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 3532 | if (!ext4_setup_super(sb, es, 0)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3533 | sb->s_flags &= ~MS_RDONLY; |
| 3534 | } |
| 3535 | } |
Theodore Ts'o | 6fd058f | 2009-05-17 15:38:01 -0400 | [diff] [blame] | 3536 | ext4_setup_system_zone(sb); |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3537 | if (sbi->s_journal == NULL) |
Theodore Ts'o | e2d6705 | 2009-05-01 00:33:44 -0400 | [diff] [blame] | 3538 | ext4_commit_super(sb, 1); |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3539 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3540 | #ifdef CONFIG_QUOTA |
| 3541 | /* Release old quota file names */ |
| 3542 | for (i = 0; i < MAXQUOTAS; i++) |
| 3543 | if (old_opts.s_qf_names[i] && |
| 3544 | old_opts.s_qf_names[i] != sbi->s_qf_names[i]) |
| 3545 | kfree(old_opts.s_qf_names[i]); |
| 3546 | #endif |
| 3547 | return 0; |
| 3548 | restore_opts: |
| 3549 | sb->s_flags = old_sb_flags; |
| 3550 | sbi->s_mount_opt = old_opts.s_mount_opt; |
| 3551 | sbi->s_resuid = old_opts.s_resuid; |
| 3552 | sbi->s_resgid = old_opts.s_resgid; |
| 3553 | sbi->s_commit_interval = old_opts.s_commit_interval; |
Theodore Ts'o | 3077384 | 2009-01-03 20:27:38 -0500 | [diff] [blame] | 3554 | sbi->s_min_batch_time = old_opts.s_min_batch_time; |
| 3555 | sbi->s_max_batch_time = old_opts.s_max_batch_time; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3556 | #ifdef CONFIG_QUOTA |
| 3557 | sbi->s_jquota_fmt = old_opts.s_jquota_fmt; |
| 3558 | for (i = 0; i < MAXQUOTAS; i++) { |
| 3559 | if (sbi->s_qf_names[i] && |
| 3560 | old_opts.s_qf_names[i] != sbi->s_qf_names[i]) |
| 3561 | kfree(sbi->s_qf_names[i]); |
| 3562 | sbi->s_qf_names[i] = old_opts.s_qf_names[i]; |
| 3563 | } |
| 3564 | #endif |
| 3565 | return err; |
| 3566 | } |
| 3567 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 3568 | static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3569 | { |
| 3570 | struct super_block *sb = dentry->d_sb; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3571 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
| 3572 | struct ext4_super_block *es = sbi->s_es; |
Pekka Enberg | 960cc39 | 2006-12-06 20:35:29 -0800 | [diff] [blame] | 3573 | u64 fsid; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3574 | |
Badari Pulavarty | 5e70030 | 2007-07-15 23:42:00 -0700 | [diff] [blame] | 3575 | if (test_opt(sb, MINIX_DF)) { |
| 3576 | sbi->s_overhead_last = 0; |
Aneesh Kumar K.V | 6bc9fef | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 3577 | } else if (sbi->s_blocks_last != ext4_blocks_count(es)) { |
Theodore Ts'o | 8df9675 | 2009-05-01 08:50:38 -0400 | [diff] [blame] | 3578 | ext4_group_t i, ngroups = ext4_get_groups_count(sb); |
Badari Pulavarty | 5e70030 | 2007-07-15 23:42:00 -0700 | [diff] [blame] | 3579 | ext4_fsblk_t overhead = 0; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3580 | |
| 3581 | /* |
Badari Pulavarty | 5e70030 | 2007-07-15 23:42:00 -0700 | [diff] [blame] | 3582 | * Compute the overhead (FS structures). This is constant |
| 3583 | * for a given filesystem unless the number of block groups |
| 3584 | * changes so we cache the previous value until it does. |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3585 | */ |
| 3586 | |
| 3587 | /* |
| 3588 | * All of the blocks before first_data_block are |
| 3589 | * overhead |
| 3590 | */ |
| 3591 | overhead = le32_to_cpu(es->s_first_data_block); |
| 3592 | |
| 3593 | /* |
| 3594 | * Add the overhead attributed to the superblock and |
| 3595 | * block group descriptors. If the sparse superblocks |
| 3596 | * feature is turned on, then not all groups have this. |
| 3597 | */ |
| 3598 | for (i = 0; i < ngroups; i++) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3599 | overhead += ext4_bg_has_super(sb, i) + |
| 3600 | ext4_bg_num_gdb(sb, i); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3601 | cond_resched(); |
| 3602 | } |
| 3603 | |
| 3604 | /* |
| 3605 | * Every block group has an inode bitmap, a block |
| 3606 | * bitmap, and an inode table. |
| 3607 | */ |
Badari Pulavarty | 5e70030 | 2007-07-15 23:42:00 -0700 | [diff] [blame] | 3608 | overhead += ngroups * (2 + sbi->s_itb_per_group); |
| 3609 | sbi->s_overhead_last = overhead; |
| 3610 | smp_wmb(); |
Aneesh Kumar K.V | 6bc9fef | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 3611 | sbi->s_blocks_last = ext4_blocks_count(es); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3614 | buf->f_type = EXT4_SUPER_MAGIC; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3615 | buf->f_bsize = sb->s_blocksize; |
Badari Pulavarty | 5e70030 | 2007-07-15 23:42:00 -0700 | [diff] [blame] | 3616 | buf->f_blocks = ext4_blocks_count(es) - sbi->s_overhead_last; |
Aneesh Kumar K.V | 6bc6e63 | 2008-10-10 09:39:00 -0400 | [diff] [blame] | 3617 | buf->f_bfree = percpu_counter_sum_positive(&sbi->s_freeblocks_counter) - |
| 3618 | percpu_counter_sum_positive(&sbi->s_dirtyblocks_counter); |
Aneesh Kumar K.V | 308ba3e | 2007-10-16 18:38:25 -0400 | [diff] [blame] | 3619 | ext4_free_blocks_count_set(es, buf->f_bfree); |
Laurent Vivier | bd81d8e | 2006-10-11 01:21:10 -0700 | [diff] [blame] | 3620 | buf->f_bavail = buf->f_bfree - ext4_r_blocks_count(es); |
| 3621 | if (buf->f_bfree < ext4_r_blocks_count(es)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3622 | buf->f_bavail = 0; |
| 3623 | buf->f_files = le32_to_cpu(es->s_inodes_count); |
Peter Zijlstra | 52d9f3b | 2007-10-16 23:25:44 -0700 | [diff] [blame] | 3624 | buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter); |
Badari Pulavarty | 5e70030 | 2007-07-15 23:42:00 -0700 | [diff] [blame] | 3625 | es->s_free_inodes_count = cpu_to_le32(buf->f_ffree); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3626 | buf->f_namelen = EXT4_NAME_LEN; |
Pekka Enberg | 960cc39 | 2006-12-06 20:35:29 -0800 | [diff] [blame] | 3627 | fsid = le64_to_cpup((void *)es->s_uuid) ^ |
| 3628 | le64_to_cpup((void *)es->s_uuid + sizeof(u64)); |
| 3629 | buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL; |
| 3630 | buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3631 | return 0; |
| 3632 | } |
| 3633 | |
| 3634 | /* Helper function for writing quotas on sync - we need to start transaction before quota file |
| 3635 | * is locked for write. Otherwise the are possible deadlocks: |
| 3636 | * Process 1 Process 2 |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3637 | * ext4_create() quota_sync() |
Jan Kara | a269eb1 | 2009-01-26 17:04:39 +0100 | [diff] [blame] | 3638 | * jbd2_journal_start() write_dquot() |
| 3639 | * vfs_dq_init() down(dqio_mutex) |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 3640 | * down(dqio_mutex) jbd2_journal_start() |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3641 | * |
| 3642 | */ |
| 3643 | |
| 3644 | #ifdef CONFIG_QUOTA |
| 3645 | |
| 3646 | static inline struct inode *dquot_to_inode(struct dquot *dquot) |
| 3647 | { |
| 3648 | return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type]; |
| 3649 | } |
| 3650 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3651 | static int ext4_write_dquot(struct dquot *dquot) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3652 | { |
| 3653 | int ret, err; |
| 3654 | handle_t *handle; |
| 3655 | struct inode *inode; |
| 3656 | |
| 3657 | inode = dquot_to_inode(dquot); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3658 | handle = ext4_journal_start(inode, |
| 3659 | EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3660 | if (IS_ERR(handle)) |
| 3661 | return PTR_ERR(handle); |
| 3662 | ret = dquot_commit(dquot); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3663 | err = ext4_journal_stop(handle); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3664 | if (!ret) |
| 3665 | ret = err; |
| 3666 | return ret; |
| 3667 | } |
| 3668 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3669 | static int ext4_acquire_dquot(struct dquot *dquot) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3670 | { |
| 3671 | int ret, err; |
| 3672 | handle_t *handle; |
| 3673 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3674 | handle = ext4_journal_start(dquot_to_inode(dquot), |
| 3675 | EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3676 | if (IS_ERR(handle)) |
| 3677 | return PTR_ERR(handle); |
| 3678 | ret = dquot_acquire(dquot); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3679 | err = ext4_journal_stop(handle); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3680 | if (!ret) |
| 3681 | ret = err; |
| 3682 | return ret; |
| 3683 | } |
| 3684 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3685 | static int ext4_release_dquot(struct dquot *dquot) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3686 | { |
| 3687 | int ret, err; |
| 3688 | handle_t *handle; |
| 3689 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3690 | handle = ext4_journal_start(dquot_to_inode(dquot), |
| 3691 | EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb)); |
Jan Kara | 9c3013e | 2007-09-11 15:23:29 -0700 | [diff] [blame] | 3692 | if (IS_ERR(handle)) { |
| 3693 | /* Release dquot anyway to avoid endless cycle in dqput() */ |
| 3694 | dquot_release(dquot); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3695 | return PTR_ERR(handle); |
Jan Kara | 9c3013e | 2007-09-11 15:23:29 -0700 | [diff] [blame] | 3696 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3697 | ret = dquot_release(dquot); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3698 | err = ext4_journal_stop(handle); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3699 | if (!ret) |
| 3700 | ret = err; |
| 3701 | return ret; |
| 3702 | } |
| 3703 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3704 | static int ext4_mark_dquot_dirty(struct dquot *dquot) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3705 | { |
Jan Kara | 2c8be6b | 2008-05-13 21:27:55 -0400 | [diff] [blame] | 3706 | /* Are we journaling quotas? */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3707 | if (EXT4_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] || |
| 3708 | EXT4_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3709 | dquot_mark_dquot_dirty(dquot); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3710 | return ext4_write_dquot(dquot); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3711 | } else { |
| 3712 | return dquot_mark_dquot_dirty(dquot); |
| 3713 | } |
| 3714 | } |
| 3715 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3716 | static int ext4_write_info(struct super_block *sb, int type) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3717 | { |
| 3718 | int ret, err; |
| 3719 | handle_t *handle; |
| 3720 | |
| 3721 | /* Data block + inode block */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3722 | handle = ext4_journal_start(sb->s_root->d_inode, 2); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3723 | if (IS_ERR(handle)) |
| 3724 | return PTR_ERR(handle); |
| 3725 | ret = dquot_commit_info(sb, type); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3726 | err = ext4_journal_stop(handle); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3727 | if (!ret) |
| 3728 | ret = err; |
| 3729 | return ret; |
| 3730 | } |
| 3731 | |
| 3732 | /* |
| 3733 | * Turn on quotas during mount time - we need to find |
| 3734 | * the quota file and such... |
| 3735 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3736 | static int ext4_quota_on_mount(struct super_block *sb, int type) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3737 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3738 | return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type], |
| 3739 | EXT4_SB(sb)->s_jquota_fmt, type); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3740 | } |
| 3741 | |
| 3742 | /* |
| 3743 | * Standard function to be called on quota_on |
| 3744 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3745 | static int ext4_quota_on(struct super_block *sb, int type, int format_id, |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 3746 | char *name, int remount) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3747 | { |
| 3748 | int err; |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 3749 | struct path path; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3750 | |
| 3751 | if (!test_opt(sb, QUOTA)) |
| 3752 | return -EINVAL; |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 3753 | /* When remounting, no checks are needed and in fact, name is NULL */ |
Jan Kara | 0623543 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 3754 | if (remount) |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 3755 | return vfs_quota_on(sb, type, format_id, name, remount); |
Jan Kara | 0623543 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 3756 | |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 3757 | err = kern_path(name, LOOKUP_FOLLOW, &path); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3758 | if (err) |
| 3759 | return err; |
Jan Kara | 0623543 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 3760 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3761 | /* Quotafile not on the same filesystem? */ |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 3762 | if (path.mnt->mnt_sb != sb) { |
| 3763 | path_put(&path); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3764 | return -EXDEV; |
| 3765 | } |
Jan Kara | 0623543 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 3766 | /* Journaling quota? */ |
| 3767 | if (EXT4_SB(sb)->s_qf_names[type]) { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 3768 | /* Quotafile not in fs root? */ |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 3769 | if (path.dentry->d_parent != sb->s_root) |
Jan Kara | 0623543 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 3770 | printk(KERN_WARNING |
| 3771 | "EXT4-fs: Quota file not on filesystem root. " |
| 3772 | "Journaled quota will not work.\n"); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 3773 | } |
Jan Kara | 0623543 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 3774 | |
| 3775 | /* |
| 3776 | * When we journal data on quota file, we have to flush journal to see |
| 3777 | * all updates to the file when we bypass pagecache... |
| 3778 | */ |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3779 | if (EXT4_SB(sb)->s_journal && |
| 3780 | ext4_should_journal_data(path.dentry->d_inode)) { |
Jan Kara | 0623543 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 3781 | /* |
| 3782 | * We don't need to lock updates but journal_flush() could |
| 3783 | * otherwise be livelocked... |
| 3784 | */ |
| 3785 | jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); |
Hidehiro Kawai | 7ffe1ea | 2008-10-10 20:29:21 -0400 | [diff] [blame] | 3786 | err = jbd2_journal_flush(EXT4_SB(sb)->s_journal); |
Jan Kara | 0623543 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 3787 | jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); |
Hidehiro Kawai | 7ffe1ea | 2008-10-10 20:29:21 -0400 | [diff] [blame] | 3788 | if (err) { |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 3789 | path_put(&path); |
Hidehiro Kawai | 7ffe1ea | 2008-10-10 20:29:21 -0400 | [diff] [blame] | 3790 | return err; |
| 3791 | } |
Jan Kara | 0623543 | 2008-05-13 19:11:51 -0400 | [diff] [blame] | 3792 | } |
| 3793 | |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 3794 | err = vfs_quota_on_path(sb, type, format_id, &path); |
| 3795 | path_put(&path); |
Al Viro | 77e69da | 2008-08-01 04:29:18 -0400 | [diff] [blame] | 3796 | return err; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | /* Read data from quotafile - avoid pagecache and such because we cannot afford |
| 3800 | * acquiring the locks... As quota files are never truncated and quota code |
| 3801 | * itself serializes the operations (and noone else should touch the files) |
| 3802 | * we don't have to be afraid of races */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3803 | static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3804 | size_t len, loff_t off) |
| 3805 | { |
| 3806 | struct inode *inode = sb_dqopt(sb)->files[type]; |
Aneesh Kumar K.V | 725d26d | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 3807 | ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3808 | int err = 0; |
| 3809 | int offset = off & (sb->s_blocksize - 1); |
| 3810 | int tocopy; |
| 3811 | size_t toread; |
| 3812 | struct buffer_head *bh; |
| 3813 | loff_t i_size = i_size_read(inode); |
| 3814 | |
| 3815 | if (off > i_size) |
| 3816 | return 0; |
| 3817 | if (off+len > i_size) |
| 3818 | len = i_size-off; |
| 3819 | toread = len; |
| 3820 | while (toread > 0) { |
| 3821 | tocopy = sb->s_blocksize - offset < toread ? |
| 3822 | sb->s_blocksize - offset : toread; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3823 | bh = ext4_bread(NULL, inode, blk, 0, &err); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3824 | if (err) |
| 3825 | return err; |
| 3826 | if (!bh) /* A hole? */ |
| 3827 | memset(data, 0, tocopy); |
| 3828 | else |
| 3829 | memcpy(data, bh->b_data+offset, tocopy); |
| 3830 | brelse(bh); |
| 3831 | offset = 0; |
| 3832 | toread -= tocopy; |
| 3833 | data += tocopy; |
| 3834 | blk++; |
| 3835 | } |
| 3836 | return len; |
| 3837 | } |
| 3838 | |
| 3839 | /* Write to quotafile (we know the transaction is already started and has |
| 3840 | * enough credits) */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3841 | static ssize_t ext4_quota_write(struct super_block *sb, int type, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3842 | const char *data, size_t len, loff_t off) |
| 3843 | { |
| 3844 | struct inode *inode = sb_dqopt(sb)->files[type]; |
Aneesh Kumar K.V | 725d26d | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 3845 | ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3846 | int err = 0; |
| 3847 | int offset = off & (sb->s_blocksize - 1); |
| 3848 | int tocopy; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3849 | int journal_quota = EXT4_SB(sb)->s_qf_names[type] != NULL; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3850 | size_t towrite = len; |
| 3851 | struct buffer_head *bh; |
| 3852 | handle_t *handle = journal_current_handle(); |
| 3853 | |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3854 | if (EXT4_SB(sb)->s_journal && !handle) { |
Theodore Ts'o | e5f8eab | 2008-09-08 22:25:04 -0400 | [diff] [blame] | 3855 | printk(KERN_WARNING "EXT4-fs: Quota write (off=%llu, len=%llu)" |
Jan Kara | 9c3013e | 2007-09-11 15:23:29 -0700 | [diff] [blame] | 3856 | " cancelled because transaction is not started.\n", |
| 3857 | (unsigned long long)off, (unsigned long long)len); |
| 3858 | return -EIO; |
| 3859 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3860 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); |
| 3861 | while (towrite > 0) { |
| 3862 | tocopy = sb->s_blocksize - offset < towrite ? |
| 3863 | sb->s_blocksize - offset : towrite; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3864 | bh = ext4_bread(handle, inode, blk, 1, &err); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3865 | if (!bh) |
| 3866 | goto out; |
| 3867 | if (journal_quota) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3868 | err = ext4_journal_get_write_access(handle, bh); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3869 | if (err) { |
| 3870 | brelse(bh); |
| 3871 | goto out; |
| 3872 | } |
| 3873 | } |
| 3874 | lock_buffer(bh); |
| 3875 | memcpy(bh->b_data+offset, data, tocopy); |
| 3876 | flush_dcache_page(bh->b_page); |
| 3877 | unlock_buffer(bh); |
| 3878 | if (journal_quota) |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 3879 | err = ext4_handle_dirty_metadata(handle, NULL, bh); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3880 | else { |
| 3881 | /* Always do at least ordered writes for quotas */ |
Jan Kara | 678aaf4 | 2008-07-11 19:27:31 -0400 | [diff] [blame] | 3882 | err = ext4_jbd2_file_inode(handle, inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3883 | mark_buffer_dirty(bh); |
| 3884 | } |
| 3885 | brelse(bh); |
| 3886 | if (err) |
| 3887 | goto out; |
| 3888 | offset = 0; |
| 3889 | towrite -= tocopy; |
| 3890 | data += tocopy; |
| 3891 | blk++; |
| 3892 | } |
| 3893 | out: |
Jan Kara | 4d04e4f | 2008-07-04 09:59:34 -0700 | [diff] [blame] | 3894 | if (len == towrite) { |
| 3895 | mutex_unlock(&inode->i_mutex); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3896 | return err; |
Jan Kara | 4d04e4f | 2008-07-04 09:59:34 -0700 | [diff] [blame] | 3897 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3898 | if (inode->i_size < off+len-towrite) { |
| 3899 | i_size_write(inode, off+len-towrite); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3900 | EXT4_I(inode)->i_disksize = inode->i_size; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3901 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3902 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3903 | ext4_mark_inode_dirty(handle, inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3904 | mutex_unlock(&inode->i_mutex); |
| 3905 | return len - towrite; |
| 3906 | } |
| 3907 | |
| 3908 | #endif |
| 3909 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3910 | static int ext4_get_sb(struct file_system_type *fs_type, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3911 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) |
| 3912 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3913 | return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3914 | } |
| 3915 | |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 3916 | static struct file_system_type ext4_fs_type = { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3917 | .owner = THIS_MODULE, |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 3918 | .name = "ext4", |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3919 | .get_sb = ext4_get_sb, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3920 | .kill_sb = kill_block_super, |
| 3921 | .fs_flags = FS_REQUIRES_DEV, |
| 3922 | }; |
| 3923 | |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 3924 | #ifdef CONFIG_EXT4DEV_COMPAT |
| 3925 | static int ext4dev_get_sb(struct file_system_type *fs_type, |
| 3926 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) |
| 3927 | { |
| 3928 | printk(KERN_WARNING "EXT4-fs: Update your userspace programs " |
| 3929 | "to mount using ext4\n"); |
| 3930 | printk(KERN_WARNING "EXT4-fs: ext4dev backwards compatibility " |
| 3931 | "will go away by 2.6.31\n"); |
| 3932 | return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt); |
| 3933 | } |
| 3934 | |
| 3935 | static struct file_system_type ext4dev_fs_type = { |
| 3936 | .owner = THIS_MODULE, |
| 3937 | .name = "ext4dev", |
| 3938 | .get_sb = ext4dev_get_sb, |
| 3939 | .kill_sb = kill_block_super, |
| 3940 | .fs_flags = FS_REQUIRES_DEV, |
| 3941 | }; |
| 3942 | MODULE_ALIAS("ext4dev"); |
| 3943 | #endif |
| 3944 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3945 | static int __init init_ext4_fs(void) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3946 | { |
Alex Tomas | c9de560 | 2008-01-29 00:19:52 -0500 | [diff] [blame] | 3947 | int err; |
| 3948 | |
Theodore Ts'o | 6fd058f | 2009-05-17 15:38:01 -0400 | [diff] [blame] | 3949 | err = init_ext4_system_zone(); |
| 3950 | if (err) |
| 3951 | return err; |
Theodore Ts'o | 3197ebd | 2009-03-31 09:10:09 -0400 | [diff] [blame] | 3952 | ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj); |
| 3953 | if (!ext4_kset) |
Theodore Ts'o | 6fd058f | 2009-05-17 15:38:01 -0400 | [diff] [blame] | 3954 | goto out4; |
Theodore Ts'o | 9f6200b | 2008-09-23 09:18:24 -0400 | [diff] [blame] | 3955 | ext4_proc_root = proc_mkdir("fs/ext4", NULL); |
Alex Tomas | c9de560 | 2008-01-29 00:19:52 -0500 | [diff] [blame] | 3956 | err = init_ext4_mballoc(); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3957 | if (err) |
Theodore Ts'o | 6fd058f | 2009-05-17 15:38:01 -0400 | [diff] [blame] | 3958 | goto out3; |
Alex Tomas | c9de560 | 2008-01-29 00:19:52 -0500 | [diff] [blame] | 3959 | |
| 3960 | err = init_ext4_xattr(); |
| 3961 | if (err) |
| 3962 | goto out2; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3963 | err = init_inodecache(); |
| 3964 | if (err) |
| 3965 | goto out1; |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 3966 | err = register_filesystem(&ext4_fs_type); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3967 | if (err) |
| 3968 | goto out; |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 3969 | #ifdef CONFIG_EXT4DEV_COMPAT |
| 3970 | err = register_filesystem(&ext4dev_fs_type); |
| 3971 | if (err) { |
| 3972 | unregister_filesystem(&ext4_fs_type); |
| 3973 | goto out; |
| 3974 | } |
| 3975 | #endif |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3976 | return 0; |
| 3977 | out: |
| 3978 | destroy_inodecache(); |
| 3979 | out1: |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3980 | exit_ext4_xattr(); |
Alex Tomas | c9de560 | 2008-01-29 00:19:52 -0500 | [diff] [blame] | 3981 | out2: |
| 3982 | exit_ext4_mballoc(); |
Theodore Ts'o | 6fd058f | 2009-05-17 15:38:01 -0400 | [diff] [blame] | 3983 | out3: |
| 3984 | remove_proc_entry("fs/ext4", NULL); |
| 3985 | kset_unregister(ext4_kset); |
| 3986 | out4: |
| 3987 | exit_ext4_system_zone(); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3988 | return err; |
| 3989 | } |
| 3990 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3991 | static void __exit exit_ext4_fs(void) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3992 | { |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 3993 | unregister_filesystem(&ext4_fs_type); |
| 3994 | #ifdef CONFIG_EXT4DEV_COMPAT |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3995 | unregister_filesystem(&ext4dev_fs_type); |
Theodore Ts'o | 03010a3 | 2008-10-10 20:02:48 -0400 | [diff] [blame] | 3996 | #endif |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3997 | destroy_inodecache(); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3998 | exit_ext4_xattr(); |
Alex Tomas | c9de560 | 2008-01-29 00:19:52 -0500 | [diff] [blame] | 3999 | exit_ext4_mballoc(); |
Theodore Ts'o | 9f6200b | 2008-09-23 09:18:24 -0400 | [diff] [blame] | 4000 | remove_proc_entry("fs/ext4", NULL); |
Theodore Ts'o | 3197ebd | 2009-03-31 09:10:09 -0400 | [diff] [blame] | 4001 | kset_unregister(ext4_kset); |
Theodore Ts'o | 6fd058f | 2009-05-17 15:38:01 -0400 | [diff] [blame] | 4002 | exit_ext4_system_zone(); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); |
Theodore Ts'o | 83982b6 | 2009-01-06 14:53:16 -0500 | [diff] [blame] | 4006 | MODULE_DESCRIPTION("Fourth Extended Filesystem"); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 4007 | MODULE_LICENSE("GPL"); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 4008 | module_init(init_ext4_fs) |
| 4009 | module_exit(exit_ext4_fs) |