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