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