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