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