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