1ac27a0ecSDave Kleikamp /* 2617ba13bSMingming Cao * linux/fs/ext4/super.c 3ac27a0ecSDave Kleikamp * 4ac27a0ecSDave Kleikamp * Copyright (C) 1992, 1993, 1994, 1995 5ac27a0ecSDave Kleikamp * Remy Card (card@masi.ibp.fr) 6ac27a0ecSDave Kleikamp * Laboratoire MASI - Institut Blaise Pascal 7ac27a0ecSDave Kleikamp * Universite Pierre et Marie Curie (Paris VI) 8ac27a0ecSDave Kleikamp * 9ac27a0ecSDave Kleikamp * from 10ac27a0ecSDave Kleikamp * 11ac27a0ecSDave Kleikamp * linux/fs/minix/inode.c 12ac27a0ecSDave Kleikamp * 13ac27a0ecSDave Kleikamp * Copyright (C) 1991, 1992 Linus Torvalds 14ac27a0ecSDave Kleikamp * 15ac27a0ecSDave Kleikamp * Big-endian to little-endian byte-swapping/bitmaps by 16ac27a0ecSDave Kleikamp * David S. Miller (davem@caip.rutgers.edu), 1995 17ac27a0ecSDave Kleikamp */ 18ac27a0ecSDave Kleikamp 19ac27a0ecSDave Kleikamp #include <linux/module.h> 20ac27a0ecSDave Kleikamp #include <linux/string.h> 21ac27a0ecSDave Kleikamp #include <linux/fs.h> 22ac27a0ecSDave Kleikamp #include <linux/time.h> 23c5ca7c76STheodore Ts'o #include <linux/vmalloc.h> 24dab291afSMingming Cao #include <linux/jbd2.h> 25ac27a0ecSDave Kleikamp #include <linux/slab.h> 26ac27a0ecSDave Kleikamp #include <linux/init.h> 27ac27a0ecSDave Kleikamp #include <linux/blkdev.h> 28ac27a0ecSDave Kleikamp #include <linux/parser.h> 29ac27a0ecSDave Kleikamp #include <linux/smp_lock.h> 30ac27a0ecSDave Kleikamp #include <linux/buffer_head.h> 31a5694255SChristoph Hellwig #include <linux/exportfs.h> 32ac27a0ecSDave Kleikamp #include <linux/vfs.h> 33ac27a0ecSDave Kleikamp #include <linux/random.h> 34ac27a0ecSDave Kleikamp #include <linux/mount.h> 35ac27a0ecSDave Kleikamp #include <linux/namei.h> 36ac27a0ecSDave Kleikamp #include <linux/quotaops.h> 37ac27a0ecSDave Kleikamp #include <linux/seq_file.h> 389f6200bbSTheodore Ts'o #include <linux/proc_fs.h> 393197ebdbSTheodore Ts'o #include <linux/ctype.h> 401330593eSVignesh Babu #include <linux/log2.h> 41717d50e4SAndreas Dilger #include <linux/crc16.h> 42ac27a0ecSDave Kleikamp #include <asm/uaccess.h> 43ac27a0ecSDave Kleikamp 443dcf5451SChristoph Hellwig #include "ext4.h" 453dcf5451SChristoph Hellwig #include "ext4_jbd2.h" 46ac27a0ecSDave Kleikamp #include "xattr.h" 47ac27a0ecSDave Kleikamp #include "acl.h" 483661d286STheodore Ts'o #include "mballoc.h" 49ac27a0ecSDave Kleikamp 509bffad1eSTheodore Ts'o #define CREATE_TRACE_POINTS 519bffad1eSTheodore Ts'o #include <trace/events/ext4.h> 529bffad1eSTheodore Ts'o 539f6200bbSTheodore Ts'o struct proc_dir_entry *ext4_proc_root; 543197ebdbSTheodore Ts'o static struct kset *ext4_kset; 559f6200bbSTheodore Ts'o 56617ba13bSMingming Cao static int ext4_load_journal(struct super_block *, struct ext4_super_block *, 57ac27a0ecSDave Kleikamp unsigned long journal_devnum); 58e2d67052STheodore Ts'o static int ext4_commit_super(struct super_block *sb, int sync); 59617ba13bSMingming Cao static void ext4_mark_recovery_complete(struct super_block *sb, 60617ba13bSMingming Cao struct ext4_super_block *es); 61617ba13bSMingming Cao static void ext4_clear_journal_err(struct super_block *sb, 62617ba13bSMingming Cao struct ext4_super_block *es); 63617ba13bSMingming Cao static int ext4_sync_fs(struct super_block *sb, int wait); 64617ba13bSMingming Cao static const char *ext4_decode_error(struct super_block *sb, int errno, 65ac27a0ecSDave Kleikamp char nbuf[16]); 66617ba13bSMingming Cao static int ext4_remount(struct super_block *sb, int *flags, char *data); 67617ba13bSMingming Cao static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf); 68c4be0c1dSTakashi Sato static int ext4_unfreeze(struct super_block *sb); 69617ba13bSMingming Cao static void ext4_write_super(struct super_block *sb); 70c4be0c1dSTakashi Sato static int ext4_freeze(struct super_block *sb); 71ba69f9abSJan Kara static int ext4_get_sb(struct file_system_type *fs_type, int flags, 72ba69f9abSJan Kara const char *dev_name, void *data, struct vfsmount *mnt); 73ac27a0ecSDave Kleikamp 74ba69f9abSJan Kara #if !defined(CONFIG_EXT3_FS) && !defined(CONFIG_EXT3_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23) 75ba69f9abSJan Kara static struct file_system_type ext3_fs_type = { 76ba69f9abSJan Kara .owner = THIS_MODULE, 77ba69f9abSJan Kara .name = "ext3", 78ba69f9abSJan Kara .get_sb = ext4_get_sb, 79ba69f9abSJan Kara .kill_sb = kill_block_super, 80ba69f9abSJan Kara .fs_flags = FS_REQUIRES_DEV, 81ba69f9abSJan Kara }; 82ba69f9abSJan Kara #define IS_EXT3_SB(sb) ((sb)->s_bdev->bd_holder == &ext3_fs_type) 83ba69f9abSJan Kara #else 84ba69f9abSJan Kara #define IS_EXT3_SB(sb) (0) 85ba69f9abSJan Kara #endif 86bd81d8eeSLaurent Vivier 878fadc143SAlexandre Ratchov ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, 888fadc143SAlexandre Ratchov struct ext4_group_desc *bg) 89bd81d8eeSLaurent Vivier { 903a14589cSAneesh Kumar K.V return le32_to_cpu(bg->bg_block_bitmap_lo) | 918fadc143SAlexandre Ratchov (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 928fadc143SAlexandre Ratchov (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0); 93bd81d8eeSLaurent Vivier } 94bd81d8eeSLaurent Vivier 958fadc143SAlexandre Ratchov ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, 968fadc143SAlexandre Ratchov struct ext4_group_desc *bg) 97bd81d8eeSLaurent Vivier { 985272f837SAneesh Kumar K.V return le32_to_cpu(bg->bg_inode_bitmap_lo) | 998fadc143SAlexandre Ratchov (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 1008fadc143SAlexandre Ratchov (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0); 101bd81d8eeSLaurent Vivier } 102bd81d8eeSLaurent Vivier 1038fadc143SAlexandre Ratchov ext4_fsblk_t ext4_inode_table(struct super_block *sb, 1048fadc143SAlexandre Ratchov struct ext4_group_desc *bg) 105bd81d8eeSLaurent Vivier { 1065272f837SAneesh Kumar K.V return le32_to_cpu(bg->bg_inode_table_lo) | 1078fadc143SAlexandre Ratchov (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 1088fadc143SAlexandre Ratchov (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0); 109bd81d8eeSLaurent Vivier } 110bd81d8eeSLaurent Vivier 111560671a0SAneesh Kumar K.V __u32 ext4_free_blks_count(struct super_block *sb, 112560671a0SAneesh Kumar K.V struct ext4_group_desc *bg) 113560671a0SAneesh Kumar K.V { 114560671a0SAneesh Kumar K.V return le16_to_cpu(bg->bg_free_blocks_count_lo) | 115560671a0SAneesh Kumar K.V (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 116560671a0SAneesh Kumar K.V (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0); 117560671a0SAneesh Kumar K.V } 118560671a0SAneesh Kumar K.V 119560671a0SAneesh Kumar K.V __u32 ext4_free_inodes_count(struct super_block *sb, 120560671a0SAneesh Kumar K.V struct ext4_group_desc *bg) 121560671a0SAneesh Kumar K.V { 122560671a0SAneesh Kumar K.V return le16_to_cpu(bg->bg_free_inodes_count_lo) | 123560671a0SAneesh Kumar K.V (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 124560671a0SAneesh Kumar K.V (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0); 125560671a0SAneesh Kumar K.V } 126560671a0SAneesh Kumar K.V 127560671a0SAneesh Kumar K.V __u32 ext4_used_dirs_count(struct super_block *sb, 128560671a0SAneesh Kumar K.V struct ext4_group_desc *bg) 129560671a0SAneesh Kumar K.V { 130560671a0SAneesh Kumar K.V return le16_to_cpu(bg->bg_used_dirs_count_lo) | 131560671a0SAneesh Kumar K.V (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 132560671a0SAneesh Kumar K.V (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0); 133560671a0SAneesh Kumar K.V } 134560671a0SAneesh Kumar K.V 135560671a0SAneesh Kumar K.V __u32 ext4_itable_unused_count(struct super_block *sb, 136560671a0SAneesh Kumar K.V struct ext4_group_desc *bg) 137560671a0SAneesh Kumar K.V { 138560671a0SAneesh Kumar K.V return le16_to_cpu(bg->bg_itable_unused_lo) | 139560671a0SAneesh Kumar K.V (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 140560671a0SAneesh Kumar K.V (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0); 141560671a0SAneesh Kumar K.V } 142560671a0SAneesh Kumar K.V 1438fadc143SAlexandre Ratchov void ext4_block_bitmap_set(struct super_block *sb, 1448fadc143SAlexandre Ratchov struct ext4_group_desc *bg, ext4_fsblk_t blk) 145bd81d8eeSLaurent Vivier { 1463a14589cSAneesh Kumar K.V bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk); 1478fadc143SAlexandre Ratchov if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 1488fadc143SAlexandre Ratchov bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32); 149bd81d8eeSLaurent Vivier } 150bd81d8eeSLaurent Vivier 1518fadc143SAlexandre Ratchov void ext4_inode_bitmap_set(struct super_block *sb, 1528fadc143SAlexandre Ratchov struct ext4_group_desc *bg, ext4_fsblk_t blk) 153bd81d8eeSLaurent Vivier { 1545272f837SAneesh Kumar K.V bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk); 1558fadc143SAlexandre Ratchov if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 1568fadc143SAlexandre Ratchov bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32); 157bd81d8eeSLaurent Vivier } 158bd81d8eeSLaurent Vivier 1598fadc143SAlexandre Ratchov void ext4_inode_table_set(struct super_block *sb, 1608fadc143SAlexandre Ratchov struct ext4_group_desc *bg, ext4_fsblk_t blk) 161bd81d8eeSLaurent Vivier { 1625272f837SAneesh Kumar K.V bg->bg_inode_table_lo = cpu_to_le32((u32)blk); 1638fadc143SAlexandre Ratchov if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 1648fadc143SAlexandre Ratchov bg->bg_inode_table_hi = cpu_to_le32(blk >> 32); 165bd81d8eeSLaurent Vivier } 166bd81d8eeSLaurent Vivier 167560671a0SAneesh Kumar K.V void ext4_free_blks_set(struct super_block *sb, 168560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count) 169560671a0SAneesh Kumar K.V { 170560671a0SAneesh Kumar K.V bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count); 171560671a0SAneesh Kumar K.V if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 172560671a0SAneesh Kumar K.V bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16); 173560671a0SAneesh Kumar K.V } 174560671a0SAneesh Kumar K.V 175560671a0SAneesh Kumar K.V void ext4_free_inodes_set(struct super_block *sb, 176560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count) 177560671a0SAneesh Kumar K.V { 178560671a0SAneesh Kumar K.V bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count); 179560671a0SAneesh Kumar K.V if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 180560671a0SAneesh Kumar K.V bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16); 181560671a0SAneesh Kumar K.V } 182560671a0SAneesh Kumar K.V 183560671a0SAneesh Kumar K.V void ext4_used_dirs_set(struct super_block *sb, 184560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count) 185560671a0SAneesh Kumar K.V { 186560671a0SAneesh Kumar K.V bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count); 187560671a0SAneesh Kumar K.V if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 188560671a0SAneesh Kumar K.V bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16); 189560671a0SAneesh Kumar K.V } 190560671a0SAneesh Kumar K.V 191560671a0SAneesh Kumar K.V void ext4_itable_unused_set(struct super_block *sb, 192560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count) 193560671a0SAneesh Kumar K.V { 194560671a0SAneesh Kumar K.V bg->bg_itable_unused_lo = cpu_to_le16((__u16)count); 195560671a0SAneesh Kumar K.V if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 196560671a0SAneesh Kumar K.V bg->bg_itable_unused_hi = cpu_to_le16(count >> 16); 197560671a0SAneesh Kumar K.V } 198560671a0SAneesh Kumar K.V 199d3d1faf6SCurt Wohlgemuth 200d3d1faf6SCurt Wohlgemuth /* Just increment the non-pointer handle value */ 201d3d1faf6SCurt Wohlgemuth static handle_t *ext4_get_nojournal(void) 202d3d1faf6SCurt Wohlgemuth { 203d3d1faf6SCurt Wohlgemuth handle_t *handle = current->journal_info; 204d3d1faf6SCurt Wohlgemuth unsigned long ref_cnt = (unsigned long)handle; 205d3d1faf6SCurt Wohlgemuth 206d3d1faf6SCurt Wohlgemuth BUG_ON(ref_cnt >= EXT4_NOJOURNAL_MAX_REF_COUNT); 207d3d1faf6SCurt Wohlgemuth 208d3d1faf6SCurt Wohlgemuth ref_cnt++; 209d3d1faf6SCurt Wohlgemuth handle = (handle_t *)ref_cnt; 210d3d1faf6SCurt Wohlgemuth 211d3d1faf6SCurt Wohlgemuth current->journal_info = handle; 212d3d1faf6SCurt Wohlgemuth return handle; 213d3d1faf6SCurt Wohlgemuth } 214d3d1faf6SCurt Wohlgemuth 215d3d1faf6SCurt Wohlgemuth 216d3d1faf6SCurt Wohlgemuth /* Decrement the non-pointer handle value */ 217d3d1faf6SCurt Wohlgemuth static void ext4_put_nojournal(handle_t *handle) 218d3d1faf6SCurt Wohlgemuth { 219d3d1faf6SCurt Wohlgemuth unsigned long ref_cnt = (unsigned long)handle; 220d3d1faf6SCurt Wohlgemuth 221d3d1faf6SCurt Wohlgemuth BUG_ON(ref_cnt == 0); 222d3d1faf6SCurt Wohlgemuth 223d3d1faf6SCurt Wohlgemuth ref_cnt--; 224d3d1faf6SCurt Wohlgemuth handle = (handle_t *)ref_cnt; 225d3d1faf6SCurt Wohlgemuth 226d3d1faf6SCurt Wohlgemuth current->journal_info = handle; 227d3d1faf6SCurt Wohlgemuth } 228d3d1faf6SCurt Wohlgemuth 229ac27a0ecSDave Kleikamp /* 230dab291afSMingming Cao * Wrappers for jbd2_journal_start/end. 231ac27a0ecSDave Kleikamp * 232ac27a0ecSDave Kleikamp * The only special thing we need to do here is to make sure that all 233ac27a0ecSDave Kleikamp * journal_end calls result in the superblock being marked dirty, so 234ac27a0ecSDave Kleikamp * that sync() will call the filesystem's write_super callback if 235ac27a0ecSDave Kleikamp * appropriate. 236ac27a0ecSDave Kleikamp */ 237617ba13bSMingming Cao handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks) 238ac27a0ecSDave Kleikamp { 239ac27a0ecSDave Kleikamp journal_t *journal; 240ac27a0ecSDave Kleikamp 241ac27a0ecSDave Kleikamp if (sb->s_flags & MS_RDONLY) 242ac27a0ecSDave Kleikamp return ERR_PTR(-EROFS); 243ac27a0ecSDave Kleikamp 244*437f88ccSEric Sandeen vfs_check_frozen(sb, SB_FREEZE_TRANS); 245ac27a0ecSDave Kleikamp /* Special case here: if the journal has aborted behind our 246ac27a0ecSDave Kleikamp * backs (eg. EIO in the commit thread), then we still need to 247ac27a0ecSDave Kleikamp * take the FS itself readonly cleanly. */ 248617ba13bSMingming Cao journal = EXT4_SB(sb)->s_journal; 2490390131bSFrank Mayhar if (journal) { 250ac27a0ecSDave Kleikamp if (is_journal_aborted(journal)) { 251c67d859eSTheodore Ts'o ext4_abort(sb, "Detected aborted journal"); 252ac27a0ecSDave Kleikamp return ERR_PTR(-EROFS); 253ac27a0ecSDave Kleikamp } 254dab291afSMingming Cao return jbd2_journal_start(journal, nblocks); 255ac27a0ecSDave Kleikamp } 256d3d1faf6SCurt Wohlgemuth return ext4_get_nojournal(); 2570390131bSFrank Mayhar } 258ac27a0ecSDave Kleikamp 259ac27a0ecSDave Kleikamp /* 260ac27a0ecSDave Kleikamp * The only special thing we need to do here is to make sure that all 261dab291afSMingming Cao * jbd2_journal_stop calls result in the superblock being marked dirty, so 262ac27a0ecSDave Kleikamp * that sync() will call the filesystem's write_super callback if 263ac27a0ecSDave Kleikamp * appropriate. 264ac27a0ecSDave Kleikamp */ 265c398eda0STheodore Ts'o int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle) 266ac27a0ecSDave Kleikamp { 267ac27a0ecSDave Kleikamp struct super_block *sb; 268ac27a0ecSDave Kleikamp int err; 269ac27a0ecSDave Kleikamp int rc; 270ac27a0ecSDave Kleikamp 2710390131bSFrank Mayhar if (!ext4_handle_valid(handle)) { 272d3d1faf6SCurt Wohlgemuth ext4_put_nojournal(handle); 2730390131bSFrank Mayhar return 0; 2740390131bSFrank Mayhar } 275ac27a0ecSDave Kleikamp sb = handle->h_transaction->t_journal->j_private; 276ac27a0ecSDave Kleikamp err = handle->h_err; 277dab291afSMingming Cao rc = jbd2_journal_stop(handle); 278ac27a0ecSDave Kleikamp 279ac27a0ecSDave Kleikamp if (!err) 280ac27a0ecSDave Kleikamp err = rc; 281ac27a0ecSDave Kleikamp if (err) 282c398eda0STheodore Ts'o __ext4_std_error(sb, where, line, err); 283ac27a0ecSDave Kleikamp return err; 284ac27a0ecSDave Kleikamp } 285ac27a0ecSDave Kleikamp 28690c7201bSTheodore Ts'o void ext4_journal_abort_handle(const char *caller, unsigned int line, 28790c7201bSTheodore Ts'o const char *err_fn, struct buffer_head *bh, 28890c7201bSTheodore Ts'o handle_t *handle, int err) 289ac27a0ecSDave Kleikamp { 290ac27a0ecSDave Kleikamp char nbuf[16]; 291617ba13bSMingming Cao const char *errstr = ext4_decode_error(NULL, err, nbuf); 292ac27a0ecSDave Kleikamp 2930390131bSFrank Mayhar BUG_ON(!ext4_handle_valid(handle)); 2940390131bSFrank Mayhar 295ac27a0ecSDave Kleikamp if (bh) 296ac27a0ecSDave Kleikamp BUFFER_TRACE(bh, "abort"); 297ac27a0ecSDave Kleikamp 298ac27a0ecSDave Kleikamp if (!handle->h_err) 299ac27a0ecSDave Kleikamp handle->h_err = err; 300ac27a0ecSDave Kleikamp 301ac27a0ecSDave Kleikamp if (is_handle_aborted(handle)) 302ac27a0ecSDave Kleikamp return; 303ac27a0ecSDave Kleikamp 30490c7201bSTheodore Ts'o printk(KERN_ERR "%s:%d: aborting transaction: %s in %s\n", 30590c7201bSTheodore Ts'o caller, line, errstr, err_fn); 306ac27a0ecSDave Kleikamp 307dab291afSMingming Cao jbd2_journal_abort_handle(handle); 308ac27a0ecSDave Kleikamp } 309ac27a0ecSDave Kleikamp 3101c13d5c0STheodore Ts'o static void __save_error_info(struct super_block *sb, const char *func, 3111c13d5c0STheodore Ts'o unsigned int line) 3121c13d5c0STheodore Ts'o { 3131c13d5c0STheodore Ts'o struct ext4_super_block *es = EXT4_SB(sb)->s_es; 3141c13d5c0STheodore Ts'o 3151c13d5c0STheodore Ts'o EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 3161c13d5c0STheodore Ts'o es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 3171c13d5c0STheodore Ts'o es->s_last_error_time = cpu_to_le32(get_seconds()); 3181c13d5c0STheodore Ts'o strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func)); 3191c13d5c0STheodore Ts'o es->s_last_error_line = cpu_to_le32(line); 3201c13d5c0STheodore Ts'o if (!es->s_first_error_time) { 3211c13d5c0STheodore Ts'o es->s_first_error_time = es->s_last_error_time; 3221c13d5c0STheodore Ts'o strncpy(es->s_first_error_func, func, 3231c13d5c0STheodore Ts'o sizeof(es->s_first_error_func)); 3241c13d5c0STheodore Ts'o es->s_first_error_line = cpu_to_le32(line); 3251c13d5c0STheodore Ts'o es->s_first_error_ino = es->s_last_error_ino; 3261c13d5c0STheodore Ts'o es->s_first_error_block = es->s_last_error_block; 3271c13d5c0STheodore Ts'o } 32866e61a9eSTheodore Ts'o /* 32966e61a9eSTheodore Ts'o * Start the daily error reporting function if it hasn't been 33066e61a9eSTheodore Ts'o * started already 33166e61a9eSTheodore Ts'o */ 33266e61a9eSTheodore Ts'o if (!es->s_error_count) 33366e61a9eSTheodore Ts'o mod_timer(&EXT4_SB(sb)->s_err_report, jiffies + 24*60*60*HZ); 3341c13d5c0STheodore Ts'o es->s_error_count = cpu_to_le32(le32_to_cpu(es->s_error_count) + 1); 3351c13d5c0STheodore Ts'o } 3361c13d5c0STheodore Ts'o 3371c13d5c0STheodore Ts'o static void save_error_info(struct super_block *sb, const char *func, 3381c13d5c0STheodore Ts'o unsigned int line) 3391c13d5c0STheodore Ts'o { 3401c13d5c0STheodore Ts'o __save_error_info(sb, func, line); 3411c13d5c0STheodore Ts'o ext4_commit_super(sb, 1); 3421c13d5c0STheodore Ts'o } 3431c13d5c0STheodore Ts'o 3441c13d5c0STheodore Ts'o 345ac27a0ecSDave Kleikamp /* Deal with the reporting of failure conditions on a filesystem such as 346ac27a0ecSDave Kleikamp * inconsistencies detected or read IO failures. 347ac27a0ecSDave Kleikamp * 348ac27a0ecSDave Kleikamp * On ext2, we can store the error state of the filesystem in the 349617ba13bSMingming Cao * superblock. That is not possible on ext4, because we may have other 350ac27a0ecSDave Kleikamp * write ordering constraints on the superblock which prevent us from 351ac27a0ecSDave Kleikamp * writing it out straight away; and given that the journal is about to 352ac27a0ecSDave Kleikamp * be aborted, we can't rely on the current, or future, transactions to 353ac27a0ecSDave Kleikamp * write out the superblock safely. 354ac27a0ecSDave Kleikamp * 355dab291afSMingming Cao * We'll just use the jbd2_journal_abort() error code to record an error in 356d6b198bcSThadeu Lima de Souza Cascardo * the journal instead. On recovery, the journal will complain about 357ac27a0ecSDave Kleikamp * that error until we've noted it down and cleared it. 358ac27a0ecSDave Kleikamp */ 359ac27a0ecSDave Kleikamp 360617ba13bSMingming Cao static void ext4_handle_error(struct super_block *sb) 361ac27a0ecSDave Kleikamp { 362ac27a0ecSDave Kleikamp if (sb->s_flags & MS_RDONLY) 363ac27a0ecSDave Kleikamp return; 364ac27a0ecSDave Kleikamp 365ac27a0ecSDave Kleikamp if (!test_opt(sb, ERRORS_CONT)) { 366617ba13bSMingming Cao journal_t *journal = EXT4_SB(sb)->s_journal; 367ac27a0ecSDave Kleikamp 3684ab2f15bSTheodore Ts'o EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED; 369ac27a0ecSDave Kleikamp if (journal) 370dab291afSMingming Cao jbd2_journal_abort(journal, -EIO); 371ac27a0ecSDave Kleikamp } 372ac27a0ecSDave Kleikamp if (test_opt(sb, ERRORS_RO)) { 373b31e1552SEric Sandeen ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only"); 374ac27a0ecSDave Kleikamp sb->s_flags |= MS_RDONLY; 375ac27a0ecSDave Kleikamp } 376ac27a0ecSDave Kleikamp if (test_opt(sb, ERRORS_PANIC)) 377617ba13bSMingming Cao panic("EXT4-fs (device %s): panic forced after error\n", 378ac27a0ecSDave Kleikamp sb->s_id); 379ac27a0ecSDave Kleikamp } 380ac27a0ecSDave Kleikamp 38112062dddSEric Sandeen void __ext4_error(struct super_block *sb, const char *function, 382c398eda0STheodore Ts'o unsigned int line, const char *fmt, ...) 383ac27a0ecSDave Kleikamp { 384ac27a0ecSDave Kleikamp va_list args; 385ac27a0ecSDave Kleikamp 386ac27a0ecSDave Kleikamp va_start(args, fmt); 387c398eda0STheodore Ts'o printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: comm %s: ", 388c398eda0STheodore Ts'o sb->s_id, function, line, current->comm); 389ac27a0ecSDave Kleikamp vprintk(fmt, args); 390ac27a0ecSDave Kleikamp printk("\n"); 391ac27a0ecSDave Kleikamp va_end(args); 392ac27a0ecSDave Kleikamp 393617ba13bSMingming Cao ext4_handle_error(sb); 394ac27a0ecSDave Kleikamp } 395ac27a0ecSDave Kleikamp 396c398eda0STheodore Ts'o void ext4_error_inode(struct inode *inode, const char *function, 397c398eda0STheodore Ts'o unsigned int line, ext4_fsblk_t block, 398273df556SFrank Mayhar const char *fmt, ...) 399273df556SFrank Mayhar { 400273df556SFrank Mayhar va_list args; 4011c13d5c0STheodore Ts'o struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es; 402273df556SFrank Mayhar 4031c13d5c0STheodore Ts'o es->s_last_error_ino = cpu_to_le32(inode->i_ino); 4041c13d5c0STheodore Ts'o es->s_last_error_block = cpu_to_le64(block); 4051c13d5c0STheodore Ts'o save_error_info(inode->i_sb, function, line); 406273df556SFrank Mayhar va_start(args, fmt); 407c398eda0STheodore Ts'o printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: inode #%lu: ", 408c398eda0STheodore Ts'o inode->i_sb->s_id, function, line, inode->i_ino); 409c398eda0STheodore Ts'o if (block) 410c398eda0STheodore Ts'o printk("block %llu: ", block); 411c398eda0STheodore Ts'o printk("comm %s: ", current->comm); 412273df556SFrank Mayhar vprintk(fmt, args); 413273df556SFrank Mayhar printk("\n"); 414273df556SFrank Mayhar va_end(args); 415273df556SFrank Mayhar 416273df556SFrank Mayhar ext4_handle_error(inode->i_sb); 417273df556SFrank Mayhar } 418273df556SFrank Mayhar 419c398eda0STheodore Ts'o void ext4_error_file(struct file *file, const char *function, 420c398eda0STheodore Ts'o unsigned int line, const char *fmt, ...) 421273df556SFrank Mayhar { 422273df556SFrank Mayhar va_list args; 4231c13d5c0STheodore Ts'o struct ext4_super_block *es; 424273df556SFrank Mayhar struct inode *inode = file->f_dentry->d_inode; 425273df556SFrank Mayhar char pathname[80], *path; 426273df556SFrank Mayhar 4271c13d5c0STheodore Ts'o es = EXT4_SB(inode->i_sb)->s_es; 4281c13d5c0STheodore Ts'o es->s_last_error_ino = cpu_to_le32(inode->i_ino); 4291c13d5c0STheodore Ts'o save_error_info(inode->i_sb, function, line); 430273df556SFrank Mayhar va_start(args, fmt); 431273df556SFrank Mayhar path = d_path(&(file->f_path), pathname, sizeof(pathname)); 432273df556SFrank Mayhar if (!path) 433273df556SFrank Mayhar path = "(unknown)"; 434273df556SFrank Mayhar printk(KERN_CRIT 435c398eda0STheodore Ts'o "EXT4-fs error (device %s): %s:%d: inode #%lu " 436c398eda0STheodore Ts'o "(comm %s path %s): ", 437c398eda0STheodore Ts'o inode->i_sb->s_id, function, line, inode->i_ino, 438c398eda0STheodore Ts'o current->comm, path); 439273df556SFrank Mayhar vprintk(fmt, args); 440273df556SFrank Mayhar printk("\n"); 441273df556SFrank Mayhar va_end(args); 442273df556SFrank Mayhar 443273df556SFrank Mayhar ext4_handle_error(inode->i_sb); 444273df556SFrank Mayhar } 445273df556SFrank Mayhar 446617ba13bSMingming Cao static const char *ext4_decode_error(struct super_block *sb, int errno, 447ac27a0ecSDave Kleikamp char nbuf[16]) 448ac27a0ecSDave Kleikamp { 449ac27a0ecSDave Kleikamp char *errstr = NULL; 450ac27a0ecSDave Kleikamp 451ac27a0ecSDave Kleikamp switch (errno) { 452ac27a0ecSDave Kleikamp case -EIO: 453ac27a0ecSDave Kleikamp errstr = "IO failure"; 454ac27a0ecSDave Kleikamp break; 455ac27a0ecSDave Kleikamp case -ENOMEM: 456ac27a0ecSDave Kleikamp errstr = "Out of memory"; 457ac27a0ecSDave Kleikamp break; 458ac27a0ecSDave Kleikamp case -EROFS: 45978f1ddbbSTheodore Ts'o if (!sb || (EXT4_SB(sb)->s_journal && 46078f1ddbbSTheodore Ts'o EXT4_SB(sb)->s_journal->j_flags & JBD2_ABORT)) 461ac27a0ecSDave Kleikamp errstr = "Journal has aborted"; 462ac27a0ecSDave Kleikamp else 463ac27a0ecSDave Kleikamp errstr = "Readonly filesystem"; 464ac27a0ecSDave Kleikamp break; 465ac27a0ecSDave Kleikamp default: 466ac27a0ecSDave Kleikamp /* If the caller passed in an extra buffer for unknown 467ac27a0ecSDave Kleikamp * errors, textualise them now. Else we just return 468ac27a0ecSDave Kleikamp * NULL. */ 469ac27a0ecSDave Kleikamp if (nbuf) { 470ac27a0ecSDave Kleikamp /* Check for truncated error codes... */ 471ac27a0ecSDave Kleikamp if (snprintf(nbuf, 16, "error %d", -errno) >= 0) 472ac27a0ecSDave Kleikamp errstr = nbuf; 473ac27a0ecSDave Kleikamp } 474ac27a0ecSDave Kleikamp break; 475ac27a0ecSDave Kleikamp } 476ac27a0ecSDave Kleikamp 477ac27a0ecSDave Kleikamp return errstr; 478ac27a0ecSDave Kleikamp } 479ac27a0ecSDave Kleikamp 480617ba13bSMingming Cao /* __ext4_std_error decodes expected errors from journaling functions 481ac27a0ecSDave Kleikamp * automatically and invokes the appropriate error response. */ 482ac27a0ecSDave Kleikamp 483c398eda0STheodore Ts'o void __ext4_std_error(struct super_block *sb, const char *function, 484c398eda0STheodore Ts'o unsigned int line, int errno) 485ac27a0ecSDave Kleikamp { 486ac27a0ecSDave Kleikamp char nbuf[16]; 487ac27a0ecSDave Kleikamp const char *errstr; 488ac27a0ecSDave Kleikamp 489ac27a0ecSDave Kleikamp /* Special case: if the error is EROFS, and we're not already 490ac27a0ecSDave Kleikamp * inside a transaction, then there's really no point in logging 491ac27a0ecSDave Kleikamp * an error. */ 492ac27a0ecSDave Kleikamp if (errno == -EROFS && journal_current_handle() == NULL && 493ac27a0ecSDave Kleikamp (sb->s_flags & MS_RDONLY)) 494ac27a0ecSDave Kleikamp return; 495ac27a0ecSDave Kleikamp 496617ba13bSMingming Cao errstr = ext4_decode_error(sb, errno, nbuf); 497c398eda0STheodore Ts'o printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n", 498c398eda0STheodore Ts'o sb->s_id, function, line, errstr); 4991c13d5c0STheodore Ts'o save_error_info(sb, function, line); 500ac27a0ecSDave Kleikamp 501617ba13bSMingming Cao ext4_handle_error(sb); 502ac27a0ecSDave Kleikamp } 503ac27a0ecSDave Kleikamp 504ac27a0ecSDave Kleikamp /* 505617ba13bSMingming Cao * ext4_abort is a much stronger failure handler than ext4_error. The 506ac27a0ecSDave Kleikamp * abort function may be used to deal with unrecoverable failures such 507ac27a0ecSDave Kleikamp * as journal IO errors or ENOMEM at a critical moment in log management. 508ac27a0ecSDave Kleikamp * 509ac27a0ecSDave Kleikamp * We unconditionally force the filesystem into an ABORT|READONLY state, 510ac27a0ecSDave Kleikamp * unless the error response on the fs has been set to panic in which 511ac27a0ecSDave Kleikamp * case we take the easy way out and panic immediately. 512ac27a0ecSDave Kleikamp */ 513ac27a0ecSDave Kleikamp 514c67d859eSTheodore Ts'o void __ext4_abort(struct super_block *sb, const char *function, 515c398eda0STheodore Ts'o unsigned int line, const char *fmt, ...) 516ac27a0ecSDave Kleikamp { 517ac27a0ecSDave Kleikamp va_list args; 518ac27a0ecSDave Kleikamp 5191c13d5c0STheodore Ts'o save_error_info(sb, function, line); 520ac27a0ecSDave Kleikamp va_start(args, fmt); 521c398eda0STheodore Ts'o printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: ", sb->s_id, 522c398eda0STheodore Ts'o function, line); 523ac27a0ecSDave Kleikamp vprintk(fmt, args); 524ac27a0ecSDave Kleikamp printk("\n"); 525ac27a0ecSDave Kleikamp va_end(args); 526ac27a0ecSDave Kleikamp 5271c13d5c0STheodore Ts'o if ((sb->s_flags & MS_RDONLY) == 0) { 528b31e1552SEric Sandeen ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only"); 529ac27a0ecSDave Kleikamp sb->s_flags |= MS_RDONLY; 5304ab2f15bSTheodore Ts'o EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED; 531ef2cabf7SHidehiro Kawai if (EXT4_SB(sb)->s_journal) 532dab291afSMingming Cao jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO); 5331c13d5c0STheodore Ts'o save_error_info(sb, function, line); 5341c13d5c0STheodore Ts'o } 5351c13d5c0STheodore Ts'o if (test_opt(sb, ERRORS_PANIC)) 5361c13d5c0STheodore Ts'o panic("EXT4-fs panic from previous error\n"); 537ac27a0ecSDave Kleikamp } 538ac27a0ecSDave Kleikamp 539b31e1552SEric Sandeen void ext4_msg (struct super_block * sb, const char *prefix, 540b31e1552SEric Sandeen const char *fmt, ...) 541b31e1552SEric Sandeen { 542b31e1552SEric Sandeen va_list args; 543b31e1552SEric Sandeen 544b31e1552SEric Sandeen va_start(args, fmt); 545b31e1552SEric Sandeen printk("%sEXT4-fs (%s): ", prefix, sb->s_id); 546b31e1552SEric Sandeen vprintk(fmt, args); 547b31e1552SEric Sandeen printk("\n"); 548b31e1552SEric Sandeen va_end(args); 549b31e1552SEric Sandeen } 550b31e1552SEric Sandeen 55112062dddSEric Sandeen void __ext4_warning(struct super_block *sb, const char *function, 552c398eda0STheodore Ts'o unsigned int line, const char *fmt, ...) 553ac27a0ecSDave Kleikamp { 554ac27a0ecSDave Kleikamp va_list args; 555ac27a0ecSDave Kleikamp 556ac27a0ecSDave Kleikamp va_start(args, fmt); 557c398eda0STheodore Ts'o printk(KERN_WARNING "EXT4-fs warning (device %s): %s:%d: ", 558c398eda0STheodore Ts'o sb->s_id, function, line); 559ac27a0ecSDave Kleikamp vprintk(fmt, args); 560ac27a0ecSDave Kleikamp printk("\n"); 561ac27a0ecSDave Kleikamp va_end(args); 562ac27a0ecSDave Kleikamp } 563ac27a0ecSDave Kleikamp 564e29136f8STheodore Ts'o void __ext4_grp_locked_error(const char *function, unsigned int line, 565e29136f8STheodore Ts'o struct super_block *sb, ext4_group_t grp, 566e29136f8STheodore Ts'o unsigned long ino, ext4_fsblk_t block, 567e29136f8STheodore Ts'o const char *fmt, ...) 5685d1b1b3fSAneesh Kumar K.V __releases(bitlock) 5695d1b1b3fSAneesh Kumar K.V __acquires(bitlock) 5705d1b1b3fSAneesh Kumar K.V { 5715d1b1b3fSAneesh Kumar K.V va_list args; 5725d1b1b3fSAneesh Kumar K.V struct ext4_super_block *es = EXT4_SB(sb)->s_es; 5735d1b1b3fSAneesh Kumar K.V 5741c13d5c0STheodore Ts'o es->s_last_error_ino = cpu_to_le32(ino); 5751c13d5c0STheodore Ts'o es->s_last_error_block = cpu_to_le64(block); 5761c13d5c0STheodore Ts'o __save_error_info(sb, function, line); 5775d1b1b3fSAneesh Kumar K.V va_start(args, fmt); 578e29136f8STheodore Ts'o printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: group %u", 579e29136f8STheodore Ts'o sb->s_id, function, line, grp); 580e29136f8STheodore Ts'o if (ino) 581e29136f8STheodore Ts'o printk("inode %lu: ", ino); 582e29136f8STheodore Ts'o if (block) 583e29136f8STheodore Ts'o printk("block %llu:", (unsigned long long) block); 5845d1b1b3fSAneesh Kumar K.V vprintk(fmt, args); 5855d1b1b3fSAneesh Kumar K.V printk("\n"); 5865d1b1b3fSAneesh Kumar K.V va_end(args); 5875d1b1b3fSAneesh Kumar K.V 5885d1b1b3fSAneesh Kumar K.V if (test_opt(sb, ERRORS_CONT)) { 589e2d67052STheodore Ts'o ext4_commit_super(sb, 0); 5905d1b1b3fSAneesh Kumar K.V return; 5915d1b1b3fSAneesh Kumar K.V } 5921c13d5c0STheodore Ts'o 5935d1b1b3fSAneesh Kumar K.V ext4_unlock_group(sb, grp); 5945d1b1b3fSAneesh Kumar K.V ext4_handle_error(sb); 5955d1b1b3fSAneesh Kumar K.V /* 5965d1b1b3fSAneesh Kumar K.V * We only get here in the ERRORS_RO case; relocking the group 5975d1b1b3fSAneesh Kumar K.V * may be dangerous, but nothing bad will happen since the 5985d1b1b3fSAneesh Kumar K.V * filesystem will have already been marked read/only and the 5995d1b1b3fSAneesh Kumar K.V * journal has been aborted. We return 1 as a hint to callers 6005d1b1b3fSAneesh Kumar K.V * who might what to use the return value from 6015d1b1b3fSAneesh Kumar K.V * ext4_grp_locked_error() to distinguish beween the 6025d1b1b3fSAneesh Kumar K.V * ERRORS_CONT and ERRORS_RO case, and perhaps return more 6035d1b1b3fSAneesh Kumar K.V * aggressively from the ext4 function in question, with a 6045d1b1b3fSAneesh Kumar K.V * more appropriate error code. 6055d1b1b3fSAneesh Kumar K.V */ 6065d1b1b3fSAneesh Kumar K.V ext4_lock_group(sb, grp); 6075d1b1b3fSAneesh Kumar K.V return; 6085d1b1b3fSAneesh Kumar K.V } 6095d1b1b3fSAneesh Kumar K.V 610617ba13bSMingming Cao void ext4_update_dynamic_rev(struct super_block *sb) 611ac27a0ecSDave Kleikamp { 612617ba13bSMingming Cao struct ext4_super_block *es = EXT4_SB(sb)->s_es; 613ac27a0ecSDave Kleikamp 614617ba13bSMingming Cao if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV) 615ac27a0ecSDave Kleikamp return; 616ac27a0ecSDave Kleikamp 61712062dddSEric Sandeen ext4_warning(sb, 618ac27a0ecSDave Kleikamp "updating to rev %d because of new feature flag, " 619ac27a0ecSDave Kleikamp "running e2fsck is recommended", 620617ba13bSMingming Cao EXT4_DYNAMIC_REV); 621ac27a0ecSDave Kleikamp 622617ba13bSMingming Cao es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO); 623617ba13bSMingming Cao es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE); 624617ba13bSMingming Cao es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV); 625ac27a0ecSDave Kleikamp /* leave es->s_feature_*compat flags alone */ 626ac27a0ecSDave Kleikamp /* es->s_uuid will be set by e2fsck if empty */ 627ac27a0ecSDave Kleikamp 628ac27a0ecSDave Kleikamp /* 629ac27a0ecSDave Kleikamp * The rest of the superblock fields should be zero, and if not it 630ac27a0ecSDave Kleikamp * means they are likely already in use, so leave them alone. We 631ac27a0ecSDave Kleikamp * can leave it up to e2fsck to clean up any inconsistencies there. 632ac27a0ecSDave Kleikamp */ 633ac27a0ecSDave Kleikamp } 634ac27a0ecSDave Kleikamp 635ac27a0ecSDave Kleikamp /* 636ac27a0ecSDave Kleikamp * Open the external journal device 637ac27a0ecSDave Kleikamp */ 638b31e1552SEric Sandeen static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb) 639ac27a0ecSDave Kleikamp { 640ac27a0ecSDave Kleikamp struct block_device *bdev; 641ac27a0ecSDave Kleikamp char b[BDEVNAME_SIZE]; 642ac27a0ecSDave Kleikamp 643ac27a0ecSDave Kleikamp bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); 644ac27a0ecSDave Kleikamp if (IS_ERR(bdev)) 645ac27a0ecSDave Kleikamp goto fail; 646ac27a0ecSDave Kleikamp return bdev; 647ac27a0ecSDave Kleikamp 648ac27a0ecSDave Kleikamp fail: 649b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "failed to open journal device %s: %ld", 650ac27a0ecSDave Kleikamp __bdevname(dev, b), PTR_ERR(bdev)); 651ac27a0ecSDave Kleikamp return NULL; 652ac27a0ecSDave Kleikamp } 653ac27a0ecSDave Kleikamp 654ac27a0ecSDave Kleikamp /* 655ac27a0ecSDave Kleikamp * Release the journal device 656ac27a0ecSDave Kleikamp */ 657617ba13bSMingming Cao static int ext4_blkdev_put(struct block_device *bdev) 658ac27a0ecSDave Kleikamp { 659ac27a0ecSDave Kleikamp bd_release(bdev); 6609a1c3542SAl Viro return blkdev_put(bdev, FMODE_READ|FMODE_WRITE); 661ac27a0ecSDave Kleikamp } 662ac27a0ecSDave Kleikamp 663617ba13bSMingming Cao static int ext4_blkdev_remove(struct ext4_sb_info *sbi) 664ac27a0ecSDave Kleikamp { 665ac27a0ecSDave Kleikamp struct block_device *bdev; 666ac27a0ecSDave Kleikamp int ret = -ENODEV; 667ac27a0ecSDave Kleikamp 668ac27a0ecSDave Kleikamp bdev = sbi->journal_bdev; 669ac27a0ecSDave Kleikamp if (bdev) { 670617ba13bSMingming Cao ret = ext4_blkdev_put(bdev); 671ac27a0ecSDave Kleikamp sbi->journal_bdev = NULL; 672ac27a0ecSDave Kleikamp } 673ac27a0ecSDave Kleikamp return ret; 674ac27a0ecSDave Kleikamp } 675ac27a0ecSDave Kleikamp 676ac27a0ecSDave Kleikamp static inline struct inode *orphan_list_entry(struct list_head *l) 677ac27a0ecSDave Kleikamp { 678617ba13bSMingming Cao return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode; 679ac27a0ecSDave Kleikamp } 680ac27a0ecSDave Kleikamp 681617ba13bSMingming Cao static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi) 682ac27a0ecSDave Kleikamp { 683ac27a0ecSDave Kleikamp struct list_head *l; 684ac27a0ecSDave Kleikamp 685b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "sb orphan head is %d", 686ac27a0ecSDave Kleikamp le32_to_cpu(sbi->s_es->s_last_orphan)); 687ac27a0ecSDave Kleikamp 688ac27a0ecSDave Kleikamp printk(KERN_ERR "sb_info orphan list:\n"); 689ac27a0ecSDave Kleikamp list_for_each(l, &sbi->s_orphan) { 690ac27a0ecSDave Kleikamp struct inode *inode = orphan_list_entry(l); 691ac27a0ecSDave Kleikamp printk(KERN_ERR " " 692ac27a0ecSDave Kleikamp "inode %s:%lu at %p: mode %o, nlink %d, next %d\n", 693ac27a0ecSDave Kleikamp inode->i_sb->s_id, inode->i_ino, inode, 694ac27a0ecSDave Kleikamp inode->i_mode, inode->i_nlink, 695ac27a0ecSDave Kleikamp NEXT_ORPHAN(inode)); 696ac27a0ecSDave Kleikamp } 697ac27a0ecSDave Kleikamp } 698ac27a0ecSDave Kleikamp 699617ba13bSMingming Cao static void ext4_put_super(struct super_block *sb) 700ac27a0ecSDave Kleikamp { 701617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 702617ba13bSMingming Cao struct ext4_super_block *es = sbi->s_es; 703ef2cabf7SHidehiro Kawai int i, err; 704ac27a0ecSDave Kleikamp 705e0ccfd95SChristoph Hellwig dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); 706e0ccfd95SChristoph Hellwig 7074c0425ffSMingming Cao flush_workqueue(sbi->dio_unwritten_wq); 7084c0425ffSMingming Cao destroy_workqueue(sbi->dio_unwritten_wq); 7094c0425ffSMingming Cao 710a9e220f8SAl Viro lock_super(sb); 7116cfd0148SChristoph Hellwig lock_kernel(); 7128c85e125SChristoph Hellwig if (sb->s_dirt) 713ebc1ac16SChristoph Hellwig ext4_commit_super(sb, 1); 7148c85e125SChristoph Hellwig 7150390131bSFrank Mayhar if (sbi->s_journal) { 716ef2cabf7SHidehiro Kawai err = jbd2_journal_destroy(sbi->s_journal); 71747b4a50bSJan Kara sbi->s_journal = NULL; 718ef2cabf7SHidehiro Kawai if (err < 0) 719c67d859eSTheodore Ts'o ext4_abort(sb, "Couldn't clean up the journal"); 7200390131bSFrank Mayhar } 721d4edac31SJosef Bacik 722d4edac31SJosef Bacik ext4_release_system_zone(sb); 723d4edac31SJosef Bacik ext4_mb_release(sb); 724d4edac31SJosef Bacik ext4_ext_release(sb); 725d4edac31SJosef Bacik ext4_xattr_put_super(sb); 726d4edac31SJosef Bacik 727ac27a0ecSDave Kleikamp if (!(sb->s_flags & MS_RDONLY)) { 728617ba13bSMingming Cao EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 729ac27a0ecSDave Kleikamp es->s_state = cpu_to_le16(sbi->s_mount_state); 730e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 731ac27a0ecSDave Kleikamp } 732240799cdSTheodore Ts'o if (sbi->s_proc) { 7339f6200bbSTheodore Ts'o remove_proc_entry(sb->s_id, ext4_proc_root); 734240799cdSTheodore Ts'o } 7353197ebdbSTheodore Ts'o kobject_del(&sbi->s_kobj); 736ac27a0ecSDave Kleikamp 737ac27a0ecSDave Kleikamp for (i = 0; i < sbi->s_gdb_count; i++) 738ac27a0ecSDave Kleikamp brelse(sbi->s_group_desc[i]); 739ac27a0ecSDave Kleikamp kfree(sbi->s_group_desc); 740c5ca7c76STheodore Ts'o if (is_vmalloc_addr(sbi->s_flex_groups)) 741c5ca7c76STheodore Ts'o vfree(sbi->s_flex_groups); 742c5ca7c76STheodore Ts'o else 743772cb7c8SJose R. Santos kfree(sbi->s_flex_groups); 744ac27a0ecSDave Kleikamp percpu_counter_destroy(&sbi->s_freeblocks_counter); 745ac27a0ecSDave Kleikamp percpu_counter_destroy(&sbi->s_freeinodes_counter); 746ac27a0ecSDave Kleikamp percpu_counter_destroy(&sbi->s_dirs_counter); 7476bc6e63fSAneesh Kumar K.V percpu_counter_destroy(&sbi->s_dirtyblocks_counter); 748ac27a0ecSDave Kleikamp brelse(sbi->s_sbh); 749ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 750ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) 751ac27a0ecSDave Kleikamp kfree(sbi->s_qf_names[i]); 752ac27a0ecSDave Kleikamp #endif 753ac27a0ecSDave Kleikamp 754ac27a0ecSDave Kleikamp /* Debugging code just in case the in-memory inode orphan list 755ac27a0ecSDave Kleikamp * isn't empty. The on-disk one can be non-empty if we've 756ac27a0ecSDave Kleikamp * detected an error and taken the fs readonly, but the 757ac27a0ecSDave Kleikamp * in-memory list had better be clean by this point. */ 758ac27a0ecSDave Kleikamp if (!list_empty(&sbi->s_orphan)) 759ac27a0ecSDave Kleikamp dump_orphan_list(sb, sbi); 760ac27a0ecSDave Kleikamp J_ASSERT(list_empty(&sbi->s_orphan)); 761ac27a0ecSDave Kleikamp 762f98393a6SPeter Zijlstra invalidate_bdev(sb->s_bdev); 763ac27a0ecSDave Kleikamp if (sbi->journal_bdev && sbi->journal_bdev != sb->s_bdev) { 764ac27a0ecSDave Kleikamp /* 765ac27a0ecSDave Kleikamp * Invalidate the journal device's buffers. We don't want them 766ac27a0ecSDave Kleikamp * floating about in memory - the physical journal device may 767ac27a0ecSDave Kleikamp * hotswapped, and it breaks the `ro-after' testing code. 768ac27a0ecSDave Kleikamp */ 769ac27a0ecSDave Kleikamp sync_blockdev(sbi->journal_bdev); 770f98393a6SPeter Zijlstra invalidate_bdev(sbi->journal_bdev); 771617ba13bSMingming Cao ext4_blkdev_remove(sbi); 772ac27a0ecSDave Kleikamp } 773ac27a0ecSDave Kleikamp sb->s_fs_info = NULL; 7743197ebdbSTheodore Ts'o /* 7753197ebdbSTheodore Ts'o * Now that we are completely done shutting down the 7763197ebdbSTheodore Ts'o * superblock, we need to actually destroy the kobject. 7773197ebdbSTheodore Ts'o */ 7783197ebdbSTheodore Ts'o unlock_kernel(); 7793197ebdbSTheodore Ts'o unlock_super(sb); 7803197ebdbSTheodore Ts'o kobject_put(&sbi->s_kobj); 7813197ebdbSTheodore Ts'o wait_for_completion(&sbi->s_kobj_unregister); 782705895b6SPekka Enberg kfree(sbi->s_blockgroup_lock); 783ac27a0ecSDave Kleikamp kfree(sbi); 784ac27a0ecSDave Kleikamp } 785ac27a0ecSDave Kleikamp 786e18b890bSChristoph Lameter static struct kmem_cache *ext4_inode_cachep; 787ac27a0ecSDave Kleikamp 788ac27a0ecSDave Kleikamp /* 789ac27a0ecSDave Kleikamp * Called inside transaction, so use GFP_NOFS 790ac27a0ecSDave Kleikamp */ 791617ba13bSMingming Cao static struct inode *ext4_alloc_inode(struct super_block *sb) 792ac27a0ecSDave Kleikamp { 793617ba13bSMingming Cao struct ext4_inode_info *ei; 794ac27a0ecSDave Kleikamp 795e6b4f8daSChristoph Lameter ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS); 796ac27a0ecSDave Kleikamp if (!ei) 797ac27a0ecSDave Kleikamp return NULL; 7980b8e58a1SAndreas Dilger 799ac27a0ecSDave Kleikamp ei->vfs_inode.i_version = 1; 80091246c00SAneesh Kumar K.V ei->vfs_inode.i_data.writeback_index = 0; 801a86c6181SAlex Tomas memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache)); 802c9de560dSAlex Tomas INIT_LIST_HEAD(&ei->i_prealloc_list); 803c9de560dSAlex Tomas spin_lock_init(&ei->i_prealloc_lock); 8040390131bSFrank Mayhar /* 8050390131bSFrank Mayhar * Note: We can be called before EXT4_SB(sb)->s_journal is set, 8060390131bSFrank Mayhar * therefore it can be null here. Don't check it, just initialize 8070390131bSFrank Mayhar * jinode. 8080390131bSFrank Mayhar */ 809678aaf48SJan Kara jbd2_journal_init_jbd_inode(&ei->jinode, &ei->vfs_inode); 810d2a17637SMingming Cao ei->i_reserved_data_blocks = 0; 811d2a17637SMingming Cao ei->i_reserved_meta_blocks = 0; 812d2a17637SMingming Cao ei->i_allocated_meta_blocks = 0; 8139d0be502STheodore Ts'o ei->i_da_metadata_calc_len = 0; 814d2a17637SMingming Cao ei->i_delalloc_reserved_flag = 0; 815d2a17637SMingming Cao spin_lock_init(&(ei->i_block_reservation_lock)); 816a9e7f447SDmitry Monakhov #ifdef CONFIG_QUOTA 817a9e7f447SDmitry Monakhov ei->i_reserved_quota = 0; 818a9e7f447SDmitry Monakhov #endif 819c7064ef1SJiaying Zhang INIT_LIST_HEAD(&ei->i_completed_io_list); 820744692dcSJiaying Zhang spin_lock_init(&ei->i_completed_io_lock); 8218d5d02e6SMingming Cao ei->cur_aio_dio = NULL; 822b436b9beSJan Kara ei->i_sync_tid = 0; 823b436b9beSJan Kara ei->i_datasync_tid = 0; 8240b8e58a1SAndreas Dilger 825ac27a0ecSDave Kleikamp return &ei->vfs_inode; 826ac27a0ecSDave Kleikamp } 827ac27a0ecSDave Kleikamp 828617ba13bSMingming Cao static void ext4_destroy_inode(struct inode *inode) 829ac27a0ecSDave Kleikamp { 8309f7dd93dSVasily Averin if (!list_empty(&(EXT4_I(inode)->i_orphan))) { 831b31e1552SEric Sandeen ext4_msg(inode->i_sb, KERN_ERR, 832b31e1552SEric Sandeen "Inode %lu (%p): orphan list check failed!", 833b31e1552SEric Sandeen inode->i_ino, EXT4_I(inode)); 8349f7dd93dSVasily Averin print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4, 8359f7dd93dSVasily Averin EXT4_I(inode), sizeof(struct ext4_inode_info), 8369f7dd93dSVasily Averin true); 8379f7dd93dSVasily Averin dump_stack(); 8389f7dd93dSVasily Averin } 839617ba13bSMingming Cao kmem_cache_free(ext4_inode_cachep, EXT4_I(inode)); 840ac27a0ecSDave Kleikamp } 841ac27a0ecSDave Kleikamp 84251cc5068SAlexey Dobriyan static void init_once(void *foo) 843ac27a0ecSDave Kleikamp { 844617ba13bSMingming Cao struct ext4_inode_info *ei = (struct ext4_inode_info *) foo; 845ac27a0ecSDave Kleikamp 846ac27a0ecSDave Kleikamp INIT_LIST_HEAD(&ei->i_orphan); 84703010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_XATTR 848ac27a0ecSDave Kleikamp init_rwsem(&ei->xattr_sem); 849ac27a0ecSDave Kleikamp #endif 8500e855ac8SAneesh Kumar K.V init_rwsem(&ei->i_data_sem); 851ac27a0ecSDave Kleikamp inode_init_once(&ei->vfs_inode); 852ac27a0ecSDave Kleikamp } 853ac27a0ecSDave Kleikamp 854ac27a0ecSDave Kleikamp static int init_inodecache(void) 855ac27a0ecSDave Kleikamp { 856617ba13bSMingming Cao ext4_inode_cachep = kmem_cache_create("ext4_inode_cache", 857617ba13bSMingming Cao sizeof(struct ext4_inode_info), 858ac27a0ecSDave Kleikamp 0, (SLAB_RECLAIM_ACCOUNT| 859ac27a0ecSDave Kleikamp SLAB_MEM_SPREAD), 86020c2df83SPaul Mundt init_once); 861617ba13bSMingming Cao if (ext4_inode_cachep == NULL) 862ac27a0ecSDave Kleikamp return -ENOMEM; 863ac27a0ecSDave Kleikamp return 0; 864ac27a0ecSDave Kleikamp } 865ac27a0ecSDave Kleikamp 866ac27a0ecSDave Kleikamp static void destroy_inodecache(void) 867ac27a0ecSDave Kleikamp { 868617ba13bSMingming Cao kmem_cache_destroy(ext4_inode_cachep); 869ac27a0ecSDave Kleikamp } 870ac27a0ecSDave Kleikamp 871617ba13bSMingming Cao static void ext4_clear_inode(struct inode *inode) 872ac27a0ecSDave Kleikamp { 8739f754758SChristoph Hellwig dquot_drop(inode); 874c2ea3fdeSTheodore Ts'o ext4_discard_preallocations(inode); 8750390131bSFrank Mayhar if (EXT4_JOURNAL(inode)) 876678aaf48SJan Kara jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal, 877678aaf48SJan Kara &EXT4_I(inode)->jinode); 878ac27a0ecSDave Kleikamp } 879ac27a0ecSDave Kleikamp 8802b2d6d01STheodore Ts'o static inline void ext4_show_quota_options(struct seq_file *seq, 8812b2d6d01STheodore Ts'o struct super_block *sb) 882ac27a0ecSDave Kleikamp { 883ac27a0ecSDave Kleikamp #if defined(CONFIG_QUOTA) 884617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 885ac27a0ecSDave Kleikamp 8865a20bdfcSJan Kara if (sbi->s_jquota_fmt) { 8875a20bdfcSJan Kara char *fmtname = ""; 8885a20bdfcSJan Kara 8895a20bdfcSJan Kara switch (sbi->s_jquota_fmt) { 8905a20bdfcSJan Kara case QFMT_VFS_OLD: 8915a20bdfcSJan Kara fmtname = "vfsold"; 8925a20bdfcSJan Kara break; 8935a20bdfcSJan Kara case QFMT_VFS_V0: 8945a20bdfcSJan Kara fmtname = "vfsv0"; 8955a20bdfcSJan Kara break; 8965a20bdfcSJan Kara case QFMT_VFS_V1: 8975a20bdfcSJan Kara fmtname = "vfsv1"; 8985a20bdfcSJan Kara break; 8995a20bdfcSJan Kara } 9005a20bdfcSJan Kara seq_printf(seq, ",jqfmt=%s", fmtname); 9015a20bdfcSJan Kara } 902ac27a0ecSDave Kleikamp 903ac27a0ecSDave Kleikamp if (sbi->s_qf_names[USRQUOTA]) 904ac27a0ecSDave Kleikamp seq_printf(seq, ",usrjquota=%s", sbi->s_qf_names[USRQUOTA]); 905ac27a0ecSDave Kleikamp 906ac27a0ecSDave Kleikamp if (sbi->s_qf_names[GRPQUOTA]) 907ac27a0ecSDave Kleikamp seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]); 908ac27a0ecSDave Kleikamp 909482a7425SDmitry Monakhov if (test_opt(sb, USRQUOTA)) 910ac27a0ecSDave Kleikamp seq_puts(seq, ",usrquota"); 911ac27a0ecSDave Kleikamp 912482a7425SDmitry Monakhov if (test_opt(sb, GRPQUOTA)) 913ac27a0ecSDave Kleikamp seq_puts(seq, ",grpquota"); 914ac27a0ecSDave Kleikamp #endif 915ac27a0ecSDave Kleikamp } 916ac27a0ecSDave Kleikamp 917d9c9bef1SMiklos Szeredi /* 918d9c9bef1SMiklos Szeredi * Show an option if 919d9c9bef1SMiklos Szeredi * - it's set to a non-default value OR 920d9c9bef1SMiklos Szeredi * - if the per-sb default is different from the global default 921d9c9bef1SMiklos Szeredi */ 922617ba13bSMingming Cao static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs) 923ac27a0ecSDave Kleikamp { 924aa22df2cSAneesh Kumar K.V int def_errors; 925aa22df2cSAneesh Kumar K.V unsigned long def_mount_opts; 926ac27a0ecSDave Kleikamp struct super_block *sb = vfs->mnt_sb; 927d9c9bef1SMiklos Szeredi struct ext4_sb_info *sbi = EXT4_SB(sb); 928d9c9bef1SMiklos Szeredi struct ext4_super_block *es = sbi->s_es; 929d9c9bef1SMiklos Szeredi 930d9c9bef1SMiklos Szeredi def_mount_opts = le32_to_cpu(es->s_default_mount_opts); 931aa22df2cSAneesh Kumar K.V def_errors = le16_to_cpu(es->s_errors); 932d9c9bef1SMiklos Szeredi 933d9c9bef1SMiklos Szeredi if (sbi->s_sb_block != 1) 934d9c9bef1SMiklos Szeredi seq_printf(seq, ",sb=%llu", sbi->s_sb_block); 935d9c9bef1SMiklos Szeredi if (test_opt(sb, MINIX_DF)) 936d9c9bef1SMiklos Szeredi seq_puts(seq, ",minixdf"); 937aa22df2cSAneesh Kumar K.V if (test_opt(sb, GRPID) && !(def_mount_opts & EXT4_DEFM_BSDGROUPS)) 938d9c9bef1SMiklos Szeredi seq_puts(seq, ",grpid"); 939d9c9bef1SMiklos Szeredi if (!test_opt(sb, GRPID) && (def_mount_opts & EXT4_DEFM_BSDGROUPS)) 940d9c9bef1SMiklos Szeredi seq_puts(seq, ",nogrpid"); 941d9c9bef1SMiklos Szeredi if (sbi->s_resuid != EXT4_DEF_RESUID || 942d9c9bef1SMiklos Szeredi le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID) { 943d9c9bef1SMiklos Szeredi seq_printf(seq, ",resuid=%u", sbi->s_resuid); 944d9c9bef1SMiklos Szeredi } 945d9c9bef1SMiklos Szeredi if (sbi->s_resgid != EXT4_DEF_RESGID || 946d9c9bef1SMiklos Szeredi le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID) { 947d9c9bef1SMiklos Szeredi seq_printf(seq, ",resgid=%u", sbi->s_resgid); 948d9c9bef1SMiklos Szeredi } 949bb4f397aSAneesh Kumar K.V if (test_opt(sb, ERRORS_RO)) { 950d9c9bef1SMiklos Szeredi if (def_errors == EXT4_ERRORS_PANIC || 951bb4f397aSAneesh Kumar K.V def_errors == EXT4_ERRORS_CONTINUE) { 952d9c9bef1SMiklos Szeredi seq_puts(seq, ",errors=remount-ro"); 953bb4f397aSAneesh Kumar K.V } 954bb4f397aSAneesh Kumar K.V } 955aa22df2cSAneesh Kumar K.V if (test_opt(sb, ERRORS_CONT) && def_errors != EXT4_ERRORS_CONTINUE) 956bb4f397aSAneesh Kumar K.V seq_puts(seq, ",errors=continue"); 957aa22df2cSAneesh Kumar K.V if (test_opt(sb, ERRORS_PANIC) && def_errors != EXT4_ERRORS_PANIC) 958d9c9bef1SMiklos Szeredi seq_puts(seq, ",errors=panic"); 959aa22df2cSAneesh Kumar K.V if (test_opt(sb, NO_UID32) && !(def_mount_opts & EXT4_DEFM_UID16)) 960d9c9bef1SMiklos Szeredi seq_puts(seq, ",nouid32"); 961aa22df2cSAneesh Kumar K.V if (test_opt(sb, DEBUG) && !(def_mount_opts & EXT4_DEFM_DEBUG)) 962d9c9bef1SMiklos Szeredi seq_puts(seq, ",debug"); 963d9c9bef1SMiklos Szeredi if (test_opt(sb, OLDALLOC)) 964d9c9bef1SMiklos Szeredi seq_puts(seq, ",oldalloc"); 96503010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_XATTR 966aa22df2cSAneesh Kumar K.V if (test_opt(sb, XATTR_USER) && 967aa22df2cSAneesh Kumar K.V !(def_mount_opts & EXT4_DEFM_XATTR_USER)) 968d9c9bef1SMiklos Szeredi seq_puts(seq, ",user_xattr"); 969d9c9bef1SMiklos Szeredi if (!test_opt(sb, XATTR_USER) && 970d9c9bef1SMiklos Szeredi (def_mount_opts & EXT4_DEFM_XATTR_USER)) { 971d9c9bef1SMiklos Szeredi seq_puts(seq, ",nouser_xattr"); 972d9c9bef1SMiklos Szeredi } 973d9c9bef1SMiklos Szeredi #endif 97403010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_POSIX_ACL 975aa22df2cSAneesh Kumar K.V if (test_opt(sb, POSIX_ACL) && !(def_mount_opts & EXT4_DEFM_ACL)) 976d9c9bef1SMiklos Szeredi seq_puts(seq, ",acl"); 977d9c9bef1SMiklos Szeredi if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT4_DEFM_ACL)) 978d9c9bef1SMiklos Szeredi seq_puts(seq, ",noacl"); 979d9c9bef1SMiklos Szeredi #endif 98030773840STheodore Ts'o if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) { 981d9c9bef1SMiklos Szeredi seq_printf(seq, ",commit=%u", 982d9c9bef1SMiklos Szeredi (unsigned) (sbi->s_commit_interval / HZ)); 983d9c9bef1SMiklos Szeredi } 98430773840STheodore Ts'o if (sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME) { 98530773840STheodore Ts'o seq_printf(seq, ",min_batch_time=%u", 98630773840STheodore Ts'o (unsigned) sbi->s_min_batch_time); 98730773840STheodore Ts'o } 98830773840STheodore Ts'o if (sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME) { 98930773840STheodore Ts'o seq_printf(seq, ",max_batch_time=%u", 99030773840STheodore Ts'o (unsigned) sbi->s_min_batch_time); 99130773840STheodore Ts'o } 99230773840STheodore Ts'o 993571640caSEric Sandeen /* 994571640caSEric Sandeen * We're changing the default of barrier mount option, so 995571640caSEric Sandeen * let's always display its mount state so it's clear what its 996571640caSEric Sandeen * status is. 997571640caSEric Sandeen */ 998571640caSEric Sandeen seq_puts(seq, ",barrier="); 999571640caSEric Sandeen seq_puts(seq, test_opt(sb, BARRIER) ? "1" : "0"); 1000cd0b6a39STheodore Ts'o if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) 1001cd0b6a39STheodore Ts'o seq_puts(seq, ",journal_async_commit"); 100239a4badeSJan Kara else if (test_opt(sb, JOURNAL_CHECKSUM)) 100339a4badeSJan Kara seq_puts(seq, ",journal_checksum"); 100425ec56b5SJean Noel Cordenner if (test_opt(sb, I_VERSION)) 100525ec56b5SJean Noel Cordenner seq_puts(seq, ",i_version"); 1006dd919b98SAneesh Kumar K.V if (!test_opt(sb, DELALLOC)) 1007dd919b98SAneesh Kumar K.V seq_puts(seq, ",nodelalloc"); 1008dd919b98SAneesh Kumar K.V 1009ac27a0ecSDave Kleikamp 1010cb45bbe4SMiklos Szeredi if (sbi->s_stripe) 1011cb45bbe4SMiklos Szeredi seq_printf(seq, ",stripe=%lu", sbi->s_stripe); 1012aa22df2cSAneesh Kumar K.V /* 1013aa22df2cSAneesh Kumar K.V * journal mode get enabled in different ways 1014aa22df2cSAneesh Kumar K.V * So just print the value even if we didn't specify it 1015aa22df2cSAneesh Kumar K.V */ 1016617ba13bSMingming Cao if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) 1017ac27a0ecSDave Kleikamp seq_puts(seq, ",data=journal"); 1018617ba13bSMingming Cao else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) 1019ac27a0ecSDave Kleikamp seq_puts(seq, ",data=ordered"); 1020617ba13bSMingming Cao else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA) 1021ac27a0ecSDave Kleikamp seq_puts(seq, ",data=writeback"); 1022ac27a0ecSDave Kleikamp 1023240799cdSTheodore Ts'o if (sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS) 1024240799cdSTheodore Ts'o seq_printf(seq, ",inode_readahead_blks=%u", 1025240799cdSTheodore Ts'o sbi->s_inode_readahead_blks); 1026240799cdSTheodore Ts'o 10275bf5683aSHidehiro Kawai if (test_opt(sb, DATA_ERR_ABORT)) 10285bf5683aSHidehiro Kawai seq_puts(seq, ",data_err=abort"); 10295bf5683aSHidehiro Kawai 1030afd4672dSTheodore Ts'o if (test_opt(sb, NO_AUTO_DA_ALLOC)) 103106705bffSTheodore Ts'o seq_puts(seq, ",noauto_da_alloc"); 1032afd4672dSTheodore Ts'o 10335328e635SEric Sandeen if (test_opt(sb, DISCARD)) 10345328e635SEric Sandeen seq_puts(seq, ",discard"); 10355328e635SEric Sandeen 1036e3bb52aeSEric Sandeen if (test_opt(sb, NOLOAD)) 1037e3bb52aeSEric Sandeen seq_puts(seq, ",norecovery"); 1038e3bb52aeSEric Sandeen 1039744692dcSJiaying Zhang if (test_opt(sb, DIOREAD_NOLOCK)) 1040744692dcSJiaying Zhang seq_puts(seq, ",dioread_nolock"); 1041744692dcSJiaying Zhang 1042617ba13bSMingming Cao ext4_show_quota_options(seq, sb); 10430b8e58a1SAndreas Dilger 1044ac27a0ecSDave Kleikamp return 0; 1045ac27a0ecSDave Kleikamp } 1046ac27a0ecSDave Kleikamp 10471b961ac0SChristoph Hellwig static struct inode *ext4_nfs_get_inode(struct super_block *sb, 10481b961ac0SChristoph Hellwig u64 ino, u32 generation) 1049ac27a0ecSDave Kleikamp { 1050ac27a0ecSDave Kleikamp struct inode *inode; 1051ac27a0ecSDave Kleikamp 1052617ba13bSMingming Cao if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO) 1053ac27a0ecSDave Kleikamp return ERR_PTR(-ESTALE); 1054617ba13bSMingming Cao if (ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)) 1055ac27a0ecSDave Kleikamp return ERR_PTR(-ESTALE); 1056ac27a0ecSDave Kleikamp 1057ac27a0ecSDave Kleikamp /* iget isn't really right if the inode is currently unallocated!! 1058ac27a0ecSDave Kleikamp * 1059617ba13bSMingming Cao * ext4_read_inode will return a bad_inode if the inode had been 1060ac27a0ecSDave Kleikamp * deleted, so we should be safe. 1061ac27a0ecSDave Kleikamp * 1062ac27a0ecSDave Kleikamp * Currently we don't know the generation for parent directory, so 1063ac27a0ecSDave Kleikamp * a generation of 0 means "accept any" 1064ac27a0ecSDave Kleikamp */ 10651d1fe1eeSDavid Howells inode = ext4_iget(sb, ino); 10661d1fe1eeSDavid Howells if (IS_ERR(inode)) 10671d1fe1eeSDavid Howells return ERR_CAST(inode); 10681d1fe1eeSDavid Howells if (generation && inode->i_generation != generation) { 1069ac27a0ecSDave Kleikamp iput(inode); 1070ac27a0ecSDave Kleikamp return ERR_PTR(-ESTALE); 1071ac27a0ecSDave Kleikamp } 10721b961ac0SChristoph Hellwig 10731b961ac0SChristoph Hellwig return inode; 1074ac27a0ecSDave Kleikamp } 10751b961ac0SChristoph Hellwig 10761b961ac0SChristoph Hellwig static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid, 10771b961ac0SChristoph Hellwig int fh_len, int fh_type) 10781b961ac0SChristoph Hellwig { 10791b961ac0SChristoph Hellwig return generic_fh_to_dentry(sb, fid, fh_len, fh_type, 10801b961ac0SChristoph Hellwig ext4_nfs_get_inode); 10811b961ac0SChristoph Hellwig } 10821b961ac0SChristoph Hellwig 10831b961ac0SChristoph Hellwig static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid, 10841b961ac0SChristoph Hellwig int fh_len, int fh_type) 10851b961ac0SChristoph Hellwig { 10861b961ac0SChristoph Hellwig return generic_fh_to_parent(sb, fid, fh_len, fh_type, 10871b961ac0SChristoph Hellwig ext4_nfs_get_inode); 1088ac27a0ecSDave Kleikamp } 1089ac27a0ecSDave Kleikamp 1090c39a7f84SToshiyuki Okajima /* 1091c39a7f84SToshiyuki Okajima * Try to release metadata pages (indirect blocks, directories) which are 1092c39a7f84SToshiyuki Okajima * mapped via the block device. Since these pages could have journal heads 1093c39a7f84SToshiyuki Okajima * which would prevent try_to_free_buffers() from freeing them, we must use 1094c39a7f84SToshiyuki Okajima * jbd2 layer's try_to_free_buffers() function to release them. 1095c39a7f84SToshiyuki Okajima */ 10960b8e58a1SAndreas Dilger static int bdev_try_to_free_page(struct super_block *sb, struct page *page, 10970b8e58a1SAndreas Dilger gfp_t wait) 1098c39a7f84SToshiyuki Okajima { 1099c39a7f84SToshiyuki Okajima journal_t *journal = EXT4_SB(sb)->s_journal; 1100c39a7f84SToshiyuki Okajima 1101c39a7f84SToshiyuki Okajima WARN_ON(PageChecked(page)); 1102c39a7f84SToshiyuki Okajima if (!page_has_buffers(page)) 1103c39a7f84SToshiyuki Okajima return 0; 1104c39a7f84SToshiyuki Okajima if (journal) 1105c39a7f84SToshiyuki Okajima return jbd2_journal_try_to_free_buffers(journal, page, 1106c39a7f84SToshiyuki Okajima wait & ~__GFP_WAIT); 1107c39a7f84SToshiyuki Okajima return try_to_free_buffers(page); 1108c39a7f84SToshiyuki Okajima } 1109c39a7f84SToshiyuki Okajima 1110ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 1111ac27a0ecSDave Kleikamp #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group") 1112ac27a0ecSDave Kleikamp #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA)) 1113ac27a0ecSDave Kleikamp 1114617ba13bSMingming Cao static int ext4_write_dquot(struct dquot *dquot); 1115617ba13bSMingming Cao static int ext4_acquire_dquot(struct dquot *dquot); 1116617ba13bSMingming Cao static int ext4_release_dquot(struct dquot *dquot); 1117617ba13bSMingming Cao static int ext4_mark_dquot_dirty(struct dquot *dquot); 1118617ba13bSMingming Cao static int ext4_write_info(struct super_block *sb, int type); 11196f28e087SJan Kara static int ext4_quota_on(struct super_block *sb, int type, int format_id, 1120307ae18aSChristoph Hellwig char *path); 1121617ba13bSMingming Cao static int ext4_quota_on_mount(struct super_block *sb, int type); 1122617ba13bSMingming Cao static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, 1123ac27a0ecSDave Kleikamp size_t len, loff_t off); 1124617ba13bSMingming Cao static ssize_t ext4_quota_write(struct super_block *sb, int type, 1125ac27a0ecSDave Kleikamp const char *data, size_t len, loff_t off); 1126ac27a0ecSDave Kleikamp 112761e225dcSAlexey Dobriyan static const struct dquot_operations ext4_quota_operations = { 1128a9e7f447SDmitry Monakhov #ifdef CONFIG_QUOTA 112960e58e0fSMingming Cao .get_reserved_space = ext4_get_reserved_space, 1130a9e7f447SDmitry Monakhov #endif 1131617ba13bSMingming Cao .write_dquot = ext4_write_dquot, 1132617ba13bSMingming Cao .acquire_dquot = ext4_acquire_dquot, 1133617ba13bSMingming Cao .release_dquot = ext4_release_dquot, 1134617ba13bSMingming Cao .mark_dirty = ext4_mark_dquot_dirty, 1135a5b5ee32SJan Kara .write_info = ext4_write_info, 1136a5b5ee32SJan Kara .alloc_dquot = dquot_alloc, 1137a5b5ee32SJan Kara .destroy_dquot = dquot_destroy, 1138ac27a0ecSDave Kleikamp }; 1139ac27a0ecSDave Kleikamp 11400d54b217SAlexey Dobriyan static const struct quotactl_ops ext4_qctl_operations = { 1141617ba13bSMingming Cao .quota_on = ext4_quota_on, 1142287a8095SChristoph Hellwig .quota_off = dquot_quota_off, 1143287a8095SChristoph Hellwig .quota_sync = dquot_quota_sync, 1144287a8095SChristoph Hellwig .get_info = dquot_get_dqinfo, 1145287a8095SChristoph Hellwig .set_info = dquot_set_dqinfo, 1146287a8095SChristoph Hellwig .get_dqblk = dquot_get_dqblk, 1147287a8095SChristoph Hellwig .set_dqblk = dquot_set_dqblk 1148ac27a0ecSDave Kleikamp }; 1149ac27a0ecSDave Kleikamp #endif 1150ac27a0ecSDave Kleikamp 1151ee9b6d61SJosef 'Jeff' Sipek static const struct super_operations ext4_sops = { 1152617ba13bSMingming Cao .alloc_inode = ext4_alloc_inode, 1153617ba13bSMingming Cao .destroy_inode = ext4_destroy_inode, 1154617ba13bSMingming Cao .write_inode = ext4_write_inode, 1155617ba13bSMingming Cao .dirty_inode = ext4_dirty_inode, 1156617ba13bSMingming Cao .delete_inode = ext4_delete_inode, 1157617ba13bSMingming Cao .put_super = ext4_put_super, 1158617ba13bSMingming Cao .sync_fs = ext4_sync_fs, 1159c4be0c1dSTakashi Sato .freeze_fs = ext4_freeze, 1160c4be0c1dSTakashi Sato .unfreeze_fs = ext4_unfreeze, 1161617ba13bSMingming Cao .statfs = ext4_statfs, 1162617ba13bSMingming Cao .remount_fs = ext4_remount, 1163617ba13bSMingming Cao .clear_inode = ext4_clear_inode, 1164617ba13bSMingming Cao .show_options = ext4_show_options, 1165ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 1166617ba13bSMingming Cao .quota_read = ext4_quota_read, 1167617ba13bSMingming Cao .quota_write = ext4_quota_write, 1168ac27a0ecSDave Kleikamp #endif 1169c39a7f84SToshiyuki Okajima .bdev_try_to_free_page = bdev_try_to_free_page, 1170ac27a0ecSDave Kleikamp }; 1171ac27a0ecSDave Kleikamp 11729ca92389STheodore Ts'o static const struct super_operations ext4_nojournal_sops = { 11739ca92389STheodore Ts'o .alloc_inode = ext4_alloc_inode, 11749ca92389STheodore Ts'o .destroy_inode = ext4_destroy_inode, 11759ca92389STheodore Ts'o .write_inode = ext4_write_inode, 11769ca92389STheodore Ts'o .dirty_inode = ext4_dirty_inode, 11779ca92389STheodore Ts'o .delete_inode = ext4_delete_inode, 11789ca92389STheodore Ts'o .write_super = ext4_write_super, 11799ca92389STheodore Ts'o .put_super = ext4_put_super, 11809ca92389STheodore Ts'o .statfs = ext4_statfs, 11819ca92389STheodore Ts'o .remount_fs = ext4_remount, 11829ca92389STheodore Ts'o .clear_inode = ext4_clear_inode, 11839ca92389STheodore Ts'o .show_options = ext4_show_options, 11849ca92389STheodore Ts'o #ifdef CONFIG_QUOTA 11859ca92389STheodore Ts'o .quota_read = ext4_quota_read, 11869ca92389STheodore Ts'o .quota_write = ext4_quota_write, 11879ca92389STheodore Ts'o #endif 11889ca92389STheodore Ts'o .bdev_try_to_free_page = bdev_try_to_free_page, 11899ca92389STheodore Ts'o }; 11909ca92389STheodore Ts'o 119139655164SChristoph Hellwig static const struct export_operations ext4_export_ops = { 11921b961ac0SChristoph Hellwig .fh_to_dentry = ext4_fh_to_dentry, 11931b961ac0SChristoph Hellwig .fh_to_parent = ext4_fh_to_parent, 1194617ba13bSMingming Cao .get_parent = ext4_get_parent, 1195ac27a0ecSDave Kleikamp }; 1196ac27a0ecSDave Kleikamp 1197ac27a0ecSDave Kleikamp enum { 1198ac27a0ecSDave Kleikamp Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid, 1199ac27a0ecSDave Kleikamp Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro, 120001436ef2STheodore Ts'o Opt_nouid32, Opt_debug, Opt_oldalloc, Opt_orlov, 1201ac27a0ecSDave Kleikamp Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, 120206705bffSTheodore Ts'o Opt_auto_da_alloc, Opt_noauto_da_alloc, Opt_noload, Opt_nobh, Opt_bh, 120330773840STheodore Ts'o Opt_commit, Opt_min_batch_time, Opt_max_batch_time, 1204c3191067STheodore Ts'o Opt_journal_update, Opt_journal_dev, 1205818d276cSGirish Shilamkar Opt_journal_checksum, Opt_journal_async_commit, 1206ac27a0ecSDave Kleikamp Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, 1207296c355cSTheodore Ts'o Opt_data_err_abort, Opt_data_err_ignore, 1208ac27a0ecSDave Kleikamp Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, 12095a20bdfcSJan Kara Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota, 12105a20bdfcSJan Kara Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, 12115a20bdfcSJan Kara Opt_resize, Opt_usrquota, Opt_grpquota, Opt_i_version, 121201436ef2STheodore Ts'o Opt_stripe, Opt_delalloc, Opt_nodelalloc, 12136fd058f7STheodore Ts'o Opt_block_validity, Opt_noblock_validity, 12145328e635SEric Sandeen Opt_inode_readahead_blks, Opt_journal_ioprio, 1215744692dcSJiaying Zhang Opt_dioread_nolock, Opt_dioread_lock, 12165328e635SEric Sandeen Opt_discard, Opt_nodiscard, 1217ac27a0ecSDave Kleikamp }; 1218ac27a0ecSDave Kleikamp 1219a447c093SSteven Whitehouse static const match_table_t tokens = { 1220ac27a0ecSDave Kleikamp {Opt_bsd_df, "bsddf"}, 1221ac27a0ecSDave Kleikamp {Opt_minix_df, "minixdf"}, 1222ac27a0ecSDave Kleikamp {Opt_grpid, "grpid"}, 1223ac27a0ecSDave Kleikamp {Opt_grpid, "bsdgroups"}, 1224ac27a0ecSDave Kleikamp {Opt_nogrpid, "nogrpid"}, 1225ac27a0ecSDave Kleikamp {Opt_nogrpid, "sysvgroups"}, 1226ac27a0ecSDave Kleikamp {Opt_resgid, "resgid=%u"}, 1227ac27a0ecSDave Kleikamp {Opt_resuid, "resuid=%u"}, 1228ac27a0ecSDave Kleikamp {Opt_sb, "sb=%u"}, 1229ac27a0ecSDave Kleikamp {Opt_err_cont, "errors=continue"}, 1230ac27a0ecSDave Kleikamp {Opt_err_panic, "errors=panic"}, 1231ac27a0ecSDave Kleikamp {Opt_err_ro, "errors=remount-ro"}, 1232ac27a0ecSDave Kleikamp {Opt_nouid32, "nouid32"}, 1233ac27a0ecSDave Kleikamp {Opt_debug, "debug"}, 1234ac27a0ecSDave Kleikamp {Opt_oldalloc, "oldalloc"}, 1235ac27a0ecSDave Kleikamp {Opt_orlov, "orlov"}, 1236ac27a0ecSDave Kleikamp {Opt_user_xattr, "user_xattr"}, 1237ac27a0ecSDave Kleikamp {Opt_nouser_xattr, "nouser_xattr"}, 1238ac27a0ecSDave Kleikamp {Opt_acl, "acl"}, 1239ac27a0ecSDave Kleikamp {Opt_noacl, "noacl"}, 1240ac27a0ecSDave Kleikamp {Opt_noload, "noload"}, 1241e3bb52aeSEric Sandeen {Opt_noload, "norecovery"}, 1242ac27a0ecSDave Kleikamp {Opt_nobh, "nobh"}, 1243ac27a0ecSDave Kleikamp {Opt_bh, "bh"}, 1244ac27a0ecSDave Kleikamp {Opt_commit, "commit=%u"}, 124530773840STheodore Ts'o {Opt_min_batch_time, "min_batch_time=%u"}, 124630773840STheodore Ts'o {Opt_max_batch_time, "max_batch_time=%u"}, 1247ac27a0ecSDave Kleikamp {Opt_journal_update, "journal=update"}, 1248ac27a0ecSDave Kleikamp {Opt_journal_dev, "journal_dev=%u"}, 1249818d276cSGirish Shilamkar {Opt_journal_checksum, "journal_checksum"}, 1250818d276cSGirish Shilamkar {Opt_journal_async_commit, "journal_async_commit"}, 1251ac27a0ecSDave Kleikamp {Opt_abort, "abort"}, 1252ac27a0ecSDave Kleikamp {Opt_data_journal, "data=journal"}, 1253ac27a0ecSDave Kleikamp {Opt_data_ordered, "data=ordered"}, 1254ac27a0ecSDave Kleikamp {Opt_data_writeback, "data=writeback"}, 12555bf5683aSHidehiro Kawai {Opt_data_err_abort, "data_err=abort"}, 12565bf5683aSHidehiro Kawai {Opt_data_err_ignore, "data_err=ignore"}, 1257ac27a0ecSDave Kleikamp {Opt_offusrjquota, "usrjquota="}, 1258ac27a0ecSDave Kleikamp {Opt_usrjquota, "usrjquota=%s"}, 1259ac27a0ecSDave Kleikamp {Opt_offgrpjquota, "grpjquota="}, 1260ac27a0ecSDave Kleikamp {Opt_grpjquota, "grpjquota=%s"}, 1261ac27a0ecSDave Kleikamp {Opt_jqfmt_vfsold, "jqfmt=vfsold"}, 1262ac27a0ecSDave Kleikamp {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, 12635a20bdfcSJan Kara {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"}, 1264ac27a0ecSDave Kleikamp {Opt_grpquota, "grpquota"}, 1265ac27a0ecSDave Kleikamp {Opt_noquota, "noquota"}, 1266ac27a0ecSDave Kleikamp {Opt_quota, "quota"}, 1267ac27a0ecSDave Kleikamp {Opt_usrquota, "usrquota"}, 1268ac27a0ecSDave Kleikamp {Opt_barrier, "barrier=%u"}, 126906705bffSTheodore Ts'o {Opt_barrier, "barrier"}, 127006705bffSTheodore Ts'o {Opt_nobarrier, "nobarrier"}, 127125ec56b5SJean Noel Cordenner {Opt_i_version, "i_version"}, 1272c9de560dSAlex Tomas {Opt_stripe, "stripe=%u"}, 1273ac27a0ecSDave Kleikamp {Opt_resize, "resize"}, 127464769240SAlex Tomas {Opt_delalloc, "delalloc"}, 1275dd919b98SAneesh Kumar K.V {Opt_nodelalloc, "nodelalloc"}, 12766fd058f7STheodore Ts'o {Opt_block_validity, "block_validity"}, 12776fd058f7STheodore Ts'o {Opt_noblock_validity, "noblock_validity"}, 1278240799cdSTheodore Ts'o {Opt_inode_readahead_blks, "inode_readahead_blks=%u"}, 1279b3881f74STheodore Ts'o {Opt_journal_ioprio, "journal_ioprio=%u"}, 1280afd4672dSTheodore Ts'o {Opt_auto_da_alloc, "auto_da_alloc=%u"}, 128106705bffSTheodore Ts'o {Opt_auto_da_alloc, "auto_da_alloc"}, 128206705bffSTheodore Ts'o {Opt_noauto_da_alloc, "noauto_da_alloc"}, 1283744692dcSJiaying Zhang {Opt_dioread_nolock, "dioread_nolock"}, 1284744692dcSJiaying Zhang {Opt_dioread_lock, "dioread_lock"}, 12855328e635SEric Sandeen {Opt_discard, "discard"}, 12865328e635SEric Sandeen {Opt_nodiscard, "nodiscard"}, 1287f3f12faaSJosef Bacik {Opt_err, NULL}, 1288ac27a0ecSDave Kleikamp }; 1289ac27a0ecSDave Kleikamp 1290617ba13bSMingming Cao static ext4_fsblk_t get_sb_block(void **data) 1291ac27a0ecSDave Kleikamp { 1292617ba13bSMingming Cao ext4_fsblk_t sb_block; 1293ac27a0ecSDave Kleikamp char *options = (char *) *data; 1294ac27a0ecSDave Kleikamp 1295ac27a0ecSDave Kleikamp if (!options || strncmp(options, "sb=", 3) != 0) 1296ac27a0ecSDave Kleikamp return 1; /* Default location */ 12970b8e58a1SAndreas Dilger 1298ac27a0ecSDave Kleikamp options += 3; 12990b8e58a1SAndreas Dilger /* TODO: use simple_strtoll with >32bit ext4 */ 1300ac27a0ecSDave Kleikamp sb_block = simple_strtoul(options, &options, 0); 1301ac27a0ecSDave Kleikamp if (*options && *options != ',') { 13024776004fSTheodore Ts'o printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n", 1303ac27a0ecSDave Kleikamp (char *) *data); 1304ac27a0ecSDave Kleikamp return 1; 1305ac27a0ecSDave Kleikamp } 1306ac27a0ecSDave Kleikamp if (*options == ',') 1307ac27a0ecSDave Kleikamp options++; 1308ac27a0ecSDave Kleikamp *data = (void *) options; 13090b8e58a1SAndreas Dilger 1310ac27a0ecSDave Kleikamp return sb_block; 1311ac27a0ecSDave Kleikamp } 1312ac27a0ecSDave Kleikamp 1313b3881f74STheodore Ts'o #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3)) 1314437ca0fdSDmitry Monakhov static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n" 1315437ca0fdSDmitry Monakhov "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n"; 1316b3881f74STheodore Ts'o 131756c50f11SDmitry Monakhov #ifdef CONFIG_QUOTA 131856c50f11SDmitry Monakhov static int set_qf_name(struct super_block *sb, int qtype, substring_t *args) 131956c50f11SDmitry Monakhov { 132056c50f11SDmitry Monakhov struct ext4_sb_info *sbi = EXT4_SB(sb); 132156c50f11SDmitry Monakhov char *qname; 132256c50f11SDmitry Monakhov 132356c50f11SDmitry Monakhov if (sb_any_quota_loaded(sb) && 132456c50f11SDmitry Monakhov !sbi->s_qf_names[qtype]) { 132556c50f11SDmitry Monakhov ext4_msg(sb, KERN_ERR, 132656c50f11SDmitry Monakhov "Cannot change journaled " 132756c50f11SDmitry Monakhov "quota options when quota turned on"); 132856c50f11SDmitry Monakhov return 0; 132956c50f11SDmitry Monakhov } 133056c50f11SDmitry Monakhov qname = match_strdup(args); 133156c50f11SDmitry Monakhov if (!qname) { 133256c50f11SDmitry Monakhov ext4_msg(sb, KERN_ERR, 133356c50f11SDmitry Monakhov "Not enough memory for storing quotafile name"); 133456c50f11SDmitry Monakhov return 0; 133556c50f11SDmitry Monakhov } 133656c50f11SDmitry Monakhov if (sbi->s_qf_names[qtype] && 133756c50f11SDmitry Monakhov strcmp(sbi->s_qf_names[qtype], qname)) { 133856c50f11SDmitry Monakhov ext4_msg(sb, KERN_ERR, 133956c50f11SDmitry Monakhov "%s quota file already specified", QTYPE2NAME(qtype)); 134056c50f11SDmitry Monakhov kfree(qname); 134156c50f11SDmitry Monakhov return 0; 134256c50f11SDmitry Monakhov } 134356c50f11SDmitry Monakhov sbi->s_qf_names[qtype] = qname; 134456c50f11SDmitry Monakhov if (strchr(sbi->s_qf_names[qtype], '/')) { 134556c50f11SDmitry Monakhov ext4_msg(sb, KERN_ERR, 134656c50f11SDmitry Monakhov "quotafile must be on filesystem root"); 134756c50f11SDmitry Monakhov kfree(sbi->s_qf_names[qtype]); 134856c50f11SDmitry Monakhov sbi->s_qf_names[qtype] = NULL; 134956c50f11SDmitry Monakhov return 0; 135056c50f11SDmitry Monakhov } 135156c50f11SDmitry Monakhov set_opt(sbi->s_mount_opt, QUOTA); 135256c50f11SDmitry Monakhov return 1; 135356c50f11SDmitry Monakhov } 135456c50f11SDmitry Monakhov 135556c50f11SDmitry Monakhov static int clear_qf_name(struct super_block *sb, int qtype) 135656c50f11SDmitry Monakhov { 135756c50f11SDmitry Monakhov 135856c50f11SDmitry Monakhov struct ext4_sb_info *sbi = EXT4_SB(sb); 135956c50f11SDmitry Monakhov 136056c50f11SDmitry Monakhov if (sb_any_quota_loaded(sb) && 136156c50f11SDmitry Monakhov sbi->s_qf_names[qtype]) { 136256c50f11SDmitry Monakhov ext4_msg(sb, KERN_ERR, "Cannot change journaled quota options" 136356c50f11SDmitry Monakhov " when quota turned on"); 136456c50f11SDmitry Monakhov return 0; 136556c50f11SDmitry Monakhov } 136656c50f11SDmitry Monakhov /* 136756c50f11SDmitry Monakhov * The space will be released later when all options are confirmed 136856c50f11SDmitry Monakhov * to be correct 136956c50f11SDmitry Monakhov */ 137056c50f11SDmitry Monakhov sbi->s_qf_names[qtype] = NULL; 137156c50f11SDmitry Monakhov return 1; 137256c50f11SDmitry Monakhov } 137356c50f11SDmitry Monakhov #endif 137456c50f11SDmitry Monakhov 1375ac27a0ecSDave Kleikamp static int parse_options(char *options, struct super_block *sb, 1376c3191067STheodore Ts'o unsigned long *journal_devnum, 1377b3881f74STheodore Ts'o unsigned int *journal_ioprio, 1378617ba13bSMingming Cao ext4_fsblk_t *n_blocks_count, int is_remount) 1379ac27a0ecSDave Kleikamp { 1380617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 1381ac27a0ecSDave Kleikamp char *p; 1382ac27a0ecSDave Kleikamp substring_t args[MAX_OPT_ARGS]; 1383ac27a0ecSDave Kleikamp int data_opt = 0; 1384ac27a0ecSDave Kleikamp int option; 1385ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 138656c50f11SDmitry Monakhov int qfmt; 1387ac27a0ecSDave Kleikamp #endif 1388ac27a0ecSDave Kleikamp 1389ac27a0ecSDave Kleikamp if (!options) 1390ac27a0ecSDave Kleikamp return 1; 1391ac27a0ecSDave Kleikamp 1392ac27a0ecSDave Kleikamp while ((p = strsep(&options, ",")) != NULL) { 1393ac27a0ecSDave Kleikamp int token; 1394ac27a0ecSDave Kleikamp if (!*p) 1395ac27a0ecSDave Kleikamp continue; 1396ac27a0ecSDave Kleikamp 139715121c18SEric Sandeen /* 139815121c18SEric Sandeen * Initialize args struct so we know whether arg was 139915121c18SEric Sandeen * found; some options take optional arguments. 140015121c18SEric Sandeen */ 140115121c18SEric Sandeen args[0].to = args[0].from = 0; 1402ac27a0ecSDave Kleikamp token = match_token(p, tokens, args); 1403ac27a0ecSDave Kleikamp switch (token) { 1404ac27a0ecSDave Kleikamp case Opt_bsd_df: 1405437ca0fdSDmitry Monakhov ext4_msg(sb, KERN_WARNING, deprecated_msg, p, "2.6.38"); 1406ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, MINIX_DF); 1407ac27a0ecSDave Kleikamp break; 1408ac27a0ecSDave Kleikamp case Opt_minix_df: 1409437ca0fdSDmitry Monakhov ext4_msg(sb, KERN_WARNING, deprecated_msg, p, "2.6.38"); 1410ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, MINIX_DF); 1411437ca0fdSDmitry Monakhov 1412ac27a0ecSDave Kleikamp break; 1413ac27a0ecSDave Kleikamp case Opt_grpid: 1414437ca0fdSDmitry Monakhov ext4_msg(sb, KERN_WARNING, deprecated_msg, p, "2.6.38"); 1415ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, GRPID); 1416437ca0fdSDmitry Monakhov 1417ac27a0ecSDave Kleikamp break; 1418ac27a0ecSDave Kleikamp case Opt_nogrpid: 1419437ca0fdSDmitry Monakhov ext4_msg(sb, KERN_WARNING, deprecated_msg, p, "2.6.38"); 1420ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, GRPID); 1421437ca0fdSDmitry Monakhov 1422ac27a0ecSDave Kleikamp break; 1423ac27a0ecSDave Kleikamp case Opt_resuid: 1424ac27a0ecSDave Kleikamp if (match_int(&args[0], &option)) 1425ac27a0ecSDave Kleikamp return 0; 1426ac27a0ecSDave Kleikamp sbi->s_resuid = option; 1427ac27a0ecSDave Kleikamp break; 1428ac27a0ecSDave Kleikamp case Opt_resgid: 1429ac27a0ecSDave Kleikamp if (match_int(&args[0], &option)) 1430ac27a0ecSDave Kleikamp return 0; 1431ac27a0ecSDave Kleikamp sbi->s_resgid = option; 1432ac27a0ecSDave Kleikamp break; 1433ac27a0ecSDave Kleikamp case Opt_sb: 1434ac27a0ecSDave Kleikamp /* handled by get_sb_block() instead of here */ 1435ac27a0ecSDave Kleikamp /* *sb_block = match_int(&args[0]); */ 1436ac27a0ecSDave Kleikamp break; 1437ac27a0ecSDave Kleikamp case Opt_err_panic: 1438ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, ERRORS_CONT); 1439ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, ERRORS_RO); 1440ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, ERRORS_PANIC); 1441ac27a0ecSDave Kleikamp break; 1442ac27a0ecSDave Kleikamp case Opt_err_ro: 1443ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, ERRORS_CONT); 1444ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, ERRORS_PANIC); 1445ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, ERRORS_RO); 1446ac27a0ecSDave Kleikamp break; 1447ac27a0ecSDave Kleikamp case Opt_err_cont: 1448ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, ERRORS_RO); 1449ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, ERRORS_PANIC); 1450ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, ERRORS_CONT); 1451ac27a0ecSDave Kleikamp break; 1452ac27a0ecSDave Kleikamp case Opt_nouid32: 1453ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, NO_UID32); 1454ac27a0ecSDave Kleikamp break; 1455ac27a0ecSDave Kleikamp case Opt_debug: 1456ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, DEBUG); 1457ac27a0ecSDave Kleikamp break; 1458ac27a0ecSDave Kleikamp case Opt_oldalloc: 1459ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, OLDALLOC); 1460ac27a0ecSDave Kleikamp break; 1461ac27a0ecSDave Kleikamp case Opt_orlov: 1462ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, OLDALLOC); 1463ac27a0ecSDave Kleikamp break; 146403010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_XATTR 1465ac27a0ecSDave Kleikamp case Opt_user_xattr: 1466ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, XATTR_USER); 1467ac27a0ecSDave Kleikamp break; 1468ac27a0ecSDave Kleikamp case Opt_nouser_xattr: 1469ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, XATTR_USER); 1470ac27a0ecSDave Kleikamp break; 1471ac27a0ecSDave Kleikamp #else 1472ac27a0ecSDave Kleikamp case Opt_user_xattr: 1473ac27a0ecSDave Kleikamp case Opt_nouser_xattr: 1474b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "(no)user_xattr options not supported"); 1475ac27a0ecSDave Kleikamp break; 1476ac27a0ecSDave Kleikamp #endif 147703010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_POSIX_ACL 1478ac27a0ecSDave Kleikamp case Opt_acl: 1479ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, POSIX_ACL); 1480ac27a0ecSDave Kleikamp break; 1481ac27a0ecSDave Kleikamp case Opt_noacl: 1482ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, POSIX_ACL); 1483ac27a0ecSDave Kleikamp break; 1484ac27a0ecSDave Kleikamp #else 1485ac27a0ecSDave Kleikamp case Opt_acl: 1486ac27a0ecSDave Kleikamp case Opt_noacl: 1487b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "(no)acl options not supported"); 1488ac27a0ecSDave Kleikamp break; 1489ac27a0ecSDave Kleikamp #endif 1490ac27a0ecSDave Kleikamp case Opt_journal_update: 1491ac27a0ecSDave Kleikamp /* @@@ FIXME */ 1492ac27a0ecSDave Kleikamp /* Eventually we will want to be able to create 1493ac27a0ecSDave Kleikamp a journal file here. For now, only allow the 1494ac27a0ecSDave Kleikamp user to specify an existing inode to be the 1495ac27a0ecSDave Kleikamp journal file. */ 1496ac27a0ecSDave Kleikamp if (is_remount) { 1497b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 1498b31e1552SEric Sandeen "Cannot specify journal on remount"); 1499ac27a0ecSDave Kleikamp return 0; 1500ac27a0ecSDave Kleikamp } 1501ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, UPDATE_JOURNAL); 1502ac27a0ecSDave Kleikamp break; 1503ac27a0ecSDave Kleikamp case Opt_journal_dev: 1504ac27a0ecSDave Kleikamp if (is_remount) { 1505b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 1506b31e1552SEric Sandeen "Cannot specify journal on remount"); 1507ac27a0ecSDave Kleikamp return 0; 1508ac27a0ecSDave Kleikamp } 1509ac27a0ecSDave Kleikamp if (match_int(&args[0], &option)) 1510ac27a0ecSDave Kleikamp return 0; 1511ac27a0ecSDave Kleikamp *journal_devnum = option; 1512ac27a0ecSDave Kleikamp break; 1513818d276cSGirish Shilamkar case Opt_journal_checksum: 1514d4da6c9cSLinus Torvalds set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM); 1515d4da6c9cSLinus Torvalds break; 1516818d276cSGirish Shilamkar case Opt_journal_async_commit: 1517818d276cSGirish Shilamkar set_opt(sbi->s_mount_opt, JOURNAL_ASYNC_COMMIT); 1518d4da6c9cSLinus Torvalds set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM); 1519818d276cSGirish Shilamkar break; 1520ac27a0ecSDave Kleikamp case Opt_noload: 1521ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, NOLOAD); 1522ac27a0ecSDave Kleikamp break; 1523ac27a0ecSDave Kleikamp case Opt_commit: 1524ac27a0ecSDave Kleikamp if (match_int(&args[0], &option)) 1525ac27a0ecSDave Kleikamp return 0; 1526ac27a0ecSDave Kleikamp if (option < 0) 1527ac27a0ecSDave Kleikamp return 0; 1528ac27a0ecSDave Kleikamp if (option == 0) 1529cd02ff0bSMingming Cao option = JBD2_DEFAULT_MAX_COMMIT_AGE; 1530ac27a0ecSDave Kleikamp sbi->s_commit_interval = HZ * option; 1531ac27a0ecSDave Kleikamp break; 153230773840STheodore Ts'o case Opt_max_batch_time: 153330773840STheodore Ts'o if (match_int(&args[0], &option)) 153430773840STheodore Ts'o return 0; 153530773840STheodore Ts'o if (option < 0) 153630773840STheodore Ts'o return 0; 153730773840STheodore Ts'o if (option == 0) 153830773840STheodore Ts'o option = EXT4_DEF_MAX_BATCH_TIME; 153930773840STheodore Ts'o sbi->s_max_batch_time = option; 154030773840STheodore Ts'o break; 154130773840STheodore Ts'o case Opt_min_batch_time: 154230773840STheodore Ts'o if (match_int(&args[0], &option)) 154330773840STheodore Ts'o return 0; 154430773840STheodore Ts'o if (option < 0) 154530773840STheodore Ts'o return 0; 154630773840STheodore Ts'o sbi->s_min_batch_time = option; 154730773840STheodore Ts'o break; 1548ac27a0ecSDave Kleikamp case Opt_data_journal: 1549617ba13bSMingming Cao data_opt = EXT4_MOUNT_JOURNAL_DATA; 1550ac27a0ecSDave Kleikamp goto datacheck; 1551ac27a0ecSDave Kleikamp case Opt_data_ordered: 1552617ba13bSMingming Cao data_opt = EXT4_MOUNT_ORDERED_DATA; 1553ac27a0ecSDave Kleikamp goto datacheck; 1554ac27a0ecSDave Kleikamp case Opt_data_writeback: 1555617ba13bSMingming Cao data_opt = EXT4_MOUNT_WRITEBACK_DATA; 1556ac27a0ecSDave Kleikamp datacheck: 1557ac27a0ecSDave Kleikamp if (is_remount) { 1558482a7425SDmitry Monakhov if (test_opt(sb, DATA_FLAGS) != data_opt) { 1559b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 1560b31e1552SEric Sandeen "Cannot change data mode on remount"); 1561ac27a0ecSDave Kleikamp return 0; 1562ac27a0ecSDave Kleikamp } 1563ac27a0ecSDave Kleikamp } else { 1564482a7425SDmitry Monakhov clear_opt(sbi->s_mount_opt, DATA_FLAGS); 1565ac27a0ecSDave Kleikamp sbi->s_mount_opt |= data_opt; 1566ac27a0ecSDave Kleikamp } 1567ac27a0ecSDave Kleikamp break; 15685bf5683aSHidehiro Kawai case Opt_data_err_abort: 15695bf5683aSHidehiro Kawai set_opt(sbi->s_mount_opt, DATA_ERR_ABORT); 15705bf5683aSHidehiro Kawai break; 15715bf5683aSHidehiro Kawai case Opt_data_err_ignore: 15725bf5683aSHidehiro Kawai clear_opt(sbi->s_mount_opt, DATA_ERR_ABORT); 15735bf5683aSHidehiro Kawai break; 1574ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 1575ac27a0ecSDave Kleikamp case Opt_usrjquota: 157656c50f11SDmitry Monakhov if (!set_qf_name(sb, USRQUOTA, &args[0])) 157756c50f11SDmitry Monakhov return 0; 157856c50f11SDmitry Monakhov break; 1579ac27a0ecSDave Kleikamp case Opt_grpjquota: 158056c50f11SDmitry Monakhov if (!set_qf_name(sb, GRPQUOTA, &args[0])) 1581ac27a0ecSDave Kleikamp return 0; 1582ac27a0ecSDave Kleikamp break; 1583ac27a0ecSDave Kleikamp case Opt_offusrjquota: 158456c50f11SDmitry Monakhov if (!clear_qf_name(sb, USRQUOTA)) 1585ac27a0ecSDave Kleikamp return 0; 1586ac27a0ecSDave Kleikamp break; 158756c50f11SDmitry Monakhov case Opt_offgrpjquota: 158856c50f11SDmitry Monakhov if (!clear_qf_name(sb, GRPQUOTA)) 158956c50f11SDmitry Monakhov return 0; 159056c50f11SDmitry Monakhov break; 159156c50f11SDmitry Monakhov 1592ac27a0ecSDave Kleikamp case Opt_jqfmt_vfsold: 1593dfc5d03fSJan Kara qfmt = QFMT_VFS_OLD; 1594dfc5d03fSJan Kara goto set_qf_format; 1595ac27a0ecSDave Kleikamp case Opt_jqfmt_vfsv0: 1596dfc5d03fSJan Kara qfmt = QFMT_VFS_V0; 15975a20bdfcSJan Kara goto set_qf_format; 15985a20bdfcSJan Kara case Opt_jqfmt_vfsv1: 15995a20bdfcSJan Kara qfmt = QFMT_VFS_V1; 1600dfc5d03fSJan Kara set_qf_format: 160117bd13b3SJan Kara if (sb_any_quota_loaded(sb) && 1602dfc5d03fSJan Kara sbi->s_jquota_fmt != qfmt) { 1603b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "Cannot change " 1604dfc5d03fSJan Kara "journaled quota options when " 1605b31e1552SEric Sandeen "quota turned on"); 1606dfc5d03fSJan Kara return 0; 1607dfc5d03fSJan Kara } 1608dfc5d03fSJan Kara sbi->s_jquota_fmt = qfmt; 1609ac27a0ecSDave Kleikamp break; 1610ac27a0ecSDave Kleikamp case Opt_quota: 1611ac27a0ecSDave Kleikamp case Opt_usrquota: 1612ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, QUOTA); 1613ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, USRQUOTA); 1614ac27a0ecSDave Kleikamp break; 1615ac27a0ecSDave Kleikamp case Opt_grpquota: 1616ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, QUOTA); 1617ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, GRPQUOTA); 1618ac27a0ecSDave Kleikamp break; 1619ac27a0ecSDave Kleikamp case Opt_noquota: 162017bd13b3SJan Kara if (sb_any_quota_loaded(sb)) { 1621b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "Cannot change quota " 1622b31e1552SEric Sandeen "options when quota turned on"); 1623ac27a0ecSDave Kleikamp return 0; 1624ac27a0ecSDave Kleikamp } 1625ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, QUOTA); 1626ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, USRQUOTA); 1627ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, GRPQUOTA); 1628ac27a0ecSDave Kleikamp break; 1629ac27a0ecSDave Kleikamp #else 1630ac27a0ecSDave Kleikamp case Opt_quota: 1631ac27a0ecSDave Kleikamp case Opt_usrquota: 1632ac27a0ecSDave Kleikamp case Opt_grpquota: 1633b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 1634b31e1552SEric Sandeen "quota options not supported"); 1635cd59e7b9SJan Kara break; 1636ac27a0ecSDave Kleikamp case Opt_usrjquota: 1637ac27a0ecSDave Kleikamp case Opt_grpjquota: 1638ac27a0ecSDave Kleikamp case Opt_offusrjquota: 1639ac27a0ecSDave Kleikamp case Opt_offgrpjquota: 1640ac27a0ecSDave Kleikamp case Opt_jqfmt_vfsold: 1641ac27a0ecSDave Kleikamp case Opt_jqfmt_vfsv0: 16425a20bdfcSJan Kara case Opt_jqfmt_vfsv1: 1643b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 1644b31e1552SEric Sandeen "journaled quota options not supported"); 1645ac27a0ecSDave Kleikamp break; 1646ac27a0ecSDave Kleikamp case Opt_noquota: 1647ac27a0ecSDave Kleikamp break; 1648ac27a0ecSDave Kleikamp #endif 1649ac27a0ecSDave Kleikamp case Opt_abort: 16504ab2f15bSTheodore Ts'o sbi->s_mount_flags |= EXT4_MF_FS_ABORTED; 1651ac27a0ecSDave Kleikamp break; 165206705bffSTheodore Ts'o case Opt_nobarrier: 165306705bffSTheodore Ts'o clear_opt(sbi->s_mount_opt, BARRIER); 165406705bffSTheodore Ts'o break; 1655ac27a0ecSDave Kleikamp case Opt_barrier: 165615121c18SEric Sandeen if (args[0].from) { 165715121c18SEric Sandeen if (match_int(&args[0], &option)) 165815121c18SEric Sandeen return 0; 165915121c18SEric Sandeen } else 166015121c18SEric Sandeen option = 1; /* No argument, default to 1 */ 1661ac27a0ecSDave Kleikamp if (option) 1662ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, BARRIER); 1663ac27a0ecSDave Kleikamp else 1664ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, BARRIER); 1665ac27a0ecSDave Kleikamp break; 1666ac27a0ecSDave Kleikamp case Opt_ignore: 1667ac27a0ecSDave Kleikamp break; 1668ac27a0ecSDave Kleikamp case Opt_resize: 1669ac27a0ecSDave Kleikamp if (!is_remount) { 1670b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 1671b31e1552SEric Sandeen "resize option only available " 1672b31e1552SEric Sandeen "for remount"); 1673ac27a0ecSDave Kleikamp return 0; 1674ac27a0ecSDave Kleikamp } 1675ac27a0ecSDave Kleikamp if (match_int(&args[0], &option) != 0) 1676ac27a0ecSDave Kleikamp return 0; 1677ac27a0ecSDave Kleikamp *n_blocks_count = option; 1678ac27a0ecSDave Kleikamp break; 1679ac27a0ecSDave Kleikamp case Opt_nobh: 1680206f7ab4SChristoph Hellwig ext4_msg(sb, KERN_WARNING, 1681206f7ab4SChristoph Hellwig "Ignoring deprecated nobh option"); 1682ac27a0ecSDave Kleikamp break; 1683ac27a0ecSDave Kleikamp case Opt_bh: 1684206f7ab4SChristoph Hellwig ext4_msg(sb, KERN_WARNING, 1685206f7ab4SChristoph Hellwig "Ignoring deprecated bh option"); 1686ac27a0ecSDave Kleikamp break; 168725ec56b5SJean Noel Cordenner case Opt_i_version: 168825ec56b5SJean Noel Cordenner set_opt(sbi->s_mount_opt, I_VERSION); 168925ec56b5SJean Noel Cordenner sb->s_flags |= MS_I_VERSION; 169025ec56b5SJean Noel Cordenner break; 1691dd919b98SAneesh Kumar K.V case Opt_nodelalloc: 1692dd919b98SAneesh Kumar K.V clear_opt(sbi->s_mount_opt, DELALLOC); 1693dd919b98SAneesh Kumar K.V break; 1694c9de560dSAlex Tomas case Opt_stripe: 1695c9de560dSAlex Tomas if (match_int(&args[0], &option)) 1696c9de560dSAlex Tomas return 0; 1697c9de560dSAlex Tomas if (option < 0) 1698c9de560dSAlex Tomas return 0; 1699c9de560dSAlex Tomas sbi->s_stripe = option; 1700c9de560dSAlex Tomas break; 170164769240SAlex Tomas case Opt_delalloc: 170264769240SAlex Tomas set_opt(sbi->s_mount_opt, DELALLOC); 170364769240SAlex Tomas break; 17046fd058f7STheodore Ts'o case Opt_block_validity: 17056fd058f7STheodore Ts'o set_opt(sbi->s_mount_opt, BLOCK_VALIDITY); 17066fd058f7STheodore Ts'o break; 17076fd058f7STheodore Ts'o case Opt_noblock_validity: 17086fd058f7STheodore Ts'o clear_opt(sbi->s_mount_opt, BLOCK_VALIDITY); 17096fd058f7STheodore Ts'o break; 1710240799cdSTheodore Ts'o case Opt_inode_readahead_blks: 1711240799cdSTheodore Ts'o if (match_int(&args[0], &option)) 1712240799cdSTheodore Ts'o return 0; 1713240799cdSTheodore Ts'o if (option < 0 || option > (1 << 30)) 1714240799cdSTheodore Ts'o return 0; 1715f7c43950STheodore Ts'o if (!is_power_of_2(option)) { 1716b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 1717b31e1552SEric Sandeen "EXT4-fs: inode_readahead_blks" 1718b31e1552SEric Sandeen " must be a power of 2"); 17193197ebdbSTheodore Ts'o return 0; 17203197ebdbSTheodore Ts'o } 1721240799cdSTheodore Ts'o sbi->s_inode_readahead_blks = option; 1722240799cdSTheodore Ts'o break; 1723b3881f74STheodore Ts'o case Opt_journal_ioprio: 1724b3881f74STheodore Ts'o if (match_int(&args[0], &option)) 1725b3881f74STheodore Ts'o return 0; 1726b3881f74STheodore Ts'o if (option < 0 || option > 7) 1727b3881f74STheodore Ts'o break; 1728b3881f74STheodore Ts'o *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 1729b3881f74STheodore Ts'o option); 1730b3881f74STheodore Ts'o break; 173106705bffSTheodore Ts'o case Opt_noauto_da_alloc: 173206705bffSTheodore Ts'o set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC); 173306705bffSTheodore Ts'o break; 1734afd4672dSTheodore Ts'o case Opt_auto_da_alloc: 173515121c18SEric Sandeen if (args[0].from) { 173615121c18SEric Sandeen if (match_int(&args[0], &option)) 173715121c18SEric Sandeen return 0; 173815121c18SEric Sandeen } else 173915121c18SEric Sandeen option = 1; /* No argument, default to 1 */ 1740afd4672dSTheodore Ts'o if (option) 1741afd4672dSTheodore Ts'o clear_opt(sbi->s_mount_opt, NO_AUTO_DA_ALLOC); 1742afd4672dSTheodore Ts'o else 1743afd4672dSTheodore Ts'o set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC); 1744afd4672dSTheodore Ts'o break; 17455328e635SEric Sandeen case Opt_discard: 17465328e635SEric Sandeen set_opt(sbi->s_mount_opt, DISCARD); 17475328e635SEric Sandeen break; 17485328e635SEric Sandeen case Opt_nodiscard: 17495328e635SEric Sandeen clear_opt(sbi->s_mount_opt, DISCARD); 17505328e635SEric Sandeen break; 1751744692dcSJiaying Zhang case Opt_dioread_nolock: 1752744692dcSJiaying Zhang set_opt(sbi->s_mount_opt, DIOREAD_NOLOCK); 1753744692dcSJiaying Zhang break; 1754744692dcSJiaying Zhang case Opt_dioread_lock: 1755744692dcSJiaying Zhang clear_opt(sbi->s_mount_opt, DIOREAD_NOLOCK); 1756744692dcSJiaying Zhang break; 1757ac27a0ecSDave Kleikamp default: 1758b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 1759b31e1552SEric Sandeen "Unrecognized mount option \"%s\" " 1760b31e1552SEric Sandeen "or missing value", p); 1761ac27a0ecSDave Kleikamp return 0; 1762ac27a0ecSDave Kleikamp } 1763ac27a0ecSDave Kleikamp } 1764ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 1765ac27a0ecSDave Kleikamp if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { 1766482a7425SDmitry Monakhov if (test_opt(sb, USRQUOTA) && sbi->s_qf_names[USRQUOTA]) 1767ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, USRQUOTA); 1768ac27a0ecSDave Kleikamp 1769482a7425SDmitry Monakhov if (test_opt(sb, GRPQUOTA) && sbi->s_qf_names[GRPQUOTA]) 1770ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, GRPQUOTA); 1771ac27a0ecSDave Kleikamp 177256c50f11SDmitry Monakhov if (test_opt(sb, GRPQUOTA) || test_opt(sb, USRQUOTA)) { 1773b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "old and new quota " 1774b31e1552SEric Sandeen "format mixing"); 1775ac27a0ecSDave Kleikamp return 0; 1776ac27a0ecSDave Kleikamp } 1777ac27a0ecSDave Kleikamp 1778ac27a0ecSDave Kleikamp if (!sbi->s_jquota_fmt) { 1779b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "journaled quota format " 1780b31e1552SEric Sandeen "not specified"); 1781ac27a0ecSDave Kleikamp return 0; 1782ac27a0ecSDave Kleikamp } 1783ac27a0ecSDave Kleikamp } else { 1784ac27a0ecSDave Kleikamp if (sbi->s_jquota_fmt) { 1785b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "journaled quota format " 17862c8be6b2SJan Kara "specified with no journaling " 1787b31e1552SEric Sandeen "enabled"); 1788ac27a0ecSDave Kleikamp return 0; 1789ac27a0ecSDave Kleikamp } 1790ac27a0ecSDave Kleikamp } 1791ac27a0ecSDave Kleikamp #endif 1792ac27a0ecSDave Kleikamp return 1; 1793ac27a0ecSDave Kleikamp } 1794ac27a0ecSDave Kleikamp 1795617ba13bSMingming Cao static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, 1796ac27a0ecSDave Kleikamp int read_only) 1797ac27a0ecSDave Kleikamp { 1798617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 1799ac27a0ecSDave Kleikamp int res = 0; 1800ac27a0ecSDave Kleikamp 1801617ba13bSMingming Cao if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) { 1802b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "revision level too high, " 1803b31e1552SEric Sandeen "forcing read-only mode"); 1804ac27a0ecSDave Kleikamp res = MS_RDONLY; 1805ac27a0ecSDave Kleikamp } 1806ac27a0ecSDave Kleikamp if (read_only) 1807ac27a0ecSDave Kleikamp return res; 1808617ba13bSMingming Cao if (!(sbi->s_mount_state & EXT4_VALID_FS)) 1809b31e1552SEric Sandeen ext4_msg(sb, KERN_WARNING, "warning: mounting unchecked fs, " 1810b31e1552SEric Sandeen "running e2fsck is recommended"); 1811617ba13bSMingming Cao else if ((sbi->s_mount_state & EXT4_ERROR_FS)) 1812b31e1552SEric Sandeen ext4_msg(sb, KERN_WARNING, 1813b31e1552SEric Sandeen "warning: mounting fs with errors, " 1814b31e1552SEric Sandeen "running e2fsck is recommended"); 1815ac27a0ecSDave Kleikamp else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 && 1816ac27a0ecSDave Kleikamp le16_to_cpu(es->s_mnt_count) >= 1817ac27a0ecSDave Kleikamp (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count)) 1818b31e1552SEric Sandeen ext4_msg(sb, KERN_WARNING, 1819b31e1552SEric Sandeen "warning: maximal mount count reached, " 1820b31e1552SEric Sandeen "running e2fsck is recommended"); 1821ac27a0ecSDave Kleikamp else if (le32_to_cpu(es->s_checkinterval) && 1822ac27a0ecSDave Kleikamp (le32_to_cpu(es->s_lastcheck) + 1823ac27a0ecSDave Kleikamp le32_to_cpu(es->s_checkinterval) <= get_seconds())) 1824b31e1552SEric Sandeen ext4_msg(sb, KERN_WARNING, 1825b31e1552SEric Sandeen "warning: checktime reached, " 1826b31e1552SEric Sandeen "running e2fsck is recommended"); 18270390131bSFrank Mayhar if (!sbi->s_journal) 1828216c34b2SMarcin Slusarz es->s_state &= cpu_to_le16(~EXT4_VALID_FS); 1829ac27a0ecSDave Kleikamp if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) 1830617ba13bSMingming Cao es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); 1831e8546d06SMarcin Slusarz le16_add_cpu(&es->s_mnt_count, 1); 1832ac27a0ecSDave Kleikamp es->s_mtime = cpu_to_le32(get_seconds()); 1833617ba13bSMingming Cao ext4_update_dynamic_rev(sb); 18340390131bSFrank Mayhar if (sbi->s_journal) 1835617ba13bSMingming Cao EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 1836ac27a0ecSDave Kleikamp 1837e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 1838ac27a0ecSDave Kleikamp if (test_opt(sb, DEBUG)) 1839a9df9a49STheodore Ts'o printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, " 18407f4520ccSTheodore Ts'o "bpg=%lu, ipg=%lu, mo=%04x]\n", 1841ac27a0ecSDave Kleikamp sb->s_blocksize, 1842ac27a0ecSDave Kleikamp sbi->s_groups_count, 1843617ba13bSMingming Cao EXT4_BLOCKS_PER_GROUP(sb), 1844617ba13bSMingming Cao EXT4_INODES_PER_GROUP(sb), 1845ac27a0ecSDave Kleikamp sbi->s_mount_opt); 1846ac27a0ecSDave Kleikamp 1847ac27a0ecSDave Kleikamp return res; 1848ac27a0ecSDave Kleikamp } 1849ac27a0ecSDave Kleikamp 1850772cb7c8SJose R. Santos static int ext4_fill_flex_info(struct super_block *sb) 1851772cb7c8SJose R. Santos { 1852772cb7c8SJose R. Santos struct ext4_sb_info *sbi = EXT4_SB(sb); 1853772cb7c8SJose R. Santos struct ext4_group_desc *gdp = NULL; 1854772cb7c8SJose R. Santos ext4_group_t flex_group_count; 1855772cb7c8SJose R. Santos ext4_group_t flex_group; 1856772cb7c8SJose R. Santos int groups_per_flex = 0; 1857c5ca7c76STheodore Ts'o size_t size; 1858772cb7c8SJose R. Santos int i; 1859772cb7c8SJose R. Santos 1860503358aeSTheodore Ts'o sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex; 1861503358aeSTheodore Ts'o groups_per_flex = 1 << sbi->s_log_groups_per_flex; 1862503358aeSTheodore Ts'o 1863503358aeSTheodore Ts'o if (groups_per_flex < 2) { 1864772cb7c8SJose R. Santos sbi->s_log_groups_per_flex = 0; 1865772cb7c8SJose R. Santos return 1; 1866772cb7c8SJose R. Santos } 1867772cb7c8SJose R. Santos 1868c62a11fdSFrederic Bohe /* We allocate both existing and potentially added groups */ 1869c62a11fdSFrederic Bohe flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) + 1870d94e99a6SAneesh Kumar K.V ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) << 1871d94e99a6SAneesh Kumar K.V EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex; 1872c5ca7c76STheodore Ts'o size = flex_group_count * sizeof(struct flex_groups); 1873c5ca7c76STheodore Ts'o sbi->s_flex_groups = kzalloc(size, GFP_KERNEL); 1874c5ca7c76STheodore Ts'o if (sbi->s_flex_groups == NULL) { 1875c5ca7c76STheodore Ts'o sbi->s_flex_groups = vmalloc(size); 1876c5ca7c76STheodore Ts'o if (sbi->s_flex_groups) 1877c5ca7c76STheodore Ts'o memset(sbi->s_flex_groups, 0, size); 1878c5ca7c76STheodore Ts'o } 1879772cb7c8SJose R. Santos if (sbi->s_flex_groups == NULL) { 1880b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "not enough memory for " 1881b31e1552SEric Sandeen "%u flex groups", flex_group_count); 1882772cb7c8SJose R. Santos goto failed; 1883772cb7c8SJose R. Santos } 1884772cb7c8SJose R. Santos 1885772cb7c8SJose R. Santos for (i = 0; i < sbi->s_groups_count; i++) { 188688b6edd1STheodore Ts'o gdp = ext4_get_group_desc(sb, i, NULL); 1887772cb7c8SJose R. Santos 1888772cb7c8SJose R. Santos flex_group = ext4_flex_group(sbi, i); 18897ad9bb65STheodore Ts'o atomic_add(ext4_free_inodes_count(sb, gdp), 18907ad9bb65STheodore Ts'o &sbi->s_flex_groups[flex_group].free_inodes); 18917ad9bb65STheodore Ts'o atomic_add(ext4_free_blks_count(sb, gdp), 18927ad9bb65STheodore Ts'o &sbi->s_flex_groups[flex_group].free_blocks); 18937ad9bb65STheodore Ts'o atomic_add(ext4_used_dirs_count(sb, gdp), 18947ad9bb65STheodore Ts'o &sbi->s_flex_groups[flex_group].used_dirs); 1895772cb7c8SJose R. Santos } 1896772cb7c8SJose R. Santos 1897772cb7c8SJose R. Santos return 1; 1898772cb7c8SJose R. Santos failed: 1899772cb7c8SJose R. Santos return 0; 1900772cb7c8SJose R. Santos } 1901772cb7c8SJose R. Santos 1902717d50e4SAndreas Dilger __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group, 1903717d50e4SAndreas Dilger struct ext4_group_desc *gdp) 1904717d50e4SAndreas Dilger { 1905717d50e4SAndreas Dilger __u16 crc = 0; 1906717d50e4SAndreas Dilger 1907717d50e4SAndreas Dilger if (sbi->s_es->s_feature_ro_compat & 1908717d50e4SAndreas Dilger cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { 1909717d50e4SAndreas Dilger int offset = offsetof(struct ext4_group_desc, bg_checksum); 1910717d50e4SAndreas Dilger __le32 le_group = cpu_to_le32(block_group); 1911717d50e4SAndreas Dilger 1912717d50e4SAndreas Dilger crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid)); 1913717d50e4SAndreas Dilger crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group)); 1914717d50e4SAndreas Dilger crc = crc16(crc, (__u8 *)gdp, offset); 1915717d50e4SAndreas Dilger offset += sizeof(gdp->bg_checksum); /* skip checksum */ 1916717d50e4SAndreas Dilger /* for checksum of struct ext4_group_desc do the rest...*/ 1917717d50e4SAndreas Dilger if ((sbi->s_es->s_feature_incompat & 1918717d50e4SAndreas Dilger cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) && 1919717d50e4SAndreas Dilger offset < le16_to_cpu(sbi->s_es->s_desc_size)) 1920717d50e4SAndreas Dilger crc = crc16(crc, (__u8 *)gdp + offset, 1921717d50e4SAndreas Dilger le16_to_cpu(sbi->s_es->s_desc_size) - 1922717d50e4SAndreas Dilger offset); 1923717d50e4SAndreas Dilger } 1924717d50e4SAndreas Dilger 1925717d50e4SAndreas Dilger return cpu_to_le16(crc); 1926717d50e4SAndreas Dilger } 1927717d50e4SAndreas Dilger 1928717d50e4SAndreas Dilger int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group, 1929717d50e4SAndreas Dilger struct ext4_group_desc *gdp) 1930717d50e4SAndreas Dilger { 1931717d50e4SAndreas Dilger if ((sbi->s_es->s_feature_ro_compat & 1932717d50e4SAndreas Dilger cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) && 1933717d50e4SAndreas Dilger (gdp->bg_checksum != ext4_group_desc_csum(sbi, block_group, gdp))) 1934717d50e4SAndreas Dilger return 0; 1935717d50e4SAndreas Dilger 1936717d50e4SAndreas Dilger return 1; 1937717d50e4SAndreas Dilger } 1938717d50e4SAndreas Dilger 1939ac27a0ecSDave Kleikamp /* Called at mount-time, super-block is locked */ 1940617ba13bSMingming Cao static int ext4_check_descriptors(struct super_block *sb) 1941ac27a0ecSDave Kleikamp { 1942617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 1943617ba13bSMingming Cao ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block); 1944617ba13bSMingming Cao ext4_fsblk_t last_block; 1945bd81d8eeSLaurent Vivier ext4_fsblk_t block_bitmap; 1946bd81d8eeSLaurent Vivier ext4_fsblk_t inode_bitmap; 1947bd81d8eeSLaurent Vivier ext4_fsblk_t inode_table; 1948ce421581SJose R. Santos int flexbg_flag = 0; 1949fd2d4291SAvantika Mathur ext4_group_t i; 1950ac27a0ecSDave Kleikamp 1951ce421581SJose R. Santos if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) 1952ce421581SJose R. Santos flexbg_flag = 1; 1953ce421581SJose R. Santos 1954617ba13bSMingming Cao ext4_debug("Checking group descriptors"); 1955ac27a0ecSDave Kleikamp 1956197cd65aSAkinobu Mita for (i = 0; i < sbi->s_groups_count; i++) { 1957197cd65aSAkinobu Mita struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL); 1958197cd65aSAkinobu Mita 1959ce421581SJose R. Santos if (i == sbi->s_groups_count - 1 || flexbg_flag) 1960bd81d8eeSLaurent Vivier last_block = ext4_blocks_count(sbi->s_es) - 1; 1961ac27a0ecSDave Kleikamp else 1962ac27a0ecSDave Kleikamp last_block = first_block + 1963617ba13bSMingming Cao (EXT4_BLOCKS_PER_GROUP(sb) - 1); 1964ac27a0ecSDave Kleikamp 19658fadc143SAlexandre Ratchov block_bitmap = ext4_block_bitmap(sb, gdp); 19662b2d6d01STheodore Ts'o if (block_bitmap < first_block || block_bitmap > last_block) { 1967b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " 1968a9df9a49STheodore Ts'o "Block bitmap for group %u not in group " 1969b31e1552SEric Sandeen "(block %llu)!", i, block_bitmap); 1970ac27a0ecSDave Kleikamp return 0; 1971ac27a0ecSDave Kleikamp } 19728fadc143SAlexandre Ratchov inode_bitmap = ext4_inode_bitmap(sb, gdp); 19732b2d6d01STheodore Ts'o if (inode_bitmap < first_block || inode_bitmap > last_block) { 1974b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " 1975a9df9a49STheodore Ts'o "Inode bitmap for group %u not in group " 1976b31e1552SEric Sandeen "(block %llu)!", i, inode_bitmap); 1977ac27a0ecSDave Kleikamp return 0; 1978ac27a0ecSDave Kleikamp } 19798fadc143SAlexandre Ratchov inode_table = ext4_inode_table(sb, gdp); 1980bd81d8eeSLaurent Vivier if (inode_table < first_block || 19812b2d6d01STheodore Ts'o inode_table + sbi->s_itb_per_group - 1 > last_block) { 1982b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " 1983a9df9a49STheodore Ts'o "Inode table for group %u not in group " 1984b31e1552SEric Sandeen "(block %llu)!", i, inode_table); 1985ac27a0ecSDave Kleikamp return 0; 1986ac27a0ecSDave Kleikamp } 1987955ce5f5SAneesh Kumar K.V ext4_lock_group(sb, i); 1988717d50e4SAndreas Dilger if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { 1989b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " 1990b31e1552SEric Sandeen "Checksum for group %u failed (%u!=%u)", 1991fd2d4291SAvantika Mathur i, le16_to_cpu(ext4_group_desc_csum(sbi, i, 1992fd2d4291SAvantika Mathur gdp)), le16_to_cpu(gdp->bg_checksum)); 19937ee1ec4cSLi Zefan if (!(sb->s_flags & MS_RDONLY)) { 1994955ce5f5SAneesh Kumar K.V ext4_unlock_group(sb, i); 1995717d50e4SAndreas Dilger return 0; 1996717d50e4SAndreas Dilger } 19977ee1ec4cSLi Zefan } 1998955ce5f5SAneesh Kumar K.V ext4_unlock_group(sb, i); 1999ce421581SJose R. Santos if (!flexbg_flag) 2000617ba13bSMingming Cao first_block += EXT4_BLOCKS_PER_GROUP(sb); 2001ac27a0ecSDave Kleikamp } 2002ac27a0ecSDave Kleikamp 2003bd81d8eeSLaurent Vivier ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb)); 2004617ba13bSMingming Cao sbi->s_es->s_free_inodes_count =cpu_to_le32(ext4_count_free_inodes(sb)); 2005ac27a0ecSDave Kleikamp return 1; 2006ac27a0ecSDave Kleikamp } 2007ac27a0ecSDave Kleikamp 2008617ba13bSMingming Cao /* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at 2009ac27a0ecSDave Kleikamp * the superblock) which were deleted from all directories, but held open by 2010ac27a0ecSDave Kleikamp * a process at the time of a crash. We walk the list and try to delete these 2011ac27a0ecSDave Kleikamp * inodes at recovery time (only with a read-write filesystem). 2012ac27a0ecSDave Kleikamp * 2013ac27a0ecSDave Kleikamp * In order to keep the orphan inode chain consistent during traversal (in 2014ac27a0ecSDave Kleikamp * case of crash during recovery), we link each inode into the superblock 2015ac27a0ecSDave Kleikamp * orphan list_head and handle it the same way as an inode deletion during 2016ac27a0ecSDave Kleikamp * normal operation (which journals the operations for us). 2017ac27a0ecSDave Kleikamp * 2018ac27a0ecSDave Kleikamp * We only do an iget() and an iput() on each inode, which is very safe if we 2019ac27a0ecSDave Kleikamp * accidentally point at an in-use or already deleted inode. The worst that 2020ac27a0ecSDave Kleikamp * can happen in this case is that we get a "bit already cleared" message from 2021617ba13bSMingming Cao * ext4_free_inode(). The only reason we would point at a wrong inode is if 2022ac27a0ecSDave Kleikamp * e2fsck was run on this filesystem, and it must have already done the orphan 2023ac27a0ecSDave Kleikamp * inode cleanup for us, so we can safely abort without any further action. 2024ac27a0ecSDave Kleikamp */ 2025617ba13bSMingming Cao static void ext4_orphan_cleanup(struct super_block *sb, 2026617ba13bSMingming Cao struct ext4_super_block *es) 2027ac27a0ecSDave Kleikamp { 2028ac27a0ecSDave Kleikamp unsigned int s_flags = sb->s_flags; 2029ac27a0ecSDave Kleikamp int nr_orphans = 0, nr_truncates = 0; 2030ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 2031ac27a0ecSDave Kleikamp int i; 2032ac27a0ecSDave Kleikamp #endif 2033ac27a0ecSDave Kleikamp if (!es->s_last_orphan) { 2034ac27a0ecSDave Kleikamp jbd_debug(4, "no orphan inodes to clean up\n"); 2035ac27a0ecSDave Kleikamp return; 2036ac27a0ecSDave Kleikamp } 2037ac27a0ecSDave Kleikamp 2038a8f48a95SEric Sandeen if (bdev_read_only(sb->s_bdev)) { 2039b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "write access " 2040b31e1552SEric Sandeen "unavailable, skipping orphan cleanup"); 2041a8f48a95SEric Sandeen return; 2042a8f48a95SEric Sandeen } 2043a8f48a95SEric Sandeen 2044617ba13bSMingming Cao if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) { 2045ac27a0ecSDave Kleikamp if (es->s_last_orphan) 2046ac27a0ecSDave Kleikamp jbd_debug(1, "Errors on filesystem, " 2047ac27a0ecSDave Kleikamp "clearing orphan list.\n"); 2048ac27a0ecSDave Kleikamp es->s_last_orphan = 0; 2049ac27a0ecSDave Kleikamp jbd_debug(1, "Skipping orphan recovery on fs with errors.\n"); 2050ac27a0ecSDave Kleikamp return; 2051ac27a0ecSDave Kleikamp } 2052ac27a0ecSDave Kleikamp 2053ac27a0ecSDave Kleikamp if (s_flags & MS_RDONLY) { 2054b31e1552SEric Sandeen ext4_msg(sb, KERN_INFO, "orphan cleanup on readonly fs"); 2055ac27a0ecSDave Kleikamp sb->s_flags &= ~MS_RDONLY; 2056ac27a0ecSDave Kleikamp } 2057ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 2058ac27a0ecSDave Kleikamp /* Needed for iput() to work correctly and not trash data */ 2059ac27a0ecSDave Kleikamp sb->s_flags |= MS_ACTIVE; 2060ac27a0ecSDave Kleikamp /* Turn on quotas so that they are updated correctly */ 2061ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) { 2062617ba13bSMingming Cao if (EXT4_SB(sb)->s_qf_names[i]) { 2063617ba13bSMingming Cao int ret = ext4_quota_on_mount(sb, i); 2064ac27a0ecSDave Kleikamp if (ret < 0) 2065b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 2066b31e1552SEric Sandeen "Cannot turn on journaled " 2067b31e1552SEric Sandeen "quota: error %d", ret); 2068ac27a0ecSDave Kleikamp } 2069ac27a0ecSDave Kleikamp } 2070ac27a0ecSDave Kleikamp #endif 2071ac27a0ecSDave Kleikamp 2072ac27a0ecSDave Kleikamp while (es->s_last_orphan) { 2073ac27a0ecSDave Kleikamp struct inode *inode; 2074ac27a0ecSDave Kleikamp 207597bd42b9SJosef Bacik inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan)); 207697bd42b9SJosef Bacik if (IS_ERR(inode)) { 2077ac27a0ecSDave Kleikamp es->s_last_orphan = 0; 2078ac27a0ecSDave Kleikamp break; 2079ac27a0ecSDave Kleikamp } 2080ac27a0ecSDave Kleikamp 2081617ba13bSMingming Cao list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan); 2082871a2931SChristoph Hellwig dquot_initialize(inode); 2083ac27a0ecSDave Kleikamp if (inode->i_nlink) { 2084b31e1552SEric Sandeen ext4_msg(sb, KERN_DEBUG, 2085b31e1552SEric Sandeen "%s: truncating inode %lu to %lld bytes", 208646e665e9SHarvey Harrison __func__, inode->i_ino, inode->i_size); 2087e5f8eab8STheodore Ts'o jbd_debug(2, "truncating inode %lu to %lld bytes\n", 2088ac27a0ecSDave Kleikamp inode->i_ino, inode->i_size); 2089617ba13bSMingming Cao ext4_truncate(inode); 2090ac27a0ecSDave Kleikamp nr_truncates++; 2091ac27a0ecSDave Kleikamp } else { 2092b31e1552SEric Sandeen ext4_msg(sb, KERN_DEBUG, 2093b31e1552SEric Sandeen "%s: deleting unreferenced inode %lu", 209446e665e9SHarvey Harrison __func__, inode->i_ino); 2095ac27a0ecSDave Kleikamp jbd_debug(2, "deleting unreferenced inode %lu\n", 2096ac27a0ecSDave Kleikamp inode->i_ino); 2097ac27a0ecSDave Kleikamp nr_orphans++; 2098ac27a0ecSDave Kleikamp } 2099ac27a0ecSDave Kleikamp iput(inode); /* The delete magic happens here! */ 2100ac27a0ecSDave Kleikamp } 2101ac27a0ecSDave Kleikamp 2102ac27a0ecSDave Kleikamp #define PLURAL(x) (x), ((x) == 1) ? "" : "s" 2103ac27a0ecSDave Kleikamp 2104ac27a0ecSDave Kleikamp if (nr_orphans) 2105b31e1552SEric Sandeen ext4_msg(sb, KERN_INFO, "%d orphan inode%s deleted", 2106b31e1552SEric Sandeen PLURAL(nr_orphans)); 2107ac27a0ecSDave Kleikamp if (nr_truncates) 2108b31e1552SEric Sandeen ext4_msg(sb, KERN_INFO, "%d truncate%s cleaned up", 2109b31e1552SEric Sandeen PLURAL(nr_truncates)); 2110ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 2111ac27a0ecSDave Kleikamp /* Turn quotas off */ 2112ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) { 2113ac27a0ecSDave Kleikamp if (sb_dqopt(sb)->files[i]) 2114287a8095SChristoph Hellwig dquot_quota_off(sb, i); 2115ac27a0ecSDave Kleikamp } 2116ac27a0ecSDave Kleikamp #endif 2117ac27a0ecSDave Kleikamp sb->s_flags = s_flags; /* Restore MS_RDONLY status */ 2118ac27a0ecSDave Kleikamp } 21190b8e58a1SAndreas Dilger 2120cd2291a4SEric Sandeen /* 2121cd2291a4SEric Sandeen * Maximal extent format file size. 2122cd2291a4SEric Sandeen * Resulting logical blkno at s_maxbytes must fit in our on-disk 2123cd2291a4SEric Sandeen * extent format containers, within a sector_t, and within i_blocks 2124cd2291a4SEric Sandeen * in the vfs. ext4 inode has 48 bits of i_block in fsblock units, 2125cd2291a4SEric Sandeen * so that won't be a limiting factor. 2126cd2291a4SEric Sandeen * 2127cd2291a4SEric Sandeen * Note, this does *not* consider any metadata overhead for vfs i_blocks. 2128cd2291a4SEric Sandeen */ 2129f287a1a5STheodore Ts'o static loff_t ext4_max_size(int blkbits, int has_huge_files) 2130cd2291a4SEric Sandeen { 2131cd2291a4SEric Sandeen loff_t res; 2132cd2291a4SEric Sandeen loff_t upper_limit = MAX_LFS_FILESIZE; 2133cd2291a4SEric Sandeen 2134cd2291a4SEric Sandeen /* small i_blocks in vfs inode? */ 2135f287a1a5STheodore Ts'o if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) { 2136cd2291a4SEric Sandeen /* 213790c699a9SBartlomiej Zolnierkiewicz * CONFIG_LBDAF is not enabled implies the inode 2138cd2291a4SEric Sandeen * i_block represent total blocks in 512 bytes 2139cd2291a4SEric Sandeen * 32 == size of vfs inode i_blocks * 8 2140cd2291a4SEric Sandeen */ 2141cd2291a4SEric Sandeen upper_limit = (1LL << 32) - 1; 2142cd2291a4SEric Sandeen 2143cd2291a4SEric Sandeen /* total blocks in file system block size */ 2144cd2291a4SEric Sandeen upper_limit >>= (blkbits - 9); 2145cd2291a4SEric Sandeen upper_limit <<= blkbits; 2146cd2291a4SEric Sandeen } 2147cd2291a4SEric Sandeen 2148cd2291a4SEric Sandeen /* 32-bit extent-start container, ee_block */ 2149cd2291a4SEric Sandeen res = 1LL << 32; 2150cd2291a4SEric Sandeen res <<= blkbits; 2151cd2291a4SEric Sandeen res -= 1; 2152cd2291a4SEric Sandeen 2153cd2291a4SEric Sandeen /* Sanity check against vm- & vfs- imposed limits */ 2154cd2291a4SEric Sandeen if (res > upper_limit) 2155cd2291a4SEric Sandeen res = upper_limit; 2156cd2291a4SEric Sandeen 2157cd2291a4SEric Sandeen return res; 2158cd2291a4SEric Sandeen } 2159ac27a0ecSDave Kleikamp 2160ac27a0ecSDave Kleikamp /* 2161cd2291a4SEric Sandeen * Maximal bitmap file size. There is a direct, and {,double-,triple-}indirect 21620fc1b451SAneesh Kumar K.V * block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks. 21630fc1b451SAneesh Kumar K.V * We need to be 1 filesystem block less than the 2^48 sector limit. 2164ac27a0ecSDave Kleikamp */ 2165f287a1a5STheodore Ts'o static loff_t ext4_max_bitmap_size(int bits, int has_huge_files) 2166ac27a0ecSDave Kleikamp { 2167617ba13bSMingming Cao loff_t res = EXT4_NDIR_BLOCKS; 21680fc1b451SAneesh Kumar K.V int meta_blocks; 21690fc1b451SAneesh Kumar K.V loff_t upper_limit; 21700b8e58a1SAndreas Dilger /* This is calculated to be the largest file size for a dense, block 21710b8e58a1SAndreas Dilger * mapped file such that the file's total number of 512-byte sectors, 21720b8e58a1SAndreas Dilger * including data and all indirect blocks, does not exceed (2^48 - 1). 21730b8e58a1SAndreas Dilger * 21740b8e58a1SAndreas Dilger * __u32 i_blocks_lo and _u16 i_blocks_high represent the total 21750b8e58a1SAndreas Dilger * number of 512-byte sectors of the file. 21760fc1b451SAneesh Kumar K.V */ 21770fc1b451SAneesh Kumar K.V 2178f287a1a5STheodore Ts'o if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) { 21790fc1b451SAneesh Kumar K.V /* 218090c699a9SBartlomiej Zolnierkiewicz * !has_huge_files or CONFIG_LBDAF not enabled implies that 21810b8e58a1SAndreas Dilger * the inode i_block field represents total file blocks in 21820b8e58a1SAndreas Dilger * 2^32 512-byte sectors == size of vfs inode i_blocks * 8 21830fc1b451SAneesh Kumar K.V */ 21840fc1b451SAneesh Kumar K.V upper_limit = (1LL << 32) - 1; 21850fc1b451SAneesh Kumar K.V 21860fc1b451SAneesh Kumar K.V /* total blocks in file system block size */ 21870fc1b451SAneesh Kumar K.V upper_limit >>= (bits - 9); 21880fc1b451SAneesh Kumar K.V 21890fc1b451SAneesh Kumar K.V } else { 21908180a562SAneesh Kumar K.V /* 21918180a562SAneesh Kumar K.V * We use 48 bit ext4_inode i_blocks 21928180a562SAneesh Kumar K.V * With EXT4_HUGE_FILE_FL set the i_blocks 21938180a562SAneesh Kumar K.V * represent total number of blocks in 21948180a562SAneesh Kumar K.V * file system block size 21958180a562SAneesh Kumar K.V */ 21960fc1b451SAneesh Kumar K.V upper_limit = (1LL << 48) - 1; 21970fc1b451SAneesh Kumar K.V 21980fc1b451SAneesh Kumar K.V } 21990fc1b451SAneesh Kumar K.V 22000fc1b451SAneesh Kumar K.V /* indirect blocks */ 22010fc1b451SAneesh Kumar K.V meta_blocks = 1; 22020fc1b451SAneesh Kumar K.V /* double indirect blocks */ 22030fc1b451SAneesh Kumar K.V meta_blocks += 1 + (1LL << (bits-2)); 22040fc1b451SAneesh Kumar K.V /* tripple indirect blocks */ 22050fc1b451SAneesh Kumar K.V meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2))); 22060fc1b451SAneesh Kumar K.V 22070fc1b451SAneesh Kumar K.V upper_limit -= meta_blocks; 22080fc1b451SAneesh Kumar K.V upper_limit <<= bits; 2209ac27a0ecSDave Kleikamp 2210ac27a0ecSDave Kleikamp res += 1LL << (bits-2); 2211ac27a0ecSDave Kleikamp res += 1LL << (2*(bits-2)); 2212ac27a0ecSDave Kleikamp res += 1LL << (3*(bits-2)); 2213ac27a0ecSDave Kleikamp res <<= bits; 2214ac27a0ecSDave Kleikamp if (res > upper_limit) 2215ac27a0ecSDave Kleikamp res = upper_limit; 22160fc1b451SAneesh Kumar K.V 22170fc1b451SAneesh Kumar K.V if (res > MAX_LFS_FILESIZE) 22180fc1b451SAneesh Kumar K.V res = MAX_LFS_FILESIZE; 22190fc1b451SAneesh Kumar K.V 2220ac27a0ecSDave Kleikamp return res; 2221ac27a0ecSDave Kleikamp } 2222ac27a0ecSDave Kleikamp 2223617ba13bSMingming Cao static ext4_fsblk_t descriptor_loc(struct super_block *sb, 222470bbb3e0SAndrew Morton ext4_fsblk_t logical_sb_block, int nr) 2225ac27a0ecSDave Kleikamp { 2226617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 2227fd2d4291SAvantika Mathur ext4_group_t bg, first_meta_bg; 2228ac27a0ecSDave Kleikamp int has_super = 0; 2229ac27a0ecSDave Kleikamp 2230ac27a0ecSDave Kleikamp first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg); 2231ac27a0ecSDave Kleikamp 2232617ba13bSMingming Cao if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) || 2233ac27a0ecSDave Kleikamp nr < first_meta_bg) 223470bbb3e0SAndrew Morton return logical_sb_block + nr + 1; 2235ac27a0ecSDave Kleikamp bg = sbi->s_desc_per_block * nr; 2236617ba13bSMingming Cao if (ext4_bg_has_super(sb, bg)) 2237ac27a0ecSDave Kleikamp has_super = 1; 22380b8e58a1SAndreas Dilger 2239617ba13bSMingming Cao return (has_super + ext4_group_first_block_no(sb, bg)); 2240ac27a0ecSDave Kleikamp } 2241ac27a0ecSDave Kleikamp 2242c9de560dSAlex Tomas /** 2243c9de560dSAlex Tomas * ext4_get_stripe_size: Get the stripe size. 2244c9de560dSAlex Tomas * @sbi: In memory super block info 2245c9de560dSAlex Tomas * 2246c9de560dSAlex Tomas * If we have specified it via mount option, then 2247c9de560dSAlex Tomas * use the mount option value. If the value specified at mount time is 2248c9de560dSAlex Tomas * greater than the blocks per group use the super block value. 2249c9de560dSAlex Tomas * If the super block value is greater than blocks per group return 0. 2250c9de560dSAlex Tomas * Allocator needs it be less than blocks per group. 2251c9de560dSAlex Tomas * 2252c9de560dSAlex Tomas */ 2253c9de560dSAlex Tomas static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi) 2254c9de560dSAlex Tomas { 2255c9de560dSAlex Tomas unsigned long stride = le16_to_cpu(sbi->s_es->s_raid_stride); 2256c9de560dSAlex Tomas unsigned long stripe_width = 2257c9de560dSAlex Tomas le32_to_cpu(sbi->s_es->s_raid_stripe_width); 2258c9de560dSAlex Tomas 2259c9de560dSAlex Tomas if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group) 2260c9de560dSAlex Tomas return sbi->s_stripe; 2261c9de560dSAlex Tomas 2262c9de560dSAlex Tomas if (stripe_width <= sbi->s_blocks_per_group) 2263c9de560dSAlex Tomas return stripe_width; 2264c9de560dSAlex Tomas 2265c9de560dSAlex Tomas if (stride <= sbi->s_blocks_per_group) 2266c9de560dSAlex Tomas return stride; 2267c9de560dSAlex Tomas 2268c9de560dSAlex Tomas return 0; 2269c9de560dSAlex Tomas } 2270ac27a0ecSDave Kleikamp 22713197ebdbSTheodore Ts'o /* sysfs supprt */ 22723197ebdbSTheodore Ts'o 22733197ebdbSTheodore Ts'o struct ext4_attr { 22743197ebdbSTheodore Ts'o struct attribute attr; 22753197ebdbSTheodore Ts'o ssize_t (*show)(struct ext4_attr *, struct ext4_sb_info *, char *); 22763197ebdbSTheodore Ts'o ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *, 22773197ebdbSTheodore Ts'o const char *, size_t); 22783197ebdbSTheodore Ts'o int offset; 22793197ebdbSTheodore Ts'o }; 22803197ebdbSTheodore Ts'o 22813197ebdbSTheodore Ts'o static int parse_strtoul(const char *buf, 22823197ebdbSTheodore Ts'o unsigned long max, unsigned long *value) 22833197ebdbSTheodore Ts'o { 22843197ebdbSTheodore Ts'o char *endp; 22853197ebdbSTheodore Ts'o 2286e7d2860bSAndré Goddard Rosa *value = simple_strtoul(skip_spaces(buf), &endp, 0); 2287e7d2860bSAndré Goddard Rosa endp = skip_spaces(endp); 22883197ebdbSTheodore Ts'o if (*endp || *value > max) 22893197ebdbSTheodore Ts'o return -EINVAL; 22903197ebdbSTheodore Ts'o 22913197ebdbSTheodore Ts'o return 0; 22923197ebdbSTheodore Ts'o } 22933197ebdbSTheodore Ts'o 22943197ebdbSTheodore Ts'o static ssize_t delayed_allocation_blocks_show(struct ext4_attr *a, 22953197ebdbSTheodore Ts'o struct ext4_sb_info *sbi, 22963197ebdbSTheodore Ts'o char *buf) 22973197ebdbSTheodore Ts'o { 22983197ebdbSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "%llu\n", 22993197ebdbSTheodore Ts'o (s64) percpu_counter_sum(&sbi->s_dirtyblocks_counter)); 23003197ebdbSTheodore Ts'o } 23013197ebdbSTheodore Ts'o 23023197ebdbSTheodore Ts'o static ssize_t session_write_kbytes_show(struct ext4_attr *a, 23033197ebdbSTheodore Ts'o struct ext4_sb_info *sbi, char *buf) 23043197ebdbSTheodore Ts'o { 23053197ebdbSTheodore Ts'o struct super_block *sb = sbi->s_buddy_cache->i_sb; 23063197ebdbSTheodore Ts'o 2307f613dfcbSTheodore Ts'o if (!sb->s_bdev->bd_part) 2308f613dfcbSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "0\n"); 23093197ebdbSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "%lu\n", 23103197ebdbSTheodore Ts'o (part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 23113197ebdbSTheodore Ts'o sbi->s_sectors_written_start) >> 1); 23123197ebdbSTheodore Ts'o } 23133197ebdbSTheodore Ts'o 23143197ebdbSTheodore Ts'o static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a, 23153197ebdbSTheodore Ts'o struct ext4_sb_info *sbi, char *buf) 23163197ebdbSTheodore Ts'o { 23173197ebdbSTheodore Ts'o struct super_block *sb = sbi->s_buddy_cache->i_sb; 23183197ebdbSTheodore Ts'o 2319f613dfcbSTheodore Ts'o if (!sb->s_bdev->bd_part) 2320f613dfcbSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "0\n"); 23213197ebdbSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "%llu\n", 2322a6b43e38SAndrew Morton (unsigned long long)(sbi->s_kbytes_written + 23233197ebdbSTheodore Ts'o ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 2324a6b43e38SAndrew Morton EXT4_SB(sb)->s_sectors_written_start) >> 1))); 23253197ebdbSTheodore Ts'o } 23263197ebdbSTheodore Ts'o 23273197ebdbSTheodore Ts'o static ssize_t inode_readahead_blks_store(struct ext4_attr *a, 23283197ebdbSTheodore Ts'o struct ext4_sb_info *sbi, 23293197ebdbSTheodore Ts'o const char *buf, size_t count) 23303197ebdbSTheodore Ts'o { 23313197ebdbSTheodore Ts'o unsigned long t; 23323197ebdbSTheodore Ts'o 23333197ebdbSTheodore Ts'o if (parse_strtoul(buf, 0x40000000, &t)) 23343197ebdbSTheodore Ts'o return -EINVAL; 23353197ebdbSTheodore Ts'o 2336f7c43950STheodore Ts'o if (!is_power_of_2(t)) 23373197ebdbSTheodore Ts'o return -EINVAL; 23383197ebdbSTheodore Ts'o 23393197ebdbSTheodore Ts'o sbi->s_inode_readahead_blks = t; 23403197ebdbSTheodore Ts'o return count; 23413197ebdbSTheodore Ts'o } 23423197ebdbSTheodore Ts'o 23433197ebdbSTheodore Ts'o static ssize_t sbi_ui_show(struct ext4_attr *a, 23443197ebdbSTheodore Ts'o struct ext4_sb_info *sbi, char *buf) 23453197ebdbSTheodore Ts'o { 23463197ebdbSTheodore Ts'o unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset); 23473197ebdbSTheodore Ts'o 23483197ebdbSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "%u\n", *ui); 23493197ebdbSTheodore Ts'o } 23503197ebdbSTheodore Ts'o 23513197ebdbSTheodore Ts'o static ssize_t sbi_ui_store(struct ext4_attr *a, 23523197ebdbSTheodore Ts'o struct ext4_sb_info *sbi, 23533197ebdbSTheodore Ts'o const char *buf, size_t count) 23543197ebdbSTheodore Ts'o { 23553197ebdbSTheodore Ts'o unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset); 23563197ebdbSTheodore Ts'o unsigned long t; 23573197ebdbSTheodore Ts'o 23583197ebdbSTheodore Ts'o if (parse_strtoul(buf, 0xffffffff, &t)) 23593197ebdbSTheodore Ts'o return -EINVAL; 23603197ebdbSTheodore Ts'o *ui = t; 23613197ebdbSTheodore Ts'o return count; 23623197ebdbSTheodore Ts'o } 23633197ebdbSTheodore Ts'o 23643197ebdbSTheodore Ts'o #define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \ 23653197ebdbSTheodore Ts'o static struct ext4_attr ext4_attr_##_name = { \ 23663197ebdbSTheodore Ts'o .attr = {.name = __stringify(_name), .mode = _mode }, \ 23673197ebdbSTheodore Ts'o .show = _show, \ 23683197ebdbSTheodore Ts'o .store = _store, \ 23693197ebdbSTheodore Ts'o .offset = offsetof(struct ext4_sb_info, _elname), \ 23703197ebdbSTheodore Ts'o } 23713197ebdbSTheodore Ts'o #define EXT4_ATTR(name, mode, show, store) \ 23723197ebdbSTheodore Ts'o static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store) 23733197ebdbSTheodore Ts'o 23743197ebdbSTheodore Ts'o #define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL) 23753197ebdbSTheodore Ts'o #define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store) 23763197ebdbSTheodore Ts'o #define EXT4_RW_ATTR_SBI_UI(name, elname) \ 23773197ebdbSTheodore Ts'o EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname) 23783197ebdbSTheodore Ts'o #define ATTR_LIST(name) &ext4_attr_##name.attr 23793197ebdbSTheodore Ts'o 23803197ebdbSTheodore Ts'o EXT4_RO_ATTR(delayed_allocation_blocks); 23813197ebdbSTheodore Ts'o EXT4_RO_ATTR(session_write_kbytes); 23823197ebdbSTheodore Ts'o EXT4_RO_ATTR(lifetime_write_kbytes); 23833197ebdbSTheodore Ts'o EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show, 23843197ebdbSTheodore Ts'o inode_readahead_blks_store, s_inode_readahead_blks); 238511013911SAndreas Dilger EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal); 23863197ebdbSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats); 23873197ebdbSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan); 23883197ebdbSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan); 23893197ebdbSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs); 23903197ebdbSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request); 23913197ebdbSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc); 239255138e0bSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(max_writeback_mb_bump, s_max_writeback_mb_bump); 23933197ebdbSTheodore Ts'o 23943197ebdbSTheodore Ts'o static struct attribute *ext4_attrs[] = { 23953197ebdbSTheodore Ts'o ATTR_LIST(delayed_allocation_blocks), 23963197ebdbSTheodore Ts'o ATTR_LIST(session_write_kbytes), 23973197ebdbSTheodore Ts'o ATTR_LIST(lifetime_write_kbytes), 23983197ebdbSTheodore Ts'o ATTR_LIST(inode_readahead_blks), 239911013911SAndreas Dilger ATTR_LIST(inode_goal), 24003197ebdbSTheodore Ts'o ATTR_LIST(mb_stats), 24013197ebdbSTheodore Ts'o ATTR_LIST(mb_max_to_scan), 24023197ebdbSTheodore Ts'o ATTR_LIST(mb_min_to_scan), 24033197ebdbSTheodore Ts'o ATTR_LIST(mb_order2_req), 24043197ebdbSTheodore Ts'o ATTR_LIST(mb_stream_req), 24053197ebdbSTheodore Ts'o ATTR_LIST(mb_group_prealloc), 240655138e0bSTheodore Ts'o ATTR_LIST(max_writeback_mb_bump), 24073197ebdbSTheodore Ts'o NULL, 24083197ebdbSTheodore Ts'o }; 24093197ebdbSTheodore Ts'o 24103197ebdbSTheodore Ts'o static ssize_t ext4_attr_show(struct kobject *kobj, 24113197ebdbSTheodore Ts'o struct attribute *attr, char *buf) 24123197ebdbSTheodore Ts'o { 24133197ebdbSTheodore Ts'o struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 24143197ebdbSTheodore Ts'o s_kobj); 24153197ebdbSTheodore Ts'o struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); 24163197ebdbSTheodore Ts'o 24173197ebdbSTheodore Ts'o return a->show ? a->show(a, sbi, buf) : 0; 24183197ebdbSTheodore Ts'o } 24193197ebdbSTheodore Ts'o 24203197ebdbSTheodore Ts'o static ssize_t ext4_attr_store(struct kobject *kobj, 24213197ebdbSTheodore Ts'o struct attribute *attr, 24223197ebdbSTheodore Ts'o const char *buf, size_t len) 24233197ebdbSTheodore Ts'o { 24243197ebdbSTheodore Ts'o struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 24253197ebdbSTheodore Ts'o s_kobj); 24263197ebdbSTheodore Ts'o struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); 24273197ebdbSTheodore Ts'o 24283197ebdbSTheodore Ts'o return a->store ? a->store(a, sbi, buf, len) : 0; 24293197ebdbSTheodore Ts'o } 24303197ebdbSTheodore Ts'o 24313197ebdbSTheodore Ts'o static void ext4_sb_release(struct kobject *kobj) 24323197ebdbSTheodore Ts'o { 24333197ebdbSTheodore Ts'o struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 24343197ebdbSTheodore Ts'o s_kobj); 24353197ebdbSTheodore Ts'o complete(&sbi->s_kobj_unregister); 24363197ebdbSTheodore Ts'o } 24373197ebdbSTheodore Ts'o 24383197ebdbSTheodore Ts'o 243952cf25d0SEmese Revfy static const struct sysfs_ops ext4_attr_ops = { 24403197ebdbSTheodore Ts'o .show = ext4_attr_show, 24413197ebdbSTheodore Ts'o .store = ext4_attr_store, 24423197ebdbSTheodore Ts'o }; 24433197ebdbSTheodore Ts'o 24443197ebdbSTheodore Ts'o static struct kobj_type ext4_ktype = { 24453197ebdbSTheodore Ts'o .default_attrs = ext4_attrs, 24463197ebdbSTheodore Ts'o .sysfs_ops = &ext4_attr_ops, 24473197ebdbSTheodore Ts'o .release = ext4_sb_release, 24483197ebdbSTheodore Ts'o }; 24493197ebdbSTheodore Ts'o 2450a13fb1a4SEric Sandeen /* 2451a13fb1a4SEric Sandeen * Check whether this filesystem can be mounted based on 2452a13fb1a4SEric Sandeen * the features present and the RDONLY/RDWR mount requested. 2453a13fb1a4SEric Sandeen * Returns 1 if this filesystem can be mounted as requested, 2454a13fb1a4SEric Sandeen * 0 if it cannot be. 2455a13fb1a4SEric Sandeen */ 2456a13fb1a4SEric Sandeen static int ext4_feature_set_ok(struct super_block *sb, int readonly) 2457a13fb1a4SEric Sandeen { 2458a13fb1a4SEric Sandeen if (EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP)) { 2459a13fb1a4SEric Sandeen ext4_msg(sb, KERN_ERR, 2460a13fb1a4SEric Sandeen "Couldn't mount because of " 2461a13fb1a4SEric Sandeen "unsupported optional features (%x)", 2462a13fb1a4SEric Sandeen (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) & 2463a13fb1a4SEric Sandeen ~EXT4_FEATURE_INCOMPAT_SUPP)); 2464a13fb1a4SEric Sandeen return 0; 2465a13fb1a4SEric Sandeen } 2466a13fb1a4SEric Sandeen 2467a13fb1a4SEric Sandeen if (readonly) 2468a13fb1a4SEric Sandeen return 1; 2469a13fb1a4SEric Sandeen 2470a13fb1a4SEric Sandeen /* Check that feature set is OK for a read-write mount */ 2471a13fb1a4SEric Sandeen if (EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP)) { 2472a13fb1a4SEric Sandeen ext4_msg(sb, KERN_ERR, "couldn't mount RDWR because of " 2473a13fb1a4SEric Sandeen "unsupported optional features (%x)", 2474a13fb1a4SEric Sandeen (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) & 2475a13fb1a4SEric Sandeen ~EXT4_FEATURE_RO_COMPAT_SUPP)); 2476a13fb1a4SEric Sandeen return 0; 2477a13fb1a4SEric Sandeen } 2478a13fb1a4SEric Sandeen /* 2479a13fb1a4SEric Sandeen * Large file size enabled file system can only be mounted 2480a13fb1a4SEric Sandeen * read-write on 32-bit systems if kernel is built with CONFIG_LBDAF 2481a13fb1a4SEric Sandeen */ 2482a13fb1a4SEric Sandeen if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) { 2483a13fb1a4SEric Sandeen if (sizeof(blkcnt_t) < sizeof(u64)) { 2484a13fb1a4SEric Sandeen ext4_msg(sb, KERN_ERR, "Filesystem with huge files " 2485a13fb1a4SEric Sandeen "cannot be mounted RDWR without " 2486a13fb1a4SEric Sandeen "CONFIG_LBDAF"); 2487a13fb1a4SEric Sandeen return 0; 2488a13fb1a4SEric Sandeen } 2489a13fb1a4SEric Sandeen } 2490a13fb1a4SEric Sandeen return 1; 2491a13fb1a4SEric Sandeen } 2492a13fb1a4SEric Sandeen 249366e61a9eSTheodore Ts'o /* 249466e61a9eSTheodore Ts'o * This function is called once a day if we have errors logged 249566e61a9eSTheodore Ts'o * on the file system 249666e61a9eSTheodore Ts'o */ 249766e61a9eSTheodore Ts'o static void print_daily_error_info(unsigned long arg) 249866e61a9eSTheodore Ts'o { 249966e61a9eSTheodore Ts'o struct super_block *sb = (struct super_block *) arg; 250066e61a9eSTheodore Ts'o struct ext4_sb_info *sbi; 250166e61a9eSTheodore Ts'o struct ext4_super_block *es; 250266e61a9eSTheodore Ts'o 250366e61a9eSTheodore Ts'o sbi = EXT4_SB(sb); 250466e61a9eSTheodore Ts'o es = sbi->s_es; 250566e61a9eSTheodore Ts'o 250666e61a9eSTheodore Ts'o if (es->s_error_count) 250766e61a9eSTheodore Ts'o ext4_msg(sb, KERN_NOTICE, "error count: %u", 250866e61a9eSTheodore Ts'o le32_to_cpu(es->s_error_count)); 250966e61a9eSTheodore Ts'o if (es->s_first_error_time) { 251066e61a9eSTheodore Ts'o printk(KERN_NOTICE "EXT4-fs (%s): initial error at %u: %.*s:%d", 251166e61a9eSTheodore Ts'o sb->s_id, le32_to_cpu(es->s_first_error_time), 251266e61a9eSTheodore Ts'o (int) sizeof(es->s_first_error_func), 251366e61a9eSTheodore Ts'o es->s_first_error_func, 251466e61a9eSTheodore Ts'o le32_to_cpu(es->s_first_error_line)); 251566e61a9eSTheodore Ts'o if (es->s_first_error_ino) 251666e61a9eSTheodore Ts'o printk(": inode %u", 251766e61a9eSTheodore Ts'o le32_to_cpu(es->s_first_error_ino)); 251866e61a9eSTheodore Ts'o if (es->s_first_error_block) 251966e61a9eSTheodore Ts'o printk(": block %llu", (unsigned long long) 252066e61a9eSTheodore Ts'o le64_to_cpu(es->s_first_error_block)); 252166e61a9eSTheodore Ts'o printk("\n"); 252266e61a9eSTheodore Ts'o } 252366e61a9eSTheodore Ts'o if (es->s_last_error_time) { 252466e61a9eSTheodore Ts'o printk(KERN_NOTICE "EXT4-fs (%s): last error at %u: %.*s:%d", 252566e61a9eSTheodore Ts'o sb->s_id, le32_to_cpu(es->s_last_error_time), 252666e61a9eSTheodore Ts'o (int) sizeof(es->s_last_error_func), 252766e61a9eSTheodore Ts'o es->s_last_error_func, 252866e61a9eSTheodore Ts'o le32_to_cpu(es->s_last_error_line)); 252966e61a9eSTheodore Ts'o if (es->s_last_error_ino) 253066e61a9eSTheodore Ts'o printk(": inode %u", 253166e61a9eSTheodore Ts'o le32_to_cpu(es->s_last_error_ino)); 253266e61a9eSTheodore Ts'o if (es->s_last_error_block) 253366e61a9eSTheodore Ts'o printk(": block %llu", (unsigned long long) 253466e61a9eSTheodore Ts'o le64_to_cpu(es->s_last_error_block)); 253566e61a9eSTheodore Ts'o printk("\n"); 253666e61a9eSTheodore Ts'o } 253766e61a9eSTheodore Ts'o mod_timer(&sbi->s_err_report, jiffies + 24*60*60*HZ); /* Once a day */ 253866e61a9eSTheodore Ts'o } 253966e61a9eSTheodore Ts'o 2540617ba13bSMingming Cao static int ext4_fill_super(struct super_block *sb, void *data, int silent) 25417477827fSAneesh Kumar K.V __releases(kernel_lock) 25427477827fSAneesh Kumar K.V __acquires(kernel_lock) 2543ac27a0ecSDave Kleikamp { 2544d4c402d9SCurt Wohlgemuth char *orig_data = kstrdup(data, GFP_KERNEL); 2545ac27a0ecSDave Kleikamp struct buffer_head *bh; 2546617ba13bSMingming Cao struct ext4_super_block *es = NULL; 2547617ba13bSMingming Cao struct ext4_sb_info *sbi; 2548617ba13bSMingming Cao ext4_fsblk_t block; 2549617ba13bSMingming Cao ext4_fsblk_t sb_block = get_sb_block(&data); 255070bbb3e0SAndrew Morton ext4_fsblk_t logical_sb_block; 2551ac27a0ecSDave Kleikamp unsigned long offset = 0; 2552ac27a0ecSDave Kleikamp unsigned long journal_devnum = 0; 2553ac27a0ecSDave Kleikamp unsigned long def_mount_opts; 2554ac27a0ecSDave Kleikamp struct inode *root; 25559f6200bbSTheodore Ts'o char *cp; 25560390131bSFrank Mayhar const char *descr; 2557dcc7dae3SCyrill Gorcunov int ret = -ENOMEM; 2558ac27a0ecSDave Kleikamp int blocksize; 25594ec11028STheodore Ts'o unsigned int db_count; 25604ec11028STheodore Ts'o unsigned int i; 2561f287a1a5STheodore Ts'o int needs_recovery, has_huge_files; 2562bd81d8eeSLaurent Vivier __u64 blocks_count; 2563833f4077SPeter Zijlstra int err; 2564b3881f74STheodore Ts'o unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; 2565ac27a0ecSDave Kleikamp 2566ac27a0ecSDave Kleikamp sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); 2567ac27a0ecSDave Kleikamp if (!sbi) 2568dcc7dae3SCyrill Gorcunov goto out_free_orig; 2569705895b6SPekka Enberg 2570705895b6SPekka Enberg sbi->s_blockgroup_lock = 2571705895b6SPekka Enberg kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); 2572705895b6SPekka Enberg if (!sbi->s_blockgroup_lock) { 2573705895b6SPekka Enberg kfree(sbi); 2574dcc7dae3SCyrill Gorcunov goto out_free_orig; 2575705895b6SPekka Enberg } 2576ac27a0ecSDave Kleikamp sb->s_fs_info = sbi; 2577ac27a0ecSDave Kleikamp sbi->s_mount_opt = 0; 2578617ba13bSMingming Cao sbi->s_resuid = EXT4_DEF_RESUID; 2579617ba13bSMingming Cao sbi->s_resgid = EXT4_DEF_RESGID; 2580240799cdSTheodore Ts'o sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; 2581d9c9bef1SMiklos Szeredi sbi->s_sb_block = sb_block; 2582f613dfcbSTheodore Ts'o if (sb->s_bdev->bd_part) 2583f613dfcbSTheodore Ts'o sbi->s_sectors_written_start = 2584f613dfcbSTheodore Ts'o part_stat_read(sb->s_bdev->bd_part, sectors[1]); 2585ac27a0ecSDave Kleikamp 2586ac27a0ecSDave Kleikamp unlock_kernel(); 2587ac27a0ecSDave Kleikamp 25889f6200bbSTheodore Ts'o /* Cleanup superblock name */ 25899f6200bbSTheodore Ts'o for (cp = sb->s_id; (cp = strchr(cp, '/'));) 25909f6200bbSTheodore Ts'o *cp = '!'; 25919f6200bbSTheodore Ts'o 2592dcc7dae3SCyrill Gorcunov ret = -EINVAL; 2593617ba13bSMingming Cao blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE); 2594ac27a0ecSDave Kleikamp if (!blocksize) { 2595b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "unable to set blocksize"); 2596ac27a0ecSDave Kleikamp goto out_fail; 2597ac27a0ecSDave Kleikamp } 2598ac27a0ecSDave Kleikamp 2599ac27a0ecSDave Kleikamp /* 2600617ba13bSMingming Cao * The ext4 superblock will not be buffer aligned for other than 1kB 2601ac27a0ecSDave Kleikamp * block sizes. We need to calculate the offset from buffer start. 2602ac27a0ecSDave Kleikamp */ 2603617ba13bSMingming Cao if (blocksize != EXT4_MIN_BLOCK_SIZE) { 260470bbb3e0SAndrew Morton logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; 260570bbb3e0SAndrew Morton offset = do_div(logical_sb_block, blocksize); 2606ac27a0ecSDave Kleikamp } else { 260770bbb3e0SAndrew Morton logical_sb_block = sb_block; 2608ac27a0ecSDave Kleikamp } 2609ac27a0ecSDave Kleikamp 261070bbb3e0SAndrew Morton if (!(bh = sb_bread(sb, logical_sb_block))) { 2611b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "unable to read superblock"); 2612ac27a0ecSDave Kleikamp goto out_fail; 2613ac27a0ecSDave Kleikamp } 2614ac27a0ecSDave Kleikamp /* 2615ac27a0ecSDave Kleikamp * Note: s_es must be initialized as soon as possible because 2616617ba13bSMingming Cao * some ext4 macro-instructions depend on its value 2617ac27a0ecSDave Kleikamp */ 2618617ba13bSMingming Cao es = (struct ext4_super_block *) (((char *)bh->b_data) + offset); 2619ac27a0ecSDave Kleikamp sbi->s_es = es; 2620ac27a0ecSDave Kleikamp sb->s_magic = le16_to_cpu(es->s_magic); 2621617ba13bSMingming Cao if (sb->s_magic != EXT4_SUPER_MAGIC) 2622617ba13bSMingming Cao goto cantfind_ext4; 2623afc32f7eSTheodore Ts'o sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written); 2624ac27a0ecSDave Kleikamp 2625ac27a0ecSDave Kleikamp /* Set defaults before we parse the mount options */ 2626ac27a0ecSDave Kleikamp def_mount_opts = le32_to_cpu(es->s_default_mount_opts); 2627617ba13bSMingming Cao if (def_mount_opts & EXT4_DEFM_DEBUG) 2628ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, DEBUG); 2629437ca0fdSDmitry Monakhov if (def_mount_opts & EXT4_DEFM_BSDGROUPS) { 2630437ca0fdSDmitry Monakhov ext4_msg(sb, KERN_WARNING, deprecated_msg, "bsdgroups", 2631437ca0fdSDmitry Monakhov "2.6.38"); 2632ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, GRPID); 2633437ca0fdSDmitry Monakhov } 2634617ba13bSMingming Cao if (def_mount_opts & EXT4_DEFM_UID16) 2635ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, NO_UID32); 263603010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_XATTR 2637617ba13bSMingming Cao if (def_mount_opts & EXT4_DEFM_XATTR_USER) 2638ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, XATTR_USER); 26392e7842b8SHugh Dickins #endif 264003010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_POSIX_ACL 2641617ba13bSMingming Cao if (def_mount_opts & EXT4_DEFM_ACL) 2642ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, POSIX_ACL); 26432e7842b8SHugh Dickins #endif 2644617ba13bSMingming Cao if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA) 2645482a7425SDmitry Monakhov set_opt(sbi->s_mount_opt, JOURNAL_DATA); 2646617ba13bSMingming Cao else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED) 2647482a7425SDmitry Monakhov set_opt(sbi->s_mount_opt, ORDERED_DATA); 2648617ba13bSMingming Cao else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK) 2649482a7425SDmitry Monakhov set_opt(sbi->s_mount_opt, WRITEBACK_DATA); 2650ac27a0ecSDave Kleikamp 2651617ba13bSMingming Cao if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC) 2652ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, ERRORS_PANIC); 2653bb4f397aSAneesh Kumar K.V else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE) 2654ceea16bfSDmitry Mishin set_opt(sbi->s_mount_opt, ERRORS_CONT); 2655bb4f397aSAneesh Kumar K.V else 2656bb4f397aSAneesh Kumar K.V set_opt(sbi->s_mount_opt, ERRORS_RO); 2657ac27a0ecSDave Kleikamp 2658ac27a0ecSDave Kleikamp sbi->s_resuid = le16_to_cpu(es->s_def_resuid); 2659ac27a0ecSDave Kleikamp sbi->s_resgid = le16_to_cpu(es->s_def_resgid); 266030773840STheodore Ts'o sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ; 266130773840STheodore Ts'o sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME; 266230773840STheodore Ts'o sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME; 2663ac27a0ecSDave Kleikamp 2664571640caSEric Sandeen set_opt(sbi->s_mount_opt, BARRIER); 2665ac27a0ecSDave Kleikamp 26661e2462f9SMingming Cao /* 2667dd919b98SAneesh Kumar K.V * enable delayed allocation by default 2668dd919b98SAneesh Kumar K.V * Use -o nodelalloc to turn it off 2669dd919b98SAneesh Kumar K.V */ 2670ba69f9abSJan Kara if (!IS_EXT3_SB(sb)) 2671dd919b98SAneesh Kumar K.V set_opt(sbi->s_mount_opt, DELALLOC); 2672dd919b98SAneesh Kumar K.V 2673b3881f74STheodore Ts'o if (!parse_options((char *) data, sb, &journal_devnum, 2674b3881f74STheodore Ts'o &journal_ioprio, NULL, 0)) 2675ac27a0ecSDave Kleikamp goto failed_mount; 2676ac27a0ecSDave Kleikamp 2677ac27a0ecSDave Kleikamp sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 2678482a7425SDmitry Monakhov (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0); 2679ac27a0ecSDave Kleikamp 2680617ba13bSMingming Cao if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV && 2681617ba13bSMingming Cao (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) || 2682617ba13bSMingming Cao EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) || 2683617ba13bSMingming Cao EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U))) 2684b31e1552SEric Sandeen ext4_msg(sb, KERN_WARNING, 2685b31e1552SEric Sandeen "feature flags set on rev 0 fs, " 2686b31e1552SEric Sandeen "running e2fsck is recommended"); 2687469108ffSTheodore Tso 2688469108ffSTheodore Tso /* 2689ac27a0ecSDave Kleikamp * Check feature flags regardless of the revision level, since we 2690ac27a0ecSDave Kleikamp * previously didn't change the revision level when setting the flags, 2691ac27a0ecSDave Kleikamp * so there is a chance incompat flags are set on a rev 0 filesystem. 2692ac27a0ecSDave Kleikamp */ 2693a13fb1a4SEric Sandeen if (!ext4_feature_set_ok(sb, (sb->s_flags & MS_RDONLY))) 2694ac27a0ecSDave Kleikamp goto failed_mount; 2695a13fb1a4SEric Sandeen 2696ac27a0ecSDave Kleikamp blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size); 2697ac27a0ecSDave Kleikamp 2698617ba13bSMingming Cao if (blocksize < EXT4_MIN_BLOCK_SIZE || 2699617ba13bSMingming Cao blocksize > EXT4_MAX_BLOCK_SIZE) { 2700b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 2701b31e1552SEric Sandeen "Unsupported filesystem blocksize %d", blocksize); 2702ac27a0ecSDave Kleikamp goto failed_mount; 2703ac27a0ecSDave Kleikamp } 2704ac27a0ecSDave Kleikamp 2705ac27a0ecSDave Kleikamp if (sb->s_blocksize != blocksize) { 2706ce40733cSAneesh Kumar K.V /* Validate the filesystem blocksize */ 2707ce40733cSAneesh Kumar K.V if (!sb_set_blocksize(sb, blocksize)) { 2708b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "bad block size %d", 2709ce40733cSAneesh Kumar K.V blocksize); 2710ac27a0ecSDave Kleikamp goto failed_mount; 2711ac27a0ecSDave Kleikamp } 2712ac27a0ecSDave Kleikamp 2713ac27a0ecSDave Kleikamp brelse(bh); 271470bbb3e0SAndrew Morton logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; 271570bbb3e0SAndrew Morton offset = do_div(logical_sb_block, blocksize); 271670bbb3e0SAndrew Morton bh = sb_bread(sb, logical_sb_block); 2717ac27a0ecSDave Kleikamp if (!bh) { 2718b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 2719b31e1552SEric Sandeen "Can't read superblock on 2nd try"); 2720ac27a0ecSDave Kleikamp goto failed_mount; 2721ac27a0ecSDave Kleikamp } 2722617ba13bSMingming Cao es = (struct ext4_super_block *)(((char *)bh->b_data) + offset); 2723ac27a0ecSDave Kleikamp sbi->s_es = es; 2724617ba13bSMingming Cao if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) { 2725b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 2726b31e1552SEric Sandeen "Magic mismatch, very weird!"); 2727ac27a0ecSDave Kleikamp goto failed_mount; 2728ac27a0ecSDave Kleikamp } 2729ac27a0ecSDave Kleikamp } 2730ac27a0ecSDave Kleikamp 2731a13fb1a4SEric Sandeen has_huge_files = EXT4_HAS_RO_COMPAT_FEATURE(sb, 2732a13fb1a4SEric Sandeen EXT4_FEATURE_RO_COMPAT_HUGE_FILE); 2733f287a1a5STheodore Ts'o sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits, 2734f287a1a5STheodore Ts'o has_huge_files); 2735f287a1a5STheodore Ts'o sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files); 2736ac27a0ecSDave Kleikamp 2737617ba13bSMingming Cao if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) { 2738617ba13bSMingming Cao sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE; 2739617ba13bSMingming Cao sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO; 2740ac27a0ecSDave Kleikamp } else { 2741ac27a0ecSDave Kleikamp sbi->s_inode_size = le16_to_cpu(es->s_inode_size); 2742ac27a0ecSDave Kleikamp sbi->s_first_ino = le32_to_cpu(es->s_first_ino); 2743617ba13bSMingming Cao if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) || 27441330593eSVignesh Babu (!is_power_of_2(sbi->s_inode_size)) || 2745ac27a0ecSDave Kleikamp (sbi->s_inode_size > blocksize)) { 2746b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 2747b31e1552SEric Sandeen "unsupported inode size: %d", 2748ac27a0ecSDave Kleikamp sbi->s_inode_size); 2749ac27a0ecSDave Kleikamp goto failed_mount; 2750ac27a0ecSDave Kleikamp } 2751ef7f3835SKalpak Shah if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) 2752ef7f3835SKalpak Shah sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2); 2753ac27a0ecSDave Kleikamp } 27540b8e58a1SAndreas Dilger 27550d1ee42fSAlexandre Ratchov sbi->s_desc_size = le16_to_cpu(es->s_desc_size); 27560d1ee42fSAlexandre Ratchov if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) { 27578fadc143SAlexandre Ratchov if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT || 27580d1ee42fSAlexandre Ratchov sbi->s_desc_size > EXT4_MAX_DESC_SIZE || 2759d8ea6cf8Svignesh babu !is_power_of_2(sbi->s_desc_size)) { 2760b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 2761b31e1552SEric Sandeen "unsupported descriptor size %lu", 27620d1ee42fSAlexandre Ratchov sbi->s_desc_size); 27630d1ee42fSAlexandre Ratchov goto failed_mount; 27640d1ee42fSAlexandre Ratchov } 27650d1ee42fSAlexandre Ratchov } else 27660d1ee42fSAlexandre Ratchov sbi->s_desc_size = EXT4_MIN_DESC_SIZE; 27670b8e58a1SAndreas Dilger 2768ac27a0ecSDave Kleikamp sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); 2769ac27a0ecSDave Kleikamp sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); 2770b47b6f38SAndries E. Brouwer if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0) 2771617ba13bSMingming Cao goto cantfind_ext4; 27720b8e58a1SAndreas Dilger 2773617ba13bSMingming Cao sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb); 2774ac27a0ecSDave Kleikamp if (sbi->s_inodes_per_block == 0) 2775617ba13bSMingming Cao goto cantfind_ext4; 2776ac27a0ecSDave Kleikamp sbi->s_itb_per_group = sbi->s_inodes_per_group / 2777ac27a0ecSDave Kleikamp sbi->s_inodes_per_block; 27780d1ee42fSAlexandre Ratchov sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb); 2779ac27a0ecSDave Kleikamp sbi->s_sbh = bh; 2780ac27a0ecSDave Kleikamp sbi->s_mount_state = le16_to_cpu(es->s_state); 2781e57aa839SFengguang Wu sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb)); 2782e57aa839SFengguang Wu sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb)); 27830b8e58a1SAndreas Dilger 2784ac27a0ecSDave Kleikamp for (i = 0; i < 4; i++) 2785ac27a0ecSDave Kleikamp sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); 2786ac27a0ecSDave Kleikamp sbi->s_def_hash_version = es->s_def_hash_version; 2787f99b2589STheodore Ts'o i = le32_to_cpu(es->s_flags); 2788f99b2589STheodore Ts'o if (i & EXT2_FLAGS_UNSIGNED_HASH) 2789f99b2589STheodore Ts'o sbi->s_hash_unsigned = 3; 2790f99b2589STheodore Ts'o else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) { 2791f99b2589STheodore Ts'o #ifdef __CHAR_UNSIGNED__ 2792f99b2589STheodore Ts'o es->s_flags |= cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH); 2793f99b2589STheodore Ts'o sbi->s_hash_unsigned = 3; 2794f99b2589STheodore Ts'o #else 2795f99b2589STheodore Ts'o es->s_flags |= cpu_to_le32(EXT2_FLAGS_SIGNED_HASH); 2796f99b2589STheodore Ts'o #endif 2797f99b2589STheodore Ts'o sb->s_dirt = 1; 2798f99b2589STheodore Ts'o } 2799ac27a0ecSDave Kleikamp 2800ac27a0ecSDave Kleikamp if (sbi->s_blocks_per_group > blocksize * 8) { 2801b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 2802b31e1552SEric Sandeen "#blocks per group too big: %lu", 2803ac27a0ecSDave Kleikamp sbi->s_blocks_per_group); 2804ac27a0ecSDave Kleikamp goto failed_mount; 2805ac27a0ecSDave Kleikamp } 2806ac27a0ecSDave Kleikamp if (sbi->s_inodes_per_group > blocksize * 8) { 2807b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 2808b31e1552SEric Sandeen "#inodes per group too big: %lu", 2809ac27a0ecSDave Kleikamp sbi->s_inodes_per_group); 2810ac27a0ecSDave Kleikamp goto failed_mount; 2811ac27a0ecSDave Kleikamp } 2812ac27a0ecSDave Kleikamp 2813bf43d84bSEric Sandeen /* 2814bf43d84bSEric Sandeen * Test whether we have more sectors than will fit in sector_t, 2815bf43d84bSEric Sandeen * and whether the max offset is addressable by the page cache. 2816bf43d84bSEric Sandeen */ 2817bf43d84bSEric Sandeen if ((ext4_blocks_count(es) > 2818bf43d84bSEric Sandeen (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) || 2819bf43d84bSEric Sandeen (ext4_blocks_count(es) > 2820bf43d84bSEric Sandeen (pgoff_t)(~0ULL) >> (PAGE_CACHE_SHIFT - sb->s_blocksize_bits))) { 2821b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "filesystem" 2822bf43d84bSEric Sandeen " too large to mount safely on this system"); 2823ac27a0ecSDave Kleikamp if (sizeof(sector_t) < 8) 282490c699a9SBartlomiej Zolnierkiewicz ext4_msg(sb, KERN_WARNING, "CONFIG_LBDAF not enabled"); 2825bf43d84bSEric Sandeen ret = -EFBIG; 2826ac27a0ecSDave Kleikamp goto failed_mount; 2827ac27a0ecSDave Kleikamp } 2828ac27a0ecSDave Kleikamp 2829617ba13bSMingming Cao if (EXT4_BLOCKS_PER_GROUP(sb) == 0) 2830617ba13bSMingming Cao goto cantfind_ext4; 2831e7c95593SEric Sandeen 28320f2ddca6SFrom: Thiemo Nagel /* check blocks count against device size */ 28330f2ddca6SFrom: Thiemo Nagel blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits; 28340f2ddca6SFrom: Thiemo Nagel if (blocks_count && ext4_blocks_count(es) > blocks_count) { 2835b31e1552SEric Sandeen ext4_msg(sb, KERN_WARNING, "bad geometry: block count %llu " 2836b31e1552SEric Sandeen "exceeds size of device (%llu blocks)", 28370f2ddca6SFrom: Thiemo Nagel ext4_blocks_count(es), blocks_count); 28380f2ddca6SFrom: Thiemo Nagel goto failed_mount; 28390f2ddca6SFrom: Thiemo Nagel } 28400f2ddca6SFrom: Thiemo Nagel 28414ec11028STheodore Ts'o /* 28424ec11028STheodore Ts'o * It makes no sense for the first data block to be beyond the end 28434ec11028STheodore Ts'o * of the filesystem. 28444ec11028STheodore Ts'o */ 28454ec11028STheodore Ts'o if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) { 2846b31e1552SEric Sandeen ext4_msg(sb, KERN_WARNING, "bad geometry: first data" 2847b31e1552SEric Sandeen "block %u is beyond end of filesystem (%llu)", 2848e7c95593SEric Sandeen le32_to_cpu(es->s_first_data_block), 28494ec11028STheodore Ts'o ext4_blocks_count(es)); 2850e7c95593SEric Sandeen goto failed_mount; 2851e7c95593SEric Sandeen } 2852bd81d8eeSLaurent Vivier blocks_count = (ext4_blocks_count(es) - 2853bd81d8eeSLaurent Vivier le32_to_cpu(es->s_first_data_block) + 2854bd81d8eeSLaurent Vivier EXT4_BLOCKS_PER_GROUP(sb) - 1); 2855bd81d8eeSLaurent Vivier do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb)); 28564ec11028STheodore Ts'o if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) { 2857b31e1552SEric Sandeen ext4_msg(sb, KERN_WARNING, "groups count too large: %u " 28584ec11028STheodore Ts'o "(block count %llu, first data block %u, " 2859b31e1552SEric Sandeen "blocks per group %lu)", sbi->s_groups_count, 28604ec11028STheodore Ts'o ext4_blocks_count(es), 28614ec11028STheodore Ts'o le32_to_cpu(es->s_first_data_block), 28624ec11028STheodore Ts'o EXT4_BLOCKS_PER_GROUP(sb)); 28634ec11028STheodore Ts'o goto failed_mount; 28644ec11028STheodore Ts'o } 2865bd81d8eeSLaurent Vivier sbi->s_groups_count = blocks_count; 2866fb0a387dSEric Sandeen sbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count, 2867fb0a387dSEric Sandeen (EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb))); 2868617ba13bSMingming Cao db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) / 2869617ba13bSMingming Cao EXT4_DESC_PER_BLOCK(sb); 2870ac27a0ecSDave Kleikamp sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *), 2871ac27a0ecSDave Kleikamp GFP_KERNEL); 2872ac27a0ecSDave Kleikamp if (sbi->s_group_desc == NULL) { 2873b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "not enough memory"); 2874ac27a0ecSDave Kleikamp goto failed_mount; 2875ac27a0ecSDave Kleikamp } 2876ac27a0ecSDave Kleikamp 28773244fcb1SAlexander Beregalov #ifdef CONFIG_PROC_FS 28789f6200bbSTheodore Ts'o if (ext4_proc_root) 28799f6200bbSTheodore Ts'o sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); 28803244fcb1SAlexander Beregalov #endif 2881240799cdSTheodore Ts'o 2882705895b6SPekka Enberg bgl_lock_init(sbi->s_blockgroup_lock); 2883ac27a0ecSDave Kleikamp 2884ac27a0ecSDave Kleikamp for (i = 0; i < db_count; i++) { 288570bbb3e0SAndrew Morton block = descriptor_loc(sb, logical_sb_block, i); 2886ac27a0ecSDave Kleikamp sbi->s_group_desc[i] = sb_bread(sb, block); 2887ac27a0ecSDave Kleikamp if (!sbi->s_group_desc[i]) { 2888b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 2889b31e1552SEric Sandeen "can't read group descriptor %d", i); 2890ac27a0ecSDave Kleikamp db_count = i; 2891ac27a0ecSDave Kleikamp goto failed_mount2; 2892ac27a0ecSDave Kleikamp } 2893ac27a0ecSDave Kleikamp } 2894617ba13bSMingming Cao if (!ext4_check_descriptors(sb)) { 2895b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "group descriptors corrupted!"); 2896ac27a0ecSDave Kleikamp goto failed_mount2; 2897ac27a0ecSDave Kleikamp } 2898772cb7c8SJose R. Santos if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) 2899772cb7c8SJose R. Santos if (!ext4_fill_flex_info(sb)) { 2900b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 2901b31e1552SEric Sandeen "unable to initialize " 2902b31e1552SEric Sandeen "flex_bg meta info!"); 2903772cb7c8SJose R. Santos goto failed_mount2; 2904772cb7c8SJose R. Santos } 2905772cb7c8SJose R. Santos 2906ac27a0ecSDave Kleikamp sbi->s_gdb_count = db_count; 2907ac27a0ecSDave Kleikamp get_random_bytes(&sbi->s_next_generation, sizeof(u32)); 2908ac27a0ecSDave Kleikamp spin_lock_init(&sbi->s_next_gen_lock); 2909ac27a0ecSDave Kleikamp 2910c9de560dSAlex Tomas sbi->s_stripe = ext4_get_stripe_size(sbi); 291155138e0bSTheodore Ts'o sbi->s_max_writeback_mb_bump = 128; 2912c9de560dSAlex Tomas 2913ac27a0ecSDave Kleikamp /* 2914ac27a0ecSDave Kleikamp * set up enough so that it can read an inode 2915ac27a0ecSDave Kleikamp */ 29169ca92389STheodore Ts'o if (!test_opt(sb, NOLOAD) && 29179ca92389STheodore Ts'o EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) 2918617ba13bSMingming Cao sb->s_op = &ext4_sops; 29199ca92389STheodore Ts'o else 29209ca92389STheodore Ts'o sb->s_op = &ext4_nojournal_sops; 2921617ba13bSMingming Cao sb->s_export_op = &ext4_export_ops; 2922617ba13bSMingming Cao sb->s_xattr = ext4_xattr_handlers; 2923ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 2924617ba13bSMingming Cao sb->s_qcop = &ext4_qctl_operations; 2925617ba13bSMingming Cao sb->dq_op = &ext4_quota_operations; 2926ac27a0ecSDave Kleikamp #endif 2927ac27a0ecSDave Kleikamp INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ 29283b9d4ed2STheodore Ts'o mutex_init(&sbi->s_orphan_lock); 292932ed5058STheodore Ts'o mutex_init(&sbi->s_resize_lock); 2930ac27a0ecSDave Kleikamp 2931ac27a0ecSDave Kleikamp sb->s_root = NULL; 2932ac27a0ecSDave Kleikamp 2933ac27a0ecSDave Kleikamp needs_recovery = (es->s_last_orphan != 0 || 2934617ba13bSMingming Cao EXT4_HAS_INCOMPAT_FEATURE(sb, 2935617ba13bSMingming Cao EXT4_FEATURE_INCOMPAT_RECOVER)); 2936ac27a0ecSDave Kleikamp 2937ac27a0ecSDave Kleikamp /* 2938ac27a0ecSDave Kleikamp * The first inode we look at is the journal inode. Don't try 2939ac27a0ecSDave Kleikamp * root first: it may be modified in the journal! 2940ac27a0ecSDave Kleikamp */ 2941ac27a0ecSDave Kleikamp if (!test_opt(sb, NOLOAD) && 2942617ba13bSMingming Cao EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) { 2943617ba13bSMingming Cao if (ext4_load_journal(sb, es, journal_devnum)) 2944ac27a0ecSDave Kleikamp goto failed_mount3; 29450390131bSFrank Mayhar } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) && 29460390131bSFrank Mayhar EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { 2947b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "required journal recovery " 2948b31e1552SEric Sandeen "suppressed and not mounted read-only"); 2949744692dcSJiaying Zhang goto failed_mount_wq; 2950ac27a0ecSDave Kleikamp } else { 29510390131bSFrank Mayhar clear_opt(sbi->s_mount_opt, DATA_FLAGS); 29520390131bSFrank Mayhar set_opt(sbi->s_mount_opt, WRITEBACK_DATA); 29530390131bSFrank Mayhar sbi->s_journal = NULL; 29540390131bSFrank Mayhar needs_recovery = 0; 29550390131bSFrank Mayhar goto no_journal; 2956ac27a0ecSDave Kleikamp } 2957ac27a0ecSDave Kleikamp 2958eb40a09cSJose R. Santos if (ext4_blocks_count(es) > 0xffffffffULL && 2959eb40a09cSJose R. Santos !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0, 2960eb40a09cSJose R. Santos JBD2_FEATURE_INCOMPAT_64BIT)) { 2961b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "Failed to set 64-bit journal feature"); 2962744692dcSJiaying Zhang goto failed_mount_wq; 2963eb40a09cSJose R. Santos } 2964eb40a09cSJose R. Santos 2965d4da6c9cSLinus Torvalds if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) { 2966d4da6c9cSLinus Torvalds jbd2_journal_set_features(sbi->s_journal, 2967d4da6c9cSLinus Torvalds JBD2_FEATURE_COMPAT_CHECKSUM, 0, 2968d4da6c9cSLinus Torvalds JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); 2969d4da6c9cSLinus Torvalds } else if (test_opt(sb, JOURNAL_CHECKSUM)) { 2970818d276cSGirish Shilamkar jbd2_journal_set_features(sbi->s_journal, 2971818d276cSGirish Shilamkar JBD2_FEATURE_COMPAT_CHECKSUM, 0, 0); 2972818d276cSGirish Shilamkar jbd2_journal_clear_features(sbi->s_journal, 0, 0, 2973818d276cSGirish Shilamkar JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); 2974d4da6c9cSLinus Torvalds } else { 2975d4da6c9cSLinus Torvalds jbd2_journal_clear_features(sbi->s_journal, 2976d4da6c9cSLinus Torvalds JBD2_FEATURE_COMPAT_CHECKSUM, 0, 2977d4da6c9cSLinus Torvalds JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); 2978d4da6c9cSLinus Torvalds } 2979818d276cSGirish Shilamkar 2980ac27a0ecSDave Kleikamp /* We have now updated the journal if required, so we can 2981ac27a0ecSDave Kleikamp * validate the data journaling mode. */ 2982ac27a0ecSDave Kleikamp switch (test_opt(sb, DATA_FLAGS)) { 2983ac27a0ecSDave Kleikamp case 0: 2984ac27a0ecSDave Kleikamp /* No mode set, assume a default based on the journal 298563f57933SAndrew Morton * capabilities: ORDERED_DATA if the journal can 298663f57933SAndrew Morton * cope, else JOURNAL_DATA 298763f57933SAndrew Morton */ 2988dab291afSMingming Cao if (jbd2_journal_check_available_features 2989dab291afSMingming Cao (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) 2990ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, ORDERED_DATA); 2991ac27a0ecSDave Kleikamp else 2992ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, JOURNAL_DATA); 2993ac27a0ecSDave Kleikamp break; 2994ac27a0ecSDave Kleikamp 2995617ba13bSMingming Cao case EXT4_MOUNT_ORDERED_DATA: 2996617ba13bSMingming Cao case EXT4_MOUNT_WRITEBACK_DATA: 2997dab291afSMingming Cao if (!jbd2_journal_check_available_features 2998dab291afSMingming Cao (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) { 2999b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "Journal does not support " 3000b31e1552SEric Sandeen "requested data journaling mode"); 3001744692dcSJiaying Zhang goto failed_mount_wq; 3002ac27a0ecSDave Kleikamp } 3003ac27a0ecSDave Kleikamp default: 3004ac27a0ecSDave Kleikamp break; 3005ac27a0ecSDave Kleikamp } 3006b3881f74STheodore Ts'o set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); 3007ac27a0ecSDave Kleikamp 30080390131bSFrank Mayhar no_journal: 300984061e07SDmitry Monakhov err = percpu_counter_init(&sbi->s_freeblocks_counter, 301084061e07SDmitry Monakhov ext4_count_free_blocks(sb)); 301184061e07SDmitry Monakhov if (!err) 301284061e07SDmitry Monakhov err = percpu_counter_init(&sbi->s_freeinodes_counter, 301384061e07SDmitry Monakhov ext4_count_free_inodes(sb)); 301484061e07SDmitry Monakhov if (!err) 301584061e07SDmitry Monakhov err = percpu_counter_init(&sbi->s_dirs_counter, 301684061e07SDmitry Monakhov ext4_count_dirs(sb)); 301784061e07SDmitry Monakhov if (!err) 301884061e07SDmitry Monakhov err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0); 301984061e07SDmitry Monakhov if (err) { 302084061e07SDmitry Monakhov ext4_msg(sb, KERN_ERR, "insufficient memory"); 302184061e07SDmitry Monakhov goto failed_mount_wq; 302284061e07SDmitry Monakhov } 3023206f7ab4SChristoph Hellwig 30244c0425ffSMingming Cao EXT4_SB(sb)->dio_unwritten_wq = create_workqueue("ext4-dio-unwritten"); 30254c0425ffSMingming Cao if (!EXT4_SB(sb)->dio_unwritten_wq) { 30264c0425ffSMingming Cao printk(KERN_ERR "EXT4-fs: failed to create DIO workqueue\n"); 30274c0425ffSMingming Cao goto failed_mount_wq; 30284c0425ffSMingming Cao } 30294c0425ffSMingming Cao 3030ac27a0ecSDave Kleikamp /* 3031dab291afSMingming Cao * The jbd2_journal_load will have done any necessary log recovery, 3032ac27a0ecSDave Kleikamp * so we can safely mount the rest of the filesystem now. 3033ac27a0ecSDave Kleikamp */ 3034ac27a0ecSDave Kleikamp 30351d1fe1eeSDavid Howells root = ext4_iget(sb, EXT4_ROOT_INO); 30361d1fe1eeSDavid Howells if (IS_ERR(root)) { 3037b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "get root inode failed"); 30381d1fe1eeSDavid Howells ret = PTR_ERR(root); 3039ac27a0ecSDave Kleikamp goto failed_mount4; 3040ac27a0ecSDave Kleikamp } 3041ac27a0ecSDave Kleikamp if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { 30421d1fe1eeSDavid Howells iput(root); 3043b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "corrupt root inode, run e2fsck"); 3044ac27a0ecSDave Kleikamp goto failed_mount4; 3045ac27a0ecSDave Kleikamp } 30461d1fe1eeSDavid Howells sb->s_root = d_alloc_root(root); 30471d1fe1eeSDavid Howells if (!sb->s_root) { 3048b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "get root dentry failed"); 30491d1fe1eeSDavid Howells iput(root); 30501d1fe1eeSDavid Howells ret = -ENOMEM; 30511d1fe1eeSDavid Howells goto failed_mount4; 30521d1fe1eeSDavid Howells } 3053ac27a0ecSDave Kleikamp 3054617ba13bSMingming Cao ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY); 3055ef7f3835SKalpak Shah 3056ef7f3835SKalpak Shah /* determine the minimum size of new large inodes, if present */ 3057ef7f3835SKalpak Shah if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) { 3058ef7f3835SKalpak Shah sbi->s_want_extra_isize = sizeof(struct ext4_inode) - 3059ef7f3835SKalpak Shah EXT4_GOOD_OLD_INODE_SIZE; 3060ef7f3835SKalpak Shah if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 3061ef7f3835SKalpak Shah EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)) { 3062ef7f3835SKalpak Shah if (sbi->s_want_extra_isize < 3063ef7f3835SKalpak Shah le16_to_cpu(es->s_want_extra_isize)) 3064ef7f3835SKalpak Shah sbi->s_want_extra_isize = 3065ef7f3835SKalpak Shah le16_to_cpu(es->s_want_extra_isize); 3066ef7f3835SKalpak Shah if (sbi->s_want_extra_isize < 3067ef7f3835SKalpak Shah le16_to_cpu(es->s_min_extra_isize)) 3068ef7f3835SKalpak Shah sbi->s_want_extra_isize = 3069ef7f3835SKalpak Shah le16_to_cpu(es->s_min_extra_isize); 3070ef7f3835SKalpak Shah } 3071ef7f3835SKalpak Shah } 3072ef7f3835SKalpak Shah /* Check if enough inode space is available */ 3073ef7f3835SKalpak Shah if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize > 3074ef7f3835SKalpak Shah sbi->s_inode_size) { 3075ef7f3835SKalpak Shah sbi->s_want_extra_isize = sizeof(struct ext4_inode) - 3076ef7f3835SKalpak Shah EXT4_GOOD_OLD_INODE_SIZE; 3077b31e1552SEric Sandeen ext4_msg(sb, KERN_INFO, "required extra inode space not" 3078b31e1552SEric Sandeen "available"); 3079ef7f3835SKalpak Shah } 3080ef7f3835SKalpak Shah 308190576c0bSTheodore Ts'o if (test_opt(sb, DELALLOC) && 308290576c0bSTheodore Ts'o (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)) { 3083b31e1552SEric Sandeen ext4_msg(sb, KERN_WARNING, "Ignoring delalloc option - " 3084b31e1552SEric Sandeen "requested data journaling mode"); 3085c2774d84SAneesh Kumar K.V clear_opt(sbi->s_mount_opt, DELALLOC); 308690576c0bSTheodore Ts'o } 3087744692dcSJiaying Zhang if (test_opt(sb, DIOREAD_NOLOCK)) { 3088744692dcSJiaying Zhang if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) { 3089744692dcSJiaying Zhang ext4_msg(sb, KERN_WARNING, "Ignoring dioread_nolock " 3090744692dcSJiaying Zhang "option - requested data journaling mode"); 3091744692dcSJiaying Zhang clear_opt(sbi->s_mount_opt, DIOREAD_NOLOCK); 3092744692dcSJiaying Zhang } 3093744692dcSJiaying Zhang if (sb->s_blocksize < PAGE_SIZE) { 3094744692dcSJiaying Zhang ext4_msg(sb, KERN_WARNING, "Ignoring dioread_nolock " 3095744692dcSJiaying Zhang "option - block size is too small"); 3096744692dcSJiaying Zhang clear_opt(sbi->s_mount_opt, DIOREAD_NOLOCK); 3097744692dcSJiaying Zhang } 3098744692dcSJiaying Zhang } 3099c2774d84SAneesh Kumar K.V 31006fd058f7STheodore Ts'o err = ext4_setup_system_zone(sb); 31016fd058f7STheodore Ts'o if (err) { 3102b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "failed to initialize system " 3103fbe845ddSCurt Wohlgemuth "zone (%d)", err); 31046fd058f7STheodore Ts'o goto failed_mount4; 31056fd058f7STheodore Ts'o } 31066fd058f7STheodore Ts'o 3107c2774d84SAneesh Kumar K.V ext4_ext_init(sb); 3108c2774d84SAneesh Kumar K.V err = ext4_mb_init(sb, needs_recovery); 3109c2774d84SAneesh Kumar K.V if (err) { 3110b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "failed to initalize mballoc (%d)", 3111c2774d84SAneesh Kumar K.V err); 3112c2774d84SAneesh Kumar K.V goto failed_mount4; 3113c2774d84SAneesh Kumar K.V } 3114c2774d84SAneesh Kumar K.V 31153197ebdbSTheodore Ts'o sbi->s_kobj.kset = ext4_kset; 31163197ebdbSTheodore Ts'o init_completion(&sbi->s_kobj_unregister); 31173197ebdbSTheodore Ts'o err = kobject_init_and_add(&sbi->s_kobj, &ext4_ktype, NULL, 31183197ebdbSTheodore Ts'o "%s", sb->s_id); 31193197ebdbSTheodore Ts'o if (err) { 31203197ebdbSTheodore Ts'o ext4_mb_release(sb); 31213197ebdbSTheodore Ts'o ext4_ext_release(sb); 31223197ebdbSTheodore Ts'o goto failed_mount4; 31233197ebdbSTheodore Ts'o }; 31243197ebdbSTheodore Ts'o 3125617ba13bSMingming Cao EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; 3126617ba13bSMingming Cao ext4_orphan_cleanup(sb, es); 3127617ba13bSMingming Cao EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS; 31280390131bSFrank Mayhar if (needs_recovery) { 3129b31e1552SEric Sandeen ext4_msg(sb, KERN_INFO, "recovery complete"); 3130617ba13bSMingming Cao ext4_mark_recovery_complete(sb, es); 31310390131bSFrank Mayhar } 31320390131bSFrank Mayhar if (EXT4_SB(sb)->s_journal) { 31330390131bSFrank Mayhar if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) 31340390131bSFrank Mayhar descr = " journalled data mode"; 31350390131bSFrank Mayhar else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) 31360390131bSFrank Mayhar descr = " ordered data mode"; 31370390131bSFrank Mayhar else 31380390131bSFrank Mayhar descr = " writeback data mode"; 31390390131bSFrank Mayhar } else 31400390131bSFrank Mayhar descr = "out journal"; 31410390131bSFrank Mayhar 3142d4c402d9SCurt Wohlgemuth ext4_msg(sb, KERN_INFO, "mounted filesystem with%s. " 3143d4c402d9SCurt Wohlgemuth "Opts: %s", descr, orig_data); 3144ac27a0ecSDave Kleikamp 314566e61a9eSTheodore Ts'o init_timer(&sbi->s_err_report); 314666e61a9eSTheodore Ts'o sbi->s_err_report.function = print_daily_error_info; 314766e61a9eSTheodore Ts'o sbi->s_err_report.data = (unsigned long) sb; 314866e61a9eSTheodore Ts'o if (es->s_error_count) 314966e61a9eSTheodore Ts'o mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */ 315066e61a9eSTheodore Ts'o 3151ac27a0ecSDave Kleikamp lock_kernel(); 3152d4c402d9SCurt Wohlgemuth kfree(orig_data); 3153ac27a0ecSDave Kleikamp return 0; 3154ac27a0ecSDave Kleikamp 3155617ba13bSMingming Cao cantfind_ext4: 3156ac27a0ecSDave Kleikamp if (!silent) 3157b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem"); 3158ac27a0ecSDave Kleikamp goto failed_mount; 3159ac27a0ecSDave Kleikamp 3160ac27a0ecSDave Kleikamp failed_mount4: 3161b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "mount failed"); 31624c0425ffSMingming Cao destroy_workqueue(EXT4_SB(sb)->dio_unwritten_wq); 31634c0425ffSMingming Cao failed_mount_wq: 31646fd058f7STheodore Ts'o ext4_release_system_zone(sb); 31650390131bSFrank Mayhar if (sbi->s_journal) { 3166dab291afSMingming Cao jbd2_journal_destroy(sbi->s_journal); 316747b4a50bSJan Kara sbi->s_journal = NULL; 31680390131bSFrank Mayhar } 316984061e07SDmitry Monakhov percpu_counter_destroy(&sbi->s_freeblocks_counter); 317084061e07SDmitry Monakhov percpu_counter_destroy(&sbi->s_freeinodes_counter); 317184061e07SDmitry Monakhov percpu_counter_destroy(&sbi->s_dirs_counter); 317284061e07SDmitry Monakhov percpu_counter_destroy(&sbi->s_dirtyblocks_counter); 3173ac27a0ecSDave Kleikamp failed_mount3: 3174c5ca7c76STheodore Ts'o if (sbi->s_flex_groups) { 3175c5ca7c76STheodore Ts'o if (is_vmalloc_addr(sbi->s_flex_groups)) 3176c5ca7c76STheodore Ts'o vfree(sbi->s_flex_groups); 3177c5ca7c76STheodore Ts'o else 3178c5ca7c76STheodore Ts'o kfree(sbi->s_flex_groups); 3179c5ca7c76STheodore Ts'o } 3180ac27a0ecSDave Kleikamp failed_mount2: 3181ac27a0ecSDave Kleikamp for (i = 0; i < db_count; i++) 3182ac27a0ecSDave Kleikamp brelse(sbi->s_group_desc[i]); 3183ac27a0ecSDave Kleikamp kfree(sbi->s_group_desc); 3184ac27a0ecSDave Kleikamp failed_mount: 3185240799cdSTheodore Ts'o if (sbi->s_proc) { 31869f6200bbSTheodore Ts'o remove_proc_entry(sb->s_id, ext4_proc_root); 3187240799cdSTheodore Ts'o } 3188ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 3189ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) 3190ac27a0ecSDave Kleikamp kfree(sbi->s_qf_names[i]); 3191ac27a0ecSDave Kleikamp #endif 3192617ba13bSMingming Cao ext4_blkdev_remove(sbi); 3193ac27a0ecSDave Kleikamp brelse(bh); 3194ac27a0ecSDave Kleikamp out_fail: 3195ac27a0ecSDave Kleikamp sb->s_fs_info = NULL; 3196f6830165SManish Katiyar kfree(sbi->s_blockgroup_lock); 3197ac27a0ecSDave Kleikamp kfree(sbi); 3198ac27a0ecSDave Kleikamp lock_kernel(); 3199dcc7dae3SCyrill Gorcunov out_free_orig: 3200d4c402d9SCurt Wohlgemuth kfree(orig_data); 32011d1fe1eeSDavid Howells return ret; 3202ac27a0ecSDave Kleikamp } 3203ac27a0ecSDave Kleikamp 3204ac27a0ecSDave Kleikamp /* 3205ac27a0ecSDave Kleikamp * Setup any per-fs journal parameters now. We'll do this both on 3206ac27a0ecSDave Kleikamp * initial mount, once the journal has been initialised but before we've 3207ac27a0ecSDave Kleikamp * done any recovery; and again on any subsequent remount. 3208ac27a0ecSDave Kleikamp */ 3209617ba13bSMingming Cao static void ext4_init_journal_params(struct super_block *sb, journal_t *journal) 3210ac27a0ecSDave Kleikamp { 3211617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 3212ac27a0ecSDave Kleikamp 3213ac27a0ecSDave Kleikamp journal->j_commit_interval = sbi->s_commit_interval; 321430773840STheodore Ts'o journal->j_min_batch_time = sbi->s_min_batch_time; 321530773840STheodore Ts'o journal->j_max_batch_time = sbi->s_max_batch_time; 3216ac27a0ecSDave Kleikamp 3217ac27a0ecSDave Kleikamp spin_lock(&journal->j_state_lock); 3218ac27a0ecSDave Kleikamp if (test_opt(sb, BARRIER)) 3219dab291afSMingming Cao journal->j_flags |= JBD2_BARRIER; 3220ac27a0ecSDave Kleikamp else 3221dab291afSMingming Cao journal->j_flags &= ~JBD2_BARRIER; 32225bf5683aSHidehiro Kawai if (test_opt(sb, DATA_ERR_ABORT)) 32235bf5683aSHidehiro Kawai journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR; 32245bf5683aSHidehiro Kawai else 32255bf5683aSHidehiro Kawai journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR; 3226ac27a0ecSDave Kleikamp spin_unlock(&journal->j_state_lock); 3227ac27a0ecSDave Kleikamp } 3228ac27a0ecSDave Kleikamp 3229617ba13bSMingming Cao static journal_t *ext4_get_journal(struct super_block *sb, 3230ac27a0ecSDave Kleikamp unsigned int journal_inum) 3231ac27a0ecSDave Kleikamp { 3232ac27a0ecSDave Kleikamp struct inode *journal_inode; 3233ac27a0ecSDave Kleikamp journal_t *journal; 3234ac27a0ecSDave Kleikamp 32350390131bSFrank Mayhar BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 32360390131bSFrank Mayhar 3237ac27a0ecSDave Kleikamp /* First, test for the existence of a valid inode on disk. Bad 3238ac27a0ecSDave Kleikamp * things happen if we iget() an unused inode, as the subsequent 3239ac27a0ecSDave Kleikamp * iput() will try to delete it. */ 3240ac27a0ecSDave Kleikamp 32411d1fe1eeSDavid Howells journal_inode = ext4_iget(sb, journal_inum); 32421d1fe1eeSDavid Howells if (IS_ERR(journal_inode)) { 3243b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "no journal found"); 3244ac27a0ecSDave Kleikamp return NULL; 3245ac27a0ecSDave Kleikamp } 3246ac27a0ecSDave Kleikamp if (!journal_inode->i_nlink) { 3247ac27a0ecSDave Kleikamp make_bad_inode(journal_inode); 3248ac27a0ecSDave Kleikamp iput(journal_inode); 3249b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "journal inode is deleted"); 3250ac27a0ecSDave Kleikamp return NULL; 3251ac27a0ecSDave Kleikamp } 3252ac27a0ecSDave Kleikamp 3253e5f8eab8STheodore Ts'o jbd_debug(2, "Journal inode found at %p: %lld bytes\n", 3254ac27a0ecSDave Kleikamp journal_inode, journal_inode->i_size); 32551d1fe1eeSDavid Howells if (!S_ISREG(journal_inode->i_mode)) { 3256b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "invalid journal inode"); 3257ac27a0ecSDave Kleikamp iput(journal_inode); 3258ac27a0ecSDave Kleikamp return NULL; 3259ac27a0ecSDave Kleikamp } 3260ac27a0ecSDave Kleikamp 3261dab291afSMingming Cao journal = jbd2_journal_init_inode(journal_inode); 3262ac27a0ecSDave Kleikamp if (!journal) { 3263b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "Could not load journal inode"); 3264ac27a0ecSDave Kleikamp iput(journal_inode); 3265ac27a0ecSDave Kleikamp return NULL; 3266ac27a0ecSDave Kleikamp } 3267ac27a0ecSDave Kleikamp journal->j_private = sb; 3268617ba13bSMingming Cao ext4_init_journal_params(sb, journal); 3269ac27a0ecSDave Kleikamp return journal; 3270ac27a0ecSDave Kleikamp } 3271ac27a0ecSDave Kleikamp 3272617ba13bSMingming Cao static journal_t *ext4_get_dev_journal(struct super_block *sb, 3273ac27a0ecSDave Kleikamp dev_t j_dev) 3274ac27a0ecSDave Kleikamp { 3275ac27a0ecSDave Kleikamp struct buffer_head *bh; 3276ac27a0ecSDave Kleikamp journal_t *journal; 3277617ba13bSMingming Cao ext4_fsblk_t start; 3278617ba13bSMingming Cao ext4_fsblk_t len; 3279ac27a0ecSDave Kleikamp int hblock, blocksize; 3280617ba13bSMingming Cao ext4_fsblk_t sb_block; 3281ac27a0ecSDave Kleikamp unsigned long offset; 3282617ba13bSMingming Cao struct ext4_super_block *es; 3283ac27a0ecSDave Kleikamp struct block_device *bdev; 3284ac27a0ecSDave Kleikamp 32850390131bSFrank Mayhar BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 32860390131bSFrank Mayhar 3287b31e1552SEric Sandeen bdev = ext4_blkdev_get(j_dev, sb); 3288ac27a0ecSDave Kleikamp if (bdev == NULL) 3289ac27a0ecSDave Kleikamp return NULL; 3290ac27a0ecSDave Kleikamp 3291ac27a0ecSDave Kleikamp if (bd_claim(bdev, sb)) { 3292b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 3293b31e1552SEric Sandeen "failed to claim external journal device"); 32949a1c3542SAl Viro blkdev_put(bdev, FMODE_READ|FMODE_WRITE); 3295ac27a0ecSDave Kleikamp return NULL; 3296ac27a0ecSDave Kleikamp } 3297ac27a0ecSDave Kleikamp 3298ac27a0ecSDave Kleikamp blocksize = sb->s_blocksize; 3299e1defc4fSMartin K. Petersen hblock = bdev_logical_block_size(bdev); 3300ac27a0ecSDave Kleikamp if (blocksize < hblock) { 3301b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 3302b31e1552SEric Sandeen "blocksize too small for journal device"); 3303ac27a0ecSDave Kleikamp goto out_bdev; 3304ac27a0ecSDave Kleikamp } 3305ac27a0ecSDave Kleikamp 3306617ba13bSMingming Cao sb_block = EXT4_MIN_BLOCK_SIZE / blocksize; 3307617ba13bSMingming Cao offset = EXT4_MIN_BLOCK_SIZE % blocksize; 3308ac27a0ecSDave Kleikamp set_blocksize(bdev, blocksize); 3309ac27a0ecSDave Kleikamp if (!(bh = __bread(bdev, sb_block, blocksize))) { 3310b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "couldn't read superblock of " 3311b31e1552SEric Sandeen "external journal"); 3312ac27a0ecSDave Kleikamp goto out_bdev; 3313ac27a0ecSDave Kleikamp } 3314ac27a0ecSDave Kleikamp 3315617ba13bSMingming Cao es = (struct ext4_super_block *) (((char *)bh->b_data) + offset); 3316617ba13bSMingming Cao if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) || 3317ac27a0ecSDave Kleikamp !(le32_to_cpu(es->s_feature_incompat) & 3318617ba13bSMingming Cao EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) { 3319b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "external journal has " 3320b31e1552SEric Sandeen "bad superblock"); 3321ac27a0ecSDave Kleikamp brelse(bh); 3322ac27a0ecSDave Kleikamp goto out_bdev; 3323ac27a0ecSDave Kleikamp } 3324ac27a0ecSDave Kleikamp 3325617ba13bSMingming Cao if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { 3326b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "journal UUID does not match"); 3327ac27a0ecSDave Kleikamp brelse(bh); 3328ac27a0ecSDave Kleikamp goto out_bdev; 3329ac27a0ecSDave Kleikamp } 3330ac27a0ecSDave Kleikamp 3331bd81d8eeSLaurent Vivier len = ext4_blocks_count(es); 3332ac27a0ecSDave Kleikamp start = sb_block + 1; 3333ac27a0ecSDave Kleikamp brelse(bh); /* we're done with the superblock */ 3334ac27a0ecSDave Kleikamp 3335dab291afSMingming Cao journal = jbd2_journal_init_dev(bdev, sb->s_bdev, 3336ac27a0ecSDave Kleikamp start, len, blocksize); 3337ac27a0ecSDave Kleikamp if (!journal) { 3338b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "failed to create device journal"); 3339ac27a0ecSDave Kleikamp goto out_bdev; 3340ac27a0ecSDave Kleikamp } 3341ac27a0ecSDave Kleikamp journal->j_private = sb; 3342ac27a0ecSDave Kleikamp ll_rw_block(READ, 1, &journal->j_sb_buffer); 3343ac27a0ecSDave Kleikamp wait_on_buffer(journal->j_sb_buffer); 3344ac27a0ecSDave Kleikamp if (!buffer_uptodate(journal->j_sb_buffer)) { 3345b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "I/O error on journal device"); 3346ac27a0ecSDave Kleikamp goto out_journal; 3347ac27a0ecSDave Kleikamp } 3348ac27a0ecSDave Kleikamp if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) { 3349b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "External journal has more than one " 3350b31e1552SEric Sandeen "user (unsupported) - %d", 3351ac27a0ecSDave Kleikamp be32_to_cpu(journal->j_superblock->s_nr_users)); 3352ac27a0ecSDave Kleikamp goto out_journal; 3353ac27a0ecSDave Kleikamp } 3354617ba13bSMingming Cao EXT4_SB(sb)->journal_bdev = bdev; 3355617ba13bSMingming Cao ext4_init_journal_params(sb, journal); 3356ac27a0ecSDave Kleikamp return journal; 33570b8e58a1SAndreas Dilger 3358ac27a0ecSDave Kleikamp out_journal: 3359dab291afSMingming Cao jbd2_journal_destroy(journal); 3360ac27a0ecSDave Kleikamp out_bdev: 3361617ba13bSMingming Cao ext4_blkdev_put(bdev); 3362ac27a0ecSDave Kleikamp return NULL; 3363ac27a0ecSDave Kleikamp } 3364ac27a0ecSDave Kleikamp 3365617ba13bSMingming Cao static int ext4_load_journal(struct super_block *sb, 3366617ba13bSMingming Cao struct ext4_super_block *es, 3367ac27a0ecSDave Kleikamp unsigned long journal_devnum) 3368ac27a0ecSDave Kleikamp { 3369ac27a0ecSDave Kleikamp journal_t *journal; 3370ac27a0ecSDave Kleikamp unsigned int journal_inum = le32_to_cpu(es->s_journal_inum); 3371ac27a0ecSDave Kleikamp dev_t journal_dev; 3372ac27a0ecSDave Kleikamp int err = 0; 3373ac27a0ecSDave Kleikamp int really_read_only; 3374ac27a0ecSDave Kleikamp 33750390131bSFrank Mayhar BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 33760390131bSFrank Mayhar 3377ac27a0ecSDave Kleikamp if (journal_devnum && 3378ac27a0ecSDave Kleikamp journal_devnum != le32_to_cpu(es->s_journal_dev)) { 3379b31e1552SEric Sandeen ext4_msg(sb, KERN_INFO, "external journal device major/minor " 3380b31e1552SEric Sandeen "numbers have changed"); 3381ac27a0ecSDave Kleikamp journal_dev = new_decode_dev(journal_devnum); 3382ac27a0ecSDave Kleikamp } else 3383ac27a0ecSDave Kleikamp journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev)); 3384ac27a0ecSDave Kleikamp 3385ac27a0ecSDave Kleikamp really_read_only = bdev_read_only(sb->s_bdev); 3386ac27a0ecSDave Kleikamp 3387ac27a0ecSDave Kleikamp /* 3388ac27a0ecSDave Kleikamp * Are we loading a blank journal or performing recovery after a 3389ac27a0ecSDave Kleikamp * crash? For recovery, we need to check in advance whether we 3390ac27a0ecSDave Kleikamp * can get read-write access to the device. 3391ac27a0ecSDave Kleikamp */ 3392617ba13bSMingming Cao if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { 3393ac27a0ecSDave Kleikamp if (sb->s_flags & MS_RDONLY) { 3394b31e1552SEric Sandeen ext4_msg(sb, KERN_INFO, "INFO: recovery " 3395b31e1552SEric Sandeen "required on readonly filesystem"); 3396ac27a0ecSDave Kleikamp if (really_read_only) { 3397b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "write access " 3398b31e1552SEric Sandeen "unavailable, cannot proceed"); 3399ac27a0ecSDave Kleikamp return -EROFS; 3400ac27a0ecSDave Kleikamp } 3401b31e1552SEric Sandeen ext4_msg(sb, KERN_INFO, "write access will " 3402b31e1552SEric Sandeen "be enabled during recovery"); 3403ac27a0ecSDave Kleikamp } 3404ac27a0ecSDave Kleikamp } 3405ac27a0ecSDave Kleikamp 3406ac27a0ecSDave Kleikamp if (journal_inum && journal_dev) { 3407b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "filesystem has both journal " 3408b31e1552SEric Sandeen "and inode journals!"); 3409ac27a0ecSDave Kleikamp return -EINVAL; 3410ac27a0ecSDave Kleikamp } 3411ac27a0ecSDave Kleikamp 3412ac27a0ecSDave Kleikamp if (journal_inum) { 3413617ba13bSMingming Cao if (!(journal = ext4_get_journal(sb, journal_inum))) 3414ac27a0ecSDave Kleikamp return -EINVAL; 3415ac27a0ecSDave Kleikamp } else { 3416617ba13bSMingming Cao if (!(journal = ext4_get_dev_journal(sb, journal_dev))) 3417ac27a0ecSDave Kleikamp return -EINVAL; 3418ac27a0ecSDave Kleikamp } 3419ac27a0ecSDave Kleikamp 342090576c0bSTheodore Ts'o if (!(journal->j_flags & JBD2_BARRIER)) 3421b31e1552SEric Sandeen ext4_msg(sb, KERN_INFO, "barriers disabled"); 34224776004fSTheodore Ts'o 3423ac27a0ecSDave Kleikamp if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) { 3424dab291afSMingming Cao err = jbd2_journal_update_format(journal); 3425ac27a0ecSDave Kleikamp if (err) { 3426b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "error updating journal"); 3427dab291afSMingming Cao jbd2_journal_destroy(journal); 3428ac27a0ecSDave Kleikamp return err; 3429ac27a0ecSDave Kleikamp } 3430ac27a0ecSDave Kleikamp } 3431ac27a0ecSDave Kleikamp 3432617ba13bSMingming Cao if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) 3433dab291afSMingming Cao err = jbd2_journal_wipe(journal, !really_read_only); 34341c13d5c0STheodore Ts'o if (!err) { 34351c13d5c0STheodore Ts'o char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL); 34361c13d5c0STheodore Ts'o if (save) 34371c13d5c0STheodore Ts'o memcpy(save, ((char *) es) + 34381c13d5c0STheodore Ts'o EXT4_S_ERR_START, EXT4_S_ERR_LEN); 3439dab291afSMingming Cao err = jbd2_journal_load(journal); 34401c13d5c0STheodore Ts'o if (save) 34411c13d5c0STheodore Ts'o memcpy(((char *) es) + EXT4_S_ERR_START, 34421c13d5c0STheodore Ts'o save, EXT4_S_ERR_LEN); 34431c13d5c0STheodore Ts'o kfree(save); 34441c13d5c0STheodore Ts'o } 3445ac27a0ecSDave Kleikamp 3446ac27a0ecSDave Kleikamp if (err) { 3447b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "error loading journal"); 3448dab291afSMingming Cao jbd2_journal_destroy(journal); 3449ac27a0ecSDave Kleikamp return err; 3450ac27a0ecSDave Kleikamp } 3451ac27a0ecSDave Kleikamp 3452617ba13bSMingming Cao EXT4_SB(sb)->s_journal = journal; 3453617ba13bSMingming Cao ext4_clear_journal_err(sb, es); 3454ac27a0ecSDave Kleikamp 3455ac27a0ecSDave Kleikamp if (journal_devnum && 3456ac27a0ecSDave Kleikamp journal_devnum != le32_to_cpu(es->s_journal_dev)) { 3457ac27a0ecSDave Kleikamp es->s_journal_dev = cpu_to_le32(journal_devnum); 3458ac27a0ecSDave Kleikamp 3459ac27a0ecSDave Kleikamp /* Make sure we flush the recovery flag to disk. */ 3460e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 3461ac27a0ecSDave Kleikamp } 3462ac27a0ecSDave Kleikamp 3463ac27a0ecSDave Kleikamp return 0; 3464ac27a0ecSDave Kleikamp } 3465ac27a0ecSDave Kleikamp 3466e2d67052STheodore Ts'o static int ext4_commit_super(struct super_block *sb, int sync) 3467ac27a0ecSDave Kleikamp { 3468e2d67052STheodore Ts'o struct ext4_super_block *es = EXT4_SB(sb)->s_es; 3469617ba13bSMingming Cao struct buffer_head *sbh = EXT4_SB(sb)->s_sbh; 3470c4be0c1dSTakashi Sato int error = 0; 3471ac27a0ecSDave Kleikamp 3472ac27a0ecSDave Kleikamp if (!sbh) 3473c4be0c1dSTakashi Sato return error; 3474914258bfSTheodore Ts'o if (buffer_write_io_error(sbh)) { 3475914258bfSTheodore Ts'o /* 3476914258bfSTheodore Ts'o * Oh, dear. A previous attempt to write the 3477914258bfSTheodore Ts'o * superblock failed. This could happen because the 3478914258bfSTheodore Ts'o * USB device was yanked out. Or it could happen to 3479914258bfSTheodore Ts'o * be a transient write error and maybe the block will 3480914258bfSTheodore Ts'o * be remapped. Nothing we can do but to retry the 3481914258bfSTheodore Ts'o * write and hope for the best. 3482914258bfSTheodore Ts'o */ 3483b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "previous I/O error to " 3484b31e1552SEric Sandeen "superblock detected"); 3485914258bfSTheodore Ts'o clear_buffer_write_io_error(sbh); 3486914258bfSTheodore Ts'o set_buffer_uptodate(sbh); 3487914258bfSTheodore Ts'o } 348871290b36STheodore Ts'o /* 348971290b36STheodore Ts'o * If the file system is mounted read-only, don't update the 349071290b36STheodore Ts'o * superblock write time. This avoids updating the superblock 349171290b36STheodore Ts'o * write time when we are mounting the root file system 349271290b36STheodore Ts'o * read/only but we need to replay the journal; at that point, 349371290b36STheodore Ts'o * for people who are east of GMT and who make their clock 349471290b36STheodore Ts'o * tick in localtime for Windows bug-for-bug compatibility, 349571290b36STheodore Ts'o * the clock is set in the future, and this will cause e2fsck 349671290b36STheodore Ts'o * to complain and force a full file system check. 349771290b36STheodore Ts'o */ 349871290b36STheodore Ts'o if (!(sb->s_flags & MS_RDONLY)) 3499ac27a0ecSDave Kleikamp es->s_wtime = cpu_to_le32(get_seconds()); 3500f613dfcbSTheodore Ts'o if (sb->s_bdev->bd_part) 3501afc32f7eSTheodore Ts'o es->s_kbytes_written = 3502afc32f7eSTheodore Ts'o cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + 3503afc32f7eSTheodore Ts'o ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 3504afc32f7eSTheodore Ts'o EXT4_SB(sb)->s_sectors_written_start) >> 1)); 3505f613dfcbSTheodore Ts'o else 3506f613dfcbSTheodore Ts'o es->s_kbytes_written = 3507f613dfcbSTheodore Ts'o cpu_to_le64(EXT4_SB(sb)->s_kbytes_written); 35085d1b1b3fSAneesh Kumar K.V ext4_free_blocks_count_set(es, percpu_counter_sum_positive( 35095d1b1b3fSAneesh Kumar K.V &EXT4_SB(sb)->s_freeblocks_counter)); 35105d1b1b3fSAneesh Kumar K.V es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive( 35115d1b1b3fSAneesh Kumar K.V &EXT4_SB(sb)->s_freeinodes_counter)); 35127234ab2aSTheodore Ts'o sb->s_dirt = 0; 3513ac27a0ecSDave Kleikamp BUFFER_TRACE(sbh, "marking dirty"); 3514ac27a0ecSDave Kleikamp mark_buffer_dirty(sbh); 3515914258bfSTheodore Ts'o if (sync) { 3516c4be0c1dSTakashi Sato error = sync_dirty_buffer(sbh); 3517c4be0c1dSTakashi Sato if (error) 3518c4be0c1dSTakashi Sato return error; 3519c4be0c1dSTakashi Sato 3520c4be0c1dSTakashi Sato error = buffer_write_io_error(sbh); 3521c4be0c1dSTakashi Sato if (error) { 3522b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, "I/O error while writing " 3523b31e1552SEric Sandeen "superblock"); 3524914258bfSTheodore Ts'o clear_buffer_write_io_error(sbh); 3525914258bfSTheodore Ts'o set_buffer_uptodate(sbh); 3526914258bfSTheodore Ts'o } 3527914258bfSTheodore Ts'o } 3528c4be0c1dSTakashi Sato return error; 3529ac27a0ecSDave Kleikamp } 3530ac27a0ecSDave Kleikamp 3531ac27a0ecSDave Kleikamp /* 3532ac27a0ecSDave Kleikamp * Have we just finished recovery? If so, and if we are mounting (or 3533ac27a0ecSDave Kleikamp * remounting) the filesystem readonly, then we will end up with a 3534ac27a0ecSDave Kleikamp * consistent fs on disk. Record that fact. 3535ac27a0ecSDave Kleikamp */ 3536617ba13bSMingming Cao static void ext4_mark_recovery_complete(struct super_block *sb, 3537617ba13bSMingming Cao struct ext4_super_block *es) 3538ac27a0ecSDave Kleikamp { 3539617ba13bSMingming Cao journal_t *journal = EXT4_SB(sb)->s_journal; 3540ac27a0ecSDave Kleikamp 35410390131bSFrank Mayhar if (!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) { 35420390131bSFrank Mayhar BUG_ON(journal != NULL); 35430390131bSFrank Mayhar return; 35440390131bSFrank Mayhar } 3545dab291afSMingming Cao jbd2_journal_lock_updates(journal); 35467ffe1ea8SHidehiro Kawai if (jbd2_journal_flush(journal) < 0) 35477ffe1ea8SHidehiro Kawai goto out; 35487ffe1ea8SHidehiro Kawai 3549617ba13bSMingming Cao if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) && 3550ac27a0ecSDave Kleikamp sb->s_flags & MS_RDONLY) { 3551617ba13bSMingming Cao EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3552e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 3553ac27a0ecSDave Kleikamp } 35547ffe1ea8SHidehiro Kawai 35557ffe1ea8SHidehiro Kawai out: 3556dab291afSMingming Cao jbd2_journal_unlock_updates(journal); 3557ac27a0ecSDave Kleikamp } 3558ac27a0ecSDave Kleikamp 3559ac27a0ecSDave Kleikamp /* 3560ac27a0ecSDave Kleikamp * If we are mounting (or read-write remounting) a filesystem whose journal 3561ac27a0ecSDave Kleikamp * has recorded an error from a previous lifetime, move that error to the 3562ac27a0ecSDave Kleikamp * main filesystem now. 3563ac27a0ecSDave Kleikamp */ 3564617ba13bSMingming Cao static void ext4_clear_journal_err(struct super_block *sb, 3565617ba13bSMingming Cao struct ext4_super_block *es) 3566ac27a0ecSDave Kleikamp { 3567ac27a0ecSDave Kleikamp journal_t *journal; 3568ac27a0ecSDave Kleikamp int j_errno; 3569ac27a0ecSDave Kleikamp const char *errstr; 3570ac27a0ecSDave Kleikamp 35710390131bSFrank Mayhar BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 35720390131bSFrank Mayhar 3573617ba13bSMingming Cao journal = EXT4_SB(sb)->s_journal; 3574ac27a0ecSDave Kleikamp 3575ac27a0ecSDave Kleikamp /* 3576ac27a0ecSDave Kleikamp * Now check for any error status which may have been recorded in the 3577617ba13bSMingming Cao * journal by a prior ext4_error() or ext4_abort() 3578ac27a0ecSDave Kleikamp */ 3579ac27a0ecSDave Kleikamp 3580dab291afSMingming Cao j_errno = jbd2_journal_errno(journal); 3581ac27a0ecSDave Kleikamp if (j_errno) { 3582ac27a0ecSDave Kleikamp char nbuf[16]; 3583ac27a0ecSDave Kleikamp 3584617ba13bSMingming Cao errstr = ext4_decode_error(sb, j_errno, nbuf); 358512062dddSEric Sandeen ext4_warning(sb, "Filesystem error recorded " 3586ac27a0ecSDave Kleikamp "from previous mount: %s", errstr); 358712062dddSEric Sandeen ext4_warning(sb, "Marking fs in need of filesystem check."); 3588ac27a0ecSDave Kleikamp 3589617ba13bSMingming Cao EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 3590617ba13bSMingming Cao es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 3591e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 3592ac27a0ecSDave Kleikamp 3593dab291afSMingming Cao jbd2_journal_clear_err(journal); 3594ac27a0ecSDave Kleikamp } 3595ac27a0ecSDave Kleikamp } 3596ac27a0ecSDave Kleikamp 3597ac27a0ecSDave Kleikamp /* 3598ac27a0ecSDave Kleikamp * Force the running and committing transactions to commit, 3599ac27a0ecSDave Kleikamp * and wait on the commit. 3600ac27a0ecSDave Kleikamp */ 3601617ba13bSMingming Cao int ext4_force_commit(struct super_block *sb) 3602ac27a0ecSDave Kleikamp { 3603ac27a0ecSDave Kleikamp journal_t *journal; 36040390131bSFrank Mayhar int ret = 0; 3605ac27a0ecSDave Kleikamp 3606ac27a0ecSDave Kleikamp if (sb->s_flags & MS_RDONLY) 3607ac27a0ecSDave Kleikamp return 0; 3608ac27a0ecSDave Kleikamp 3609617ba13bSMingming Cao journal = EXT4_SB(sb)->s_journal; 36106b0310fbSEric Sandeen if (journal) { 3611*437f88ccSEric Sandeen vfs_check_frozen(sb, SB_FREEZE_TRANS); 3612617ba13bSMingming Cao ret = ext4_journal_force_commit(journal); 36136b0310fbSEric Sandeen } 36140390131bSFrank Mayhar 3615ac27a0ecSDave Kleikamp return ret; 3616ac27a0ecSDave Kleikamp } 3617ac27a0ecSDave Kleikamp 3618617ba13bSMingming Cao static void ext4_write_super(struct super_block *sb) 3619ac27a0ecSDave Kleikamp { 3620ebc1ac16SChristoph Hellwig lock_super(sb); 3621e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 3622ebc1ac16SChristoph Hellwig unlock_super(sb); 36230390131bSFrank Mayhar } 3624ac27a0ecSDave Kleikamp 3625617ba13bSMingming Cao static int ext4_sync_fs(struct super_block *sb, int wait) 3626ac27a0ecSDave Kleikamp { 362714ce0cb4STheodore Ts'o int ret = 0; 36289eddacf9SJan Kara tid_t target; 36298d5d02e6SMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 3630ac27a0ecSDave Kleikamp 36319bffad1eSTheodore Ts'o trace_ext4_sync_fs(sb, wait); 36328d5d02e6SMingming Cao flush_workqueue(sbi->dio_unwritten_wq); 36338d5d02e6SMingming Cao if (jbd2_journal_start_commit(sbi->s_journal, &target)) { 3634ac27a0ecSDave Kleikamp if (wait) 36358d5d02e6SMingming Cao jbd2_log_wait_commit(sbi->s_journal, target); 36360390131bSFrank Mayhar } 363714ce0cb4STheodore Ts'o return ret; 3638ac27a0ecSDave Kleikamp } 3639ac27a0ecSDave Kleikamp 3640ac27a0ecSDave Kleikamp /* 3641ac27a0ecSDave Kleikamp * LVM calls this function before a (read-only) snapshot is created. This 3642ac27a0ecSDave Kleikamp * gives us a chance to flush the journal completely and mark the fs clean. 3643ac27a0ecSDave Kleikamp */ 3644c4be0c1dSTakashi Sato static int ext4_freeze(struct super_block *sb) 3645ac27a0ecSDave Kleikamp { 3646c4be0c1dSTakashi Sato int error = 0; 3647c4be0c1dSTakashi Sato journal_t *journal; 3648ac27a0ecSDave Kleikamp 36499ca92389STheodore Ts'o if (sb->s_flags & MS_RDONLY) 36509ca92389STheodore Ts'o return 0; 36519ca92389STheodore Ts'o 3652c4be0c1dSTakashi Sato journal = EXT4_SB(sb)->s_journal; 3653ac27a0ecSDave Kleikamp 3654ac27a0ecSDave Kleikamp /* Now we set up the journal barrier. */ 3655dab291afSMingming Cao jbd2_journal_lock_updates(journal); 36567ffe1ea8SHidehiro Kawai 36577ffe1ea8SHidehiro Kawai /* 36589ca92389STheodore Ts'o * Don't clear the needs_recovery flag if we failed to flush 36599ca92389STheodore Ts'o * the journal. 36607ffe1ea8SHidehiro Kawai */ 3661c4be0c1dSTakashi Sato error = jbd2_journal_flush(journal); 36626b0310fbSEric Sandeen if (error < 0) 36636b0310fbSEric Sandeen goto out; 3664ac27a0ecSDave Kleikamp 3665ac27a0ecSDave Kleikamp /* Journal blocked and flushed, clear needs_recovery flag. */ 3666617ba13bSMingming Cao EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3667e2d67052STheodore Ts'o error = ext4_commit_super(sb, 1); 36686b0310fbSEric Sandeen out: 36696b0310fbSEric Sandeen /* we rely on s_frozen to stop further updates */ 36706b0310fbSEric Sandeen jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 36716b0310fbSEric Sandeen return error; 3672ac27a0ecSDave Kleikamp } 3673ac27a0ecSDave Kleikamp 3674ac27a0ecSDave Kleikamp /* 3675ac27a0ecSDave Kleikamp * Called by LVM after the snapshot is done. We need to reset the RECOVER 3676ac27a0ecSDave Kleikamp * flag here, even though the filesystem is not technically dirty yet. 3677ac27a0ecSDave Kleikamp */ 3678c4be0c1dSTakashi Sato static int ext4_unfreeze(struct super_block *sb) 3679ac27a0ecSDave Kleikamp { 36809ca92389STheodore Ts'o if (sb->s_flags & MS_RDONLY) 36819ca92389STheodore Ts'o return 0; 36829ca92389STheodore Ts'o 3683ac27a0ecSDave Kleikamp lock_super(sb); 36849ca92389STheodore Ts'o /* Reset the needs_recovery flag before the fs is unlocked. */ 3685617ba13bSMingming Cao EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3686e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 3687ac27a0ecSDave Kleikamp unlock_super(sb); 3688c4be0c1dSTakashi Sato return 0; 3689ac27a0ecSDave Kleikamp } 3690ac27a0ecSDave Kleikamp 3691617ba13bSMingming Cao static int ext4_remount(struct super_block *sb, int *flags, char *data) 3692ac27a0ecSDave Kleikamp { 3693617ba13bSMingming Cao struct ext4_super_block *es; 3694617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 3695617ba13bSMingming Cao ext4_fsblk_t n_blocks_count = 0; 3696ac27a0ecSDave Kleikamp unsigned long old_sb_flags; 3697617ba13bSMingming Cao struct ext4_mount_options old_opts; 3698c79d967dSChristoph Hellwig int enable_quota = 0; 36998a266467STheodore Ts'o ext4_group_t g; 3700b3881f74STheodore Ts'o unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; 3701ac27a0ecSDave Kleikamp int err; 3702ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 3703ac27a0ecSDave Kleikamp int i; 3704ac27a0ecSDave Kleikamp #endif 3705d4c402d9SCurt Wohlgemuth char *orig_data = kstrdup(data, GFP_KERNEL); 3706ac27a0ecSDave Kleikamp 3707337eb00aSAlessio Igor Bogani lock_kernel(); 3708337eb00aSAlessio Igor Bogani 3709ac27a0ecSDave Kleikamp /* Store the original options */ 3710bbd6851aSAl Viro lock_super(sb); 3711ac27a0ecSDave Kleikamp old_sb_flags = sb->s_flags; 3712ac27a0ecSDave Kleikamp old_opts.s_mount_opt = sbi->s_mount_opt; 3713ac27a0ecSDave Kleikamp old_opts.s_resuid = sbi->s_resuid; 3714ac27a0ecSDave Kleikamp old_opts.s_resgid = sbi->s_resgid; 3715ac27a0ecSDave Kleikamp old_opts.s_commit_interval = sbi->s_commit_interval; 371630773840STheodore Ts'o old_opts.s_min_batch_time = sbi->s_min_batch_time; 371730773840STheodore Ts'o old_opts.s_max_batch_time = sbi->s_max_batch_time; 3718ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 3719ac27a0ecSDave Kleikamp old_opts.s_jquota_fmt = sbi->s_jquota_fmt; 3720ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) 3721ac27a0ecSDave Kleikamp old_opts.s_qf_names[i] = sbi->s_qf_names[i]; 3722ac27a0ecSDave Kleikamp #endif 3723b3881f74STheodore Ts'o if (sbi->s_journal && sbi->s_journal->j_task->io_context) 3724b3881f74STheodore Ts'o journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; 3725ac27a0ecSDave Kleikamp 3726ac27a0ecSDave Kleikamp /* 3727ac27a0ecSDave Kleikamp * Allow the "check" option to be passed as a remount option. 3728ac27a0ecSDave Kleikamp */ 3729b3881f74STheodore Ts'o if (!parse_options(data, sb, NULL, &journal_ioprio, 3730b3881f74STheodore Ts'o &n_blocks_count, 1)) { 3731ac27a0ecSDave Kleikamp err = -EINVAL; 3732ac27a0ecSDave Kleikamp goto restore_opts; 3733ac27a0ecSDave Kleikamp } 3734ac27a0ecSDave Kleikamp 37354ab2f15bSTheodore Ts'o if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) 3736c67d859eSTheodore Ts'o ext4_abort(sb, "Abort forced by user"); 3737ac27a0ecSDave Kleikamp 3738ac27a0ecSDave Kleikamp sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 3739482a7425SDmitry Monakhov (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0); 3740ac27a0ecSDave Kleikamp 3741ac27a0ecSDave Kleikamp es = sbi->s_es; 3742ac27a0ecSDave Kleikamp 3743b3881f74STheodore Ts'o if (sbi->s_journal) { 3744617ba13bSMingming Cao ext4_init_journal_params(sb, sbi->s_journal); 3745b3881f74STheodore Ts'o set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); 3746b3881f74STheodore Ts'o } 3747ac27a0ecSDave Kleikamp 3748ac27a0ecSDave Kleikamp if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) || 3749bd81d8eeSLaurent Vivier n_blocks_count > ext4_blocks_count(es)) { 37504ab2f15bSTheodore Ts'o if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) { 3751ac27a0ecSDave Kleikamp err = -EROFS; 3752ac27a0ecSDave Kleikamp goto restore_opts; 3753ac27a0ecSDave Kleikamp } 3754ac27a0ecSDave Kleikamp 3755ac27a0ecSDave Kleikamp if (*flags & MS_RDONLY) { 37560f0dd62fSChristoph Hellwig err = dquot_suspend(sb, -1); 37570f0dd62fSChristoph Hellwig if (err < 0) 3758c79d967dSChristoph Hellwig goto restore_opts; 3759c79d967dSChristoph Hellwig 3760ac27a0ecSDave Kleikamp /* 3761ac27a0ecSDave Kleikamp * First of all, the unconditional stuff we have to do 3762ac27a0ecSDave Kleikamp * to disable replay of the journal when we next remount 3763ac27a0ecSDave Kleikamp */ 3764ac27a0ecSDave Kleikamp sb->s_flags |= MS_RDONLY; 3765ac27a0ecSDave Kleikamp 3766ac27a0ecSDave Kleikamp /* 3767ac27a0ecSDave Kleikamp * OK, test if we are remounting a valid rw partition 3768ac27a0ecSDave Kleikamp * readonly, and if so set the rdonly flag and then 3769ac27a0ecSDave Kleikamp * mark the partition as valid again. 3770ac27a0ecSDave Kleikamp */ 3771617ba13bSMingming Cao if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) && 3772617ba13bSMingming Cao (sbi->s_mount_state & EXT4_VALID_FS)) 3773ac27a0ecSDave Kleikamp es->s_state = cpu_to_le16(sbi->s_mount_state); 3774ac27a0ecSDave Kleikamp 3775a63c9eb2STheodore Ts'o if (sbi->s_journal) 3776617ba13bSMingming Cao ext4_mark_recovery_complete(sb, es); 3777ac27a0ecSDave Kleikamp } else { 3778a13fb1a4SEric Sandeen /* Make sure we can mount this feature set readwrite */ 3779a13fb1a4SEric Sandeen if (!ext4_feature_set_ok(sb, 0)) { 3780ac27a0ecSDave Kleikamp err = -EROFS; 3781ac27a0ecSDave Kleikamp goto restore_opts; 3782ac27a0ecSDave Kleikamp } 3783ead6596bSEric Sandeen /* 37848a266467STheodore Ts'o * Make sure the group descriptor checksums 37850b8e58a1SAndreas Dilger * are sane. If they aren't, refuse to remount r/w. 37868a266467STheodore Ts'o */ 37878a266467STheodore Ts'o for (g = 0; g < sbi->s_groups_count; g++) { 37888a266467STheodore Ts'o struct ext4_group_desc *gdp = 37898a266467STheodore Ts'o ext4_get_group_desc(sb, g, NULL); 37908a266467STheodore Ts'o 37918a266467STheodore Ts'o if (!ext4_group_desc_csum_verify(sbi, g, gdp)) { 3792b31e1552SEric Sandeen ext4_msg(sb, KERN_ERR, 3793b31e1552SEric Sandeen "ext4_remount: Checksum for group %u failed (%u!=%u)", 37948a266467STheodore Ts'o g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)), 37958a266467STheodore Ts'o le16_to_cpu(gdp->bg_checksum)); 37968a266467STheodore Ts'o err = -EINVAL; 37978a266467STheodore Ts'o goto restore_opts; 37988a266467STheodore Ts'o } 37998a266467STheodore Ts'o } 38008a266467STheodore Ts'o 38018a266467STheodore Ts'o /* 3802ead6596bSEric Sandeen * If we have an unprocessed orphan list hanging 3803ead6596bSEric Sandeen * around from a previously readonly bdev mount, 3804ead6596bSEric Sandeen * require a full umount/remount for now. 3805ead6596bSEric Sandeen */ 3806ead6596bSEric Sandeen if (es->s_last_orphan) { 3807b31e1552SEric Sandeen ext4_msg(sb, KERN_WARNING, "Couldn't " 3808ead6596bSEric Sandeen "remount RDWR because of unprocessed " 3809ead6596bSEric Sandeen "orphan inode list. Please " 3810b31e1552SEric Sandeen "umount/remount instead"); 3811ead6596bSEric Sandeen err = -EINVAL; 3812ead6596bSEric Sandeen goto restore_opts; 3813ead6596bSEric Sandeen } 3814ead6596bSEric Sandeen 3815ac27a0ecSDave Kleikamp /* 3816ac27a0ecSDave Kleikamp * Mounting a RDONLY partition read-write, so reread 3817ac27a0ecSDave Kleikamp * and store the current valid flag. (It may have 3818ac27a0ecSDave Kleikamp * been changed by e2fsck since we originally mounted 3819ac27a0ecSDave Kleikamp * the partition.) 3820ac27a0ecSDave Kleikamp */ 38210390131bSFrank Mayhar if (sbi->s_journal) 3822617ba13bSMingming Cao ext4_clear_journal_err(sb, es); 3823ac27a0ecSDave Kleikamp sbi->s_mount_state = le16_to_cpu(es->s_state); 3824617ba13bSMingming Cao if ((err = ext4_group_extend(sb, es, n_blocks_count))) 3825ac27a0ecSDave Kleikamp goto restore_opts; 3826617ba13bSMingming Cao if (!ext4_setup_super(sb, es, 0)) 3827ac27a0ecSDave Kleikamp sb->s_flags &= ~MS_RDONLY; 3828c79d967dSChristoph Hellwig enable_quota = 1; 3829ac27a0ecSDave Kleikamp } 3830ac27a0ecSDave Kleikamp } 38316fd058f7STheodore Ts'o ext4_setup_system_zone(sb); 38320390131bSFrank Mayhar if (sbi->s_journal == NULL) 3833e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 38340390131bSFrank Mayhar 3835ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 3836ac27a0ecSDave Kleikamp /* Release old quota file names */ 3837ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) 3838ac27a0ecSDave Kleikamp if (old_opts.s_qf_names[i] && 3839ac27a0ecSDave Kleikamp old_opts.s_qf_names[i] != sbi->s_qf_names[i]) 3840ac27a0ecSDave Kleikamp kfree(old_opts.s_qf_names[i]); 3841ac27a0ecSDave Kleikamp #endif 3842bbd6851aSAl Viro unlock_super(sb); 3843337eb00aSAlessio Igor Bogani unlock_kernel(); 3844c79d967dSChristoph Hellwig if (enable_quota) 38450f0dd62fSChristoph Hellwig dquot_resume(sb, -1); 3846d4c402d9SCurt Wohlgemuth 3847d4c402d9SCurt Wohlgemuth ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s", orig_data); 3848d4c402d9SCurt Wohlgemuth kfree(orig_data); 3849ac27a0ecSDave Kleikamp return 0; 38500b8e58a1SAndreas Dilger 3851ac27a0ecSDave Kleikamp restore_opts: 3852ac27a0ecSDave Kleikamp sb->s_flags = old_sb_flags; 3853ac27a0ecSDave Kleikamp sbi->s_mount_opt = old_opts.s_mount_opt; 3854ac27a0ecSDave Kleikamp sbi->s_resuid = old_opts.s_resuid; 3855ac27a0ecSDave Kleikamp sbi->s_resgid = old_opts.s_resgid; 3856ac27a0ecSDave Kleikamp sbi->s_commit_interval = old_opts.s_commit_interval; 385730773840STheodore Ts'o sbi->s_min_batch_time = old_opts.s_min_batch_time; 385830773840STheodore Ts'o sbi->s_max_batch_time = old_opts.s_max_batch_time; 3859ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 3860ac27a0ecSDave Kleikamp sbi->s_jquota_fmt = old_opts.s_jquota_fmt; 3861ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) { 3862ac27a0ecSDave Kleikamp if (sbi->s_qf_names[i] && 3863ac27a0ecSDave Kleikamp old_opts.s_qf_names[i] != sbi->s_qf_names[i]) 3864ac27a0ecSDave Kleikamp kfree(sbi->s_qf_names[i]); 3865ac27a0ecSDave Kleikamp sbi->s_qf_names[i] = old_opts.s_qf_names[i]; 3866ac27a0ecSDave Kleikamp } 3867ac27a0ecSDave Kleikamp #endif 3868bbd6851aSAl Viro unlock_super(sb); 3869337eb00aSAlessio Igor Bogani unlock_kernel(); 3870d4c402d9SCurt Wohlgemuth kfree(orig_data); 3871ac27a0ecSDave Kleikamp return err; 3872ac27a0ecSDave Kleikamp } 3873ac27a0ecSDave Kleikamp 3874617ba13bSMingming Cao static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf) 3875ac27a0ecSDave Kleikamp { 3876ac27a0ecSDave Kleikamp struct super_block *sb = dentry->d_sb; 3877617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 3878617ba13bSMingming Cao struct ext4_super_block *es = sbi->s_es; 3879960cc398SPekka Enberg u64 fsid; 3880ac27a0ecSDave Kleikamp 38815e70030dSBadari Pulavarty if (test_opt(sb, MINIX_DF)) { 38825e70030dSBadari Pulavarty sbi->s_overhead_last = 0; 38836bc9feffSAneesh Kumar K.V } else if (sbi->s_blocks_last != ext4_blocks_count(es)) { 38848df9675fSTheodore Ts'o ext4_group_t i, ngroups = ext4_get_groups_count(sb); 38855e70030dSBadari Pulavarty ext4_fsblk_t overhead = 0; 3886ac27a0ecSDave Kleikamp 3887ac27a0ecSDave Kleikamp /* 38885e70030dSBadari Pulavarty * Compute the overhead (FS structures). This is constant 38895e70030dSBadari Pulavarty * for a given filesystem unless the number of block groups 38905e70030dSBadari Pulavarty * changes so we cache the previous value until it does. 3891ac27a0ecSDave Kleikamp */ 3892ac27a0ecSDave Kleikamp 3893ac27a0ecSDave Kleikamp /* 3894ac27a0ecSDave Kleikamp * All of the blocks before first_data_block are 3895ac27a0ecSDave Kleikamp * overhead 3896ac27a0ecSDave Kleikamp */ 3897ac27a0ecSDave Kleikamp overhead = le32_to_cpu(es->s_first_data_block); 3898ac27a0ecSDave Kleikamp 3899ac27a0ecSDave Kleikamp /* 3900ac27a0ecSDave Kleikamp * Add the overhead attributed to the superblock and 3901ac27a0ecSDave Kleikamp * block group descriptors. If the sparse superblocks 3902ac27a0ecSDave Kleikamp * feature is turned on, then not all groups have this. 3903ac27a0ecSDave Kleikamp */ 3904ac27a0ecSDave Kleikamp for (i = 0; i < ngroups; i++) { 3905617ba13bSMingming Cao overhead += ext4_bg_has_super(sb, i) + 3906617ba13bSMingming Cao ext4_bg_num_gdb(sb, i); 3907ac27a0ecSDave Kleikamp cond_resched(); 3908ac27a0ecSDave Kleikamp } 3909ac27a0ecSDave Kleikamp 3910ac27a0ecSDave Kleikamp /* 3911ac27a0ecSDave Kleikamp * Every block group has an inode bitmap, a block 3912ac27a0ecSDave Kleikamp * bitmap, and an inode table. 3913ac27a0ecSDave Kleikamp */ 39145e70030dSBadari Pulavarty overhead += ngroups * (2 + sbi->s_itb_per_group); 39155e70030dSBadari Pulavarty sbi->s_overhead_last = overhead; 39165e70030dSBadari Pulavarty smp_wmb(); 39176bc9feffSAneesh Kumar K.V sbi->s_blocks_last = ext4_blocks_count(es); 3918ac27a0ecSDave Kleikamp } 3919ac27a0ecSDave Kleikamp 3920617ba13bSMingming Cao buf->f_type = EXT4_SUPER_MAGIC; 3921ac27a0ecSDave Kleikamp buf->f_bsize = sb->s_blocksize; 39225e70030dSBadari Pulavarty buf->f_blocks = ext4_blocks_count(es) - sbi->s_overhead_last; 39236bc6e63fSAneesh Kumar K.V buf->f_bfree = percpu_counter_sum_positive(&sbi->s_freeblocks_counter) - 39246bc6e63fSAneesh Kumar K.V percpu_counter_sum_positive(&sbi->s_dirtyblocks_counter); 3925bd81d8eeSLaurent Vivier buf->f_bavail = buf->f_bfree - ext4_r_blocks_count(es); 3926bd81d8eeSLaurent Vivier if (buf->f_bfree < ext4_r_blocks_count(es)) 3927ac27a0ecSDave Kleikamp buf->f_bavail = 0; 3928ac27a0ecSDave Kleikamp buf->f_files = le32_to_cpu(es->s_inodes_count); 392952d9f3b4SPeter Zijlstra buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter); 3930617ba13bSMingming Cao buf->f_namelen = EXT4_NAME_LEN; 3931960cc398SPekka Enberg fsid = le64_to_cpup((void *)es->s_uuid) ^ 3932960cc398SPekka Enberg le64_to_cpup((void *)es->s_uuid + sizeof(u64)); 3933960cc398SPekka Enberg buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL; 3934960cc398SPekka Enberg buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL; 39350b8e58a1SAndreas Dilger 3936ac27a0ecSDave Kleikamp return 0; 3937ac27a0ecSDave Kleikamp } 3938ac27a0ecSDave Kleikamp 39390b8e58a1SAndreas Dilger /* Helper function for writing quotas on sync - we need to start transaction 39400b8e58a1SAndreas Dilger * before quota file is locked for write. Otherwise the are possible deadlocks: 3941ac27a0ecSDave Kleikamp * Process 1 Process 2 3942617ba13bSMingming Cao * ext4_create() quota_sync() 3943dab291afSMingming Cao * jbd2_journal_start() write_dquot() 3944871a2931SChristoph Hellwig * dquot_initialize() down(dqio_mutex) 3945dab291afSMingming Cao * down(dqio_mutex) jbd2_journal_start() 3946ac27a0ecSDave Kleikamp * 3947ac27a0ecSDave Kleikamp */ 3948ac27a0ecSDave Kleikamp 3949ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 3950ac27a0ecSDave Kleikamp 3951ac27a0ecSDave Kleikamp static inline struct inode *dquot_to_inode(struct dquot *dquot) 3952ac27a0ecSDave Kleikamp { 3953ac27a0ecSDave Kleikamp return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type]; 3954ac27a0ecSDave Kleikamp } 3955ac27a0ecSDave Kleikamp 3956617ba13bSMingming Cao static int ext4_write_dquot(struct dquot *dquot) 3957ac27a0ecSDave Kleikamp { 3958ac27a0ecSDave Kleikamp int ret, err; 3959ac27a0ecSDave Kleikamp handle_t *handle; 3960ac27a0ecSDave Kleikamp struct inode *inode; 3961ac27a0ecSDave Kleikamp 3962ac27a0ecSDave Kleikamp inode = dquot_to_inode(dquot); 3963617ba13bSMingming Cao handle = ext4_journal_start(inode, 3964617ba13bSMingming Cao EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); 3965ac27a0ecSDave Kleikamp if (IS_ERR(handle)) 3966ac27a0ecSDave Kleikamp return PTR_ERR(handle); 3967ac27a0ecSDave Kleikamp ret = dquot_commit(dquot); 3968617ba13bSMingming Cao err = ext4_journal_stop(handle); 3969ac27a0ecSDave Kleikamp if (!ret) 3970ac27a0ecSDave Kleikamp ret = err; 3971ac27a0ecSDave Kleikamp return ret; 3972ac27a0ecSDave Kleikamp } 3973ac27a0ecSDave Kleikamp 3974617ba13bSMingming Cao static int ext4_acquire_dquot(struct dquot *dquot) 3975ac27a0ecSDave Kleikamp { 3976ac27a0ecSDave Kleikamp int ret, err; 3977ac27a0ecSDave Kleikamp handle_t *handle; 3978ac27a0ecSDave Kleikamp 3979617ba13bSMingming Cao handle = ext4_journal_start(dquot_to_inode(dquot), 3980617ba13bSMingming Cao EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb)); 3981ac27a0ecSDave Kleikamp if (IS_ERR(handle)) 3982ac27a0ecSDave Kleikamp return PTR_ERR(handle); 3983ac27a0ecSDave Kleikamp ret = dquot_acquire(dquot); 3984617ba13bSMingming Cao err = ext4_journal_stop(handle); 3985ac27a0ecSDave Kleikamp if (!ret) 3986ac27a0ecSDave Kleikamp ret = err; 3987ac27a0ecSDave Kleikamp return ret; 3988ac27a0ecSDave Kleikamp } 3989ac27a0ecSDave Kleikamp 3990617ba13bSMingming Cao static int ext4_release_dquot(struct dquot *dquot) 3991ac27a0ecSDave Kleikamp { 3992ac27a0ecSDave Kleikamp int ret, err; 3993ac27a0ecSDave Kleikamp handle_t *handle; 3994ac27a0ecSDave Kleikamp 3995617ba13bSMingming Cao handle = ext4_journal_start(dquot_to_inode(dquot), 3996617ba13bSMingming Cao EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb)); 39979c3013e9SJan Kara if (IS_ERR(handle)) { 39989c3013e9SJan Kara /* Release dquot anyway to avoid endless cycle in dqput() */ 39999c3013e9SJan Kara dquot_release(dquot); 4000ac27a0ecSDave Kleikamp return PTR_ERR(handle); 40019c3013e9SJan Kara } 4002ac27a0ecSDave Kleikamp ret = dquot_release(dquot); 4003617ba13bSMingming Cao err = ext4_journal_stop(handle); 4004ac27a0ecSDave Kleikamp if (!ret) 4005ac27a0ecSDave Kleikamp ret = err; 4006ac27a0ecSDave Kleikamp return ret; 4007ac27a0ecSDave Kleikamp } 4008ac27a0ecSDave Kleikamp 4009617ba13bSMingming Cao static int ext4_mark_dquot_dirty(struct dquot *dquot) 4010ac27a0ecSDave Kleikamp { 40112c8be6b2SJan Kara /* Are we journaling quotas? */ 4012617ba13bSMingming Cao if (EXT4_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] || 4013617ba13bSMingming Cao EXT4_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) { 4014ac27a0ecSDave Kleikamp dquot_mark_dquot_dirty(dquot); 4015617ba13bSMingming Cao return ext4_write_dquot(dquot); 4016ac27a0ecSDave Kleikamp } else { 4017ac27a0ecSDave Kleikamp return dquot_mark_dquot_dirty(dquot); 4018ac27a0ecSDave Kleikamp } 4019ac27a0ecSDave Kleikamp } 4020ac27a0ecSDave Kleikamp 4021617ba13bSMingming Cao static int ext4_write_info(struct super_block *sb, int type) 4022ac27a0ecSDave Kleikamp { 4023ac27a0ecSDave Kleikamp int ret, err; 4024ac27a0ecSDave Kleikamp handle_t *handle; 4025ac27a0ecSDave Kleikamp 4026ac27a0ecSDave Kleikamp /* Data block + inode block */ 4027617ba13bSMingming Cao handle = ext4_journal_start(sb->s_root->d_inode, 2); 4028ac27a0ecSDave Kleikamp if (IS_ERR(handle)) 4029ac27a0ecSDave Kleikamp return PTR_ERR(handle); 4030ac27a0ecSDave Kleikamp ret = dquot_commit_info(sb, type); 4031617ba13bSMingming Cao err = ext4_journal_stop(handle); 4032ac27a0ecSDave Kleikamp if (!ret) 4033ac27a0ecSDave Kleikamp ret = err; 4034ac27a0ecSDave Kleikamp return ret; 4035ac27a0ecSDave Kleikamp } 4036ac27a0ecSDave Kleikamp 4037ac27a0ecSDave Kleikamp /* 4038ac27a0ecSDave Kleikamp * Turn on quotas during mount time - we need to find 4039ac27a0ecSDave Kleikamp * the quota file and such... 4040ac27a0ecSDave Kleikamp */ 4041617ba13bSMingming Cao static int ext4_quota_on_mount(struct super_block *sb, int type) 4042ac27a0ecSDave Kleikamp { 4043287a8095SChristoph Hellwig return dquot_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type], 4044617ba13bSMingming Cao EXT4_SB(sb)->s_jquota_fmt, type); 4045ac27a0ecSDave Kleikamp } 4046ac27a0ecSDave Kleikamp 4047ac27a0ecSDave Kleikamp /* 4048ac27a0ecSDave Kleikamp * Standard function to be called on quota_on 4049ac27a0ecSDave Kleikamp */ 4050617ba13bSMingming Cao static int ext4_quota_on(struct super_block *sb, int type, int format_id, 4051307ae18aSChristoph Hellwig char *name) 4052ac27a0ecSDave Kleikamp { 4053ac27a0ecSDave Kleikamp int err; 40548264613dSAl Viro struct path path; 4055ac27a0ecSDave Kleikamp 4056ac27a0ecSDave Kleikamp if (!test_opt(sb, QUOTA)) 4057ac27a0ecSDave Kleikamp return -EINVAL; 40580623543bSJan Kara 40598264613dSAl Viro err = kern_path(name, LOOKUP_FOLLOW, &path); 4060ac27a0ecSDave Kleikamp if (err) 4061ac27a0ecSDave Kleikamp return err; 40620623543bSJan Kara 4063ac27a0ecSDave Kleikamp /* Quotafile not on the same filesystem? */ 40648264613dSAl Viro if (path.mnt->mnt_sb != sb) { 40658264613dSAl Viro path_put(&path); 4066ac27a0ecSDave Kleikamp return -EXDEV; 4067ac27a0ecSDave Kleikamp } 40680623543bSJan Kara /* Journaling quota? */ 40690623543bSJan Kara if (EXT4_SB(sb)->s_qf_names[type]) { 40702b2d6d01STheodore Ts'o /* Quotafile not in fs root? */ 40718264613dSAl Viro if (path.dentry->d_parent != sb->s_root) 4072b31e1552SEric Sandeen ext4_msg(sb, KERN_WARNING, 4073b31e1552SEric Sandeen "Quota file not on filesystem root. " 4074b31e1552SEric Sandeen "Journaled quota will not work"); 40750623543bSJan Kara } 40760623543bSJan Kara 40770623543bSJan Kara /* 40780623543bSJan Kara * When we journal data on quota file, we have to flush journal to see 40790623543bSJan Kara * all updates to the file when we bypass pagecache... 40800623543bSJan Kara */ 40810390131bSFrank Mayhar if (EXT4_SB(sb)->s_journal && 40820390131bSFrank Mayhar ext4_should_journal_data(path.dentry->d_inode)) { 40830623543bSJan Kara /* 40840623543bSJan Kara * We don't need to lock updates but journal_flush() could 40850623543bSJan Kara * otherwise be livelocked... 40860623543bSJan Kara */ 40870623543bSJan Kara jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); 40887ffe1ea8SHidehiro Kawai err = jbd2_journal_flush(EXT4_SB(sb)->s_journal); 40890623543bSJan Kara jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 40907ffe1ea8SHidehiro Kawai if (err) { 40918264613dSAl Viro path_put(&path); 40927ffe1ea8SHidehiro Kawai return err; 40937ffe1ea8SHidehiro Kawai } 40940623543bSJan Kara } 40950623543bSJan Kara 4096287a8095SChristoph Hellwig err = dquot_quota_on_path(sb, type, format_id, &path); 40978264613dSAl Viro path_put(&path); 409877e69dacSAl Viro return err; 4099ac27a0ecSDave Kleikamp } 4100ac27a0ecSDave Kleikamp 4101ac27a0ecSDave Kleikamp /* Read data from quotafile - avoid pagecache and such because we cannot afford 4102ac27a0ecSDave Kleikamp * acquiring the locks... As quota files are never truncated and quota code 4103ac27a0ecSDave Kleikamp * itself serializes the operations (and noone else should touch the files) 4104ac27a0ecSDave Kleikamp * we don't have to be afraid of races */ 4105617ba13bSMingming Cao static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, 4106ac27a0ecSDave Kleikamp size_t len, loff_t off) 4107ac27a0ecSDave Kleikamp { 4108ac27a0ecSDave Kleikamp struct inode *inode = sb_dqopt(sb)->files[type]; 4109725d26d3SAneesh Kumar K.V ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); 4110ac27a0ecSDave Kleikamp int err = 0; 4111ac27a0ecSDave Kleikamp int offset = off & (sb->s_blocksize - 1); 4112ac27a0ecSDave Kleikamp int tocopy; 4113ac27a0ecSDave Kleikamp size_t toread; 4114ac27a0ecSDave Kleikamp struct buffer_head *bh; 4115ac27a0ecSDave Kleikamp loff_t i_size = i_size_read(inode); 4116ac27a0ecSDave Kleikamp 4117ac27a0ecSDave Kleikamp if (off > i_size) 4118ac27a0ecSDave Kleikamp return 0; 4119ac27a0ecSDave Kleikamp if (off+len > i_size) 4120ac27a0ecSDave Kleikamp len = i_size-off; 4121ac27a0ecSDave Kleikamp toread = len; 4122ac27a0ecSDave Kleikamp while (toread > 0) { 4123ac27a0ecSDave Kleikamp tocopy = sb->s_blocksize - offset < toread ? 4124ac27a0ecSDave Kleikamp sb->s_blocksize - offset : toread; 4125617ba13bSMingming Cao bh = ext4_bread(NULL, inode, blk, 0, &err); 4126ac27a0ecSDave Kleikamp if (err) 4127ac27a0ecSDave Kleikamp return err; 4128ac27a0ecSDave Kleikamp if (!bh) /* A hole? */ 4129ac27a0ecSDave Kleikamp memset(data, 0, tocopy); 4130ac27a0ecSDave Kleikamp else 4131ac27a0ecSDave Kleikamp memcpy(data, bh->b_data+offset, tocopy); 4132ac27a0ecSDave Kleikamp brelse(bh); 4133ac27a0ecSDave Kleikamp offset = 0; 4134ac27a0ecSDave Kleikamp toread -= tocopy; 4135ac27a0ecSDave Kleikamp data += tocopy; 4136ac27a0ecSDave Kleikamp blk++; 4137ac27a0ecSDave Kleikamp } 4138ac27a0ecSDave Kleikamp return len; 4139ac27a0ecSDave Kleikamp } 4140ac27a0ecSDave Kleikamp 4141ac27a0ecSDave Kleikamp /* Write to quotafile (we know the transaction is already started and has 4142ac27a0ecSDave Kleikamp * enough credits) */ 4143617ba13bSMingming Cao static ssize_t ext4_quota_write(struct super_block *sb, int type, 4144ac27a0ecSDave Kleikamp const char *data, size_t len, loff_t off) 4145ac27a0ecSDave Kleikamp { 4146ac27a0ecSDave Kleikamp struct inode *inode = sb_dqopt(sb)->files[type]; 4147725d26d3SAneesh Kumar K.V ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); 4148ac27a0ecSDave Kleikamp int err = 0; 4149ac27a0ecSDave Kleikamp int offset = off & (sb->s_blocksize - 1); 4150ac27a0ecSDave Kleikamp struct buffer_head *bh; 4151ac27a0ecSDave Kleikamp handle_t *handle = journal_current_handle(); 4152ac27a0ecSDave Kleikamp 41530390131bSFrank Mayhar if (EXT4_SB(sb)->s_journal && !handle) { 4154b31e1552SEric Sandeen ext4_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)" 4155b31e1552SEric Sandeen " cancelled because transaction is not started", 41569c3013e9SJan Kara (unsigned long long)off, (unsigned long long)len); 41579c3013e9SJan Kara return -EIO; 41589c3013e9SJan Kara } 415967eeb568SDmitry Monakhov /* 416067eeb568SDmitry Monakhov * Since we account only one data block in transaction credits, 416167eeb568SDmitry Monakhov * then it is impossible to cross a block boundary. 416267eeb568SDmitry Monakhov */ 416367eeb568SDmitry Monakhov if (sb->s_blocksize - offset < len) { 416467eeb568SDmitry Monakhov ext4_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)" 416567eeb568SDmitry Monakhov " cancelled because not block aligned", 416667eeb568SDmitry Monakhov (unsigned long long)off, (unsigned long long)len); 416767eeb568SDmitry Monakhov return -EIO; 416867eeb568SDmitry Monakhov } 416967eeb568SDmitry Monakhov 4170ac27a0ecSDave Kleikamp mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); 4171617ba13bSMingming Cao bh = ext4_bread(handle, inode, blk, 1, &err); 4172ac27a0ecSDave Kleikamp if (!bh) 4173ac27a0ecSDave Kleikamp goto out; 4174617ba13bSMingming Cao err = ext4_journal_get_write_access(handle, bh); 4175ac27a0ecSDave Kleikamp if (err) { 4176ac27a0ecSDave Kleikamp brelse(bh); 4177ac27a0ecSDave Kleikamp goto out; 4178ac27a0ecSDave Kleikamp } 4179ac27a0ecSDave Kleikamp lock_buffer(bh); 418067eeb568SDmitry Monakhov memcpy(bh->b_data+offset, data, len); 4181ac27a0ecSDave Kleikamp flush_dcache_page(bh->b_page); 4182ac27a0ecSDave Kleikamp unlock_buffer(bh); 41830390131bSFrank Mayhar err = ext4_handle_dirty_metadata(handle, NULL, bh); 4184ac27a0ecSDave Kleikamp brelse(bh); 4185ac27a0ecSDave Kleikamp out: 418667eeb568SDmitry Monakhov if (err) { 41874d04e4fbSJan Kara mutex_unlock(&inode->i_mutex); 4188ac27a0ecSDave Kleikamp return err; 41894d04e4fbSJan Kara } 419067eeb568SDmitry Monakhov if (inode->i_size < off + len) { 419167eeb568SDmitry Monakhov i_size_write(inode, off + len); 4192617ba13bSMingming Cao EXT4_I(inode)->i_disksize = inode->i_size; 4193ac27a0ecSDave Kleikamp } 4194ac27a0ecSDave Kleikamp inode->i_mtime = inode->i_ctime = CURRENT_TIME; 4195617ba13bSMingming Cao ext4_mark_inode_dirty(handle, inode); 4196ac27a0ecSDave Kleikamp mutex_unlock(&inode->i_mutex); 419767eeb568SDmitry Monakhov return len; 4198ac27a0ecSDave Kleikamp } 4199ac27a0ecSDave Kleikamp 4200ac27a0ecSDave Kleikamp #endif 4201ac27a0ecSDave Kleikamp 42020b8e58a1SAndreas Dilger static int ext4_get_sb(struct file_system_type *fs_type, int flags, 42030b8e58a1SAndreas Dilger const char *dev_name, void *data, struct vfsmount *mnt) 4204ac27a0ecSDave Kleikamp { 4205617ba13bSMingming Cao return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super,mnt); 4206ac27a0ecSDave Kleikamp } 4207ac27a0ecSDave Kleikamp 420837f328ebSTheodore Ts'o #if !defined(CONFIG_EXT2_FS) && !defined(CONFIG_EXT2_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23) 420924b58424STheodore Ts'o static struct file_system_type ext2_fs_type = { 421024b58424STheodore Ts'o .owner = THIS_MODULE, 421124b58424STheodore Ts'o .name = "ext2", 421224b58424STheodore Ts'o .get_sb = ext4_get_sb, 421324b58424STheodore Ts'o .kill_sb = kill_block_super, 421424b58424STheodore Ts'o .fs_flags = FS_REQUIRES_DEV, 421524b58424STheodore Ts'o }; 421624b58424STheodore Ts'o 421724b58424STheodore Ts'o static inline void register_as_ext2(void) 421824b58424STheodore Ts'o { 421924b58424STheodore Ts'o int err = register_filesystem(&ext2_fs_type); 422024b58424STheodore Ts'o if (err) 422124b58424STheodore Ts'o printk(KERN_WARNING 422224b58424STheodore Ts'o "EXT4-fs: Unable to register as ext2 (%d)\n", err); 422324b58424STheodore Ts'o } 422424b58424STheodore Ts'o 422524b58424STheodore Ts'o static inline void unregister_as_ext2(void) 422624b58424STheodore Ts'o { 422724b58424STheodore Ts'o unregister_filesystem(&ext2_fs_type); 422824b58424STheodore Ts'o } 422951b7e3c9STheodore Ts'o MODULE_ALIAS("ext2"); 423024b58424STheodore Ts'o #else 423124b58424STheodore Ts'o static inline void register_as_ext2(void) { } 423224b58424STheodore Ts'o static inline void unregister_as_ext2(void) { } 423324b58424STheodore Ts'o #endif 423424b58424STheodore Ts'o 423537f328ebSTheodore Ts'o #if !defined(CONFIG_EXT3_FS) && !defined(CONFIG_EXT3_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23) 423624b58424STheodore Ts'o static inline void register_as_ext3(void) 423724b58424STheodore Ts'o { 423824b58424STheodore Ts'o int err = register_filesystem(&ext3_fs_type); 423924b58424STheodore Ts'o if (err) 424024b58424STheodore Ts'o printk(KERN_WARNING 424124b58424STheodore Ts'o "EXT4-fs: Unable to register as ext3 (%d)\n", err); 424224b58424STheodore Ts'o } 424324b58424STheodore Ts'o 424424b58424STheodore Ts'o static inline void unregister_as_ext3(void) 424524b58424STheodore Ts'o { 424624b58424STheodore Ts'o unregister_filesystem(&ext3_fs_type); 424724b58424STheodore Ts'o } 424851b7e3c9STheodore Ts'o MODULE_ALIAS("ext3"); 424924b58424STheodore Ts'o #else 425024b58424STheodore Ts'o static inline void register_as_ext3(void) { } 425124b58424STheodore Ts'o static inline void unregister_as_ext3(void) { } 425224b58424STheodore Ts'o #endif 425324b58424STheodore Ts'o 425403010a33STheodore Ts'o static struct file_system_type ext4_fs_type = { 4255ac27a0ecSDave Kleikamp .owner = THIS_MODULE, 425603010a33STheodore Ts'o .name = "ext4", 4257617ba13bSMingming Cao .get_sb = ext4_get_sb, 4258ac27a0ecSDave Kleikamp .kill_sb = kill_block_super, 4259ac27a0ecSDave Kleikamp .fs_flags = FS_REQUIRES_DEV, 4260ac27a0ecSDave Kleikamp }; 4261ac27a0ecSDave Kleikamp 4262617ba13bSMingming Cao static int __init init_ext4_fs(void) 4263ac27a0ecSDave Kleikamp { 4264c9de560dSAlex Tomas int err; 4265c9de560dSAlex Tomas 426612e9b892SDmitry Monakhov ext4_check_flag_values(); 42676fd058f7STheodore Ts'o err = init_ext4_system_zone(); 42686fd058f7STheodore Ts'o if (err) 42696fd058f7STheodore Ts'o return err; 42703197ebdbSTheodore Ts'o ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj); 42713197ebdbSTheodore Ts'o if (!ext4_kset) 42726fd058f7STheodore Ts'o goto out4; 42739f6200bbSTheodore Ts'o ext4_proc_root = proc_mkdir("fs/ext4", NULL); 4274c9de560dSAlex Tomas err = init_ext4_mballoc(); 4275ac27a0ecSDave Kleikamp if (err) 42766fd058f7STheodore Ts'o goto out3; 4277c9de560dSAlex Tomas 4278c9de560dSAlex Tomas err = init_ext4_xattr(); 4279c9de560dSAlex Tomas if (err) 4280c9de560dSAlex Tomas goto out2; 4281ac27a0ecSDave Kleikamp err = init_inodecache(); 4282ac27a0ecSDave Kleikamp if (err) 4283ac27a0ecSDave Kleikamp goto out1; 428424b58424STheodore Ts'o register_as_ext2(); 428524b58424STheodore Ts'o register_as_ext3(); 428603010a33STheodore Ts'o err = register_filesystem(&ext4_fs_type); 4287ac27a0ecSDave Kleikamp if (err) 4288ac27a0ecSDave Kleikamp goto out; 4289ac27a0ecSDave Kleikamp return 0; 4290ac27a0ecSDave Kleikamp out: 429124b58424STheodore Ts'o unregister_as_ext2(); 429224b58424STheodore Ts'o unregister_as_ext3(); 4293ac27a0ecSDave Kleikamp destroy_inodecache(); 4294ac27a0ecSDave Kleikamp out1: 4295617ba13bSMingming Cao exit_ext4_xattr(); 4296c9de560dSAlex Tomas out2: 4297c9de560dSAlex Tomas exit_ext4_mballoc(); 42986fd058f7STheodore Ts'o out3: 42996fd058f7STheodore Ts'o remove_proc_entry("fs/ext4", NULL); 43006fd058f7STheodore Ts'o kset_unregister(ext4_kset); 43016fd058f7STheodore Ts'o out4: 43026fd058f7STheodore Ts'o exit_ext4_system_zone(); 4303ac27a0ecSDave Kleikamp return err; 4304ac27a0ecSDave Kleikamp } 4305ac27a0ecSDave Kleikamp 4306617ba13bSMingming Cao static void __exit exit_ext4_fs(void) 4307ac27a0ecSDave Kleikamp { 430824b58424STheodore Ts'o unregister_as_ext2(); 430924b58424STheodore Ts'o unregister_as_ext3(); 431003010a33STheodore Ts'o unregister_filesystem(&ext4_fs_type); 4311ac27a0ecSDave Kleikamp destroy_inodecache(); 4312617ba13bSMingming Cao exit_ext4_xattr(); 4313c9de560dSAlex Tomas exit_ext4_mballoc(); 43149f6200bbSTheodore Ts'o remove_proc_entry("fs/ext4", NULL); 43153197ebdbSTheodore Ts'o kset_unregister(ext4_kset); 43166fd058f7STheodore Ts'o exit_ext4_system_zone(); 4317ac27a0ecSDave Kleikamp } 4318ac27a0ecSDave Kleikamp 4319ac27a0ecSDave Kleikamp MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); 432083982b6fSTheodore Ts'o MODULE_DESCRIPTION("Fourth Extended Filesystem"); 4321ac27a0ecSDave Kleikamp MODULE_LICENSE("GPL"); 4322617ba13bSMingming Cao module_init(init_ext4_fs) 4323617ba13bSMingming Cao module_exit(exit_ext4_fs) 4324