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