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