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