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