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> 40ede86cc4STheodore Ts'o #include <linux/marker.h> 411330593eSVignesh Babu #include <linux/log2.h> 42717d50e4SAndreas Dilger #include <linux/crc16.h> 43ac27a0ecSDave Kleikamp #include <asm/uaccess.h> 44ac27a0ecSDave Kleikamp 453dcf5451SChristoph Hellwig #include "ext4.h" 463dcf5451SChristoph Hellwig #include "ext4_jbd2.h" 47ac27a0ecSDave Kleikamp #include "xattr.h" 48ac27a0ecSDave Kleikamp #include "acl.h" 49ac27a0ecSDave Kleikamp 50*f4033903SCurt Wohlgemuth static int default_mb_history_length = 1000; 51*f4033903SCurt Wohlgemuth 52*f4033903SCurt Wohlgemuth module_param_named(default_mb_history_length, default_mb_history_length, 53*f4033903SCurt Wohlgemuth int, 0644); 54*f4033903SCurt Wohlgemuth MODULE_PARM_DESC(default_mb_history_length, 55*f4033903SCurt Wohlgemuth "Default number of entries saved for mb_history"); 56*f4033903SCurt Wohlgemuth 579f6200bbSTheodore Ts'o struct proc_dir_entry *ext4_proc_root; 583197ebdbSTheodore Ts'o static struct kset *ext4_kset; 599f6200bbSTheodore Ts'o 60617ba13bSMingming Cao static int ext4_load_journal(struct super_block *, struct ext4_super_block *, 61ac27a0ecSDave Kleikamp unsigned long journal_devnum); 62e2d67052STheodore Ts'o static int ext4_commit_super(struct super_block *sb, int sync); 63617ba13bSMingming Cao static void ext4_mark_recovery_complete(struct super_block *sb, 64617ba13bSMingming Cao struct ext4_super_block *es); 65617ba13bSMingming Cao static void ext4_clear_journal_err(struct super_block *sb, 66617ba13bSMingming Cao struct ext4_super_block *es); 67617ba13bSMingming Cao static int ext4_sync_fs(struct super_block *sb, int wait); 68617ba13bSMingming Cao static const char *ext4_decode_error(struct super_block *sb, int errno, 69ac27a0ecSDave Kleikamp char nbuf[16]); 70617ba13bSMingming Cao static int ext4_remount(struct super_block *sb, int *flags, char *data); 71617ba13bSMingming Cao static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf); 72c4be0c1dSTakashi Sato static int ext4_unfreeze(struct super_block *sb); 73617ba13bSMingming Cao static void ext4_write_super(struct super_block *sb); 74c4be0c1dSTakashi Sato static int ext4_freeze(struct super_block *sb); 75ac27a0ecSDave Kleikamp 76bd81d8eeSLaurent Vivier 778fadc143SAlexandre Ratchov ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, 788fadc143SAlexandre Ratchov struct ext4_group_desc *bg) 79bd81d8eeSLaurent Vivier { 803a14589cSAneesh Kumar K.V return le32_to_cpu(bg->bg_block_bitmap_lo) | 818fadc143SAlexandre Ratchov (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 828fadc143SAlexandre Ratchov (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0); 83bd81d8eeSLaurent Vivier } 84bd81d8eeSLaurent Vivier 858fadc143SAlexandre Ratchov ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, 868fadc143SAlexandre Ratchov struct ext4_group_desc *bg) 87bd81d8eeSLaurent Vivier { 885272f837SAneesh Kumar K.V return le32_to_cpu(bg->bg_inode_bitmap_lo) | 898fadc143SAlexandre Ratchov (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 908fadc143SAlexandre Ratchov (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0); 91bd81d8eeSLaurent Vivier } 92bd81d8eeSLaurent Vivier 938fadc143SAlexandre Ratchov ext4_fsblk_t ext4_inode_table(struct super_block *sb, 948fadc143SAlexandre Ratchov struct ext4_group_desc *bg) 95bd81d8eeSLaurent Vivier { 965272f837SAneesh Kumar K.V return le32_to_cpu(bg->bg_inode_table_lo) | 978fadc143SAlexandre Ratchov (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 988fadc143SAlexandre Ratchov (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0); 99bd81d8eeSLaurent Vivier } 100bd81d8eeSLaurent Vivier 101560671a0SAneesh Kumar K.V __u32 ext4_free_blks_count(struct super_block *sb, 102560671a0SAneesh Kumar K.V struct ext4_group_desc *bg) 103560671a0SAneesh Kumar K.V { 104560671a0SAneesh Kumar K.V return le16_to_cpu(bg->bg_free_blocks_count_lo) | 105560671a0SAneesh Kumar K.V (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 106560671a0SAneesh Kumar K.V (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0); 107560671a0SAneesh Kumar K.V } 108560671a0SAneesh Kumar K.V 109560671a0SAneesh Kumar K.V __u32 ext4_free_inodes_count(struct super_block *sb, 110560671a0SAneesh Kumar K.V struct ext4_group_desc *bg) 111560671a0SAneesh Kumar K.V { 112560671a0SAneesh Kumar K.V return le16_to_cpu(bg->bg_free_inodes_count_lo) | 113560671a0SAneesh Kumar K.V (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 114560671a0SAneesh Kumar K.V (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0); 115560671a0SAneesh Kumar K.V } 116560671a0SAneesh Kumar K.V 117560671a0SAneesh Kumar K.V __u32 ext4_used_dirs_count(struct super_block *sb, 118560671a0SAneesh Kumar K.V struct ext4_group_desc *bg) 119560671a0SAneesh Kumar K.V { 120560671a0SAneesh Kumar K.V return le16_to_cpu(bg->bg_used_dirs_count_lo) | 121560671a0SAneesh Kumar K.V (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 122560671a0SAneesh Kumar K.V (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0); 123560671a0SAneesh Kumar K.V } 124560671a0SAneesh Kumar K.V 125560671a0SAneesh Kumar K.V __u32 ext4_itable_unused_count(struct super_block *sb, 126560671a0SAneesh Kumar K.V struct ext4_group_desc *bg) 127560671a0SAneesh Kumar K.V { 128560671a0SAneesh Kumar K.V return le16_to_cpu(bg->bg_itable_unused_lo) | 129560671a0SAneesh Kumar K.V (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 130560671a0SAneesh Kumar K.V (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0); 131560671a0SAneesh Kumar K.V } 132560671a0SAneesh Kumar K.V 1338fadc143SAlexandre Ratchov void ext4_block_bitmap_set(struct super_block *sb, 1348fadc143SAlexandre Ratchov struct ext4_group_desc *bg, ext4_fsblk_t blk) 135bd81d8eeSLaurent Vivier { 1363a14589cSAneesh Kumar K.V bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk); 1378fadc143SAlexandre Ratchov if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 1388fadc143SAlexandre Ratchov bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32); 139bd81d8eeSLaurent Vivier } 140bd81d8eeSLaurent Vivier 1418fadc143SAlexandre Ratchov void ext4_inode_bitmap_set(struct super_block *sb, 1428fadc143SAlexandre Ratchov struct ext4_group_desc *bg, ext4_fsblk_t blk) 143bd81d8eeSLaurent Vivier { 1445272f837SAneesh Kumar K.V bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk); 1458fadc143SAlexandre Ratchov if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 1468fadc143SAlexandre Ratchov bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32); 147bd81d8eeSLaurent Vivier } 148bd81d8eeSLaurent Vivier 1498fadc143SAlexandre Ratchov void ext4_inode_table_set(struct super_block *sb, 1508fadc143SAlexandre Ratchov struct ext4_group_desc *bg, ext4_fsblk_t blk) 151bd81d8eeSLaurent Vivier { 1525272f837SAneesh Kumar K.V bg->bg_inode_table_lo = cpu_to_le32((u32)blk); 1538fadc143SAlexandre Ratchov if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 1548fadc143SAlexandre Ratchov bg->bg_inode_table_hi = cpu_to_le32(blk >> 32); 155bd81d8eeSLaurent Vivier } 156bd81d8eeSLaurent Vivier 157560671a0SAneesh Kumar K.V void ext4_free_blks_set(struct super_block *sb, 158560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count) 159560671a0SAneesh Kumar K.V { 160560671a0SAneesh Kumar K.V bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count); 161560671a0SAneesh Kumar K.V if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 162560671a0SAneesh Kumar K.V bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16); 163560671a0SAneesh Kumar K.V } 164560671a0SAneesh Kumar K.V 165560671a0SAneesh Kumar K.V void ext4_free_inodes_set(struct super_block *sb, 166560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count) 167560671a0SAneesh Kumar K.V { 168560671a0SAneesh Kumar K.V bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count); 169560671a0SAneesh Kumar K.V if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 170560671a0SAneesh Kumar K.V bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16); 171560671a0SAneesh Kumar K.V } 172560671a0SAneesh Kumar K.V 173560671a0SAneesh Kumar K.V void ext4_used_dirs_set(struct super_block *sb, 174560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count) 175560671a0SAneesh Kumar K.V { 176560671a0SAneesh Kumar K.V bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count); 177560671a0SAneesh Kumar K.V if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 178560671a0SAneesh Kumar K.V bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16); 179560671a0SAneesh Kumar K.V } 180560671a0SAneesh Kumar K.V 181560671a0SAneesh Kumar K.V void ext4_itable_unused_set(struct super_block *sb, 182560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count) 183560671a0SAneesh Kumar K.V { 184560671a0SAneesh Kumar K.V bg->bg_itable_unused_lo = cpu_to_le16((__u16)count); 185560671a0SAneesh Kumar K.V if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 186560671a0SAneesh Kumar K.V bg->bg_itable_unused_hi = cpu_to_le16(count >> 16); 187560671a0SAneesh Kumar K.V } 188560671a0SAneesh Kumar K.V 189ac27a0ecSDave Kleikamp /* 190dab291afSMingming Cao * Wrappers for jbd2_journal_start/end. 191ac27a0ecSDave Kleikamp * 192ac27a0ecSDave Kleikamp * The only special thing we need to do here is to make sure that all 193ac27a0ecSDave Kleikamp * journal_end calls result in the superblock being marked dirty, so 194ac27a0ecSDave Kleikamp * that sync() will call the filesystem's write_super callback if 195ac27a0ecSDave Kleikamp * appropriate. 196ac27a0ecSDave Kleikamp */ 197617ba13bSMingming Cao handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks) 198ac27a0ecSDave Kleikamp { 199ac27a0ecSDave Kleikamp journal_t *journal; 200ac27a0ecSDave Kleikamp 201ac27a0ecSDave Kleikamp if (sb->s_flags & MS_RDONLY) 202ac27a0ecSDave Kleikamp return ERR_PTR(-EROFS); 203ac27a0ecSDave Kleikamp 204ac27a0ecSDave Kleikamp /* Special case here: if the journal has aborted behind our 205ac27a0ecSDave Kleikamp * backs (eg. EIO in the commit thread), then we still need to 206ac27a0ecSDave Kleikamp * take the FS itself readonly cleanly. */ 207617ba13bSMingming Cao journal = EXT4_SB(sb)->s_journal; 2080390131bSFrank Mayhar if (journal) { 209ac27a0ecSDave Kleikamp if (is_journal_aborted(journal)) { 21046e665e9SHarvey Harrison ext4_abort(sb, __func__, 211ac27a0ecSDave Kleikamp "Detected aborted journal"); 212ac27a0ecSDave Kleikamp return ERR_PTR(-EROFS); 213ac27a0ecSDave Kleikamp } 214dab291afSMingming Cao return jbd2_journal_start(journal, nblocks); 215ac27a0ecSDave Kleikamp } 2160390131bSFrank Mayhar /* 2170390131bSFrank Mayhar * We're not journaling, return the appropriate indication. 2180390131bSFrank Mayhar */ 2190390131bSFrank Mayhar current->journal_info = EXT4_NOJOURNAL_HANDLE; 2200390131bSFrank Mayhar return current->journal_info; 2210390131bSFrank Mayhar } 222ac27a0ecSDave Kleikamp 223ac27a0ecSDave Kleikamp /* 224ac27a0ecSDave Kleikamp * The only special thing we need to do here is to make sure that all 225dab291afSMingming Cao * jbd2_journal_stop calls result in the superblock being marked dirty, so 226ac27a0ecSDave Kleikamp * that sync() will call the filesystem's write_super callback if 227ac27a0ecSDave Kleikamp * appropriate. 228ac27a0ecSDave Kleikamp */ 229617ba13bSMingming Cao int __ext4_journal_stop(const char *where, handle_t *handle) 230ac27a0ecSDave Kleikamp { 231ac27a0ecSDave Kleikamp struct super_block *sb; 232ac27a0ecSDave Kleikamp int err; 233ac27a0ecSDave Kleikamp int rc; 234ac27a0ecSDave Kleikamp 2350390131bSFrank Mayhar if (!ext4_handle_valid(handle)) { 2360390131bSFrank Mayhar /* 2370390131bSFrank Mayhar * Do this here since we don't call jbd2_journal_stop() in 2380390131bSFrank Mayhar * no-journal mode. 2390390131bSFrank Mayhar */ 2400390131bSFrank Mayhar current->journal_info = NULL; 2410390131bSFrank Mayhar return 0; 2420390131bSFrank Mayhar } 243ac27a0ecSDave Kleikamp sb = handle->h_transaction->t_journal->j_private; 244ac27a0ecSDave Kleikamp err = handle->h_err; 245dab291afSMingming Cao rc = jbd2_journal_stop(handle); 246ac27a0ecSDave Kleikamp 247ac27a0ecSDave Kleikamp if (!err) 248ac27a0ecSDave Kleikamp err = rc; 249ac27a0ecSDave Kleikamp if (err) 250617ba13bSMingming Cao __ext4_std_error(sb, where, err); 251ac27a0ecSDave Kleikamp return err; 252ac27a0ecSDave Kleikamp } 253ac27a0ecSDave Kleikamp 254617ba13bSMingming Cao void ext4_journal_abort_handle(const char *caller, const char *err_fn, 255ac27a0ecSDave Kleikamp struct buffer_head *bh, handle_t *handle, int err) 256ac27a0ecSDave Kleikamp { 257ac27a0ecSDave Kleikamp char nbuf[16]; 258617ba13bSMingming Cao const char *errstr = ext4_decode_error(NULL, err, nbuf); 259ac27a0ecSDave Kleikamp 2600390131bSFrank Mayhar BUG_ON(!ext4_handle_valid(handle)); 2610390131bSFrank Mayhar 262ac27a0ecSDave Kleikamp if (bh) 263ac27a0ecSDave Kleikamp BUFFER_TRACE(bh, "abort"); 264ac27a0ecSDave Kleikamp 265ac27a0ecSDave Kleikamp if (!handle->h_err) 266ac27a0ecSDave Kleikamp handle->h_err = err; 267ac27a0ecSDave Kleikamp 268ac27a0ecSDave Kleikamp if (is_handle_aborted(handle)) 269ac27a0ecSDave Kleikamp return; 270ac27a0ecSDave Kleikamp 271ac27a0ecSDave Kleikamp printk(KERN_ERR "%s: aborting transaction: %s in %s\n", 272ac27a0ecSDave Kleikamp caller, errstr, err_fn); 273ac27a0ecSDave Kleikamp 274dab291afSMingming Cao jbd2_journal_abort_handle(handle); 275ac27a0ecSDave Kleikamp } 276ac27a0ecSDave Kleikamp 277ac27a0ecSDave Kleikamp /* Deal with the reporting of failure conditions on a filesystem such as 278ac27a0ecSDave Kleikamp * inconsistencies detected or read IO failures. 279ac27a0ecSDave Kleikamp * 280ac27a0ecSDave Kleikamp * On ext2, we can store the error state of the filesystem in the 281617ba13bSMingming Cao * superblock. That is not possible on ext4, because we may have other 282ac27a0ecSDave Kleikamp * write ordering constraints on the superblock which prevent us from 283ac27a0ecSDave Kleikamp * writing it out straight away; and given that the journal is about to 284ac27a0ecSDave Kleikamp * be aborted, we can't rely on the current, or future, transactions to 285ac27a0ecSDave Kleikamp * write out the superblock safely. 286ac27a0ecSDave Kleikamp * 287dab291afSMingming Cao * We'll just use the jbd2_journal_abort() error code to record an error in 288ac27a0ecSDave Kleikamp * the journal instead. On recovery, the journal will compain about 289ac27a0ecSDave Kleikamp * that error until we've noted it down and cleared it. 290ac27a0ecSDave Kleikamp */ 291ac27a0ecSDave Kleikamp 292617ba13bSMingming Cao static void ext4_handle_error(struct super_block *sb) 293ac27a0ecSDave Kleikamp { 294617ba13bSMingming Cao struct ext4_super_block *es = EXT4_SB(sb)->s_es; 295ac27a0ecSDave Kleikamp 296617ba13bSMingming Cao EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 297617ba13bSMingming Cao es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 298ac27a0ecSDave Kleikamp 299ac27a0ecSDave Kleikamp if (sb->s_flags & MS_RDONLY) 300ac27a0ecSDave Kleikamp return; 301ac27a0ecSDave Kleikamp 302ac27a0ecSDave Kleikamp if (!test_opt(sb, ERRORS_CONT)) { 303617ba13bSMingming Cao journal_t *journal = EXT4_SB(sb)->s_journal; 304ac27a0ecSDave Kleikamp 305617ba13bSMingming Cao EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT; 306ac27a0ecSDave Kleikamp if (journal) 307dab291afSMingming Cao jbd2_journal_abort(journal, -EIO); 308ac27a0ecSDave Kleikamp } 309ac27a0ecSDave Kleikamp if (test_opt(sb, ERRORS_RO)) { 310ac27a0ecSDave Kleikamp printk(KERN_CRIT "Remounting filesystem read-only\n"); 311ac27a0ecSDave Kleikamp sb->s_flags |= MS_RDONLY; 312ac27a0ecSDave Kleikamp } 313e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 314ac27a0ecSDave Kleikamp if (test_opt(sb, ERRORS_PANIC)) 315617ba13bSMingming Cao panic("EXT4-fs (device %s): panic forced after error\n", 316ac27a0ecSDave Kleikamp sb->s_id); 317ac27a0ecSDave Kleikamp } 318ac27a0ecSDave Kleikamp 319617ba13bSMingming Cao void ext4_error(struct super_block *sb, const char *function, 320ac27a0ecSDave Kleikamp const char *fmt, ...) 321ac27a0ecSDave Kleikamp { 322ac27a0ecSDave Kleikamp va_list args; 323ac27a0ecSDave Kleikamp 324ac27a0ecSDave Kleikamp va_start(args, fmt); 325617ba13bSMingming Cao printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 326ac27a0ecSDave Kleikamp vprintk(fmt, args); 327ac27a0ecSDave Kleikamp printk("\n"); 328ac27a0ecSDave Kleikamp va_end(args); 329ac27a0ecSDave Kleikamp 330617ba13bSMingming Cao ext4_handle_error(sb); 331ac27a0ecSDave Kleikamp } 332ac27a0ecSDave Kleikamp 333617ba13bSMingming Cao static const char *ext4_decode_error(struct super_block *sb, int errno, 334ac27a0ecSDave Kleikamp char nbuf[16]) 335ac27a0ecSDave Kleikamp { 336ac27a0ecSDave Kleikamp char *errstr = NULL; 337ac27a0ecSDave Kleikamp 338ac27a0ecSDave Kleikamp switch (errno) { 339ac27a0ecSDave Kleikamp case -EIO: 340ac27a0ecSDave Kleikamp errstr = "IO failure"; 341ac27a0ecSDave Kleikamp break; 342ac27a0ecSDave Kleikamp case -ENOMEM: 343ac27a0ecSDave Kleikamp errstr = "Out of memory"; 344ac27a0ecSDave Kleikamp break; 345ac27a0ecSDave Kleikamp case -EROFS: 346dab291afSMingming Cao if (!sb || EXT4_SB(sb)->s_journal->j_flags & JBD2_ABORT) 347ac27a0ecSDave Kleikamp errstr = "Journal has aborted"; 348ac27a0ecSDave Kleikamp else 349ac27a0ecSDave Kleikamp errstr = "Readonly filesystem"; 350ac27a0ecSDave Kleikamp break; 351ac27a0ecSDave Kleikamp default: 352ac27a0ecSDave Kleikamp /* If the caller passed in an extra buffer for unknown 353ac27a0ecSDave Kleikamp * errors, textualise them now. Else we just return 354ac27a0ecSDave Kleikamp * NULL. */ 355ac27a0ecSDave Kleikamp if (nbuf) { 356ac27a0ecSDave Kleikamp /* Check for truncated error codes... */ 357ac27a0ecSDave Kleikamp if (snprintf(nbuf, 16, "error %d", -errno) >= 0) 358ac27a0ecSDave Kleikamp errstr = nbuf; 359ac27a0ecSDave Kleikamp } 360ac27a0ecSDave Kleikamp break; 361ac27a0ecSDave Kleikamp } 362ac27a0ecSDave Kleikamp 363ac27a0ecSDave Kleikamp return errstr; 364ac27a0ecSDave Kleikamp } 365ac27a0ecSDave Kleikamp 366617ba13bSMingming Cao /* __ext4_std_error decodes expected errors from journaling functions 367ac27a0ecSDave Kleikamp * automatically and invokes the appropriate error response. */ 368ac27a0ecSDave Kleikamp 3692b2d6d01STheodore Ts'o void __ext4_std_error(struct super_block *sb, const char *function, int errno) 370ac27a0ecSDave Kleikamp { 371ac27a0ecSDave Kleikamp char nbuf[16]; 372ac27a0ecSDave Kleikamp const char *errstr; 373ac27a0ecSDave Kleikamp 374ac27a0ecSDave Kleikamp /* Special case: if the error is EROFS, and we're not already 375ac27a0ecSDave Kleikamp * inside a transaction, then there's really no point in logging 376ac27a0ecSDave Kleikamp * an error. */ 377ac27a0ecSDave Kleikamp if (errno == -EROFS && journal_current_handle() == NULL && 378ac27a0ecSDave Kleikamp (sb->s_flags & MS_RDONLY)) 379ac27a0ecSDave Kleikamp return; 380ac27a0ecSDave Kleikamp 381617ba13bSMingming Cao errstr = ext4_decode_error(sb, errno, nbuf); 382617ba13bSMingming Cao printk(KERN_CRIT "EXT4-fs error (device %s) in %s: %s\n", 383ac27a0ecSDave Kleikamp sb->s_id, function, errstr); 384ac27a0ecSDave Kleikamp 385617ba13bSMingming Cao ext4_handle_error(sb); 386ac27a0ecSDave Kleikamp } 387ac27a0ecSDave Kleikamp 388ac27a0ecSDave Kleikamp /* 389617ba13bSMingming Cao * ext4_abort is a much stronger failure handler than ext4_error. The 390ac27a0ecSDave Kleikamp * abort function may be used to deal with unrecoverable failures such 391ac27a0ecSDave Kleikamp * as journal IO errors or ENOMEM at a critical moment in log management. 392ac27a0ecSDave Kleikamp * 393ac27a0ecSDave Kleikamp * We unconditionally force the filesystem into an ABORT|READONLY state, 394ac27a0ecSDave Kleikamp * unless the error response on the fs has been set to panic in which 395ac27a0ecSDave Kleikamp * case we take the easy way out and panic immediately. 396ac27a0ecSDave Kleikamp */ 397ac27a0ecSDave Kleikamp 398617ba13bSMingming Cao void ext4_abort(struct super_block *sb, const char *function, 399ac27a0ecSDave Kleikamp const char *fmt, ...) 400ac27a0ecSDave Kleikamp { 401ac27a0ecSDave Kleikamp va_list args; 402ac27a0ecSDave Kleikamp 403617ba13bSMingming Cao printk(KERN_CRIT "ext4_abort called.\n"); 404ac27a0ecSDave Kleikamp 405ac27a0ecSDave Kleikamp va_start(args, fmt); 406617ba13bSMingming Cao printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 407ac27a0ecSDave Kleikamp vprintk(fmt, args); 408ac27a0ecSDave Kleikamp printk("\n"); 409ac27a0ecSDave Kleikamp va_end(args); 410ac27a0ecSDave Kleikamp 411ac27a0ecSDave Kleikamp if (test_opt(sb, ERRORS_PANIC)) 412617ba13bSMingming Cao panic("EXT4-fs panic from previous error\n"); 413ac27a0ecSDave Kleikamp 414ac27a0ecSDave Kleikamp if (sb->s_flags & MS_RDONLY) 415ac27a0ecSDave Kleikamp return; 416ac27a0ecSDave Kleikamp 417ac27a0ecSDave Kleikamp printk(KERN_CRIT "Remounting filesystem read-only\n"); 418617ba13bSMingming Cao EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 419ac27a0ecSDave Kleikamp sb->s_flags |= MS_RDONLY; 420617ba13bSMingming Cao EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT; 421ef2cabf7SHidehiro Kawai if (EXT4_SB(sb)->s_journal) 422dab291afSMingming Cao jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO); 423ac27a0ecSDave Kleikamp } 424ac27a0ecSDave Kleikamp 425617ba13bSMingming Cao void ext4_warning(struct super_block *sb, const char *function, 426ac27a0ecSDave Kleikamp const char *fmt, ...) 427ac27a0ecSDave Kleikamp { 428ac27a0ecSDave Kleikamp va_list args; 429ac27a0ecSDave Kleikamp 430ac27a0ecSDave Kleikamp va_start(args, fmt); 431617ba13bSMingming Cao printk(KERN_WARNING "EXT4-fs warning (device %s): %s: ", 432ac27a0ecSDave Kleikamp sb->s_id, function); 433ac27a0ecSDave Kleikamp vprintk(fmt, args); 434ac27a0ecSDave Kleikamp printk("\n"); 435ac27a0ecSDave Kleikamp va_end(args); 436ac27a0ecSDave Kleikamp } 437ac27a0ecSDave Kleikamp 4385d1b1b3fSAneesh Kumar K.V void ext4_grp_locked_error(struct super_block *sb, ext4_group_t grp, 4395d1b1b3fSAneesh Kumar K.V const char *function, const char *fmt, ...) 4405d1b1b3fSAneesh Kumar K.V __releases(bitlock) 4415d1b1b3fSAneesh Kumar K.V __acquires(bitlock) 4425d1b1b3fSAneesh Kumar K.V { 4435d1b1b3fSAneesh Kumar K.V va_list args; 4445d1b1b3fSAneesh Kumar K.V struct ext4_super_block *es = EXT4_SB(sb)->s_es; 4455d1b1b3fSAneesh Kumar K.V 4465d1b1b3fSAneesh Kumar K.V va_start(args, fmt); 4475d1b1b3fSAneesh Kumar K.V printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 4485d1b1b3fSAneesh Kumar K.V vprintk(fmt, args); 4495d1b1b3fSAneesh Kumar K.V printk("\n"); 4505d1b1b3fSAneesh Kumar K.V va_end(args); 4515d1b1b3fSAneesh Kumar K.V 4525d1b1b3fSAneesh Kumar K.V if (test_opt(sb, ERRORS_CONT)) { 4535d1b1b3fSAneesh Kumar K.V EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 4545d1b1b3fSAneesh Kumar K.V es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 455e2d67052STheodore Ts'o ext4_commit_super(sb, 0); 4565d1b1b3fSAneesh Kumar K.V return; 4575d1b1b3fSAneesh Kumar K.V } 4585d1b1b3fSAneesh Kumar K.V ext4_unlock_group(sb, grp); 4595d1b1b3fSAneesh Kumar K.V ext4_handle_error(sb); 4605d1b1b3fSAneesh Kumar K.V /* 4615d1b1b3fSAneesh Kumar K.V * We only get here in the ERRORS_RO case; relocking the group 4625d1b1b3fSAneesh Kumar K.V * may be dangerous, but nothing bad will happen since the 4635d1b1b3fSAneesh Kumar K.V * filesystem will have already been marked read/only and the 4645d1b1b3fSAneesh Kumar K.V * journal has been aborted. We return 1 as a hint to callers 4655d1b1b3fSAneesh Kumar K.V * who might what to use the return value from 4665d1b1b3fSAneesh Kumar K.V * ext4_grp_locked_error() to distinguish beween the 4675d1b1b3fSAneesh Kumar K.V * ERRORS_CONT and ERRORS_RO case, and perhaps return more 4685d1b1b3fSAneesh Kumar K.V * aggressively from the ext4 function in question, with a 4695d1b1b3fSAneesh Kumar K.V * more appropriate error code. 4705d1b1b3fSAneesh Kumar K.V */ 4715d1b1b3fSAneesh Kumar K.V ext4_lock_group(sb, grp); 4725d1b1b3fSAneesh Kumar K.V return; 4735d1b1b3fSAneesh Kumar K.V } 4745d1b1b3fSAneesh Kumar K.V 4755d1b1b3fSAneesh Kumar K.V 476617ba13bSMingming Cao void ext4_update_dynamic_rev(struct super_block *sb) 477ac27a0ecSDave Kleikamp { 478617ba13bSMingming Cao struct ext4_super_block *es = EXT4_SB(sb)->s_es; 479ac27a0ecSDave Kleikamp 480617ba13bSMingming Cao if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV) 481ac27a0ecSDave Kleikamp return; 482ac27a0ecSDave Kleikamp 48346e665e9SHarvey Harrison ext4_warning(sb, __func__, 484ac27a0ecSDave Kleikamp "updating to rev %d because of new feature flag, " 485ac27a0ecSDave Kleikamp "running e2fsck is recommended", 486617ba13bSMingming Cao EXT4_DYNAMIC_REV); 487ac27a0ecSDave Kleikamp 488617ba13bSMingming Cao es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO); 489617ba13bSMingming Cao es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE); 490617ba13bSMingming Cao es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV); 491ac27a0ecSDave Kleikamp /* leave es->s_feature_*compat flags alone */ 492ac27a0ecSDave Kleikamp /* es->s_uuid will be set by e2fsck if empty */ 493ac27a0ecSDave Kleikamp 494ac27a0ecSDave Kleikamp /* 495ac27a0ecSDave Kleikamp * The rest of the superblock fields should be zero, and if not it 496ac27a0ecSDave Kleikamp * means they are likely already in use, so leave them alone. We 497ac27a0ecSDave Kleikamp * can leave it up to e2fsck to clean up any inconsistencies there. 498ac27a0ecSDave Kleikamp */ 499ac27a0ecSDave Kleikamp } 500ac27a0ecSDave Kleikamp 501ac27a0ecSDave Kleikamp /* 502ac27a0ecSDave Kleikamp * Open the external journal device 503ac27a0ecSDave Kleikamp */ 504617ba13bSMingming Cao static struct block_device *ext4_blkdev_get(dev_t dev) 505ac27a0ecSDave Kleikamp { 506ac27a0ecSDave Kleikamp struct block_device *bdev; 507ac27a0ecSDave Kleikamp char b[BDEVNAME_SIZE]; 508ac27a0ecSDave Kleikamp 509ac27a0ecSDave Kleikamp bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); 510ac27a0ecSDave Kleikamp if (IS_ERR(bdev)) 511ac27a0ecSDave Kleikamp goto fail; 512ac27a0ecSDave Kleikamp return bdev; 513ac27a0ecSDave Kleikamp 514ac27a0ecSDave Kleikamp fail: 515abda1418STheodore Ts'o printk(KERN_ERR "EXT4-fs: failed to open journal device %s: %ld\n", 516ac27a0ecSDave Kleikamp __bdevname(dev, b), PTR_ERR(bdev)); 517ac27a0ecSDave Kleikamp return NULL; 518ac27a0ecSDave Kleikamp } 519ac27a0ecSDave Kleikamp 520ac27a0ecSDave Kleikamp /* 521ac27a0ecSDave Kleikamp * Release the journal device 522ac27a0ecSDave Kleikamp */ 523617ba13bSMingming Cao static int ext4_blkdev_put(struct block_device *bdev) 524ac27a0ecSDave Kleikamp { 525ac27a0ecSDave Kleikamp bd_release(bdev); 5269a1c3542SAl Viro return blkdev_put(bdev, FMODE_READ|FMODE_WRITE); 527ac27a0ecSDave Kleikamp } 528ac27a0ecSDave Kleikamp 529617ba13bSMingming Cao static int ext4_blkdev_remove(struct ext4_sb_info *sbi) 530ac27a0ecSDave Kleikamp { 531ac27a0ecSDave Kleikamp struct block_device *bdev; 532ac27a0ecSDave Kleikamp int ret = -ENODEV; 533ac27a0ecSDave Kleikamp 534ac27a0ecSDave Kleikamp bdev = sbi->journal_bdev; 535ac27a0ecSDave Kleikamp if (bdev) { 536617ba13bSMingming Cao ret = ext4_blkdev_put(bdev); 537ac27a0ecSDave Kleikamp sbi->journal_bdev = NULL; 538ac27a0ecSDave Kleikamp } 539ac27a0ecSDave Kleikamp return ret; 540ac27a0ecSDave Kleikamp } 541ac27a0ecSDave Kleikamp 542ac27a0ecSDave Kleikamp static inline struct inode *orphan_list_entry(struct list_head *l) 543ac27a0ecSDave Kleikamp { 544617ba13bSMingming Cao return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode; 545ac27a0ecSDave Kleikamp } 546ac27a0ecSDave Kleikamp 547617ba13bSMingming Cao static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi) 548ac27a0ecSDave Kleikamp { 549ac27a0ecSDave Kleikamp struct list_head *l; 550ac27a0ecSDave Kleikamp 551ac27a0ecSDave Kleikamp printk(KERN_ERR "sb orphan head is %d\n", 552ac27a0ecSDave Kleikamp le32_to_cpu(sbi->s_es->s_last_orphan)); 553ac27a0ecSDave Kleikamp 554ac27a0ecSDave Kleikamp printk(KERN_ERR "sb_info orphan list:\n"); 555ac27a0ecSDave Kleikamp list_for_each(l, &sbi->s_orphan) { 556ac27a0ecSDave Kleikamp struct inode *inode = orphan_list_entry(l); 557ac27a0ecSDave Kleikamp printk(KERN_ERR " " 558ac27a0ecSDave Kleikamp "inode %s:%lu at %p: mode %o, nlink %d, next %d\n", 559ac27a0ecSDave Kleikamp inode->i_sb->s_id, inode->i_ino, inode, 560ac27a0ecSDave Kleikamp inode->i_mode, inode->i_nlink, 561ac27a0ecSDave Kleikamp NEXT_ORPHAN(inode)); 562ac27a0ecSDave Kleikamp } 563ac27a0ecSDave Kleikamp } 564ac27a0ecSDave Kleikamp 565617ba13bSMingming Cao static void ext4_put_super(struct super_block *sb) 566ac27a0ecSDave Kleikamp { 567617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 568617ba13bSMingming Cao struct ext4_super_block *es = sbi->s_es; 569ef2cabf7SHidehiro Kawai int i, err; 570ac27a0ecSDave Kleikamp 571c9de560dSAlex Tomas ext4_mb_release(sb); 572a86c6181SAlex Tomas ext4_ext_release(sb); 573617ba13bSMingming Cao ext4_xattr_put_super(sb); 5740390131bSFrank Mayhar if (sbi->s_journal) { 575ef2cabf7SHidehiro Kawai err = jbd2_journal_destroy(sbi->s_journal); 57647b4a50bSJan Kara sbi->s_journal = NULL; 577ef2cabf7SHidehiro Kawai if (err < 0) 5780390131bSFrank Mayhar ext4_abort(sb, __func__, 5790390131bSFrank Mayhar "Couldn't clean up the journal"); 5800390131bSFrank Mayhar } 581ac27a0ecSDave Kleikamp if (!(sb->s_flags & MS_RDONLY)) { 582617ba13bSMingming Cao EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 583ac27a0ecSDave Kleikamp es->s_state = cpu_to_le16(sbi->s_mount_state); 584e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 585ac27a0ecSDave Kleikamp } 586240799cdSTheodore Ts'o if (sbi->s_proc) { 5879f6200bbSTheodore Ts'o remove_proc_entry(sb->s_id, ext4_proc_root); 588240799cdSTheodore Ts'o } 5893197ebdbSTheodore Ts'o kobject_del(&sbi->s_kobj); 590ac27a0ecSDave Kleikamp 591ac27a0ecSDave Kleikamp for (i = 0; i < sbi->s_gdb_count; i++) 592ac27a0ecSDave Kleikamp brelse(sbi->s_group_desc[i]); 593ac27a0ecSDave Kleikamp kfree(sbi->s_group_desc); 594c5ca7c76STheodore Ts'o if (is_vmalloc_addr(sbi->s_flex_groups)) 595c5ca7c76STheodore Ts'o vfree(sbi->s_flex_groups); 596c5ca7c76STheodore Ts'o else 597772cb7c8SJose R. Santos kfree(sbi->s_flex_groups); 598ac27a0ecSDave Kleikamp percpu_counter_destroy(&sbi->s_freeblocks_counter); 599ac27a0ecSDave Kleikamp percpu_counter_destroy(&sbi->s_freeinodes_counter); 600ac27a0ecSDave Kleikamp percpu_counter_destroy(&sbi->s_dirs_counter); 6016bc6e63fSAneesh Kumar K.V percpu_counter_destroy(&sbi->s_dirtyblocks_counter); 602ac27a0ecSDave Kleikamp brelse(sbi->s_sbh); 603ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 604ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) 605ac27a0ecSDave Kleikamp kfree(sbi->s_qf_names[i]); 606ac27a0ecSDave Kleikamp #endif 607ac27a0ecSDave Kleikamp 608ac27a0ecSDave Kleikamp /* Debugging code just in case the in-memory inode orphan list 609ac27a0ecSDave Kleikamp * isn't empty. The on-disk one can be non-empty if we've 610ac27a0ecSDave Kleikamp * detected an error and taken the fs readonly, but the 611ac27a0ecSDave Kleikamp * in-memory list had better be clean by this point. */ 612ac27a0ecSDave Kleikamp if (!list_empty(&sbi->s_orphan)) 613ac27a0ecSDave Kleikamp dump_orphan_list(sb, sbi); 614ac27a0ecSDave Kleikamp J_ASSERT(list_empty(&sbi->s_orphan)); 615ac27a0ecSDave Kleikamp 616f98393a6SPeter Zijlstra invalidate_bdev(sb->s_bdev); 617ac27a0ecSDave Kleikamp if (sbi->journal_bdev && sbi->journal_bdev != sb->s_bdev) { 618ac27a0ecSDave Kleikamp /* 619ac27a0ecSDave Kleikamp * Invalidate the journal device's buffers. We don't want them 620ac27a0ecSDave Kleikamp * floating about in memory - the physical journal device may 621ac27a0ecSDave Kleikamp * hotswapped, and it breaks the `ro-after' testing code. 622ac27a0ecSDave Kleikamp */ 623ac27a0ecSDave Kleikamp sync_blockdev(sbi->journal_bdev); 624f98393a6SPeter Zijlstra invalidate_bdev(sbi->journal_bdev); 625617ba13bSMingming Cao ext4_blkdev_remove(sbi); 626ac27a0ecSDave Kleikamp } 627ac27a0ecSDave Kleikamp sb->s_fs_info = NULL; 6283197ebdbSTheodore Ts'o /* 6293197ebdbSTheodore Ts'o * Now that we are completely done shutting down the 6303197ebdbSTheodore Ts'o * superblock, we need to actually destroy the kobject. 6313197ebdbSTheodore Ts'o */ 6323197ebdbSTheodore Ts'o unlock_kernel(); 6333197ebdbSTheodore Ts'o unlock_super(sb); 6343197ebdbSTheodore Ts'o kobject_put(&sbi->s_kobj); 6353197ebdbSTheodore Ts'o wait_for_completion(&sbi->s_kobj_unregister); 6363197ebdbSTheodore Ts'o lock_super(sb); 6373197ebdbSTheodore Ts'o lock_kernel(); 638705895b6SPekka Enberg kfree(sbi->s_blockgroup_lock); 639ac27a0ecSDave Kleikamp kfree(sbi); 640ac27a0ecSDave Kleikamp return; 641ac27a0ecSDave Kleikamp } 642ac27a0ecSDave Kleikamp 643e18b890bSChristoph Lameter static struct kmem_cache *ext4_inode_cachep; 644ac27a0ecSDave Kleikamp 645ac27a0ecSDave Kleikamp /* 646ac27a0ecSDave Kleikamp * Called inside transaction, so use GFP_NOFS 647ac27a0ecSDave Kleikamp */ 648617ba13bSMingming Cao static struct inode *ext4_alloc_inode(struct super_block *sb) 649ac27a0ecSDave Kleikamp { 650617ba13bSMingming Cao struct ext4_inode_info *ei; 651ac27a0ecSDave Kleikamp 652e6b4f8daSChristoph Lameter ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS); 653ac27a0ecSDave Kleikamp if (!ei) 654ac27a0ecSDave Kleikamp return NULL; 65503010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_POSIX_ACL 656617ba13bSMingming Cao ei->i_acl = EXT4_ACL_NOT_CACHED; 657617ba13bSMingming Cao ei->i_default_acl = EXT4_ACL_NOT_CACHED; 658ac27a0ecSDave Kleikamp #endif 659ac27a0ecSDave Kleikamp ei->vfs_inode.i_version = 1; 66091246c00SAneesh Kumar K.V ei->vfs_inode.i_data.writeback_index = 0; 661a86c6181SAlex Tomas memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache)); 662c9de560dSAlex Tomas INIT_LIST_HEAD(&ei->i_prealloc_list); 663c9de560dSAlex Tomas spin_lock_init(&ei->i_prealloc_lock); 6640390131bSFrank Mayhar /* 6650390131bSFrank Mayhar * Note: We can be called before EXT4_SB(sb)->s_journal is set, 6660390131bSFrank Mayhar * therefore it can be null here. Don't check it, just initialize 6670390131bSFrank Mayhar * jinode. 6680390131bSFrank Mayhar */ 669678aaf48SJan Kara jbd2_journal_init_jbd_inode(&ei->jinode, &ei->vfs_inode); 670d2a17637SMingming Cao ei->i_reserved_data_blocks = 0; 671d2a17637SMingming Cao ei->i_reserved_meta_blocks = 0; 672d2a17637SMingming Cao ei->i_allocated_meta_blocks = 0; 673d2a17637SMingming Cao ei->i_delalloc_reserved_flag = 0; 674d2a17637SMingming Cao spin_lock_init(&(ei->i_block_reservation_lock)); 675ac27a0ecSDave Kleikamp return &ei->vfs_inode; 676ac27a0ecSDave Kleikamp } 677ac27a0ecSDave Kleikamp 678617ba13bSMingming Cao static void ext4_destroy_inode(struct inode *inode) 679ac27a0ecSDave Kleikamp { 6809f7dd93dSVasily Averin if (!list_empty(&(EXT4_I(inode)->i_orphan))) { 6819f7dd93dSVasily Averin printk("EXT4 Inode %p: orphan list check failed!\n", 6829f7dd93dSVasily Averin EXT4_I(inode)); 6839f7dd93dSVasily Averin print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4, 6849f7dd93dSVasily Averin EXT4_I(inode), sizeof(struct ext4_inode_info), 6859f7dd93dSVasily Averin true); 6869f7dd93dSVasily Averin dump_stack(); 6879f7dd93dSVasily Averin } 688617ba13bSMingming Cao kmem_cache_free(ext4_inode_cachep, EXT4_I(inode)); 689ac27a0ecSDave Kleikamp } 690ac27a0ecSDave Kleikamp 69151cc5068SAlexey Dobriyan static void init_once(void *foo) 692ac27a0ecSDave Kleikamp { 693617ba13bSMingming Cao struct ext4_inode_info *ei = (struct ext4_inode_info *) foo; 694ac27a0ecSDave Kleikamp 695ac27a0ecSDave Kleikamp INIT_LIST_HEAD(&ei->i_orphan); 69603010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_XATTR 697ac27a0ecSDave Kleikamp init_rwsem(&ei->xattr_sem); 698ac27a0ecSDave Kleikamp #endif 6990e855ac8SAneesh Kumar K.V init_rwsem(&ei->i_data_sem); 700ac27a0ecSDave Kleikamp inode_init_once(&ei->vfs_inode); 701ac27a0ecSDave Kleikamp } 702ac27a0ecSDave Kleikamp 703ac27a0ecSDave Kleikamp static int init_inodecache(void) 704ac27a0ecSDave Kleikamp { 705617ba13bSMingming Cao ext4_inode_cachep = kmem_cache_create("ext4_inode_cache", 706617ba13bSMingming Cao sizeof(struct ext4_inode_info), 707ac27a0ecSDave Kleikamp 0, (SLAB_RECLAIM_ACCOUNT| 708ac27a0ecSDave Kleikamp SLAB_MEM_SPREAD), 70920c2df83SPaul Mundt init_once); 710617ba13bSMingming Cao if (ext4_inode_cachep == NULL) 711ac27a0ecSDave Kleikamp return -ENOMEM; 712ac27a0ecSDave Kleikamp return 0; 713ac27a0ecSDave Kleikamp } 714ac27a0ecSDave Kleikamp 715ac27a0ecSDave Kleikamp static void destroy_inodecache(void) 716ac27a0ecSDave Kleikamp { 717617ba13bSMingming Cao kmem_cache_destroy(ext4_inode_cachep); 718ac27a0ecSDave Kleikamp } 719ac27a0ecSDave Kleikamp 720617ba13bSMingming Cao static void ext4_clear_inode(struct inode *inode) 721ac27a0ecSDave Kleikamp { 72203010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_POSIX_ACL 723617ba13bSMingming Cao if (EXT4_I(inode)->i_acl && 724617ba13bSMingming Cao EXT4_I(inode)->i_acl != EXT4_ACL_NOT_CACHED) { 725617ba13bSMingming Cao posix_acl_release(EXT4_I(inode)->i_acl); 726617ba13bSMingming Cao EXT4_I(inode)->i_acl = EXT4_ACL_NOT_CACHED; 727ac27a0ecSDave Kleikamp } 728617ba13bSMingming Cao if (EXT4_I(inode)->i_default_acl && 729617ba13bSMingming Cao EXT4_I(inode)->i_default_acl != EXT4_ACL_NOT_CACHED) { 730617ba13bSMingming Cao posix_acl_release(EXT4_I(inode)->i_default_acl); 731617ba13bSMingming Cao EXT4_I(inode)->i_default_acl = EXT4_ACL_NOT_CACHED; 732ac27a0ecSDave Kleikamp } 733ac27a0ecSDave Kleikamp #endif 734c2ea3fdeSTheodore Ts'o ext4_discard_preallocations(inode); 7350390131bSFrank Mayhar if (EXT4_JOURNAL(inode)) 736678aaf48SJan Kara jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal, 737678aaf48SJan Kara &EXT4_I(inode)->jinode); 738ac27a0ecSDave Kleikamp } 739ac27a0ecSDave Kleikamp 7402b2d6d01STheodore Ts'o static inline void ext4_show_quota_options(struct seq_file *seq, 7412b2d6d01STheodore Ts'o struct super_block *sb) 742ac27a0ecSDave Kleikamp { 743ac27a0ecSDave Kleikamp #if defined(CONFIG_QUOTA) 744617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 745ac27a0ecSDave Kleikamp 746ac27a0ecSDave Kleikamp if (sbi->s_jquota_fmt) 747ac27a0ecSDave Kleikamp seq_printf(seq, ",jqfmt=%s", 748ac27a0ecSDave Kleikamp (sbi->s_jquota_fmt == QFMT_VFS_OLD) ? "vfsold" : "vfsv0"); 749ac27a0ecSDave Kleikamp 750ac27a0ecSDave Kleikamp if (sbi->s_qf_names[USRQUOTA]) 751ac27a0ecSDave Kleikamp seq_printf(seq, ",usrjquota=%s", sbi->s_qf_names[USRQUOTA]); 752ac27a0ecSDave Kleikamp 753ac27a0ecSDave Kleikamp if (sbi->s_qf_names[GRPQUOTA]) 754ac27a0ecSDave Kleikamp seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]); 755ac27a0ecSDave Kleikamp 756617ba13bSMingming Cao if (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA) 757ac27a0ecSDave Kleikamp seq_puts(seq, ",usrquota"); 758ac27a0ecSDave Kleikamp 759617ba13bSMingming Cao if (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA) 760ac27a0ecSDave Kleikamp seq_puts(seq, ",grpquota"); 761ac27a0ecSDave Kleikamp #endif 762ac27a0ecSDave Kleikamp } 763ac27a0ecSDave Kleikamp 764d9c9bef1SMiklos Szeredi /* 765d9c9bef1SMiklos Szeredi * Show an option if 766d9c9bef1SMiklos Szeredi * - it's set to a non-default value OR 767d9c9bef1SMiklos Szeredi * - if the per-sb default is different from the global default 768d9c9bef1SMiklos Szeredi */ 769617ba13bSMingming Cao static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs) 770ac27a0ecSDave Kleikamp { 771aa22df2cSAneesh Kumar K.V int def_errors; 772aa22df2cSAneesh Kumar K.V unsigned long def_mount_opts; 773ac27a0ecSDave Kleikamp struct super_block *sb = vfs->mnt_sb; 774d9c9bef1SMiklos Szeredi struct ext4_sb_info *sbi = EXT4_SB(sb); 775d9c9bef1SMiklos Szeredi struct ext4_super_block *es = sbi->s_es; 776d9c9bef1SMiklos Szeredi 777d9c9bef1SMiklos Szeredi def_mount_opts = le32_to_cpu(es->s_default_mount_opts); 778aa22df2cSAneesh Kumar K.V def_errors = le16_to_cpu(es->s_errors); 779d9c9bef1SMiklos Szeredi 780d9c9bef1SMiklos Szeredi if (sbi->s_sb_block != 1) 781d9c9bef1SMiklos Szeredi seq_printf(seq, ",sb=%llu", sbi->s_sb_block); 782d9c9bef1SMiklos Szeredi if (test_opt(sb, MINIX_DF)) 783d9c9bef1SMiklos Szeredi seq_puts(seq, ",minixdf"); 784aa22df2cSAneesh Kumar K.V if (test_opt(sb, GRPID) && !(def_mount_opts & EXT4_DEFM_BSDGROUPS)) 785d9c9bef1SMiklos Szeredi seq_puts(seq, ",grpid"); 786d9c9bef1SMiklos Szeredi if (!test_opt(sb, GRPID) && (def_mount_opts & EXT4_DEFM_BSDGROUPS)) 787d9c9bef1SMiklos Szeredi seq_puts(seq, ",nogrpid"); 788d9c9bef1SMiklos Szeredi if (sbi->s_resuid != EXT4_DEF_RESUID || 789d9c9bef1SMiklos Szeredi le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID) { 790d9c9bef1SMiklos Szeredi seq_printf(seq, ",resuid=%u", sbi->s_resuid); 791d9c9bef1SMiklos Szeredi } 792d9c9bef1SMiklos Szeredi if (sbi->s_resgid != EXT4_DEF_RESGID || 793d9c9bef1SMiklos Szeredi le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID) { 794d9c9bef1SMiklos Szeredi seq_printf(seq, ",resgid=%u", sbi->s_resgid); 795d9c9bef1SMiklos Szeredi } 796bb4f397aSAneesh Kumar K.V if (test_opt(sb, ERRORS_RO)) { 797d9c9bef1SMiklos Szeredi if (def_errors == EXT4_ERRORS_PANIC || 798bb4f397aSAneesh Kumar K.V def_errors == EXT4_ERRORS_CONTINUE) { 799d9c9bef1SMiklos Szeredi seq_puts(seq, ",errors=remount-ro"); 800bb4f397aSAneesh Kumar K.V } 801bb4f397aSAneesh Kumar K.V } 802aa22df2cSAneesh Kumar K.V if (test_opt(sb, ERRORS_CONT) && def_errors != EXT4_ERRORS_CONTINUE) 803bb4f397aSAneesh Kumar K.V seq_puts(seq, ",errors=continue"); 804aa22df2cSAneesh Kumar K.V if (test_opt(sb, ERRORS_PANIC) && def_errors != EXT4_ERRORS_PANIC) 805d9c9bef1SMiklos Szeredi seq_puts(seq, ",errors=panic"); 806aa22df2cSAneesh Kumar K.V if (test_opt(sb, NO_UID32) && !(def_mount_opts & EXT4_DEFM_UID16)) 807d9c9bef1SMiklos Szeredi seq_puts(seq, ",nouid32"); 808aa22df2cSAneesh Kumar K.V if (test_opt(sb, DEBUG) && !(def_mount_opts & EXT4_DEFM_DEBUG)) 809d9c9bef1SMiklos Szeredi seq_puts(seq, ",debug"); 810d9c9bef1SMiklos Szeredi if (test_opt(sb, OLDALLOC)) 811d9c9bef1SMiklos Szeredi seq_puts(seq, ",oldalloc"); 81203010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_XATTR 813aa22df2cSAneesh Kumar K.V if (test_opt(sb, XATTR_USER) && 814aa22df2cSAneesh Kumar K.V !(def_mount_opts & EXT4_DEFM_XATTR_USER)) 815d9c9bef1SMiklos Szeredi seq_puts(seq, ",user_xattr"); 816d9c9bef1SMiklos Szeredi if (!test_opt(sb, XATTR_USER) && 817d9c9bef1SMiklos Szeredi (def_mount_opts & EXT4_DEFM_XATTR_USER)) { 818d9c9bef1SMiklos Szeredi seq_puts(seq, ",nouser_xattr"); 819d9c9bef1SMiklos Szeredi } 820d9c9bef1SMiklos Szeredi #endif 82103010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_POSIX_ACL 822aa22df2cSAneesh Kumar K.V if (test_opt(sb, POSIX_ACL) && !(def_mount_opts & EXT4_DEFM_ACL)) 823d9c9bef1SMiklos Szeredi seq_puts(seq, ",acl"); 824d9c9bef1SMiklos Szeredi if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT4_DEFM_ACL)) 825d9c9bef1SMiklos Szeredi seq_puts(seq, ",noacl"); 826d9c9bef1SMiklos Szeredi #endif 82730773840STheodore Ts'o if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) { 828d9c9bef1SMiklos Szeredi seq_printf(seq, ",commit=%u", 829d9c9bef1SMiklos Szeredi (unsigned) (sbi->s_commit_interval / HZ)); 830d9c9bef1SMiklos Szeredi } 83130773840STheodore Ts'o if (sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME) { 83230773840STheodore Ts'o seq_printf(seq, ",min_batch_time=%u", 83330773840STheodore Ts'o (unsigned) sbi->s_min_batch_time); 83430773840STheodore Ts'o } 83530773840STheodore Ts'o if (sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME) { 83630773840STheodore Ts'o seq_printf(seq, ",max_batch_time=%u", 83730773840STheodore Ts'o (unsigned) sbi->s_min_batch_time); 83830773840STheodore Ts'o } 83930773840STheodore Ts'o 840571640caSEric Sandeen /* 841571640caSEric Sandeen * We're changing the default of barrier mount option, so 842571640caSEric Sandeen * let's always display its mount state so it's clear what its 843571640caSEric Sandeen * status is. 844571640caSEric Sandeen */ 845571640caSEric Sandeen seq_puts(seq, ",barrier="); 846571640caSEric Sandeen seq_puts(seq, test_opt(sb, BARRIER) ? "1" : "0"); 847cd0b6a39STheodore Ts'o if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) 848cd0b6a39STheodore Ts'o seq_puts(seq, ",journal_async_commit"); 849d9c9bef1SMiklos Szeredi if (test_opt(sb, NOBH)) 850d9c9bef1SMiklos Szeredi seq_puts(seq, ",nobh"); 85125ec56b5SJean Noel Cordenner if (test_opt(sb, I_VERSION)) 85225ec56b5SJean Noel Cordenner seq_puts(seq, ",i_version"); 853dd919b98SAneesh Kumar K.V if (!test_opt(sb, DELALLOC)) 854dd919b98SAneesh Kumar K.V seq_puts(seq, ",nodelalloc"); 855dd919b98SAneesh Kumar K.V 856ac27a0ecSDave Kleikamp 857cb45bbe4SMiklos Szeredi if (sbi->s_stripe) 858cb45bbe4SMiklos Szeredi seq_printf(seq, ",stripe=%lu", sbi->s_stripe); 859aa22df2cSAneesh Kumar K.V /* 860aa22df2cSAneesh Kumar K.V * journal mode get enabled in different ways 861aa22df2cSAneesh Kumar K.V * So just print the value even if we didn't specify it 862aa22df2cSAneesh Kumar K.V */ 863617ba13bSMingming Cao if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) 864ac27a0ecSDave Kleikamp seq_puts(seq, ",data=journal"); 865617ba13bSMingming Cao else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) 866ac27a0ecSDave Kleikamp seq_puts(seq, ",data=ordered"); 867617ba13bSMingming Cao else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA) 868ac27a0ecSDave Kleikamp seq_puts(seq, ",data=writeback"); 869ac27a0ecSDave Kleikamp 870240799cdSTheodore Ts'o if (sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS) 871240799cdSTheodore Ts'o seq_printf(seq, ",inode_readahead_blks=%u", 872240799cdSTheodore Ts'o sbi->s_inode_readahead_blks); 873240799cdSTheodore Ts'o 8745bf5683aSHidehiro Kawai if (test_opt(sb, DATA_ERR_ABORT)) 8755bf5683aSHidehiro Kawai seq_puts(seq, ",data_err=abort"); 8765bf5683aSHidehiro Kawai 877afd4672dSTheodore Ts'o if (test_opt(sb, NO_AUTO_DA_ALLOC)) 87806705bffSTheodore Ts'o seq_puts(seq, ",noauto_da_alloc"); 879afd4672dSTheodore Ts'o 880617ba13bSMingming Cao ext4_show_quota_options(seq, sb); 881ac27a0ecSDave Kleikamp return 0; 882ac27a0ecSDave Kleikamp } 883ac27a0ecSDave Kleikamp 884ac27a0ecSDave Kleikamp 8851b961ac0SChristoph Hellwig static struct inode *ext4_nfs_get_inode(struct super_block *sb, 8861b961ac0SChristoph Hellwig u64 ino, u32 generation) 887ac27a0ecSDave Kleikamp { 888ac27a0ecSDave Kleikamp struct inode *inode; 889ac27a0ecSDave Kleikamp 890617ba13bSMingming Cao if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO) 891ac27a0ecSDave Kleikamp return ERR_PTR(-ESTALE); 892617ba13bSMingming Cao if (ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)) 893ac27a0ecSDave Kleikamp return ERR_PTR(-ESTALE); 894ac27a0ecSDave Kleikamp 895ac27a0ecSDave Kleikamp /* iget isn't really right if the inode is currently unallocated!! 896ac27a0ecSDave Kleikamp * 897617ba13bSMingming Cao * ext4_read_inode will return a bad_inode if the inode had been 898ac27a0ecSDave Kleikamp * deleted, so we should be safe. 899ac27a0ecSDave Kleikamp * 900ac27a0ecSDave Kleikamp * Currently we don't know the generation for parent directory, so 901ac27a0ecSDave Kleikamp * a generation of 0 means "accept any" 902ac27a0ecSDave Kleikamp */ 9031d1fe1eeSDavid Howells inode = ext4_iget(sb, ino); 9041d1fe1eeSDavid Howells if (IS_ERR(inode)) 9051d1fe1eeSDavid Howells return ERR_CAST(inode); 9061d1fe1eeSDavid Howells if (generation && inode->i_generation != generation) { 907ac27a0ecSDave Kleikamp iput(inode); 908ac27a0ecSDave Kleikamp return ERR_PTR(-ESTALE); 909ac27a0ecSDave Kleikamp } 9101b961ac0SChristoph Hellwig 9111b961ac0SChristoph Hellwig return inode; 912ac27a0ecSDave Kleikamp } 9131b961ac0SChristoph Hellwig 9141b961ac0SChristoph Hellwig static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid, 9151b961ac0SChristoph Hellwig int fh_len, int fh_type) 9161b961ac0SChristoph Hellwig { 9171b961ac0SChristoph Hellwig return generic_fh_to_dentry(sb, fid, fh_len, fh_type, 9181b961ac0SChristoph Hellwig ext4_nfs_get_inode); 9191b961ac0SChristoph Hellwig } 9201b961ac0SChristoph Hellwig 9211b961ac0SChristoph Hellwig static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid, 9221b961ac0SChristoph Hellwig int fh_len, int fh_type) 9231b961ac0SChristoph Hellwig { 9241b961ac0SChristoph Hellwig return generic_fh_to_parent(sb, fid, fh_len, fh_type, 9251b961ac0SChristoph Hellwig ext4_nfs_get_inode); 926ac27a0ecSDave Kleikamp } 927ac27a0ecSDave Kleikamp 928c39a7f84SToshiyuki Okajima /* 929c39a7f84SToshiyuki Okajima * Try to release metadata pages (indirect blocks, directories) which are 930c39a7f84SToshiyuki Okajima * mapped via the block device. Since these pages could have journal heads 931c39a7f84SToshiyuki Okajima * which would prevent try_to_free_buffers() from freeing them, we must use 932c39a7f84SToshiyuki Okajima * jbd2 layer's try_to_free_buffers() function to release them. 933c39a7f84SToshiyuki Okajima */ 934c39a7f84SToshiyuki Okajima static int bdev_try_to_free_page(struct super_block *sb, struct page *page, gfp_t wait) 935c39a7f84SToshiyuki Okajima { 936c39a7f84SToshiyuki Okajima journal_t *journal = EXT4_SB(sb)->s_journal; 937c39a7f84SToshiyuki Okajima 938c39a7f84SToshiyuki Okajima WARN_ON(PageChecked(page)); 939c39a7f84SToshiyuki Okajima if (!page_has_buffers(page)) 940c39a7f84SToshiyuki Okajima return 0; 941c39a7f84SToshiyuki Okajima if (journal) 942c39a7f84SToshiyuki Okajima return jbd2_journal_try_to_free_buffers(journal, page, 943c39a7f84SToshiyuki Okajima wait & ~__GFP_WAIT); 944c39a7f84SToshiyuki Okajima return try_to_free_buffers(page); 945c39a7f84SToshiyuki Okajima } 946c39a7f84SToshiyuki Okajima 947ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 948ac27a0ecSDave Kleikamp #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group") 949ac27a0ecSDave Kleikamp #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA)) 950ac27a0ecSDave Kleikamp 951617ba13bSMingming Cao static int ext4_write_dquot(struct dquot *dquot); 952617ba13bSMingming Cao static int ext4_acquire_dquot(struct dquot *dquot); 953617ba13bSMingming Cao static int ext4_release_dquot(struct dquot *dquot); 954617ba13bSMingming Cao static int ext4_mark_dquot_dirty(struct dquot *dquot); 955617ba13bSMingming Cao static int ext4_write_info(struct super_block *sb, int type); 9566f28e087SJan Kara static int ext4_quota_on(struct super_block *sb, int type, int format_id, 9576f28e087SJan Kara char *path, int remount); 958617ba13bSMingming Cao static int ext4_quota_on_mount(struct super_block *sb, int type); 959617ba13bSMingming Cao static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, 960ac27a0ecSDave Kleikamp size_t len, loff_t off); 961617ba13bSMingming Cao static ssize_t ext4_quota_write(struct super_block *sb, int type, 962ac27a0ecSDave Kleikamp const char *data, size_t len, loff_t off); 963ac27a0ecSDave Kleikamp 964617ba13bSMingming Cao static struct dquot_operations ext4_quota_operations = { 965edf72453SJan Kara .initialize = dquot_initialize, 966edf72453SJan Kara .drop = dquot_drop, 967ac27a0ecSDave Kleikamp .alloc_space = dquot_alloc_space, 96860e58e0fSMingming Cao .reserve_space = dquot_reserve_space, 96960e58e0fSMingming Cao .claim_space = dquot_claim_space, 97060e58e0fSMingming Cao .release_rsv = dquot_release_reserved_space, 97160e58e0fSMingming Cao .get_reserved_space = ext4_get_reserved_space, 972ac27a0ecSDave Kleikamp .alloc_inode = dquot_alloc_inode, 973ac27a0ecSDave Kleikamp .free_space = dquot_free_space, 974ac27a0ecSDave Kleikamp .free_inode = dquot_free_inode, 975ac27a0ecSDave Kleikamp .transfer = dquot_transfer, 976617ba13bSMingming Cao .write_dquot = ext4_write_dquot, 977617ba13bSMingming Cao .acquire_dquot = ext4_acquire_dquot, 978617ba13bSMingming Cao .release_dquot = ext4_release_dquot, 979617ba13bSMingming Cao .mark_dirty = ext4_mark_dquot_dirty, 980a5b5ee32SJan Kara .write_info = ext4_write_info, 981a5b5ee32SJan Kara .alloc_dquot = dquot_alloc, 982a5b5ee32SJan Kara .destroy_dquot = dquot_destroy, 983ac27a0ecSDave Kleikamp }; 984ac27a0ecSDave Kleikamp 985617ba13bSMingming Cao static struct quotactl_ops ext4_qctl_operations = { 986617ba13bSMingming Cao .quota_on = ext4_quota_on, 987ac27a0ecSDave Kleikamp .quota_off = vfs_quota_off, 988ac27a0ecSDave Kleikamp .quota_sync = vfs_quota_sync, 989ac27a0ecSDave Kleikamp .get_info = vfs_get_dqinfo, 990ac27a0ecSDave Kleikamp .set_info = vfs_set_dqinfo, 991ac27a0ecSDave Kleikamp .get_dqblk = vfs_get_dqblk, 992ac27a0ecSDave Kleikamp .set_dqblk = vfs_set_dqblk 993ac27a0ecSDave Kleikamp }; 994ac27a0ecSDave Kleikamp #endif 995ac27a0ecSDave Kleikamp 996ee9b6d61SJosef 'Jeff' Sipek static const struct super_operations ext4_sops = { 997617ba13bSMingming Cao .alloc_inode = ext4_alloc_inode, 998617ba13bSMingming Cao .destroy_inode = ext4_destroy_inode, 999617ba13bSMingming Cao .write_inode = ext4_write_inode, 1000617ba13bSMingming Cao .dirty_inode = ext4_dirty_inode, 1001617ba13bSMingming Cao .delete_inode = ext4_delete_inode, 1002617ba13bSMingming Cao .put_super = ext4_put_super, 1003617ba13bSMingming Cao .sync_fs = ext4_sync_fs, 1004c4be0c1dSTakashi Sato .freeze_fs = ext4_freeze, 1005c4be0c1dSTakashi Sato .unfreeze_fs = ext4_unfreeze, 1006617ba13bSMingming Cao .statfs = ext4_statfs, 1007617ba13bSMingming Cao .remount_fs = ext4_remount, 1008617ba13bSMingming Cao .clear_inode = ext4_clear_inode, 1009617ba13bSMingming Cao .show_options = ext4_show_options, 1010ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 1011617ba13bSMingming Cao .quota_read = ext4_quota_read, 1012617ba13bSMingming Cao .quota_write = ext4_quota_write, 1013ac27a0ecSDave Kleikamp #endif 1014c39a7f84SToshiyuki Okajima .bdev_try_to_free_page = bdev_try_to_free_page, 1015ac27a0ecSDave Kleikamp }; 1016ac27a0ecSDave Kleikamp 10179ca92389STheodore Ts'o static const struct super_operations ext4_nojournal_sops = { 10189ca92389STheodore Ts'o .alloc_inode = ext4_alloc_inode, 10199ca92389STheodore Ts'o .destroy_inode = ext4_destroy_inode, 10209ca92389STheodore Ts'o .write_inode = ext4_write_inode, 10219ca92389STheodore Ts'o .dirty_inode = ext4_dirty_inode, 10229ca92389STheodore Ts'o .delete_inode = ext4_delete_inode, 10239ca92389STheodore Ts'o .write_super = ext4_write_super, 10249ca92389STheodore Ts'o .put_super = ext4_put_super, 10259ca92389STheodore Ts'o .statfs = ext4_statfs, 10269ca92389STheodore Ts'o .remount_fs = ext4_remount, 10279ca92389STheodore Ts'o .clear_inode = ext4_clear_inode, 10289ca92389STheodore Ts'o .show_options = ext4_show_options, 10299ca92389STheodore Ts'o #ifdef CONFIG_QUOTA 10309ca92389STheodore Ts'o .quota_read = ext4_quota_read, 10319ca92389STheodore Ts'o .quota_write = ext4_quota_write, 10329ca92389STheodore Ts'o #endif 10339ca92389STheodore Ts'o .bdev_try_to_free_page = bdev_try_to_free_page, 10349ca92389STheodore Ts'o }; 10359ca92389STheodore Ts'o 103639655164SChristoph Hellwig static const struct export_operations ext4_export_ops = { 10371b961ac0SChristoph Hellwig .fh_to_dentry = ext4_fh_to_dentry, 10381b961ac0SChristoph Hellwig .fh_to_parent = ext4_fh_to_parent, 1039617ba13bSMingming Cao .get_parent = ext4_get_parent, 1040ac27a0ecSDave Kleikamp }; 1041ac27a0ecSDave Kleikamp 1042ac27a0ecSDave Kleikamp enum { 1043ac27a0ecSDave Kleikamp Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid, 1044ac27a0ecSDave Kleikamp Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro, 104501436ef2STheodore Ts'o Opt_nouid32, Opt_debug, Opt_oldalloc, Opt_orlov, 1046ac27a0ecSDave Kleikamp Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, 104706705bffSTheodore Ts'o Opt_auto_da_alloc, Opt_noauto_da_alloc, Opt_noload, Opt_nobh, Opt_bh, 104830773840STheodore Ts'o Opt_commit, Opt_min_batch_time, Opt_max_batch_time, 1049c3191067STheodore Ts'o Opt_journal_update, Opt_journal_dev, 1050818d276cSGirish Shilamkar Opt_journal_checksum, Opt_journal_async_commit, 1051ac27a0ecSDave Kleikamp Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, 1052*f4033903SCurt Wohlgemuth Opt_data_err_abort, Opt_data_err_ignore, Opt_mb_history_length, 1053ac27a0ecSDave Kleikamp Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, 1054ac27a0ecSDave Kleikamp Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, 105506705bffSTheodore Ts'o Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, Opt_resize, 105606705bffSTheodore Ts'o Opt_usrquota, Opt_grpquota, Opt_i_version, 105701436ef2STheodore Ts'o Opt_stripe, Opt_delalloc, Opt_nodelalloc, 1058b3881f74STheodore Ts'o Opt_inode_readahead_blks, Opt_journal_ioprio 1059ac27a0ecSDave Kleikamp }; 1060ac27a0ecSDave Kleikamp 1061a447c093SSteven Whitehouse static const match_table_t tokens = { 1062ac27a0ecSDave Kleikamp {Opt_bsd_df, "bsddf"}, 1063ac27a0ecSDave Kleikamp {Opt_minix_df, "minixdf"}, 1064ac27a0ecSDave Kleikamp {Opt_grpid, "grpid"}, 1065ac27a0ecSDave Kleikamp {Opt_grpid, "bsdgroups"}, 1066ac27a0ecSDave Kleikamp {Opt_nogrpid, "nogrpid"}, 1067ac27a0ecSDave Kleikamp {Opt_nogrpid, "sysvgroups"}, 1068ac27a0ecSDave Kleikamp {Opt_resgid, "resgid=%u"}, 1069ac27a0ecSDave Kleikamp {Opt_resuid, "resuid=%u"}, 1070ac27a0ecSDave Kleikamp {Opt_sb, "sb=%u"}, 1071ac27a0ecSDave Kleikamp {Opt_err_cont, "errors=continue"}, 1072ac27a0ecSDave Kleikamp {Opt_err_panic, "errors=panic"}, 1073ac27a0ecSDave Kleikamp {Opt_err_ro, "errors=remount-ro"}, 1074ac27a0ecSDave Kleikamp {Opt_nouid32, "nouid32"}, 1075ac27a0ecSDave Kleikamp {Opt_debug, "debug"}, 1076ac27a0ecSDave Kleikamp {Opt_oldalloc, "oldalloc"}, 1077ac27a0ecSDave Kleikamp {Opt_orlov, "orlov"}, 1078ac27a0ecSDave Kleikamp {Opt_user_xattr, "user_xattr"}, 1079ac27a0ecSDave Kleikamp {Opt_nouser_xattr, "nouser_xattr"}, 1080ac27a0ecSDave Kleikamp {Opt_acl, "acl"}, 1081ac27a0ecSDave Kleikamp {Opt_noacl, "noacl"}, 1082ac27a0ecSDave Kleikamp {Opt_noload, "noload"}, 1083ac27a0ecSDave Kleikamp {Opt_nobh, "nobh"}, 1084ac27a0ecSDave Kleikamp {Opt_bh, "bh"}, 1085ac27a0ecSDave Kleikamp {Opt_commit, "commit=%u"}, 108630773840STheodore Ts'o {Opt_min_batch_time, "min_batch_time=%u"}, 108730773840STheodore Ts'o {Opt_max_batch_time, "max_batch_time=%u"}, 1088ac27a0ecSDave Kleikamp {Opt_journal_update, "journal=update"}, 1089ac27a0ecSDave Kleikamp {Opt_journal_dev, "journal_dev=%u"}, 1090818d276cSGirish Shilamkar {Opt_journal_checksum, "journal_checksum"}, 1091818d276cSGirish Shilamkar {Opt_journal_async_commit, "journal_async_commit"}, 1092ac27a0ecSDave Kleikamp {Opt_abort, "abort"}, 1093ac27a0ecSDave Kleikamp {Opt_data_journal, "data=journal"}, 1094ac27a0ecSDave Kleikamp {Opt_data_ordered, "data=ordered"}, 1095ac27a0ecSDave Kleikamp {Opt_data_writeback, "data=writeback"}, 10965bf5683aSHidehiro Kawai {Opt_data_err_abort, "data_err=abort"}, 10975bf5683aSHidehiro Kawai {Opt_data_err_ignore, "data_err=ignore"}, 1098*f4033903SCurt Wohlgemuth {Opt_mb_history_length, "mb_history_length=%u"}, 1099ac27a0ecSDave Kleikamp {Opt_offusrjquota, "usrjquota="}, 1100ac27a0ecSDave Kleikamp {Opt_usrjquota, "usrjquota=%s"}, 1101ac27a0ecSDave Kleikamp {Opt_offgrpjquota, "grpjquota="}, 1102ac27a0ecSDave Kleikamp {Opt_grpjquota, "grpjquota=%s"}, 1103ac27a0ecSDave Kleikamp {Opt_jqfmt_vfsold, "jqfmt=vfsold"}, 1104ac27a0ecSDave Kleikamp {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, 1105ac27a0ecSDave Kleikamp {Opt_grpquota, "grpquota"}, 1106ac27a0ecSDave Kleikamp {Opt_noquota, "noquota"}, 1107ac27a0ecSDave Kleikamp {Opt_quota, "quota"}, 1108ac27a0ecSDave Kleikamp {Opt_usrquota, "usrquota"}, 1109ac27a0ecSDave Kleikamp {Opt_barrier, "barrier=%u"}, 111006705bffSTheodore Ts'o {Opt_barrier, "barrier"}, 111106705bffSTheodore Ts'o {Opt_nobarrier, "nobarrier"}, 111225ec56b5SJean Noel Cordenner {Opt_i_version, "i_version"}, 1113c9de560dSAlex Tomas {Opt_stripe, "stripe=%u"}, 1114ac27a0ecSDave Kleikamp {Opt_resize, "resize"}, 111564769240SAlex Tomas {Opt_delalloc, "delalloc"}, 1116dd919b98SAneesh Kumar K.V {Opt_nodelalloc, "nodelalloc"}, 1117240799cdSTheodore Ts'o {Opt_inode_readahead_blks, "inode_readahead_blks=%u"}, 1118b3881f74STheodore Ts'o {Opt_journal_ioprio, "journal_ioprio=%u"}, 1119afd4672dSTheodore Ts'o {Opt_auto_da_alloc, "auto_da_alloc=%u"}, 112006705bffSTheodore Ts'o {Opt_auto_da_alloc, "auto_da_alloc"}, 112106705bffSTheodore Ts'o {Opt_noauto_da_alloc, "noauto_da_alloc"}, 1122f3f12faaSJosef Bacik {Opt_err, NULL}, 1123ac27a0ecSDave Kleikamp }; 1124ac27a0ecSDave Kleikamp 1125617ba13bSMingming Cao static ext4_fsblk_t get_sb_block(void **data) 1126ac27a0ecSDave Kleikamp { 1127617ba13bSMingming Cao ext4_fsblk_t sb_block; 1128ac27a0ecSDave Kleikamp char *options = (char *) *data; 1129ac27a0ecSDave Kleikamp 1130ac27a0ecSDave Kleikamp if (!options || strncmp(options, "sb=", 3) != 0) 1131ac27a0ecSDave Kleikamp return 1; /* Default location */ 1132ac27a0ecSDave Kleikamp options += 3; 1133617ba13bSMingming Cao /*todo: use simple_strtoll with >32bit ext4 */ 1134ac27a0ecSDave Kleikamp sb_block = simple_strtoul(options, &options, 0); 1135ac27a0ecSDave Kleikamp if (*options && *options != ',') { 11364776004fSTheodore Ts'o printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n", 1137ac27a0ecSDave Kleikamp (char *) *data); 1138ac27a0ecSDave Kleikamp return 1; 1139ac27a0ecSDave Kleikamp } 1140ac27a0ecSDave Kleikamp if (*options == ',') 1141ac27a0ecSDave Kleikamp options++; 1142ac27a0ecSDave Kleikamp *data = (void *) options; 1143ac27a0ecSDave Kleikamp return sb_block; 1144ac27a0ecSDave Kleikamp } 1145ac27a0ecSDave Kleikamp 1146b3881f74STheodore Ts'o #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3)) 1147b3881f74STheodore Ts'o 1148ac27a0ecSDave Kleikamp static int parse_options(char *options, struct super_block *sb, 1149c3191067STheodore Ts'o unsigned long *journal_devnum, 1150b3881f74STheodore Ts'o unsigned int *journal_ioprio, 1151617ba13bSMingming Cao ext4_fsblk_t *n_blocks_count, int is_remount) 1152ac27a0ecSDave Kleikamp { 1153617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 1154ac27a0ecSDave Kleikamp char *p; 1155ac27a0ecSDave Kleikamp substring_t args[MAX_OPT_ARGS]; 1156ac27a0ecSDave Kleikamp int data_opt = 0; 1157ac27a0ecSDave Kleikamp int option; 1158ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 1159dfc5d03fSJan Kara int qtype, qfmt; 1160ac27a0ecSDave Kleikamp char *qname; 1161ac27a0ecSDave Kleikamp #endif 1162ac27a0ecSDave Kleikamp 1163ac27a0ecSDave Kleikamp if (!options) 1164ac27a0ecSDave Kleikamp return 1; 1165ac27a0ecSDave Kleikamp 1166ac27a0ecSDave Kleikamp while ((p = strsep(&options, ",")) != NULL) { 1167ac27a0ecSDave Kleikamp int token; 1168ac27a0ecSDave Kleikamp if (!*p) 1169ac27a0ecSDave Kleikamp continue; 1170ac27a0ecSDave Kleikamp 1171ac27a0ecSDave Kleikamp token = match_token(p, tokens, args); 1172ac27a0ecSDave Kleikamp switch (token) { 1173ac27a0ecSDave Kleikamp case Opt_bsd_df: 1174ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, MINIX_DF); 1175ac27a0ecSDave Kleikamp break; 1176ac27a0ecSDave Kleikamp case Opt_minix_df: 1177ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, MINIX_DF); 1178ac27a0ecSDave Kleikamp break; 1179ac27a0ecSDave Kleikamp case Opt_grpid: 1180ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, GRPID); 1181ac27a0ecSDave Kleikamp break; 1182ac27a0ecSDave Kleikamp case Opt_nogrpid: 1183ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, GRPID); 1184ac27a0ecSDave Kleikamp break; 1185ac27a0ecSDave Kleikamp case Opt_resuid: 1186ac27a0ecSDave Kleikamp if (match_int(&args[0], &option)) 1187ac27a0ecSDave Kleikamp return 0; 1188ac27a0ecSDave Kleikamp sbi->s_resuid = option; 1189ac27a0ecSDave Kleikamp break; 1190ac27a0ecSDave Kleikamp case Opt_resgid: 1191ac27a0ecSDave Kleikamp if (match_int(&args[0], &option)) 1192ac27a0ecSDave Kleikamp return 0; 1193ac27a0ecSDave Kleikamp sbi->s_resgid = option; 1194ac27a0ecSDave Kleikamp break; 1195ac27a0ecSDave Kleikamp case Opt_sb: 1196ac27a0ecSDave Kleikamp /* handled by get_sb_block() instead of here */ 1197ac27a0ecSDave Kleikamp /* *sb_block = match_int(&args[0]); */ 1198ac27a0ecSDave Kleikamp break; 1199ac27a0ecSDave Kleikamp case Opt_err_panic: 1200ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, ERRORS_CONT); 1201ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, ERRORS_RO); 1202ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, ERRORS_PANIC); 1203ac27a0ecSDave Kleikamp break; 1204ac27a0ecSDave Kleikamp case Opt_err_ro: 1205ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, ERRORS_CONT); 1206ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, ERRORS_PANIC); 1207ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, ERRORS_RO); 1208ac27a0ecSDave Kleikamp break; 1209ac27a0ecSDave Kleikamp case Opt_err_cont: 1210ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, ERRORS_RO); 1211ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, ERRORS_PANIC); 1212ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, ERRORS_CONT); 1213ac27a0ecSDave Kleikamp break; 1214ac27a0ecSDave Kleikamp case Opt_nouid32: 1215ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, NO_UID32); 1216ac27a0ecSDave Kleikamp break; 1217ac27a0ecSDave Kleikamp case Opt_debug: 1218ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, DEBUG); 1219ac27a0ecSDave Kleikamp break; 1220ac27a0ecSDave Kleikamp case Opt_oldalloc: 1221ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, OLDALLOC); 1222ac27a0ecSDave Kleikamp break; 1223ac27a0ecSDave Kleikamp case Opt_orlov: 1224ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, OLDALLOC); 1225ac27a0ecSDave Kleikamp break; 122603010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_XATTR 1227ac27a0ecSDave Kleikamp case Opt_user_xattr: 1228ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, XATTR_USER); 1229ac27a0ecSDave Kleikamp break; 1230ac27a0ecSDave Kleikamp case Opt_nouser_xattr: 1231ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, XATTR_USER); 1232ac27a0ecSDave Kleikamp break; 1233ac27a0ecSDave Kleikamp #else 1234ac27a0ecSDave Kleikamp case Opt_user_xattr: 1235ac27a0ecSDave Kleikamp case Opt_nouser_xattr: 12364776004fSTheodore Ts'o printk(KERN_ERR "EXT4 (no)user_xattr options " 12374776004fSTheodore Ts'o "not supported\n"); 1238ac27a0ecSDave Kleikamp break; 1239ac27a0ecSDave Kleikamp #endif 124003010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_POSIX_ACL 1241ac27a0ecSDave Kleikamp case Opt_acl: 1242ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, POSIX_ACL); 1243ac27a0ecSDave Kleikamp break; 1244ac27a0ecSDave Kleikamp case Opt_noacl: 1245ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, POSIX_ACL); 1246ac27a0ecSDave Kleikamp break; 1247ac27a0ecSDave Kleikamp #else 1248ac27a0ecSDave Kleikamp case Opt_acl: 1249ac27a0ecSDave Kleikamp case Opt_noacl: 12504776004fSTheodore Ts'o printk(KERN_ERR "EXT4 (no)acl options " 12514776004fSTheodore Ts'o "not supported\n"); 1252ac27a0ecSDave Kleikamp break; 1253ac27a0ecSDave Kleikamp #endif 1254ac27a0ecSDave Kleikamp case Opt_journal_update: 1255ac27a0ecSDave Kleikamp /* @@@ FIXME */ 1256ac27a0ecSDave Kleikamp /* Eventually we will want to be able to create 1257ac27a0ecSDave Kleikamp a journal file here. For now, only allow the 1258ac27a0ecSDave Kleikamp user to specify an existing inode to be the 1259ac27a0ecSDave Kleikamp journal file. */ 1260ac27a0ecSDave Kleikamp if (is_remount) { 1261617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: cannot specify " 1262ac27a0ecSDave Kleikamp "journal on remount\n"); 1263ac27a0ecSDave Kleikamp return 0; 1264ac27a0ecSDave Kleikamp } 1265ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, UPDATE_JOURNAL); 1266ac27a0ecSDave Kleikamp break; 1267ac27a0ecSDave Kleikamp case Opt_journal_dev: 1268ac27a0ecSDave Kleikamp if (is_remount) { 1269617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: cannot specify " 1270ac27a0ecSDave Kleikamp "journal on remount\n"); 1271ac27a0ecSDave Kleikamp return 0; 1272ac27a0ecSDave Kleikamp } 1273ac27a0ecSDave Kleikamp if (match_int(&args[0], &option)) 1274ac27a0ecSDave Kleikamp return 0; 1275ac27a0ecSDave Kleikamp *journal_devnum = option; 1276ac27a0ecSDave Kleikamp break; 1277818d276cSGirish Shilamkar case Opt_journal_checksum: 1278818d276cSGirish Shilamkar set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM); 1279818d276cSGirish Shilamkar break; 1280818d276cSGirish Shilamkar case Opt_journal_async_commit: 1281818d276cSGirish Shilamkar set_opt(sbi->s_mount_opt, JOURNAL_ASYNC_COMMIT); 1282818d276cSGirish Shilamkar set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM); 1283818d276cSGirish Shilamkar break; 1284ac27a0ecSDave Kleikamp case Opt_noload: 1285ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, NOLOAD); 1286ac27a0ecSDave Kleikamp break; 1287ac27a0ecSDave Kleikamp case Opt_commit: 1288ac27a0ecSDave Kleikamp if (match_int(&args[0], &option)) 1289ac27a0ecSDave Kleikamp return 0; 1290ac27a0ecSDave Kleikamp if (option < 0) 1291ac27a0ecSDave Kleikamp return 0; 1292ac27a0ecSDave Kleikamp if (option == 0) 1293cd02ff0bSMingming Cao option = JBD2_DEFAULT_MAX_COMMIT_AGE; 1294ac27a0ecSDave Kleikamp sbi->s_commit_interval = HZ * option; 1295ac27a0ecSDave Kleikamp break; 129630773840STheodore Ts'o case Opt_max_batch_time: 129730773840STheodore Ts'o if (match_int(&args[0], &option)) 129830773840STheodore Ts'o return 0; 129930773840STheodore Ts'o if (option < 0) 130030773840STheodore Ts'o return 0; 130130773840STheodore Ts'o if (option == 0) 130230773840STheodore Ts'o option = EXT4_DEF_MAX_BATCH_TIME; 130330773840STheodore Ts'o sbi->s_max_batch_time = option; 130430773840STheodore Ts'o break; 130530773840STheodore Ts'o case Opt_min_batch_time: 130630773840STheodore Ts'o if (match_int(&args[0], &option)) 130730773840STheodore Ts'o return 0; 130830773840STheodore Ts'o if (option < 0) 130930773840STheodore Ts'o return 0; 131030773840STheodore Ts'o sbi->s_min_batch_time = option; 131130773840STheodore Ts'o break; 1312ac27a0ecSDave Kleikamp case Opt_data_journal: 1313617ba13bSMingming Cao data_opt = EXT4_MOUNT_JOURNAL_DATA; 1314ac27a0ecSDave Kleikamp goto datacheck; 1315ac27a0ecSDave Kleikamp case Opt_data_ordered: 1316617ba13bSMingming Cao data_opt = EXT4_MOUNT_ORDERED_DATA; 1317ac27a0ecSDave Kleikamp goto datacheck; 1318ac27a0ecSDave Kleikamp case Opt_data_writeback: 1319617ba13bSMingming Cao data_opt = EXT4_MOUNT_WRITEBACK_DATA; 1320ac27a0ecSDave Kleikamp datacheck: 1321ac27a0ecSDave Kleikamp if (is_remount) { 1322617ba13bSMingming Cao if ((sbi->s_mount_opt & EXT4_MOUNT_DATA_FLAGS) 1323ac27a0ecSDave Kleikamp != data_opt) { 1324ac27a0ecSDave Kleikamp printk(KERN_ERR 1325617ba13bSMingming Cao "EXT4-fs: cannot change data " 1326ac27a0ecSDave Kleikamp "mode on remount\n"); 1327ac27a0ecSDave Kleikamp return 0; 1328ac27a0ecSDave Kleikamp } 1329ac27a0ecSDave Kleikamp } else { 1330617ba13bSMingming Cao sbi->s_mount_opt &= ~EXT4_MOUNT_DATA_FLAGS; 1331ac27a0ecSDave Kleikamp sbi->s_mount_opt |= data_opt; 1332ac27a0ecSDave Kleikamp } 1333ac27a0ecSDave Kleikamp break; 13345bf5683aSHidehiro Kawai case Opt_data_err_abort: 13355bf5683aSHidehiro Kawai set_opt(sbi->s_mount_opt, DATA_ERR_ABORT); 13365bf5683aSHidehiro Kawai break; 13375bf5683aSHidehiro Kawai case Opt_data_err_ignore: 13385bf5683aSHidehiro Kawai clear_opt(sbi->s_mount_opt, DATA_ERR_ABORT); 13395bf5683aSHidehiro Kawai break; 1340*f4033903SCurt Wohlgemuth case Opt_mb_history_length: 1341*f4033903SCurt Wohlgemuth if (match_int(&args[0], &option)) 1342*f4033903SCurt Wohlgemuth return 0; 1343*f4033903SCurt Wohlgemuth if (option < 0) 1344*f4033903SCurt Wohlgemuth return 0; 1345*f4033903SCurt Wohlgemuth sbi->s_mb_history_max = option; 1346*f4033903SCurt Wohlgemuth break; 1347ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 1348ac27a0ecSDave Kleikamp case Opt_usrjquota: 1349ac27a0ecSDave Kleikamp qtype = USRQUOTA; 1350ac27a0ecSDave Kleikamp goto set_qf_name; 1351ac27a0ecSDave Kleikamp case Opt_grpjquota: 1352ac27a0ecSDave Kleikamp qtype = GRPQUOTA; 1353ac27a0ecSDave Kleikamp set_qf_name: 135417bd13b3SJan Kara if (sb_any_quota_loaded(sb) && 1355dfc5d03fSJan Kara !sbi->s_qf_names[qtype]) { 1356ac27a0ecSDave Kleikamp printk(KERN_ERR 13572c8be6b2SJan Kara "EXT4-fs: Cannot change journaled " 1358ac27a0ecSDave Kleikamp "quota options when quota turned on.\n"); 1359ac27a0ecSDave Kleikamp return 0; 1360ac27a0ecSDave Kleikamp } 1361ac27a0ecSDave Kleikamp qname = match_strdup(&args[0]); 1362ac27a0ecSDave Kleikamp if (!qname) { 1363ac27a0ecSDave Kleikamp printk(KERN_ERR 1364617ba13bSMingming Cao "EXT4-fs: not enough memory for " 1365ac27a0ecSDave Kleikamp "storing quotafile name.\n"); 1366ac27a0ecSDave Kleikamp return 0; 1367ac27a0ecSDave Kleikamp } 1368ac27a0ecSDave Kleikamp if (sbi->s_qf_names[qtype] && 1369ac27a0ecSDave Kleikamp strcmp(sbi->s_qf_names[qtype], qname)) { 1370ac27a0ecSDave Kleikamp printk(KERN_ERR 1371617ba13bSMingming Cao "EXT4-fs: %s quota file already " 1372ac27a0ecSDave Kleikamp "specified.\n", QTYPE2NAME(qtype)); 1373ac27a0ecSDave Kleikamp kfree(qname); 1374ac27a0ecSDave Kleikamp return 0; 1375ac27a0ecSDave Kleikamp } 1376ac27a0ecSDave Kleikamp sbi->s_qf_names[qtype] = qname; 1377ac27a0ecSDave Kleikamp if (strchr(sbi->s_qf_names[qtype], '/')) { 1378ac27a0ecSDave Kleikamp printk(KERN_ERR 1379617ba13bSMingming Cao "EXT4-fs: quotafile must be on " 1380ac27a0ecSDave Kleikamp "filesystem root.\n"); 1381ac27a0ecSDave Kleikamp kfree(sbi->s_qf_names[qtype]); 1382ac27a0ecSDave Kleikamp sbi->s_qf_names[qtype] = NULL; 1383ac27a0ecSDave Kleikamp return 0; 1384ac27a0ecSDave Kleikamp } 1385ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, QUOTA); 1386ac27a0ecSDave Kleikamp break; 1387ac27a0ecSDave Kleikamp case Opt_offusrjquota: 1388ac27a0ecSDave Kleikamp qtype = USRQUOTA; 1389ac27a0ecSDave Kleikamp goto clear_qf_name; 1390ac27a0ecSDave Kleikamp case Opt_offgrpjquota: 1391ac27a0ecSDave Kleikamp qtype = GRPQUOTA; 1392ac27a0ecSDave Kleikamp clear_qf_name: 139317bd13b3SJan Kara if (sb_any_quota_loaded(sb) && 1394dfc5d03fSJan Kara sbi->s_qf_names[qtype]) { 1395617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: Cannot change " 13962c8be6b2SJan Kara "journaled quota options when " 1397ac27a0ecSDave Kleikamp "quota turned on.\n"); 1398ac27a0ecSDave Kleikamp return 0; 1399ac27a0ecSDave Kleikamp } 1400ac27a0ecSDave Kleikamp /* 1401ac27a0ecSDave Kleikamp * The space will be released later when all options 1402ac27a0ecSDave Kleikamp * are confirmed to be correct 1403ac27a0ecSDave Kleikamp */ 1404ac27a0ecSDave Kleikamp sbi->s_qf_names[qtype] = NULL; 1405ac27a0ecSDave Kleikamp break; 1406ac27a0ecSDave Kleikamp case Opt_jqfmt_vfsold: 1407dfc5d03fSJan Kara qfmt = QFMT_VFS_OLD; 1408dfc5d03fSJan Kara goto set_qf_format; 1409ac27a0ecSDave Kleikamp case Opt_jqfmt_vfsv0: 1410dfc5d03fSJan Kara qfmt = QFMT_VFS_V0; 1411dfc5d03fSJan Kara set_qf_format: 141217bd13b3SJan Kara if (sb_any_quota_loaded(sb) && 1413dfc5d03fSJan Kara sbi->s_jquota_fmt != qfmt) { 1414dfc5d03fSJan Kara printk(KERN_ERR "EXT4-fs: Cannot change " 1415dfc5d03fSJan Kara "journaled quota options when " 1416dfc5d03fSJan Kara "quota turned on.\n"); 1417dfc5d03fSJan Kara return 0; 1418dfc5d03fSJan Kara } 1419dfc5d03fSJan Kara sbi->s_jquota_fmt = qfmt; 1420ac27a0ecSDave Kleikamp break; 1421ac27a0ecSDave Kleikamp case Opt_quota: 1422ac27a0ecSDave Kleikamp case Opt_usrquota: 1423ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, QUOTA); 1424ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, USRQUOTA); 1425ac27a0ecSDave Kleikamp break; 1426ac27a0ecSDave Kleikamp case Opt_grpquota: 1427ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, QUOTA); 1428ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, GRPQUOTA); 1429ac27a0ecSDave Kleikamp break; 1430ac27a0ecSDave Kleikamp case Opt_noquota: 143117bd13b3SJan Kara if (sb_any_quota_loaded(sb)) { 1432617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: Cannot change quota " 1433ac27a0ecSDave Kleikamp "options when quota turned on.\n"); 1434ac27a0ecSDave Kleikamp return 0; 1435ac27a0ecSDave Kleikamp } 1436ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, QUOTA); 1437ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, USRQUOTA); 1438ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, GRPQUOTA); 1439ac27a0ecSDave Kleikamp break; 1440ac27a0ecSDave Kleikamp #else 1441ac27a0ecSDave Kleikamp case Opt_quota: 1442ac27a0ecSDave Kleikamp case Opt_usrquota: 1443ac27a0ecSDave Kleikamp case Opt_grpquota: 1444cd59e7b9SJan Kara printk(KERN_ERR 1445cd59e7b9SJan Kara "EXT4-fs: quota options not supported.\n"); 1446cd59e7b9SJan Kara break; 1447ac27a0ecSDave Kleikamp case Opt_usrjquota: 1448ac27a0ecSDave Kleikamp case Opt_grpjquota: 1449ac27a0ecSDave Kleikamp case Opt_offusrjquota: 1450ac27a0ecSDave Kleikamp case Opt_offgrpjquota: 1451ac27a0ecSDave Kleikamp case Opt_jqfmt_vfsold: 1452ac27a0ecSDave Kleikamp case Opt_jqfmt_vfsv0: 1453ac27a0ecSDave Kleikamp printk(KERN_ERR 1454cd59e7b9SJan Kara "EXT4-fs: journaled quota options not " 1455ac27a0ecSDave Kleikamp "supported.\n"); 1456ac27a0ecSDave Kleikamp break; 1457ac27a0ecSDave Kleikamp case Opt_noquota: 1458ac27a0ecSDave Kleikamp break; 1459ac27a0ecSDave Kleikamp #endif 1460ac27a0ecSDave Kleikamp case Opt_abort: 1461ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, ABORT); 1462ac27a0ecSDave Kleikamp break; 146306705bffSTheodore Ts'o case Opt_nobarrier: 146406705bffSTheodore Ts'o clear_opt(sbi->s_mount_opt, BARRIER); 146506705bffSTheodore Ts'o break; 1466ac27a0ecSDave Kleikamp case Opt_barrier: 146706705bffSTheodore Ts'o if (match_int(&args[0], &option)) { 146806705bffSTheodore Ts'o set_opt(sbi->s_mount_opt, BARRIER); 146906705bffSTheodore Ts'o break; 147006705bffSTheodore Ts'o } 1471ac27a0ecSDave Kleikamp if (option) 1472ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, BARRIER); 1473ac27a0ecSDave Kleikamp else 1474ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, BARRIER); 1475ac27a0ecSDave Kleikamp break; 1476ac27a0ecSDave Kleikamp case Opt_ignore: 1477ac27a0ecSDave Kleikamp break; 1478ac27a0ecSDave Kleikamp case Opt_resize: 1479ac27a0ecSDave Kleikamp if (!is_remount) { 1480617ba13bSMingming Cao printk("EXT4-fs: resize option only available " 1481ac27a0ecSDave Kleikamp "for remount\n"); 1482ac27a0ecSDave Kleikamp return 0; 1483ac27a0ecSDave Kleikamp } 1484ac27a0ecSDave Kleikamp if (match_int(&args[0], &option) != 0) 1485ac27a0ecSDave Kleikamp return 0; 1486ac27a0ecSDave Kleikamp *n_blocks_count = option; 1487ac27a0ecSDave Kleikamp break; 1488ac27a0ecSDave Kleikamp case Opt_nobh: 1489ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, NOBH); 1490ac27a0ecSDave Kleikamp break; 1491ac27a0ecSDave Kleikamp case Opt_bh: 1492ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, NOBH); 1493ac27a0ecSDave Kleikamp break; 149425ec56b5SJean Noel Cordenner case Opt_i_version: 149525ec56b5SJean Noel Cordenner set_opt(sbi->s_mount_opt, I_VERSION); 149625ec56b5SJean Noel Cordenner sb->s_flags |= MS_I_VERSION; 149725ec56b5SJean Noel Cordenner break; 1498dd919b98SAneesh Kumar K.V case Opt_nodelalloc: 1499dd919b98SAneesh Kumar K.V clear_opt(sbi->s_mount_opt, DELALLOC); 1500dd919b98SAneesh Kumar K.V break; 1501c9de560dSAlex Tomas case Opt_stripe: 1502c9de560dSAlex Tomas if (match_int(&args[0], &option)) 1503c9de560dSAlex Tomas return 0; 1504c9de560dSAlex Tomas if (option < 0) 1505c9de560dSAlex Tomas return 0; 1506c9de560dSAlex Tomas sbi->s_stripe = option; 1507c9de560dSAlex Tomas break; 150864769240SAlex Tomas case Opt_delalloc: 150964769240SAlex Tomas set_opt(sbi->s_mount_opt, DELALLOC); 151064769240SAlex Tomas break; 1511240799cdSTheodore Ts'o case Opt_inode_readahead_blks: 1512240799cdSTheodore Ts'o if (match_int(&args[0], &option)) 1513240799cdSTheodore Ts'o return 0; 1514240799cdSTheodore Ts'o if (option < 0 || option > (1 << 30)) 1515240799cdSTheodore Ts'o return 0; 1516f7c43950STheodore Ts'o if (!is_power_of_2(option)) { 15173197ebdbSTheodore Ts'o printk(KERN_ERR "EXT4-fs: inode_readahead_blks" 15183197ebdbSTheodore Ts'o " must be a power of 2\n"); 15193197ebdbSTheodore Ts'o return 0; 15203197ebdbSTheodore Ts'o } 1521240799cdSTheodore Ts'o sbi->s_inode_readahead_blks = option; 1522240799cdSTheodore Ts'o break; 1523b3881f74STheodore Ts'o case Opt_journal_ioprio: 1524b3881f74STheodore Ts'o if (match_int(&args[0], &option)) 1525b3881f74STheodore Ts'o return 0; 1526b3881f74STheodore Ts'o if (option < 0 || option > 7) 1527b3881f74STheodore Ts'o break; 1528b3881f74STheodore Ts'o *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 1529b3881f74STheodore Ts'o option); 1530b3881f74STheodore Ts'o break; 153106705bffSTheodore Ts'o case Opt_noauto_da_alloc: 153206705bffSTheodore Ts'o set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC); 153306705bffSTheodore Ts'o break; 1534afd4672dSTheodore Ts'o case Opt_auto_da_alloc: 153506705bffSTheodore Ts'o if (match_int(&args[0], &option)) { 153606705bffSTheodore Ts'o clear_opt(sbi->s_mount_opt, NO_AUTO_DA_ALLOC); 153706705bffSTheodore Ts'o break; 153806705bffSTheodore Ts'o } 1539afd4672dSTheodore Ts'o if (option) 1540afd4672dSTheodore Ts'o clear_opt(sbi->s_mount_opt, NO_AUTO_DA_ALLOC); 1541afd4672dSTheodore Ts'o else 1542afd4672dSTheodore Ts'o set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC); 1543afd4672dSTheodore Ts'o break; 1544ac27a0ecSDave Kleikamp default: 1545ac27a0ecSDave Kleikamp printk(KERN_ERR 1546617ba13bSMingming Cao "EXT4-fs: Unrecognized mount option \"%s\" " 1547ac27a0ecSDave Kleikamp "or missing value\n", p); 1548ac27a0ecSDave Kleikamp return 0; 1549ac27a0ecSDave Kleikamp } 1550ac27a0ecSDave Kleikamp } 1551ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 1552ac27a0ecSDave Kleikamp if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { 1553617ba13bSMingming Cao if ((sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA) && 1554ac27a0ecSDave Kleikamp sbi->s_qf_names[USRQUOTA]) 1555ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, USRQUOTA); 1556ac27a0ecSDave Kleikamp 1557617ba13bSMingming Cao if ((sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA) && 1558ac27a0ecSDave Kleikamp sbi->s_qf_names[GRPQUOTA]) 1559ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, GRPQUOTA); 1560ac27a0ecSDave Kleikamp 1561ac27a0ecSDave Kleikamp if ((sbi->s_qf_names[USRQUOTA] && 1562617ba13bSMingming Cao (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)) || 1563ac27a0ecSDave Kleikamp (sbi->s_qf_names[GRPQUOTA] && 1564617ba13bSMingming Cao (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA))) { 1565617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: old and new quota " 1566ac27a0ecSDave Kleikamp "format mixing.\n"); 1567ac27a0ecSDave Kleikamp return 0; 1568ac27a0ecSDave Kleikamp } 1569ac27a0ecSDave Kleikamp 1570ac27a0ecSDave Kleikamp if (!sbi->s_jquota_fmt) { 15712c8be6b2SJan Kara printk(KERN_ERR "EXT4-fs: journaled quota format " 1572ac27a0ecSDave Kleikamp "not specified.\n"); 1573ac27a0ecSDave Kleikamp return 0; 1574ac27a0ecSDave Kleikamp } 1575ac27a0ecSDave Kleikamp } else { 1576ac27a0ecSDave Kleikamp if (sbi->s_jquota_fmt) { 15772c8be6b2SJan Kara printk(KERN_ERR "EXT4-fs: journaled quota format " 15782c8be6b2SJan Kara "specified with no journaling " 1579ac27a0ecSDave Kleikamp "enabled.\n"); 1580ac27a0ecSDave Kleikamp return 0; 1581ac27a0ecSDave Kleikamp } 1582ac27a0ecSDave Kleikamp } 1583ac27a0ecSDave Kleikamp #endif 1584ac27a0ecSDave Kleikamp return 1; 1585ac27a0ecSDave Kleikamp } 1586ac27a0ecSDave Kleikamp 1587617ba13bSMingming Cao static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, 1588ac27a0ecSDave Kleikamp int read_only) 1589ac27a0ecSDave Kleikamp { 1590617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 1591ac27a0ecSDave Kleikamp int res = 0; 1592ac27a0ecSDave Kleikamp 1593617ba13bSMingming Cao if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) { 1594617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs warning: revision level too high, " 1595ac27a0ecSDave Kleikamp "forcing read-only mode\n"); 1596ac27a0ecSDave Kleikamp res = MS_RDONLY; 1597ac27a0ecSDave Kleikamp } 1598ac27a0ecSDave Kleikamp if (read_only) 1599ac27a0ecSDave Kleikamp return res; 1600617ba13bSMingming Cao if (!(sbi->s_mount_state & EXT4_VALID_FS)) 1601617ba13bSMingming Cao printk(KERN_WARNING "EXT4-fs warning: mounting unchecked fs, " 1602ac27a0ecSDave Kleikamp "running e2fsck is recommended\n"); 1603617ba13bSMingming Cao else if ((sbi->s_mount_state & EXT4_ERROR_FS)) 1604ac27a0ecSDave Kleikamp printk(KERN_WARNING 1605617ba13bSMingming Cao "EXT4-fs warning: mounting fs with errors, " 1606ac27a0ecSDave Kleikamp "running e2fsck is recommended\n"); 1607ac27a0ecSDave Kleikamp else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 && 1608ac27a0ecSDave Kleikamp le16_to_cpu(es->s_mnt_count) >= 1609ac27a0ecSDave Kleikamp (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count)) 1610ac27a0ecSDave Kleikamp printk(KERN_WARNING 1611617ba13bSMingming Cao "EXT4-fs warning: maximal mount count reached, " 1612ac27a0ecSDave Kleikamp "running e2fsck is recommended\n"); 1613ac27a0ecSDave Kleikamp else if (le32_to_cpu(es->s_checkinterval) && 1614ac27a0ecSDave Kleikamp (le32_to_cpu(es->s_lastcheck) + 1615ac27a0ecSDave Kleikamp le32_to_cpu(es->s_checkinterval) <= get_seconds())) 1616ac27a0ecSDave Kleikamp printk(KERN_WARNING 1617617ba13bSMingming Cao "EXT4-fs warning: checktime reached, " 1618ac27a0ecSDave Kleikamp "running e2fsck is recommended\n"); 16190390131bSFrank Mayhar if (!sbi->s_journal) 1620216c34b2SMarcin Slusarz es->s_state &= cpu_to_le16(~EXT4_VALID_FS); 1621ac27a0ecSDave Kleikamp if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) 1622617ba13bSMingming Cao es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); 1623e8546d06SMarcin Slusarz le16_add_cpu(&es->s_mnt_count, 1); 1624ac27a0ecSDave Kleikamp es->s_mtime = cpu_to_le32(get_seconds()); 1625617ba13bSMingming Cao ext4_update_dynamic_rev(sb); 16260390131bSFrank Mayhar if (sbi->s_journal) 1627617ba13bSMingming Cao EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 1628ac27a0ecSDave Kleikamp 1629e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 1630ac27a0ecSDave Kleikamp if (test_opt(sb, DEBUG)) 1631a9df9a49STheodore Ts'o printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, " 1632ac27a0ecSDave Kleikamp "bpg=%lu, ipg=%lu, mo=%04lx]\n", 1633ac27a0ecSDave Kleikamp sb->s_blocksize, 1634ac27a0ecSDave Kleikamp sbi->s_groups_count, 1635617ba13bSMingming Cao EXT4_BLOCKS_PER_GROUP(sb), 1636617ba13bSMingming Cao EXT4_INODES_PER_GROUP(sb), 1637ac27a0ecSDave Kleikamp sbi->s_mount_opt); 1638ac27a0ecSDave Kleikamp 16390390131bSFrank Mayhar if (EXT4_SB(sb)->s_journal) { 164005496769STheodore Ts'o printk(KERN_INFO "EXT4 FS on %s, %s journal on %s\n", 164105496769STheodore Ts'o sb->s_id, EXT4_SB(sb)->s_journal->j_inode ? "internal" : 164205496769STheodore Ts'o "external", EXT4_SB(sb)->s_journal->j_devname); 16430390131bSFrank Mayhar } else { 16440390131bSFrank Mayhar printk(KERN_INFO "EXT4 FS on %s, no journal\n", sb->s_id); 16450390131bSFrank Mayhar } 1646ac27a0ecSDave Kleikamp return res; 1647ac27a0ecSDave Kleikamp } 1648ac27a0ecSDave Kleikamp 1649772cb7c8SJose R. Santos static int ext4_fill_flex_info(struct super_block *sb) 1650772cb7c8SJose R. Santos { 1651772cb7c8SJose R. Santos struct ext4_sb_info *sbi = EXT4_SB(sb); 1652772cb7c8SJose R. Santos struct ext4_group_desc *gdp = NULL; 1653772cb7c8SJose R. Santos struct buffer_head *bh; 1654772cb7c8SJose R. Santos ext4_group_t flex_group_count; 1655772cb7c8SJose R. Santos ext4_group_t flex_group; 1656772cb7c8SJose R. Santos int groups_per_flex = 0; 1657c5ca7c76STheodore Ts'o size_t size; 1658772cb7c8SJose R. Santos int i; 1659772cb7c8SJose R. Santos 1660772cb7c8SJose R. Santos if (!sbi->s_es->s_log_groups_per_flex) { 1661772cb7c8SJose R. Santos sbi->s_log_groups_per_flex = 0; 1662772cb7c8SJose R. Santos return 1; 1663772cb7c8SJose R. Santos } 1664772cb7c8SJose R. Santos 1665772cb7c8SJose R. Santos sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex; 1666772cb7c8SJose R. Santos groups_per_flex = 1 << sbi->s_log_groups_per_flex; 1667772cb7c8SJose R. Santos 1668c62a11fdSFrederic Bohe /* We allocate both existing and potentially added groups */ 1669c62a11fdSFrederic Bohe flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) + 1670d94e99a6SAneesh Kumar K.V ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) << 1671d94e99a6SAneesh Kumar K.V EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex; 1672c5ca7c76STheodore Ts'o size = flex_group_count * sizeof(struct flex_groups); 1673c5ca7c76STheodore Ts'o sbi->s_flex_groups = kzalloc(size, GFP_KERNEL); 1674c5ca7c76STheodore Ts'o if (sbi->s_flex_groups == NULL) { 1675c5ca7c76STheodore Ts'o sbi->s_flex_groups = vmalloc(size); 1676c5ca7c76STheodore Ts'o if (sbi->s_flex_groups) 1677c5ca7c76STheodore Ts'o memset(sbi->s_flex_groups, 0, size); 1678c5ca7c76STheodore Ts'o } 1679772cb7c8SJose R. Santos if (sbi->s_flex_groups == NULL) { 1680ec05e868SLi Zefan printk(KERN_ERR "EXT4-fs: not enough memory for " 1681a9df9a49STheodore Ts'o "%u flex groups\n", flex_group_count); 1682772cb7c8SJose R. Santos goto failed; 1683772cb7c8SJose R. Santos } 1684772cb7c8SJose R. Santos 1685772cb7c8SJose R. Santos for (i = 0; i < sbi->s_groups_count; i++) { 1686772cb7c8SJose R. Santos gdp = ext4_get_group_desc(sb, i, &bh); 1687772cb7c8SJose R. Santos 1688772cb7c8SJose R. Santos flex_group = ext4_flex_group(sbi, i); 16899f24e420STheodore Ts'o atomic_set(&sbi->s_flex_groups[flex_group].free_inodes, 16909f24e420STheodore Ts'o ext4_free_inodes_count(sb, gdp)); 16919f24e420STheodore Ts'o atomic_set(&sbi->s_flex_groups[flex_group].free_blocks, 16929f24e420STheodore Ts'o ext4_free_blks_count(sb, gdp)); 16937d39db14STheodore Ts'o atomic_set(&sbi->s_flex_groups[flex_group].used_dirs, 16947d39db14STheodore Ts'o ext4_used_dirs_count(sb, gdp)); 1695772cb7c8SJose R. Santos } 1696772cb7c8SJose R. Santos 1697772cb7c8SJose R. Santos return 1; 1698772cb7c8SJose R. Santos failed: 1699772cb7c8SJose R. Santos return 0; 1700772cb7c8SJose R. Santos } 1701772cb7c8SJose R. Santos 1702717d50e4SAndreas Dilger __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group, 1703717d50e4SAndreas Dilger struct ext4_group_desc *gdp) 1704717d50e4SAndreas Dilger { 1705717d50e4SAndreas Dilger __u16 crc = 0; 1706717d50e4SAndreas Dilger 1707717d50e4SAndreas Dilger if (sbi->s_es->s_feature_ro_compat & 1708717d50e4SAndreas Dilger cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { 1709717d50e4SAndreas Dilger int offset = offsetof(struct ext4_group_desc, bg_checksum); 1710717d50e4SAndreas Dilger __le32 le_group = cpu_to_le32(block_group); 1711717d50e4SAndreas Dilger 1712717d50e4SAndreas Dilger crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid)); 1713717d50e4SAndreas Dilger crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group)); 1714717d50e4SAndreas Dilger crc = crc16(crc, (__u8 *)gdp, offset); 1715717d50e4SAndreas Dilger offset += sizeof(gdp->bg_checksum); /* skip checksum */ 1716717d50e4SAndreas Dilger /* for checksum of struct ext4_group_desc do the rest...*/ 1717717d50e4SAndreas Dilger if ((sbi->s_es->s_feature_incompat & 1718717d50e4SAndreas Dilger cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) && 1719717d50e4SAndreas Dilger offset < le16_to_cpu(sbi->s_es->s_desc_size)) 1720717d50e4SAndreas Dilger crc = crc16(crc, (__u8 *)gdp + offset, 1721717d50e4SAndreas Dilger le16_to_cpu(sbi->s_es->s_desc_size) - 1722717d50e4SAndreas Dilger offset); 1723717d50e4SAndreas Dilger } 1724717d50e4SAndreas Dilger 1725717d50e4SAndreas Dilger return cpu_to_le16(crc); 1726717d50e4SAndreas Dilger } 1727717d50e4SAndreas Dilger 1728717d50e4SAndreas Dilger int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group, 1729717d50e4SAndreas Dilger struct ext4_group_desc *gdp) 1730717d50e4SAndreas Dilger { 1731717d50e4SAndreas Dilger if ((sbi->s_es->s_feature_ro_compat & 1732717d50e4SAndreas Dilger cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) && 1733717d50e4SAndreas Dilger (gdp->bg_checksum != ext4_group_desc_csum(sbi, block_group, gdp))) 1734717d50e4SAndreas Dilger return 0; 1735717d50e4SAndreas Dilger 1736717d50e4SAndreas Dilger return 1; 1737717d50e4SAndreas Dilger } 1738717d50e4SAndreas Dilger 1739ac27a0ecSDave Kleikamp /* Called at mount-time, super-block is locked */ 1740617ba13bSMingming Cao static int ext4_check_descriptors(struct super_block *sb) 1741ac27a0ecSDave Kleikamp { 1742617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 1743617ba13bSMingming Cao ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block); 1744617ba13bSMingming Cao ext4_fsblk_t last_block; 1745bd81d8eeSLaurent Vivier ext4_fsblk_t block_bitmap; 1746bd81d8eeSLaurent Vivier ext4_fsblk_t inode_bitmap; 1747bd81d8eeSLaurent Vivier ext4_fsblk_t inode_table; 1748ce421581SJose R. Santos int flexbg_flag = 0; 1749fd2d4291SAvantika Mathur ext4_group_t i; 1750ac27a0ecSDave Kleikamp 1751ce421581SJose R. Santos if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) 1752ce421581SJose R. Santos flexbg_flag = 1; 1753ce421581SJose R. Santos 1754617ba13bSMingming Cao ext4_debug("Checking group descriptors"); 1755ac27a0ecSDave Kleikamp 1756197cd65aSAkinobu Mita for (i = 0; i < sbi->s_groups_count; i++) { 1757197cd65aSAkinobu Mita struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL); 1758197cd65aSAkinobu Mita 1759ce421581SJose R. Santos if (i == sbi->s_groups_count - 1 || flexbg_flag) 1760bd81d8eeSLaurent Vivier last_block = ext4_blocks_count(sbi->s_es) - 1; 1761ac27a0ecSDave Kleikamp else 1762ac27a0ecSDave Kleikamp last_block = first_block + 1763617ba13bSMingming Cao (EXT4_BLOCKS_PER_GROUP(sb) - 1); 1764ac27a0ecSDave Kleikamp 17658fadc143SAlexandre Ratchov block_bitmap = ext4_block_bitmap(sb, gdp); 17662b2d6d01STheodore Ts'o if (block_bitmap < first_block || block_bitmap > last_block) { 1767c19204b0SJosef Bacik printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1768a9df9a49STheodore Ts'o "Block bitmap for group %u not in group " 17695128273aSEric Sesterhenn "(block %llu)!\n", i, block_bitmap); 1770ac27a0ecSDave Kleikamp return 0; 1771ac27a0ecSDave Kleikamp } 17728fadc143SAlexandre Ratchov inode_bitmap = ext4_inode_bitmap(sb, gdp); 17732b2d6d01STheodore Ts'o if (inode_bitmap < first_block || inode_bitmap > last_block) { 1774c19204b0SJosef Bacik printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1775a9df9a49STheodore Ts'o "Inode bitmap for group %u not in group " 17765128273aSEric Sesterhenn "(block %llu)!\n", i, inode_bitmap); 1777ac27a0ecSDave Kleikamp return 0; 1778ac27a0ecSDave Kleikamp } 17798fadc143SAlexandre Ratchov inode_table = ext4_inode_table(sb, gdp); 1780bd81d8eeSLaurent Vivier if (inode_table < first_block || 17812b2d6d01STheodore Ts'o inode_table + sbi->s_itb_per_group - 1 > last_block) { 1782c19204b0SJosef Bacik printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1783a9df9a49STheodore Ts'o "Inode table for group %u not in group " 17845128273aSEric Sesterhenn "(block %llu)!\n", i, inode_table); 1785ac27a0ecSDave Kleikamp return 0; 1786ac27a0ecSDave Kleikamp } 1787b5f10eedSEric Sandeen spin_lock(sb_bgl_lock(sbi, i)); 1788717d50e4SAndreas Dilger if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { 1789c19204b0SJosef Bacik printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1790a9df9a49STheodore Ts'o "Checksum for group %u failed (%u!=%u)\n", 1791fd2d4291SAvantika Mathur i, le16_to_cpu(ext4_group_desc_csum(sbi, i, 1792fd2d4291SAvantika Mathur gdp)), le16_to_cpu(gdp->bg_checksum)); 17937ee1ec4cSLi Zefan if (!(sb->s_flags & MS_RDONLY)) { 17947ee1ec4cSLi Zefan spin_unlock(sb_bgl_lock(sbi, i)); 1795717d50e4SAndreas Dilger return 0; 1796717d50e4SAndreas Dilger } 17977ee1ec4cSLi Zefan } 1798b5f10eedSEric Sandeen spin_unlock(sb_bgl_lock(sbi, i)); 1799ce421581SJose R. Santos if (!flexbg_flag) 1800617ba13bSMingming Cao first_block += EXT4_BLOCKS_PER_GROUP(sb); 1801ac27a0ecSDave Kleikamp } 1802ac27a0ecSDave Kleikamp 1803bd81d8eeSLaurent Vivier ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb)); 1804617ba13bSMingming Cao sbi->s_es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb)); 1805ac27a0ecSDave Kleikamp return 1; 1806ac27a0ecSDave Kleikamp } 1807ac27a0ecSDave Kleikamp 1808617ba13bSMingming Cao /* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at 1809ac27a0ecSDave Kleikamp * the superblock) which were deleted from all directories, but held open by 1810ac27a0ecSDave Kleikamp * a process at the time of a crash. We walk the list and try to delete these 1811ac27a0ecSDave Kleikamp * inodes at recovery time (only with a read-write filesystem). 1812ac27a0ecSDave Kleikamp * 1813ac27a0ecSDave Kleikamp * In order to keep the orphan inode chain consistent during traversal (in 1814ac27a0ecSDave Kleikamp * case of crash during recovery), we link each inode into the superblock 1815ac27a0ecSDave Kleikamp * orphan list_head and handle it the same way as an inode deletion during 1816ac27a0ecSDave Kleikamp * normal operation (which journals the operations for us). 1817ac27a0ecSDave Kleikamp * 1818ac27a0ecSDave Kleikamp * We only do an iget() and an iput() on each inode, which is very safe if we 1819ac27a0ecSDave Kleikamp * accidentally point at an in-use or already deleted inode. The worst that 1820ac27a0ecSDave Kleikamp * can happen in this case is that we get a "bit already cleared" message from 1821617ba13bSMingming Cao * ext4_free_inode(). The only reason we would point at a wrong inode is if 1822ac27a0ecSDave Kleikamp * e2fsck was run on this filesystem, and it must have already done the orphan 1823ac27a0ecSDave Kleikamp * inode cleanup for us, so we can safely abort without any further action. 1824ac27a0ecSDave Kleikamp */ 1825617ba13bSMingming Cao static void ext4_orphan_cleanup(struct super_block *sb, 1826617ba13bSMingming Cao struct ext4_super_block *es) 1827ac27a0ecSDave Kleikamp { 1828ac27a0ecSDave Kleikamp unsigned int s_flags = sb->s_flags; 1829ac27a0ecSDave Kleikamp int nr_orphans = 0, nr_truncates = 0; 1830ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 1831ac27a0ecSDave Kleikamp int i; 1832ac27a0ecSDave Kleikamp #endif 1833ac27a0ecSDave Kleikamp if (!es->s_last_orphan) { 1834ac27a0ecSDave Kleikamp jbd_debug(4, "no orphan inodes to clean up\n"); 1835ac27a0ecSDave Kleikamp return; 1836ac27a0ecSDave Kleikamp } 1837ac27a0ecSDave Kleikamp 1838a8f48a95SEric Sandeen if (bdev_read_only(sb->s_bdev)) { 1839a8f48a95SEric Sandeen printk(KERN_ERR "EXT4-fs: write access " 1840a8f48a95SEric Sandeen "unavailable, skipping orphan cleanup.\n"); 1841a8f48a95SEric Sandeen return; 1842a8f48a95SEric Sandeen } 1843a8f48a95SEric Sandeen 1844617ba13bSMingming Cao if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) { 1845ac27a0ecSDave Kleikamp if (es->s_last_orphan) 1846ac27a0ecSDave Kleikamp jbd_debug(1, "Errors on filesystem, " 1847ac27a0ecSDave Kleikamp "clearing orphan list.\n"); 1848ac27a0ecSDave Kleikamp es->s_last_orphan = 0; 1849ac27a0ecSDave Kleikamp jbd_debug(1, "Skipping orphan recovery on fs with errors.\n"); 1850ac27a0ecSDave Kleikamp return; 1851ac27a0ecSDave Kleikamp } 1852ac27a0ecSDave Kleikamp 1853ac27a0ecSDave Kleikamp if (s_flags & MS_RDONLY) { 1854617ba13bSMingming Cao printk(KERN_INFO "EXT4-fs: %s: orphan cleanup on readonly fs\n", 1855ac27a0ecSDave Kleikamp sb->s_id); 1856ac27a0ecSDave Kleikamp sb->s_flags &= ~MS_RDONLY; 1857ac27a0ecSDave Kleikamp } 1858ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 1859ac27a0ecSDave Kleikamp /* Needed for iput() to work correctly and not trash data */ 1860ac27a0ecSDave Kleikamp sb->s_flags |= MS_ACTIVE; 1861ac27a0ecSDave Kleikamp /* Turn on quotas so that they are updated correctly */ 1862ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) { 1863617ba13bSMingming Cao if (EXT4_SB(sb)->s_qf_names[i]) { 1864617ba13bSMingming Cao int ret = ext4_quota_on_mount(sb, i); 1865ac27a0ecSDave Kleikamp if (ret < 0) 1866ac27a0ecSDave Kleikamp printk(KERN_ERR 18672c8be6b2SJan Kara "EXT4-fs: Cannot turn on journaled " 1868ac27a0ecSDave Kleikamp "quota: error %d\n", ret); 1869ac27a0ecSDave Kleikamp } 1870ac27a0ecSDave Kleikamp } 1871ac27a0ecSDave Kleikamp #endif 1872ac27a0ecSDave Kleikamp 1873ac27a0ecSDave Kleikamp while (es->s_last_orphan) { 1874ac27a0ecSDave Kleikamp struct inode *inode; 1875ac27a0ecSDave Kleikamp 187697bd42b9SJosef Bacik inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan)); 187797bd42b9SJosef Bacik if (IS_ERR(inode)) { 1878ac27a0ecSDave Kleikamp es->s_last_orphan = 0; 1879ac27a0ecSDave Kleikamp break; 1880ac27a0ecSDave Kleikamp } 1881ac27a0ecSDave Kleikamp 1882617ba13bSMingming Cao list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan); 1883a269eb18SJan Kara vfs_dq_init(inode); 1884ac27a0ecSDave Kleikamp if (inode->i_nlink) { 1885ac27a0ecSDave Kleikamp printk(KERN_DEBUG 1886e5f8eab8STheodore Ts'o "%s: truncating inode %lu to %lld bytes\n", 188746e665e9SHarvey Harrison __func__, inode->i_ino, inode->i_size); 1888e5f8eab8STheodore Ts'o jbd_debug(2, "truncating inode %lu to %lld bytes\n", 1889ac27a0ecSDave Kleikamp inode->i_ino, inode->i_size); 1890617ba13bSMingming Cao ext4_truncate(inode); 1891ac27a0ecSDave Kleikamp nr_truncates++; 1892ac27a0ecSDave Kleikamp } else { 1893ac27a0ecSDave Kleikamp printk(KERN_DEBUG 1894ac27a0ecSDave Kleikamp "%s: deleting unreferenced inode %lu\n", 189546e665e9SHarvey Harrison __func__, inode->i_ino); 1896ac27a0ecSDave Kleikamp jbd_debug(2, "deleting unreferenced inode %lu\n", 1897ac27a0ecSDave Kleikamp inode->i_ino); 1898ac27a0ecSDave Kleikamp nr_orphans++; 1899ac27a0ecSDave Kleikamp } 1900ac27a0ecSDave Kleikamp iput(inode); /* The delete magic happens here! */ 1901ac27a0ecSDave Kleikamp } 1902ac27a0ecSDave Kleikamp 1903ac27a0ecSDave Kleikamp #define PLURAL(x) (x), ((x) == 1) ? "" : "s" 1904ac27a0ecSDave Kleikamp 1905ac27a0ecSDave Kleikamp if (nr_orphans) 1906617ba13bSMingming Cao printk(KERN_INFO "EXT4-fs: %s: %d orphan inode%s deleted\n", 1907ac27a0ecSDave Kleikamp sb->s_id, PLURAL(nr_orphans)); 1908ac27a0ecSDave Kleikamp if (nr_truncates) 1909617ba13bSMingming Cao printk(KERN_INFO "EXT4-fs: %s: %d truncate%s cleaned up\n", 1910ac27a0ecSDave Kleikamp sb->s_id, PLURAL(nr_truncates)); 1911ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 1912ac27a0ecSDave Kleikamp /* Turn quotas off */ 1913ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) { 1914ac27a0ecSDave Kleikamp if (sb_dqopt(sb)->files[i]) 19156f28e087SJan Kara vfs_quota_off(sb, i, 0); 1916ac27a0ecSDave Kleikamp } 1917ac27a0ecSDave Kleikamp #endif 1918ac27a0ecSDave Kleikamp sb->s_flags = s_flags; /* Restore MS_RDONLY status */ 1919ac27a0ecSDave Kleikamp } 1920cd2291a4SEric Sandeen /* 1921cd2291a4SEric Sandeen * Maximal extent format file size. 1922cd2291a4SEric Sandeen * Resulting logical blkno at s_maxbytes must fit in our on-disk 1923cd2291a4SEric Sandeen * extent format containers, within a sector_t, and within i_blocks 1924cd2291a4SEric Sandeen * in the vfs. ext4 inode has 48 bits of i_block in fsblock units, 1925cd2291a4SEric Sandeen * so that won't be a limiting factor. 1926cd2291a4SEric Sandeen * 1927cd2291a4SEric Sandeen * Note, this does *not* consider any metadata overhead for vfs i_blocks. 1928cd2291a4SEric Sandeen */ 1929f287a1a5STheodore Ts'o static loff_t ext4_max_size(int blkbits, int has_huge_files) 1930cd2291a4SEric Sandeen { 1931cd2291a4SEric Sandeen loff_t res; 1932cd2291a4SEric Sandeen loff_t upper_limit = MAX_LFS_FILESIZE; 1933cd2291a4SEric Sandeen 1934cd2291a4SEric Sandeen /* small i_blocks in vfs inode? */ 1935f287a1a5STheodore Ts'o if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) { 1936cd2291a4SEric Sandeen /* 1937b3a6ffe1SJens Axboe * CONFIG_LBD is not enabled implies the inode 1938cd2291a4SEric Sandeen * i_block represent total blocks in 512 bytes 1939cd2291a4SEric Sandeen * 32 == size of vfs inode i_blocks * 8 1940cd2291a4SEric Sandeen */ 1941cd2291a4SEric Sandeen upper_limit = (1LL << 32) - 1; 1942cd2291a4SEric Sandeen 1943cd2291a4SEric Sandeen /* total blocks in file system block size */ 1944cd2291a4SEric Sandeen upper_limit >>= (blkbits - 9); 1945cd2291a4SEric Sandeen upper_limit <<= blkbits; 1946cd2291a4SEric Sandeen } 1947cd2291a4SEric Sandeen 1948cd2291a4SEric Sandeen /* 32-bit extent-start container, ee_block */ 1949cd2291a4SEric Sandeen res = 1LL << 32; 1950cd2291a4SEric Sandeen res <<= blkbits; 1951cd2291a4SEric Sandeen res -= 1; 1952cd2291a4SEric Sandeen 1953cd2291a4SEric Sandeen /* Sanity check against vm- & vfs- imposed limits */ 1954cd2291a4SEric Sandeen if (res > upper_limit) 1955cd2291a4SEric Sandeen res = upper_limit; 1956cd2291a4SEric Sandeen 1957cd2291a4SEric Sandeen return res; 1958cd2291a4SEric Sandeen } 1959ac27a0ecSDave Kleikamp 1960ac27a0ecSDave Kleikamp /* 1961cd2291a4SEric Sandeen * Maximal bitmap file size. There is a direct, and {,double-,triple-}indirect 19620fc1b451SAneesh Kumar K.V * block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks. 19630fc1b451SAneesh Kumar K.V * We need to be 1 filesystem block less than the 2^48 sector limit. 1964ac27a0ecSDave Kleikamp */ 1965f287a1a5STheodore Ts'o static loff_t ext4_max_bitmap_size(int bits, int has_huge_files) 1966ac27a0ecSDave Kleikamp { 1967617ba13bSMingming Cao loff_t res = EXT4_NDIR_BLOCKS; 19680fc1b451SAneesh Kumar K.V int meta_blocks; 19690fc1b451SAneesh Kumar K.V loff_t upper_limit; 19700fc1b451SAneesh Kumar K.V /* This is calculated to be the largest file size for a 1971cd2291a4SEric Sandeen * dense, bitmapped file such that the total number of 1972ac27a0ecSDave Kleikamp * sectors in the file, including data and all indirect blocks, 19730fc1b451SAneesh Kumar K.V * does not exceed 2^48 -1 19740fc1b451SAneesh Kumar K.V * __u32 i_blocks_lo and _u16 i_blocks_high representing the 19750fc1b451SAneesh Kumar K.V * total number of 512 bytes blocks of the file 19760fc1b451SAneesh Kumar K.V */ 19770fc1b451SAneesh Kumar K.V 1978f287a1a5STheodore Ts'o if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) { 19790fc1b451SAneesh Kumar K.V /* 1980b3a6ffe1SJens Axboe * !has_huge_files or CONFIG_LBD is not enabled 1981f287a1a5STheodore Ts'o * implies the inode i_block represent total blocks in 1982f287a1a5STheodore Ts'o * 512 bytes 32 == size of vfs inode i_blocks * 8 19830fc1b451SAneesh Kumar K.V */ 19840fc1b451SAneesh Kumar K.V upper_limit = (1LL << 32) - 1; 19850fc1b451SAneesh Kumar K.V 19860fc1b451SAneesh Kumar K.V /* total blocks in file system block size */ 19870fc1b451SAneesh Kumar K.V upper_limit >>= (bits - 9); 19880fc1b451SAneesh Kumar K.V 19890fc1b451SAneesh Kumar K.V } else { 19908180a562SAneesh Kumar K.V /* 19918180a562SAneesh Kumar K.V * We use 48 bit ext4_inode i_blocks 19928180a562SAneesh Kumar K.V * With EXT4_HUGE_FILE_FL set the i_blocks 19938180a562SAneesh Kumar K.V * represent total number of blocks in 19948180a562SAneesh Kumar K.V * file system block size 19958180a562SAneesh Kumar K.V */ 19960fc1b451SAneesh Kumar K.V upper_limit = (1LL << 48) - 1; 19970fc1b451SAneesh Kumar K.V 19980fc1b451SAneesh Kumar K.V } 19990fc1b451SAneesh Kumar K.V 20000fc1b451SAneesh Kumar K.V /* indirect blocks */ 20010fc1b451SAneesh Kumar K.V meta_blocks = 1; 20020fc1b451SAneesh Kumar K.V /* double indirect blocks */ 20030fc1b451SAneesh Kumar K.V meta_blocks += 1 + (1LL << (bits-2)); 20040fc1b451SAneesh Kumar K.V /* tripple indirect blocks */ 20050fc1b451SAneesh Kumar K.V meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2))); 20060fc1b451SAneesh Kumar K.V 20070fc1b451SAneesh Kumar K.V upper_limit -= meta_blocks; 20080fc1b451SAneesh Kumar K.V upper_limit <<= bits; 2009ac27a0ecSDave Kleikamp 2010ac27a0ecSDave Kleikamp res += 1LL << (bits-2); 2011ac27a0ecSDave Kleikamp res += 1LL << (2*(bits-2)); 2012ac27a0ecSDave Kleikamp res += 1LL << (3*(bits-2)); 2013ac27a0ecSDave Kleikamp res <<= bits; 2014ac27a0ecSDave Kleikamp if (res > upper_limit) 2015ac27a0ecSDave Kleikamp res = upper_limit; 20160fc1b451SAneesh Kumar K.V 20170fc1b451SAneesh Kumar K.V if (res > MAX_LFS_FILESIZE) 20180fc1b451SAneesh Kumar K.V res = MAX_LFS_FILESIZE; 20190fc1b451SAneesh Kumar K.V 2020ac27a0ecSDave Kleikamp return res; 2021ac27a0ecSDave Kleikamp } 2022ac27a0ecSDave Kleikamp 2023617ba13bSMingming Cao static ext4_fsblk_t descriptor_loc(struct super_block *sb, 202470bbb3e0SAndrew Morton ext4_fsblk_t logical_sb_block, int nr) 2025ac27a0ecSDave Kleikamp { 2026617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 2027fd2d4291SAvantika Mathur ext4_group_t bg, first_meta_bg; 2028ac27a0ecSDave Kleikamp int has_super = 0; 2029ac27a0ecSDave Kleikamp 2030ac27a0ecSDave Kleikamp first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg); 2031ac27a0ecSDave Kleikamp 2032617ba13bSMingming Cao if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) || 2033ac27a0ecSDave Kleikamp nr < first_meta_bg) 203470bbb3e0SAndrew Morton return logical_sb_block + nr + 1; 2035ac27a0ecSDave Kleikamp bg = sbi->s_desc_per_block * nr; 2036617ba13bSMingming Cao if (ext4_bg_has_super(sb, bg)) 2037ac27a0ecSDave Kleikamp has_super = 1; 2038617ba13bSMingming Cao return (has_super + ext4_group_first_block_no(sb, bg)); 2039ac27a0ecSDave Kleikamp } 2040ac27a0ecSDave Kleikamp 2041c9de560dSAlex Tomas /** 2042c9de560dSAlex Tomas * ext4_get_stripe_size: Get the stripe size. 2043c9de560dSAlex Tomas * @sbi: In memory super block info 2044c9de560dSAlex Tomas * 2045c9de560dSAlex Tomas * If we have specified it via mount option, then 2046c9de560dSAlex Tomas * use the mount option value. If the value specified at mount time is 2047c9de560dSAlex Tomas * greater than the blocks per group use the super block value. 2048c9de560dSAlex Tomas * If the super block value is greater than blocks per group return 0. 2049c9de560dSAlex Tomas * Allocator needs it be less than blocks per group. 2050c9de560dSAlex Tomas * 2051c9de560dSAlex Tomas */ 2052c9de560dSAlex Tomas static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi) 2053c9de560dSAlex Tomas { 2054c9de560dSAlex Tomas unsigned long stride = le16_to_cpu(sbi->s_es->s_raid_stride); 2055c9de560dSAlex Tomas unsigned long stripe_width = 2056c9de560dSAlex Tomas le32_to_cpu(sbi->s_es->s_raid_stripe_width); 2057c9de560dSAlex Tomas 2058c9de560dSAlex Tomas if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group) 2059c9de560dSAlex Tomas return sbi->s_stripe; 2060c9de560dSAlex Tomas 2061c9de560dSAlex Tomas if (stripe_width <= sbi->s_blocks_per_group) 2062c9de560dSAlex Tomas return stripe_width; 2063c9de560dSAlex Tomas 2064c9de560dSAlex Tomas if (stride <= sbi->s_blocks_per_group) 2065c9de560dSAlex Tomas return stride; 2066c9de560dSAlex Tomas 2067c9de560dSAlex Tomas return 0; 2068c9de560dSAlex Tomas } 2069ac27a0ecSDave Kleikamp 20703197ebdbSTheodore Ts'o /* sysfs supprt */ 20713197ebdbSTheodore Ts'o 20723197ebdbSTheodore Ts'o struct ext4_attr { 20733197ebdbSTheodore Ts'o struct attribute attr; 20743197ebdbSTheodore Ts'o ssize_t (*show)(struct ext4_attr *, struct ext4_sb_info *, char *); 20753197ebdbSTheodore Ts'o ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *, 20763197ebdbSTheodore Ts'o const char *, size_t); 20773197ebdbSTheodore Ts'o int offset; 20783197ebdbSTheodore Ts'o }; 20793197ebdbSTheodore Ts'o 20803197ebdbSTheodore Ts'o static int parse_strtoul(const char *buf, 20813197ebdbSTheodore Ts'o unsigned long max, unsigned long *value) 20823197ebdbSTheodore Ts'o { 20833197ebdbSTheodore Ts'o char *endp; 20843197ebdbSTheodore Ts'o 20853197ebdbSTheodore Ts'o while (*buf && isspace(*buf)) 20863197ebdbSTheodore Ts'o buf++; 20873197ebdbSTheodore Ts'o *value = simple_strtoul(buf, &endp, 0); 20883197ebdbSTheodore Ts'o while (*endp && isspace(*endp)) 20893197ebdbSTheodore Ts'o endp++; 20903197ebdbSTheodore Ts'o if (*endp || *value > max) 20913197ebdbSTheodore Ts'o return -EINVAL; 20923197ebdbSTheodore Ts'o 20933197ebdbSTheodore Ts'o return 0; 20943197ebdbSTheodore Ts'o } 20953197ebdbSTheodore Ts'o 20963197ebdbSTheodore Ts'o static ssize_t delayed_allocation_blocks_show(struct ext4_attr *a, 20973197ebdbSTheodore Ts'o struct ext4_sb_info *sbi, 20983197ebdbSTheodore Ts'o char *buf) 20993197ebdbSTheodore Ts'o { 21003197ebdbSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "%llu\n", 21013197ebdbSTheodore Ts'o (s64) percpu_counter_sum(&sbi->s_dirtyblocks_counter)); 21023197ebdbSTheodore Ts'o } 21033197ebdbSTheodore Ts'o 21043197ebdbSTheodore Ts'o static ssize_t session_write_kbytes_show(struct ext4_attr *a, 21053197ebdbSTheodore Ts'o struct ext4_sb_info *sbi, char *buf) 21063197ebdbSTheodore Ts'o { 21073197ebdbSTheodore Ts'o struct super_block *sb = sbi->s_buddy_cache->i_sb; 21083197ebdbSTheodore Ts'o 21093197ebdbSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "%lu\n", 21103197ebdbSTheodore Ts'o (part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 21113197ebdbSTheodore Ts'o sbi->s_sectors_written_start) >> 1); 21123197ebdbSTheodore Ts'o } 21133197ebdbSTheodore Ts'o 21143197ebdbSTheodore Ts'o static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a, 21153197ebdbSTheodore Ts'o struct ext4_sb_info *sbi, char *buf) 21163197ebdbSTheodore Ts'o { 21173197ebdbSTheodore Ts'o struct super_block *sb = sbi->s_buddy_cache->i_sb; 21183197ebdbSTheodore Ts'o 21193197ebdbSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "%llu\n", 21203197ebdbSTheodore Ts'o sbi->s_kbytes_written + 21213197ebdbSTheodore Ts'o ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 21223197ebdbSTheodore Ts'o EXT4_SB(sb)->s_sectors_written_start) >> 1)); 21233197ebdbSTheodore Ts'o } 21243197ebdbSTheodore Ts'o 21253197ebdbSTheodore Ts'o static ssize_t inode_readahead_blks_store(struct ext4_attr *a, 21263197ebdbSTheodore Ts'o struct ext4_sb_info *sbi, 21273197ebdbSTheodore Ts'o const char *buf, size_t count) 21283197ebdbSTheodore Ts'o { 21293197ebdbSTheodore Ts'o unsigned long t; 21303197ebdbSTheodore Ts'o 21313197ebdbSTheodore Ts'o if (parse_strtoul(buf, 0x40000000, &t)) 21323197ebdbSTheodore Ts'o return -EINVAL; 21333197ebdbSTheodore Ts'o 2134f7c43950STheodore Ts'o if (!is_power_of_2(t)) 21353197ebdbSTheodore Ts'o return -EINVAL; 21363197ebdbSTheodore Ts'o 21373197ebdbSTheodore Ts'o sbi->s_inode_readahead_blks = t; 21383197ebdbSTheodore Ts'o return count; 21393197ebdbSTheodore Ts'o } 21403197ebdbSTheodore Ts'o 21413197ebdbSTheodore Ts'o static ssize_t sbi_ui_show(struct ext4_attr *a, 21423197ebdbSTheodore Ts'o struct ext4_sb_info *sbi, char *buf) 21433197ebdbSTheodore Ts'o { 21443197ebdbSTheodore Ts'o unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset); 21453197ebdbSTheodore Ts'o 21463197ebdbSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "%u\n", *ui); 21473197ebdbSTheodore Ts'o } 21483197ebdbSTheodore Ts'o 21493197ebdbSTheodore Ts'o static ssize_t sbi_ui_store(struct ext4_attr *a, 21503197ebdbSTheodore Ts'o struct ext4_sb_info *sbi, 21513197ebdbSTheodore Ts'o const char *buf, size_t count) 21523197ebdbSTheodore Ts'o { 21533197ebdbSTheodore Ts'o unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset); 21543197ebdbSTheodore Ts'o unsigned long t; 21553197ebdbSTheodore Ts'o 21563197ebdbSTheodore Ts'o if (parse_strtoul(buf, 0xffffffff, &t)) 21573197ebdbSTheodore Ts'o return -EINVAL; 21583197ebdbSTheodore Ts'o *ui = t; 21593197ebdbSTheodore Ts'o return count; 21603197ebdbSTheodore Ts'o } 21613197ebdbSTheodore Ts'o 21623197ebdbSTheodore Ts'o #define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \ 21633197ebdbSTheodore Ts'o static struct ext4_attr ext4_attr_##_name = { \ 21643197ebdbSTheodore Ts'o .attr = {.name = __stringify(_name), .mode = _mode }, \ 21653197ebdbSTheodore Ts'o .show = _show, \ 21663197ebdbSTheodore Ts'o .store = _store, \ 21673197ebdbSTheodore Ts'o .offset = offsetof(struct ext4_sb_info, _elname), \ 21683197ebdbSTheodore Ts'o } 21693197ebdbSTheodore Ts'o #define EXT4_ATTR(name, mode, show, store) \ 21703197ebdbSTheodore Ts'o static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store) 21713197ebdbSTheodore Ts'o 21723197ebdbSTheodore Ts'o #define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL) 21733197ebdbSTheodore Ts'o #define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store) 21743197ebdbSTheodore Ts'o #define EXT4_RW_ATTR_SBI_UI(name, elname) \ 21753197ebdbSTheodore Ts'o EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname) 21763197ebdbSTheodore Ts'o #define ATTR_LIST(name) &ext4_attr_##name.attr 21773197ebdbSTheodore Ts'o 21783197ebdbSTheodore Ts'o EXT4_RO_ATTR(delayed_allocation_blocks); 21793197ebdbSTheodore Ts'o EXT4_RO_ATTR(session_write_kbytes); 21803197ebdbSTheodore Ts'o EXT4_RO_ATTR(lifetime_write_kbytes); 21813197ebdbSTheodore Ts'o EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show, 21823197ebdbSTheodore Ts'o inode_readahead_blks_store, s_inode_readahead_blks); 21833197ebdbSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats); 21843197ebdbSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan); 21853197ebdbSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan); 21863197ebdbSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs); 21873197ebdbSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request); 21883197ebdbSTheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc); 21893197ebdbSTheodore Ts'o 21903197ebdbSTheodore Ts'o static struct attribute *ext4_attrs[] = { 21913197ebdbSTheodore Ts'o ATTR_LIST(delayed_allocation_blocks), 21923197ebdbSTheodore Ts'o ATTR_LIST(session_write_kbytes), 21933197ebdbSTheodore Ts'o ATTR_LIST(lifetime_write_kbytes), 21943197ebdbSTheodore Ts'o ATTR_LIST(inode_readahead_blks), 21953197ebdbSTheodore Ts'o ATTR_LIST(mb_stats), 21963197ebdbSTheodore Ts'o ATTR_LIST(mb_max_to_scan), 21973197ebdbSTheodore Ts'o ATTR_LIST(mb_min_to_scan), 21983197ebdbSTheodore Ts'o ATTR_LIST(mb_order2_req), 21993197ebdbSTheodore Ts'o ATTR_LIST(mb_stream_req), 22003197ebdbSTheodore Ts'o ATTR_LIST(mb_group_prealloc), 22013197ebdbSTheodore Ts'o NULL, 22023197ebdbSTheodore Ts'o }; 22033197ebdbSTheodore Ts'o 22043197ebdbSTheodore Ts'o static ssize_t ext4_attr_show(struct kobject *kobj, 22053197ebdbSTheodore Ts'o struct attribute *attr, char *buf) 22063197ebdbSTheodore Ts'o { 22073197ebdbSTheodore Ts'o struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 22083197ebdbSTheodore Ts'o s_kobj); 22093197ebdbSTheodore Ts'o struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); 22103197ebdbSTheodore Ts'o 22113197ebdbSTheodore Ts'o return a->show ? a->show(a, sbi, buf) : 0; 22123197ebdbSTheodore Ts'o } 22133197ebdbSTheodore Ts'o 22143197ebdbSTheodore Ts'o static ssize_t ext4_attr_store(struct kobject *kobj, 22153197ebdbSTheodore Ts'o struct attribute *attr, 22163197ebdbSTheodore Ts'o const char *buf, size_t len) 22173197ebdbSTheodore Ts'o { 22183197ebdbSTheodore Ts'o struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 22193197ebdbSTheodore Ts'o s_kobj); 22203197ebdbSTheodore Ts'o struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); 22213197ebdbSTheodore Ts'o 22223197ebdbSTheodore Ts'o return a->store ? a->store(a, sbi, buf, len) : 0; 22233197ebdbSTheodore Ts'o } 22243197ebdbSTheodore Ts'o 22253197ebdbSTheodore Ts'o static void ext4_sb_release(struct kobject *kobj) 22263197ebdbSTheodore Ts'o { 22273197ebdbSTheodore Ts'o struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 22283197ebdbSTheodore Ts'o s_kobj); 22293197ebdbSTheodore Ts'o complete(&sbi->s_kobj_unregister); 22303197ebdbSTheodore Ts'o } 22313197ebdbSTheodore Ts'o 22323197ebdbSTheodore Ts'o 22333197ebdbSTheodore Ts'o static struct sysfs_ops ext4_attr_ops = { 22343197ebdbSTheodore Ts'o .show = ext4_attr_show, 22353197ebdbSTheodore Ts'o .store = ext4_attr_store, 22363197ebdbSTheodore Ts'o }; 22373197ebdbSTheodore Ts'o 22383197ebdbSTheodore Ts'o static struct kobj_type ext4_ktype = { 22393197ebdbSTheodore Ts'o .default_attrs = ext4_attrs, 22403197ebdbSTheodore Ts'o .sysfs_ops = &ext4_attr_ops, 22413197ebdbSTheodore Ts'o .release = ext4_sb_release, 22423197ebdbSTheodore Ts'o }; 22433197ebdbSTheodore Ts'o 2244617ba13bSMingming Cao static int ext4_fill_super(struct super_block *sb, void *data, int silent) 22457477827fSAneesh Kumar K.V __releases(kernel_lock) 22467477827fSAneesh Kumar K.V __acquires(kernel_lock) 22471d03ec98SAneesh Kumar K.V 2248ac27a0ecSDave Kleikamp { 2249ac27a0ecSDave Kleikamp struct buffer_head *bh; 2250617ba13bSMingming Cao struct ext4_super_block *es = NULL; 2251617ba13bSMingming Cao struct ext4_sb_info *sbi; 2252617ba13bSMingming Cao ext4_fsblk_t block; 2253617ba13bSMingming Cao ext4_fsblk_t sb_block = get_sb_block(&data); 225470bbb3e0SAndrew Morton ext4_fsblk_t logical_sb_block; 2255ac27a0ecSDave Kleikamp unsigned long offset = 0; 2256ac27a0ecSDave Kleikamp unsigned long journal_devnum = 0; 2257ac27a0ecSDave Kleikamp unsigned long def_mount_opts; 2258ac27a0ecSDave Kleikamp struct inode *root; 22599f6200bbSTheodore Ts'o char *cp; 22600390131bSFrank Mayhar const char *descr; 22611d1fe1eeSDavid Howells int ret = -EINVAL; 2262ac27a0ecSDave Kleikamp int blocksize; 22634ec11028STheodore Ts'o unsigned int db_count; 22644ec11028STheodore Ts'o unsigned int i; 2265f287a1a5STheodore Ts'o int needs_recovery, has_huge_files; 22663a06d778SAneesh Kumar K.V int features; 2267bd81d8eeSLaurent Vivier __u64 blocks_count; 2268833f4077SPeter Zijlstra int err; 2269b3881f74STheodore Ts'o unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; 2270ac27a0ecSDave Kleikamp 2271ac27a0ecSDave Kleikamp sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); 2272ac27a0ecSDave Kleikamp if (!sbi) 2273ac27a0ecSDave Kleikamp return -ENOMEM; 2274705895b6SPekka Enberg 2275705895b6SPekka Enberg sbi->s_blockgroup_lock = 2276705895b6SPekka Enberg kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); 2277705895b6SPekka Enberg if (!sbi->s_blockgroup_lock) { 2278705895b6SPekka Enberg kfree(sbi); 2279705895b6SPekka Enberg return -ENOMEM; 2280705895b6SPekka Enberg } 2281ac27a0ecSDave Kleikamp sb->s_fs_info = sbi; 2282ac27a0ecSDave Kleikamp sbi->s_mount_opt = 0; 2283617ba13bSMingming Cao sbi->s_resuid = EXT4_DEF_RESUID; 2284617ba13bSMingming Cao sbi->s_resgid = EXT4_DEF_RESGID; 2285240799cdSTheodore Ts'o sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; 2286d9c9bef1SMiklos Szeredi sbi->s_sb_block = sb_block; 2287afc32f7eSTheodore Ts'o sbi->s_sectors_written_start = part_stat_read(sb->s_bdev->bd_part, 2288afc32f7eSTheodore Ts'o sectors[1]); 2289ac27a0ecSDave Kleikamp 2290ac27a0ecSDave Kleikamp unlock_kernel(); 2291ac27a0ecSDave Kleikamp 22929f6200bbSTheodore Ts'o /* Cleanup superblock name */ 22939f6200bbSTheodore Ts'o for (cp = sb->s_id; (cp = strchr(cp, '/'));) 22949f6200bbSTheodore Ts'o *cp = '!'; 22959f6200bbSTheodore Ts'o 2296617ba13bSMingming Cao blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE); 2297ac27a0ecSDave Kleikamp if (!blocksize) { 2298617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: unable to set blocksize\n"); 2299ac27a0ecSDave Kleikamp goto out_fail; 2300ac27a0ecSDave Kleikamp } 2301ac27a0ecSDave Kleikamp 2302ac27a0ecSDave Kleikamp /* 2303617ba13bSMingming Cao * The ext4 superblock will not be buffer aligned for other than 1kB 2304ac27a0ecSDave Kleikamp * block sizes. We need to calculate the offset from buffer start. 2305ac27a0ecSDave Kleikamp */ 2306617ba13bSMingming Cao if (blocksize != EXT4_MIN_BLOCK_SIZE) { 230770bbb3e0SAndrew Morton logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; 230870bbb3e0SAndrew Morton offset = do_div(logical_sb_block, blocksize); 2309ac27a0ecSDave Kleikamp } else { 231070bbb3e0SAndrew Morton logical_sb_block = sb_block; 2311ac27a0ecSDave Kleikamp } 2312ac27a0ecSDave Kleikamp 231370bbb3e0SAndrew Morton if (!(bh = sb_bread(sb, logical_sb_block))) { 2314617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: unable to read superblock\n"); 2315ac27a0ecSDave Kleikamp goto out_fail; 2316ac27a0ecSDave Kleikamp } 2317ac27a0ecSDave Kleikamp /* 2318ac27a0ecSDave Kleikamp * Note: s_es must be initialized as soon as possible because 2319617ba13bSMingming Cao * some ext4 macro-instructions depend on its value 2320ac27a0ecSDave Kleikamp */ 2321617ba13bSMingming Cao es = (struct ext4_super_block *) (((char *)bh->b_data) + offset); 2322ac27a0ecSDave Kleikamp sbi->s_es = es; 2323ac27a0ecSDave Kleikamp sb->s_magic = le16_to_cpu(es->s_magic); 2324617ba13bSMingming Cao if (sb->s_magic != EXT4_SUPER_MAGIC) 2325617ba13bSMingming Cao goto cantfind_ext4; 2326afc32f7eSTheodore Ts'o sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written); 2327ac27a0ecSDave Kleikamp 2328ac27a0ecSDave Kleikamp /* Set defaults before we parse the mount options */ 2329ac27a0ecSDave Kleikamp def_mount_opts = le32_to_cpu(es->s_default_mount_opts); 2330617ba13bSMingming Cao if (def_mount_opts & EXT4_DEFM_DEBUG) 2331ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, DEBUG); 2332617ba13bSMingming Cao if (def_mount_opts & EXT4_DEFM_BSDGROUPS) 2333ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, GRPID); 2334617ba13bSMingming Cao if (def_mount_opts & EXT4_DEFM_UID16) 2335ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, NO_UID32); 233603010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_XATTR 2337617ba13bSMingming Cao if (def_mount_opts & EXT4_DEFM_XATTR_USER) 2338ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, XATTR_USER); 23392e7842b8SHugh Dickins #endif 234003010a33STheodore Ts'o #ifdef CONFIG_EXT4_FS_POSIX_ACL 2341617ba13bSMingming Cao if (def_mount_opts & EXT4_DEFM_ACL) 2342ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, POSIX_ACL); 23432e7842b8SHugh Dickins #endif 2344617ba13bSMingming Cao if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA) 2345617ba13bSMingming Cao sbi->s_mount_opt |= EXT4_MOUNT_JOURNAL_DATA; 2346617ba13bSMingming Cao else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED) 2347617ba13bSMingming Cao sbi->s_mount_opt |= EXT4_MOUNT_ORDERED_DATA; 2348617ba13bSMingming Cao else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK) 2349617ba13bSMingming Cao sbi->s_mount_opt |= EXT4_MOUNT_WRITEBACK_DATA; 2350ac27a0ecSDave Kleikamp 2351617ba13bSMingming Cao if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC) 2352ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, ERRORS_PANIC); 2353bb4f397aSAneesh Kumar K.V else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE) 2354ceea16bfSDmitry Mishin set_opt(sbi->s_mount_opt, ERRORS_CONT); 2355bb4f397aSAneesh Kumar K.V else 2356bb4f397aSAneesh Kumar K.V set_opt(sbi->s_mount_opt, ERRORS_RO); 2357ac27a0ecSDave Kleikamp 2358ac27a0ecSDave Kleikamp sbi->s_resuid = le16_to_cpu(es->s_def_resuid); 2359ac27a0ecSDave Kleikamp sbi->s_resgid = le16_to_cpu(es->s_def_resgid); 236030773840STheodore Ts'o sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ; 236130773840STheodore Ts'o sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME; 236230773840STheodore Ts'o sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME; 2363*f4033903SCurt Wohlgemuth sbi->s_mb_history_max = default_mb_history_length; 2364ac27a0ecSDave Kleikamp 2365571640caSEric Sandeen set_opt(sbi->s_mount_opt, BARRIER); 2366ac27a0ecSDave Kleikamp 23671e2462f9SMingming Cao /* 2368dd919b98SAneesh Kumar K.V * enable delayed allocation by default 2369dd919b98SAneesh Kumar K.V * Use -o nodelalloc to turn it off 2370dd919b98SAneesh Kumar K.V */ 2371dd919b98SAneesh Kumar K.V set_opt(sbi->s_mount_opt, DELALLOC); 2372dd919b98SAneesh Kumar K.V 2373dd919b98SAneesh Kumar K.V 2374b3881f74STheodore Ts'o if (!parse_options((char *) data, sb, &journal_devnum, 2375b3881f74STheodore Ts'o &journal_ioprio, NULL, 0)) 2376ac27a0ecSDave Kleikamp goto failed_mount; 2377ac27a0ecSDave Kleikamp 2378ac27a0ecSDave Kleikamp sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 2379617ba13bSMingming Cao ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); 2380ac27a0ecSDave Kleikamp 2381617ba13bSMingming Cao if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV && 2382617ba13bSMingming Cao (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) || 2383617ba13bSMingming Cao EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) || 2384617ba13bSMingming Cao EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U))) 2385ac27a0ecSDave Kleikamp printk(KERN_WARNING 2386617ba13bSMingming Cao "EXT4-fs warning: feature flags set on rev 0 fs, " 2387ac27a0ecSDave Kleikamp "running e2fsck is recommended\n"); 2388469108ffSTheodore Tso 2389469108ffSTheodore Tso /* 2390ac27a0ecSDave Kleikamp * Check feature flags regardless of the revision level, since we 2391ac27a0ecSDave Kleikamp * previously didn't change the revision level when setting the flags, 2392ac27a0ecSDave Kleikamp * so there is a chance incompat flags are set on a rev 0 filesystem. 2393ac27a0ecSDave Kleikamp */ 2394617ba13bSMingming Cao features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP); 2395ac27a0ecSDave Kleikamp if (features) { 2396617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: %s: couldn't mount because of " 23973a06d778SAneesh Kumar K.V "unsupported optional features (%x).\n", sb->s_id, 23983a06d778SAneesh Kumar K.V (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) & 23993a06d778SAneesh Kumar K.V ~EXT4_FEATURE_INCOMPAT_SUPP)); 2400ac27a0ecSDave Kleikamp goto failed_mount; 2401ac27a0ecSDave Kleikamp } 2402617ba13bSMingming Cao features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP); 2403ac27a0ecSDave Kleikamp if (!(sb->s_flags & MS_RDONLY) && features) { 2404617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: %s: couldn't mount RDWR because of " 24053a06d778SAneesh Kumar K.V "unsupported optional features (%x).\n", sb->s_id, 24063a06d778SAneesh Kumar K.V (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) & 24073a06d778SAneesh Kumar K.V ~EXT4_FEATURE_RO_COMPAT_SUPP)); 2408ac27a0ecSDave Kleikamp goto failed_mount; 2409ac27a0ecSDave Kleikamp } 2410f287a1a5STheodore Ts'o has_huge_files = EXT4_HAS_RO_COMPAT_FEATURE(sb, 2411f287a1a5STheodore Ts'o EXT4_FEATURE_RO_COMPAT_HUGE_FILE); 2412f287a1a5STheodore Ts'o if (has_huge_files) { 24130fc1b451SAneesh Kumar K.V /* 24140fc1b451SAneesh Kumar K.V * Large file size enabled file system can only be 2415b3a6ffe1SJens Axboe * mount if kernel is build with CONFIG_LBD 24160fc1b451SAneesh Kumar K.V */ 24170fc1b451SAneesh Kumar K.V if (sizeof(root->i_blocks) < sizeof(u64) && 24180fc1b451SAneesh Kumar K.V !(sb->s_flags & MS_RDONLY)) { 24190fc1b451SAneesh Kumar K.V printk(KERN_ERR "EXT4-fs: %s: Filesystem with huge " 24200fc1b451SAneesh Kumar K.V "files cannot be mounted read-write " 2421b3a6ffe1SJens Axboe "without CONFIG_LBD.\n", sb->s_id); 24220fc1b451SAneesh Kumar K.V goto failed_mount; 24230fc1b451SAneesh Kumar K.V } 24240fc1b451SAneesh Kumar K.V } 2425ac27a0ecSDave Kleikamp blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size); 2426ac27a0ecSDave Kleikamp 2427617ba13bSMingming Cao if (blocksize < EXT4_MIN_BLOCK_SIZE || 2428617ba13bSMingming Cao blocksize > EXT4_MAX_BLOCK_SIZE) { 2429ac27a0ecSDave Kleikamp printk(KERN_ERR 2430617ba13bSMingming Cao "EXT4-fs: Unsupported filesystem blocksize %d on %s.\n", 2431ac27a0ecSDave Kleikamp blocksize, sb->s_id); 2432ac27a0ecSDave Kleikamp goto failed_mount; 2433ac27a0ecSDave Kleikamp } 2434ac27a0ecSDave Kleikamp 2435ac27a0ecSDave Kleikamp if (sb->s_blocksize != blocksize) { 2436ce40733cSAneesh Kumar K.V 2437ce40733cSAneesh Kumar K.V /* Validate the filesystem blocksize */ 2438ce40733cSAneesh Kumar K.V if (!sb_set_blocksize(sb, blocksize)) { 2439ce40733cSAneesh Kumar K.V printk(KERN_ERR "EXT4-fs: bad block size %d.\n", 2440ce40733cSAneesh Kumar K.V blocksize); 2441ac27a0ecSDave Kleikamp goto failed_mount; 2442ac27a0ecSDave Kleikamp } 2443ac27a0ecSDave Kleikamp 2444ac27a0ecSDave Kleikamp brelse(bh); 244570bbb3e0SAndrew Morton logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; 244670bbb3e0SAndrew Morton offset = do_div(logical_sb_block, blocksize); 244770bbb3e0SAndrew Morton bh = sb_bread(sb, logical_sb_block); 2448ac27a0ecSDave Kleikamp if (!bh) { 2449ac27a0ecSDave Kleikamp printk(KERN_ERR 2450617ba13bSMingming Cao "EXT4-fs: Can't read superblock on 2nd try.\n"); 2451ac27a0ecSDave Kleikamp goto failed_mount; 2452ac27a0ecSDave Kleikamp } 2453617ba13bSMingming Cao es = (struct ext4_super_block *)(((char *)bh->b_data) + offset); 2454ac27a0ecSDave Kleikamp sbi->s_es = es; 2455617ba13bSMingming Cao if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) { 2456ac27a0ecSDave Kleikamp printk(KERN_ERR 2457617ba13bSMingming Cao "EXT4-fs: Magic mismatch, very weird !\n"); 2458ac27a0ecSDave Kleikamp goto failed_mount; 2459ac27a0ecSDave Kleikamp } 2460ac27a0ecSDave Kleikamp } 2461ac27a0ecSDave Kleikamp 2462f287a1a5STheodore Ts'o sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits, 2463f287a1a5STheodore Ts'o has_huge_files); 2464f287a1a5STheodore Ts'o sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files); 2465ac27a0ecSDave Kleikamp 2466617ba13bSMingming Cao if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) { 2467617ba13bSMingming Cao sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE; 2468617ba13bSMingming Cao sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO; 2469ac27a0ecSDave Kleikamp } else { 2470ac27a0ecSDave Kleikamp sbi->s_inode_size = le16_to_cpu(es->s_inode_size); 2471ac27a0ecSDave Kleikamp sbi->s_first_ino = le32_to_cpu(es->s_first_ino); 2472617ba13bSMingming Cao if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) || 24731330593eSVignesh Babu (!is_power_of_2(sbi->s_inode_size)) || 2474ac27a0ecSDave Kleikamp (sbi->s_inode_size > blocksize)) { 2475ac27a0ecSDave Kleikamp printk(KERN_ERR 2476617ba13bSMingming Cao "EXT4-fs: unsupported inode size: %d\n", 2477ac27a0ecSDave Kleikamp sbi->s_inode_size); 2478ac27a0ecSDave Kleikamp goto failed_mount; 2479ac27a0ecSDave Kleikamp } 2480ef7f3835SKalpak Shah if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) 2481ef7f3835SKalpak Shah sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2); 2482ac27a0ecSDave Kleikamp } 24830d1ee42fSAlexandre Ratchov sbi->s_desc_size = le16_to_cpu(es->s_desc_size); 24840d1ee42fSAlexandre Ratchov if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) { 24858fadc143SAlexandre Ratchov if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT || 24860d1ee42fSAlexandre Ratchov sbi->s_desc_size > EXT4_MAX_DESC_SIZE || 2487d8ea6cf8Svignesh babu !is_power_of_2(sbi->s_desc_size)) { 24880d1ee42fSAlexandre Ratchov printk(KERN_ERR 24898fadc143SAlexandre Ratchov "EXT4-fs: unsupported descriptor size %lu\n", 24900d1ee42fSAlexandre Ratchov sbi->s_desc_size); 24910d1ee42fSAlexandre Ratchov goto failed_mount; 24920d1ee42fSAlexandre Ratchov } 24930d1ee42fSAlexandre Ratchov } else 24940d1ee42fSAlexandre Ratchov sbi->s_desc_size = EXT4_MIN_DESC_SIZE; 2495ac27a0ecSDave Kleikamp sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); 2496ac27a0ecSDave Kleikamp sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); 2497b47b6f38SAndries E. Brouwer if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0) 2498617ba13bSMingming Cao goto cantfind_ext4; 2499617ba13bSMingming Cao sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb); 2500ac27a0ecSDave Kleikamp if (sbi->s_inodes_per_block == 0) 2501617ba13bSMingming Cao goto cantfind_ext4; 2502ac27a0ecSDave Kleikamp sbi->s_itb_per_group = sbi->s_inodes_per_group / 2503ac27a0ecSDave Kleikamp sbi->s_inodes_per_block; 25040d1ee42fSAlexandre Ratchov sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb); 2505ac27a0ecSDave Kleikamp sbi->s_sbh = bh; 2506ac27a0ecSDave Kleikamp sbi->s_mount_state = le16_to_cpu(es->s_state); 2507e57aa839SFengguang Wu sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb)); 2508e57aa839SFengguang Wu sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb)); 2509ac27a0ecSDave Kleikamp for (i = 0; i < 4; i++) 2510ac27a0ecSDave Kleikamp sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); 2511ac27a0ecSDave Kleikamp sbi->s_def_hash_version = es->s_def_hash_version; 2512f99b2589STheodore Ts'o i = le32_to_cpu(es->s_flags); 2513f99b2589STheodore Ts'o if (i & EXT2_FLAGS_UNSIGNED_HASH) 2514f99b2589STheodore Ts'o sbi->s_hash_unsigned = 3; 2515f99b2589STheodore Ts'o else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) { 2516f99b2589STheodore Ts'o #ifdef __CHAR_UNSIGNED__ 2517f99b2589STheodore Ts'o es->s_flags |= cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH); 2518f99b2589STheodore Ts'o sbi->s_hash_unsigned = 3; 2519f99b2589STheodore Ts'o #else 2520f99b2589STheodore Ts'o es->s_flags |= cpu_to_le32(EXT2_FLAGS_SIGNED_HASH); 2521f99b2589STheodore Ts'o #endif 2522f99b2589STheodore Ts'o sb->s_dirt = 1; 2523f99b2589STheodore Ts'o } 2524ac27a0ecSDave Kleikamp 2525ac27a0ecSDave Kleikamp if (sbi->s_blocks_per_group > blocksize * 8) { 2526ac27a0ecSDave Kleikamp printk(KERN_ERR 2527617ba13bSMingming Cao "EXT4-fs: #blocks per group too big: %lu\n", 2528ac27a0ecSDave Kleikamp sbi->s_blocks_per_group); 2529ac27a0ecSDave Kleikamp goto failed_mount; 2530ac27a0ecSDave Kleikamp } 2531ac27a0ecSDave Kleikamp if (sbi->s_inodes_per_group > blocksize * 8) { 2532ac27a0ecSDave Kleikamp printk(KERN_ERR 2533617ba13bSMingming Cao "EXT4-fs: #inodes per group too big: %lu\n", 2534ac27a0ecSDave Kleikamp sbi->s_inodes_per_group); 2535ac27a0ecSDave Kleikamp goto failed_mount; 2536ac27a0ecSDave Kleikamp } 2537ac27a0ecSDave Kleikamp 2538bd81d8eeSLaurent Vivier if (ext4_blocks_count(es) > 2539ac27a0ecSDave Kleikamp (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { 2540617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: filesystem on %s:" 2541ac27a0ecSDave Kleikamp " too large to mount safely\n", sb->s_id); 2542ac27a0ecSDave Kleikamp if (sizeof(sector_t) < 8) 2543617ba13bSMingming Cao printk(KERN_WARNING "EXT4-fs: CONFIG_LBD not " 2544ac27a0ecSDave Kleikamp "enabled\n"); 2545ac27a0ecSDave Kleikamp goto failed_mount; 2546ac27a0ecSDave Kleikamp } 2547ac27a0ecSDave Kleikamp 2548617ba13bSMingming Cao if (EXT4_BLOCKS_PER_GROUP(sb) == 0) 2549617ba13bSMingming Cao goto cantfind_ext4; 2550e7c95593SEric Sandeen 25510f2ddca6SFrom: Thiemo Nagel /* check blocks count against device size */ 25520f2ddca6SFrom: Thiemo Nagel blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits; 25530f2ddca6SFrom: Thiemo Nagel if (blocks_count && ext4_blocks_count(es) > blocks_count) { 25540f2ddca6SFrom: Thiemo Nagel printk(KERN_WARNING "EXT4-fs: bad geometry: block count %llu " 25550f2ddca6SFrom: Thiemo Nagel "exceeds size of device (%llu blocks)\n", 25560f2ddca6SFrom: Thiemo Nagel ext4_blocks_count(es), blocks_count); 25570f2ddca6SFrom: Thiemo Nagel goto failed_mount; 25580f2ddca6SFrom: Thiemo Nagel } 25590f2ddca6SFrom: Thiemo Nagel 25604ec11028STheodore Ts'o /* 25614ec11028STheodore Ts'o * It makes no sense for the first data block to be beyond the end 25624ec11028STheodore Ts'o * of the filesystem. 25634ec11028STheodore Ts'o */ 25644ec11028STheodore Ts'o if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) { 25654ec11028STheodore Ts'o printk(KERN_WARNING "EXT4-fs: bad geometry: first data" 25664ec11028STheodore Ts'o "block %u is beyond end of filesystem (%llu)\n", 2567e7c95593SEric Sandeen le32_to_cpu(es->s_first_data_block), 25684ec11028STheodore Ts'o ext4_blocks_count(es)); 2569e7c95593SEric Sandeen goto failed_mount; 2570e7c95593SEric Sandeen } 2571bd81d8eeSLaurent Vivier blocks_count = (ext4_blocks_count(es) - 2572bd81d8eeSLaurent Vivier le32_to_cpu(es->s_first_data_block) + 2573bd81d8eeSLaurent Vivier EXT4_BLOCKS_PER_GROUP(sb) - 1); 2574bd81d8eeSLaurent Vivier do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb)); 25754ec11028STheodore Ts'o if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) { 25764ec11028STheodore Ts'o printk(KERN_WARNING "EXT4-fs: groups count too large: %u " 25774ec11028STheodore Ts'o "(block count %llu, first data block %u, " 25784ec11028STheodore Ts'o "blocks per group %lu)\n", sbi->s_groups_count, 25794ec11028STheodore Ts'o ext4_blocks_count(es), 25804ec11028STheodore Ts'o le32_to_cpu(es->s_first_data_block), 25814ec11028STheodore Ts'o EXT4_BLOCKS_PER_GROUP(sb)); 25824ec11028STheodore Ts'o goto failed_mount; 25834ec11028STheodore Ts'o } 2584bd81d8eeSLaurent Vivier sbi->s_groups_count = blocks_count; 2585617ba13bSMingming Cao db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) / 2586617ba13bSMingming Cao EXT4_DESC_PER_BLOCK(sb); 2587ac27a0ecSDave Kleikamp sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *), 2588ac27a0ecSDave Kleikamp GFP_KERNEL); 2589ac27a0ecSDave Kleikamp if (sbi->s_group_desc == NULL) { 2590617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: not enough memory\n"); 2591ac27a0ecSDave Kleikamp goto failed_mount; 2592ac27a0ecSDave Kleikamp } 2593ac27a0ecSDave Kleikamp 25943244fcb1SAlexander Beregalov #ifdef CONFIG_PROC_FS 25959f6200bbSTheodore Ts'o if (ext4_proc_root) 25969f6200bbSTheodore Ts'o sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); 25973244fcb1SAlexander Beregalov #endif 2598240799cdSTheodore Ts'o 2599705895b6SPekka Enberg bgl_lock_init(sbi->s_blockgroup_lock); 2600ac27a0ecSDave Kleikamp 2601ac27a0ecSDave Kleikamp for (i = 0; i < db_count; i++) { 260270bbb3e0SAndrew Morton block = descriptor_loc(sb, logical_sb_block, i); 2603ac27a0ecSDave Kleikamp sbi->s_group_desc[i] = sb_bread(sb, block); 2604ac27a0ecSDave Kleikamp if (!sbi->s_group_desc[i]) { 2605617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: " 2606ac27a0ecSDave Kleikamp "can't read group descriptor %d\n", i); 2607ac27a0ecSDave Kleikamp db_count = i; 2608ac27a0ecSDave Kleikamp goto failed_mount2; 2609ac27a0ecSDave Kleikamp } 2610ac27a0ecSDave Kleikamp } 2611617ba13bSMingming Cao if (!ext4_check_descriptors(sb)) { 2612617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: group descriptors corrupted!\n"); 2613ac27a0ecSDave Kleikamp goto failed_mount2; 2614ac27a0ecSDave Kleikamp } 2615772cb7c8SJose R. Santos if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) 2616772cb7c8SJose R. Santos if (!ext4_fill_flex_info(sb)) { 2617772cb7c8SJose R. Santos printk(KERN_ERR 2618772cb7c8SJose R. Santos "EXT4-fs: unable to initialize " 2619772cb7c8SJose R. Santos "flex_bg meta info!\n"); 2620772cb7c8SJose R. Santos goto failed_mount2; 2621772cb7c8SJose R. Santos } 2622772cb7c8SJose R. Santos 2623ac27a0ecSDave Kleikamp sbi->s_gdb_count = db_count; 2624ac27a0ecSDave Kleikamp get_random_bytes(&sbi->s_next_generation, sizeof(u32)); 2625ac27a0ecSDave Kleikamp spin_lock_init(&sbi->s_next_gen_lock); 2626ac27a0ecSDave Kleikamp 2627833f4077SPeter Zijlstra err = percpu_counter_init(&sbi->s_freeblocks_counter, 2628617ba13bSMingming Cao ext4_count_free_blocks(sb)); 2629833f4077SPeter Zijlstra if (!err) { 2630833f4077SPeter Zijlstra err = percpu_counter_init(&sbi->s_freeinodes_counter, 2631617ba13bSMingming Cao ext4_count_free_inodes(sb)); 2632833f4077SPeter Zijlstra } 2633833f4077SPeter Zijlstra if (!err) { 2634833f4077SPeter Zijlstra err = percpu_counter_init(&sbi->s_dirs_counter, 2635617ba13bSMingming Cao ext4_count_dirs(sb)); 2636833f4077SPeter Zijlstra } 26376bc6e63fSAneesh Kumar K.V if (!err) { 26386bc6e63fSAneesh Kumar K.V err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0); 26396bc6e63fSAneesh Kumar K.V } 2640833f4077SPeter Zijlstra if (err) { 2641833f4077SPeter Zijlstra printk(KERN_ERR "EXT4-fs: insufficient memory\n"); 2642833f4077SPeter Zijlstra goto failed_mount3; 2643833f4077SPeter Zijlstra } 2644ac27a0ecSDave Kleikamp 2645c9de560dSAlex Tomas sbi->s_stripe = ext4_get_stripe_size(sbi); 2646c9de560dSAlex Tomas 2647ac27a0ecSDave Kleikamp /* 2648ac27a0ecSDave Kleikamp * set up enough so that it can read an inode 2649ac27a0ecSDave Kleikamp */ 26509ca92389STheodore Ts'o if (!test_opt(sb, NOLOAD) && 26519ca92389STheodore Ts'o EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) 2652617ba13bSMingming Cao sb->s_op = &ext4_sops; 26539ca92389STheodore Ts'o else 26549ca92389STheodore Ts'o sb->s_op = &ext4_nojournal_sops; 2655617ba13bSMingming Cao sb->s_export_op = &ext4_export_ops; 2656617ba13bSMingming Cao sb->s_xattr = ext4_xattr_handlers; 2657ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 2658617ba13bSMingming Cao sb->s_qcop = &ext4_qctl_operations; 2659617ba13bSMingming Cao sb->dq_op = &ext4_quota_operations; 2660ac27a0ecSDave Kleikamp #endif 2661ac27a0ecSDave Kleikamp INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ 26623b9d4ed2STheodore Ts'o mutex_init(&sbi->s_orphan_lock); 266332ed5058STheodore Ts'o mutex_init(&sbi->s_resize_lock); 2664ac27a0ecSDave Kleikamp 2665ac27a0ecSDave Kleikamp sb->s_root = NULL; 2666ac27a0ecSDave Kleikamp 2667ac27a0ecSDave Kleikamp needs_recovery = (es->s_last_orphan != 0 || 2668617ba13bSMingming Cao EXT4_HAS_INCOMPAT_FEATURE(sb, 2669617ba13bSMingming Cao EXT4_FEATURE_INCOMPAT_RECOVER)); 2670ac27a0ecSDave Kleikamp 2671ac27a0ecSDave Kleikamp /* 2672ac27a0ecSDave Kleikamp * The first inode we look at is the journal inode. Don't try 2673ac27a0ecSDave Kleikamp * root first: it may be modified in the journal! 2674ac27a0ecSDave Kleikamp */ 2675ac27a0ecSDave Kleikamp if (!test_opt(sb, NOLOAD) && 2676617ba13bSMingming Cao EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) { 2677617ba13bSMingming Cao if (ext4_load_journal(sb, es, journal_devnum)) 2678ac27a0ecSDave Kleikamp goto failed_mount3; 2679624080edSTheodore Ts'o if (!(sb->s_flags & MS_RDONLY) && 2680624080edSTheodore Ts'o EXT4_SB(sb)->s_journal->j_failed_commit) { 2681624080edSTheodore Ts'o printk(KERN_CRIT "EXT4-fs error (device %s): " 2682624080edSTheodore Ts'o "ext4_fill_super: Journal transaction " 2683624080edSTheodore Ts'o "%u is corrupt\n", sb->s_id, 2684624080edSTheodore Ts'o EXT4_SB(sb)->s_journal->j_failed_commit); 2685624080edSTheodore Ts'o if (test_opt(sb, ERRORS_RO)) { 2686624080edSTheodore Ts'o printk(KERN_CRIT 2687624080edSTheodore Ts'o "Mounting filesystem read-only\n"); 2688624080edSTheodore Ts'o sb->s_flags |= MS_RDONLY; 2689624080edSTheodore Ts'o EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 2690624080edSTheodore Ts'o es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 2691624080edSTheodore Ts'o } 2692624080edSTheodore Ts'o if (test_opt(sb, ERRORS_PANIC)) { 2693624080edSTheodore Ts'o EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 2694624080edSTheodore Ts'o es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 2695e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 2696624080edSTheodore Ts'o goto failed_mount4; 2697624080edSTheodore Ts'o } 2698624080edSTheodore Ts'o } 26990390131bSFrank Mayhar } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) && 27000390131bSFrank Mayhar EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { 27010390131bSFrank Mayhar printk(KERN_ERR "EXT4-fs: required journal recovery " 27020390131bSFrank Mayhar "suppressed and not mounted read-only\n"); 27030390131bSFrank Mayhar goto failed_mount4; 2704ac27a0ecSDave Kleikamp } else { 27050390131bSFrank Mayhar clear_opt(sbi->s_mount_opt, DATA_FLAGS); 27060390131bSFrank Mayhar set_opt(sbi->s_mount_opt, WRITEBACK_DATA); 27070390131bSFrank Mayhar sbi->s_journal = NULL; 27080390131bSFrank Mayhar needs_recovery = 0; 27090390131bSFrank Mayhar goto no_journal; 2710ac27a0ecSDave Kleikamp } 2711ac27a0ecSDave Kleikamp 2712eb40a09cSJose R. Santos if (ext4_blocks_count(es) > 0xffffffffULL && 2713eb40a09cSJose R. Santos !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0, 2714eb40a09cSJose R. Santos JBD2_FEATURE_INCOMPAT_64BIT)) { 2715abda1418STheodore Ts'o printk(KERN_ERR "EXT4-fs: Failed to set 64-bit journal feature\n"); 2716eb40a09cSJose R. Santos goto failed_mount4; 2717eb40a09cSJose R. Santos } 2718eb40a09cSJose R. Santos 2719818d276cSGirish Shilamkar if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) { 2720818d276cSGirish Shilamkar jbd2_journal_set_features(sbi->s_journal, 2721818d276cSGirish Shilamkar JBD2_FEATURE_COMPAT_CHECKSUM, 0, 2722818d276cSGirish Shilamkar JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); 2723818d276cSGirish Shilamkar } else if (test_opt(sb, JOURNAL_CHECKSUM)) { 2724818d276cSGirish Shilamkar jbd2_journal_set_features(sbi->s_journal, 2725818d276cSGirish Shilamkar JBD2_FEATURE_COMPAT_CHECKSUM, 0, 0); 2726818d276cSGirish Shilamkar jbd2_journal_clear_features(sbi->s_journal, 0, 0, 2727818d276cSGirish Shilamkar JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); 2728818d276cSGirish Shilamkar } else { 2729818d276cSGirish Shilamkar jbd2_journal_clear_features(sbi->s_journal, 2730818d276cSGirish Shilamkar JBD2_FEATURE_COMPAT_CHECKSUM, 0, 2731818d276cSGirish Shilamkar JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); 2732818d276cSGirish Shilamkar } 2733818d276cSGirish Shilamkar 2734ac27a0ecSDave Kleikamp /* We have now updated the journal if required, so we can 2735ac27a0ecSDave Kleikamp * validate the data journaling mode. */ 2736ac27a0ecSDave Kleikamp switch (test_opt(sb, DATA_FLAGS)) { 2737ac27a0ecSDave Kleikamp case 0: 2738ac27a0ecSDave Kleikamp /* No mode set, assume a default based on the journal 273963f57933SAndrew Morton * capabilities: ORDERED_DATA if the journal can 274063f57933SAndrew Morton * cope, else JOURNAL_DATA 274163f57933SAndrew Morton */ 2742dab291afSMingming Cao if (jbd2_journal_check_available_features 2743dab291afSMingming Cao (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) 2744ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, ORDERED_DATA); 2745ac27a0ecSDave Kleikamp else 2746ac27a0ecSDave Kleikamp set_opt(sbi->s_mount_opt, JOURNAL_DATA); 2747ac27a0ecSDave Kleikamp break; 2748ac27a0ecSDave Kleikamp 2749617ba13bSMingming Cao case EXT4_MOUNT_ORDERED_DATA: 2750617ba13bSMingming Cao case EXT4_MOUNT_WRITEBACK_DATA: 2751dab291afSMingming Cao if (!jbd2_journal_check_available_features 2752dab291afSMingming Cao (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) { 2753617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: Journal does not support " 2754ac27a0ecSDave Kleikamp "requested data journaling mode\n"); 2755ac27a0ecSDave Kleikamp goto failed_mount4; 2756ac27a0ecSDave Kleikamp } 2757ac27a0ecSDave Kleikamp default: 2758ac27a0ecSDave Kleikamp break; 2759ac27a0ecSDave Kleikamp } 2760b3881f74STheodore Ts'o set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); 2761ac27a0ecSDave Kleikamp 27620390131bSFrank Mayhar no_journal: 2763ac27a0ecSDave Kleikamp 2764ac27a0ecSDave Kleikamp if (test_opt(sb, NOBH)) { 2765617ba13bSMingming Cao if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) { 2766617ba13bSMingming Cao printk(KERN_WARNING "EXT4-fs: Ignoring nobh option - " 2767ac27a0ecSDave Kleikamp "its supported only with writeback mode\n"); 2768ac27a0ecSDave Kleikamp clear_opt(sbi->s_mount_opt, NOBH); 2769ac27a0ecSDave Kleikamp } 2770ac27a0ecSDave Kleikamp } 2771ac27a0ecSDave Kleikamp /* 2772dab291afSMingming Cao * The jbd2_journal_load will have done any necessary log recovery, 2773ac27a0ecSDave Kleikamp * so we can safely mount the rest of the filesystem now. 2774ac27a0ecSDave Kleikamp */ 2775ac27a0ecSDave Kleikamp 27761d1fe1eeSDavid Howells root = ext4_iget(sb, EXT4_ROOT_INO); 27771d1fe1eeSDavid Howells if (IS_ERR(root)) { 2778617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: get root inode failed\n"); 27791d1fe1eeSDavid Howells ret = PTR_ERR(root); 2780ac27a0ecSDave Kleikamp goto failed_mount4; 2781ac27a0ecSDave Kleikamp } 2782ac27a0ecSDave Kleikamp if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { 27831d1fe1eeSDavid Howells iput(root); 2784617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n"); 2785ac27a0ecSDave Kleikamp goto failed_mount4; 2786ac27a0ecSDave Kleikamp } 27871d1fe1eeSDavid Howells sb->s_root = d_alloc_root(root); 27881d1fe1eeSDavid Howells if (!sb->s_root) { 27891d1fe1eeSDavid Howells printk(KERN_ERR "EXT4-fs: get root dentry failed\n"); 27901d1fe1eeSDavid Howells iput(root); 27911d1fe1eeSDavid Howells ret = -ENOMEM; 27921d1fe1eeSDavid Howells goto failed_mount4; 27931d1fe1eeSDavid Howells } 2794ac27a0ecSDave Kleikamp 2795617ba13bSMingming Cao ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY); 2796ef7f3835SKalpak Shah 2797ef7f3835SKalpak Shah /* determine the minimum size of new large inodes, if present */ 2798ef7f3835SKalpak Shah if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) { 2799ef7f3835SKalpak Shah sbi->s_want_extra_isize = sizeof(struct ext4_inode) - 2800ef7f3835SKalpak Shah EXT4_GOOD_OLD_INODE_SIZE; 2801ef7f3835SKalpak Shah if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 2802ef7f3835SKalpak Shah EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)) { 2803ef7f3835SKalpak Shah if (sbi->s_want_extra_isize < 2804ef7f3835SKalpak Shah le16_to_cpu(es->s_want_extra_isize)) 2805ef7f3835SKalpak Shah sbi->s_want_extra_isize = 2806ef7f3835SKalpak Shah le16_to_cpu(es->s_want_extra_isize); 2807ef7f3835SKalpak Shah if (sbi->s_want_extra_isize < 2808ef7f3835SKalpak Shah le16_to_cpu(es->s_min_extra_isize)) 2809ef7f3835SKalpak Shah sbi->s_want_extra_isize = 2810ef7f3835SKalpak Shah le16_to_cpu(es->s_min_extra_isize); 2811ef7f3835SKalpak Shah } 2812ef7f3835SKalpak Shah } 2813ef7f3835SKalpak Shah /* Check if enough inode space is available */ 2814ef7f3835SKalpak Shah if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize > 2815ef7f3835SKalpak Shah sbi->s_inode_size) { 2816ef7f3835SKalpak Shah sbi->s_want_extra_isize = sizeof(struct ext4_inode) - 2817ef7f3835SKalpak Shah EXT4_GOOD_OLD_INODE_SIZE; 2818ef7f3835SKalpak Shah printk(KERN_INFO "EXT4-fs: required extra inode space not" 2819ef7f3835SKalpak Shah "available.\n"); 2820ef7f3835SKalpak Shah } 2821ef7f3835SKalpak Shah 2822c2774d84SAneesh Kumar K.V if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) { 2823c2774d84SAneesh Kumar K.V printk(KERN_WARNING "EXT4-fs: Ignoring delalloc option - " 2824c2774d84SAneesh Kumar K.V "requested data journaling mode\n"); 2825c2774d84SAneesh Kumar K.V clear_opt(sbi->s_mount_opt, DELALLOC); 2826c2774d84SAneesh Kumar K.V } else if (test_opt(sb, DELALLOC)) 2827c2774d84SAneesh Kumar K.V printk(KERN_INFO "EXT4-fs: delayed allocation enabled\n"); 2828c2774d84SAneesh Kumar K.V 2829c2774d84SAneesh Kumar K.V ext4_ext_init(sb); 2830c2774d84SAneesh Kumar K.V err = ext4_mb_init(sb, needs_recovery); 2831c2774d84SAneesh Kumar K.V if (err) { 2832c2774d84SAneesh Kumar K.V printk(KERN_ERR "EXT4-fs: failed to initalize mballoc (%d)\n", 2833c2774d84SAneesh Kumar K.V err); 2834c2774d84SAneesh Kumar K.V goto failed_mount4; 2835c2774d84SAneesh Kumar K.V } 2836c2774d84SAneesh Kumar K.V 28373197ebdbSTheodore Ts'o sbi->s_kobj.kset = ext4_kset; 28383197ebdbSTheodore Ts'o init_completion(&sbi->s_kobj_unregister); 28393197ebdbSTheodore Ts'o err = kobject_init_and_add(&sbi->s_kobj, &ext4_ktype, NULL, 28403197ebdbSTheodore Ts'o "%s", sb->s_id); 28413197ebdbSTheodore Ts'o if (err) { 28423197ebdbSTheodore Ts'o ext4_mb_release(sb); 28433197ebdbSTheodore Ts'o ext4_ext_release(sb); 28443197ebdbSTheodore Ts'o goto failed_mount4; 28453197ebdbSTheodore Ts'o }; 28463197ebdbSTheodore Ts'o 2847617ba13bSMingming Cao EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; 2848617ba13bSMingming Cao ext4_orphan_cleanup(sb, es); 2849617ba13bSMingming Cao EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS; 28500390131bSFrank Mayhar if (needs_recovery) { 2851617ba13bSMingming Cao printk(KERN_INFO "EXT4-fs: recovery complete.\n"); 2852617ba13bSMingming Cao ext4_mark_recovery_complete(sb, es); 28530390131bSFrank Mayhar } 28540390131bSFrank Mayhar if (EXT4_SB(sb)->s_journal) { 28550390131bSFrank Mayhar if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) 28560390131bSFrank Mayhar descr = " journalled data mode"; 28570390131bSFrank Mayhar else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) 28580390131bSFrank Mayhar descr = " ordered data mode"; 28590390131bSFrank Mayhar else 28600390131bSFrank Mayhar descr = " writeback data mode"; 28610390131bSFrank Mayhar } else 28620390131bSFrank Mayhar descr = "out journal"; 28630390131bSFrank Mayhar 28640390131bSFrank Mayhar printk(KERN_INFO "EXT4-fs: mounted filesystem %s with%s\n", 28650390131bSFrank Mayhar sb->s_id, descr); 2866ac27a0ecSDave Kleikamp 2867ac27a0ecSDave Kleikamp lock_kernel(); 2868ac27a0ecSDave Kleikamp return 0; 2869ac27a0ecSDave Kleikamp 2870617ba13bSMingming Cao cantfind_ext4: 2871ac27a0ecSDave Kleikamp if (!silent) 2872617ba13bSMingming Cao printk(KERN_ERR "VFS: Can't find ext4 filesystem on dev %s.\n", 2873ac27a0ecSDave Kleikamp sb->s_id); 2874ac27a0ecSDave Kleikamp goto failed_mount; 2875ac27a0ecSDave Kleikamp 2876ac27a0ecSDave Kleikamp failed_mount4: 28770390131bSFrank Mayhar printk(KERN_ERR "EXT4-fs (device %s): mount failed\n", sb->s_id); 28780390131bSFrank Mayhar if (sbi->s_journal) { 2879dab291afSMingming Cao jbd2_journal_destroy(sbi->s_journal); 288047b4a50bSJan Kara sbi->s_journal = NULL; 28810390131bSFrank Mayhar } 2882ac27a0ecSDave Kleikamp failed_mount3: 2883c5ca7c76STheodore Ts'o if (sbi->s_flex_groups) { 2884c5ca7c76STheodore Ts'o if (is_vmalloc_addr(sbi->s_flex_groups)) 2885c5ca7c76STheodore Ts'o vfree(sbi->s_flex_groups); 2886c5ca7c76STheodore Ts'o else 2887c5ca7c76STheodore Ts'o kfree(sbi->s_flex_groups); 2888c5ca7c76STheodore Ts'o } 2889ac27a0ecSDave Kleikamp percpu_counter_destroy(&sbi->s_freeblocks_counter); 2890ac27a0ecSDave Kleikamp percpu_counter_destroy(&sbi->s_freeinodes_counter); 2891ac27a0ecSDave Kleikamp percpu_counter_destroy(&sbi->s_dirs_counter); 28926bc6e63fSAneesh Kumar K.V percpu_counter_destroy(&sbi->s_dirtyblocks_counter); 2893ac27a0ecSDave Kleikamp failed_mount2: 2894ac27a0ecSDave Kleikamp for (i = 0; i < db_count; i++) 2895ac27a0ecSDave Kleikamp brelse(sbi->s_group_desc[i]); 2896ac27a0ecSDave Kleikamp kfree(sbi->s_group_desc); 2897ac27a0ecSDave Kleikamp failed_mount: 2898240799cdSTheodore Ts'o if (sbi->s_proc) { 28999f6200bbSTheodore Ts'o remove_proc_entry(sb->s_id, ext4_proc_root); 2900240799cdSTheodore Ts'o } 2901ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 2902ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) 2903ac27a0ecSDave Kleikamp kfree(sbi->s_qf_names[i]); 2904ac27a0ecSDave Kleikamp #endif 2905617ba13bSMingming Cao ext4_blkdev_remove(sbi); 2906ac27a0ecSDave Kleikamp brelse(bh); 2907ac27a0ecSDave Kleikamp out_fail: 2908ac27a0ecSDave Kleikamp sb->s_fs_info = NULL; 2909ac27a0ecSDave Kleikamp kfree(sbi); 2910ac27a0ecSDave Kleikamp lock_kernel(); 29111d1fe1eeSDavid Howells return ret; 2912ac27a0ecSDave Kleikamp } 2913ac27a0ecSDave Kleikamp 2914ac27a0ecSDave Kleikamp /* 2915ac27a0ecSDave Kleikamp * Setup any per-fs journal parameters now. We'll do this both on 2916ac27a0ecSDave Kleikamp * initial mount, once the journal has been initialised but before we've 2917ac27a0ecSDave Kleikamp * done any recovery; and again on any subsequent remount. 2918ac27a0ecSDave Kleikamp */ 2919617ba13bSMingming Cao static void ext4_init_journal_params(struct super_block *sb, journal_t *journal) 2920ac27a0ecSDave Kleikamp { 2921617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 2922ac27a0ecSDave Kleikamp 2923ac27a0ecSDave Kleikamp journal->j_commit_interval = sbi->s_commit_interval; 292430773840STheodore Ts'o journal->j_min_batch_time = sbi->s_min_batch_time; 292530773840STheodore Ts'o journal->j_max_batch_time = sbi->s_max_batch_time; 2926ac27a0ecSDave Kleikamp 2927ac27a0ecSDave Kleikamp spin_lock(&journal->j_state_lock); 2928ac27a0ecSDave Kleikamp if (test_opt(sb, BARRIER)) 2929dab291afSMingming Cao journal->j_flags |= JBD2_BARRIER; 2930ac27a0ecSDave Kleikamp else 2931dab291afSMingming Cao journal->j_flags &= ~JBD2_BARRIER; 29325bf5683aSHidehiro Kawai if (test_opt(sb, DATA_ERR_ABORT)) 29335bf5683aSHidehiro Kawai journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR; 29345bf5683aSHidehiro Kawai else 29355bf5683aSHidehiro Kawai journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR; 2936ac27a0ecSDave Kleikamp spin_unlock(&journal->j_state_lock); 2937ac27a0ecSDave Kleikamp } 2938ac27a0ecSDave Kleikamp 2939617ba13bSMingming Cao static journal_t *ext4_get_journal(struct super_block *sb, 2940ac27a0ecSDave Kleikamp unsigned int journal_inum) 2941ac27a0ecSDave Kleikamp { 2942ac27a0ecSDave Kleikamp struct inode *journal_inode; 2943ac27a0ecSDave Kleikamp journal_t *journal; 2944ac27a0ecSDave Kleikamp 29450390131bSFrank Mayhar BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 29460390131bSFrank Mayhar 2947ac27a0ecSDave Kleikamp /* First, test for the existence of a valid inode on disk. Bad 2948ac27a0ecSDave Kleikamp * things happen if we iget() an unused inode, as the subsequent 2949ac27a0ecSDave Kleikamp * iput() will try to delete it. */ 2950ac27a0ecSDave Kleikamp 29511d1fe1eeSDavid Howells journal_inode = ext4_iget(sb, journal_inum); 29521d1fe1eeSDavid Howells if (IS_ERR(journal_inode)) { 2953617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: no journal found.\n"); 2954ac27a0ecSDave Kleikamp return NULL; 2955ac27a0ecSDave Kleikamp } 2956ac27a0ecSDave Kleikamp if (!journal_inode->i_nlink) { 2957ac27a0ecSDave Kleikamp make_bad_inode(journal_inode); 2958ac27a0ecSDave Kleikamp iput(journal_inode); 2959617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: journal inode is deleted.\n"); 2960ac27a0ecSDave Kleikamp return NULL; 2961ac27a0ecSDave Kleikamp } 2962ac27a0ecSDave Kleikamp 2963e5f8eab8STheodore Ts'o jbd_debug(2, "Journal inode found at %p: %lld bytes\n", 2964ac27a0ecSDave Kleikamp journal_inode, journal_inode->i_size); 29651d1fe1eeSDavid Howells if (!S_ISREG(journal_inode->i_mode)) { 2966617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: invalid journal inode.\n"); 2967ac27a0ecSDave Kleikamp iput(journal_inode); 2968ac27a0ecSDave Kleikamp return NULL; 2969ac27a0ecSDave Kleikamp } 2970ac27a0ecSDave Kleikamp 2971dab291afSMingming Cao journal = jbd2_journal_init_inode(journal_inode); 2972ac27a0ecSDave Kleikamp if (!journal) { 2973617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: Could not load journal inode\n"); 2974ac27a0ecSDave Kleikamp iput(journal_inode); 2975ac27a0ecSDave Kleikamp return NULL; 2976ac27a0ecSDave Kleikamp } 2977ac27a0ecSDave Kleikamp journal->j_private = sb; 2978617ba13bSMingming Cao ext4_init_journal_params(sb, journal); 2979ac27a0ecSDave Kleikamp return journal; 2980ac27a0ecSDave Kleikamp } 2981ac27a0ecSDave Kleikamp 2982617ba13bSMingming Cao static journal_t *ext4_get_dev_journal(struct super_block *sb, 2983ac27a0ecSDave Kleikamp dev_t j_dev) 2984ac27a0ecSDave Kleikamp { 2985ac27a0ecSDave Kleikamp struct buffer_head *bh; 2986ac27a0ecSDave Kleikamp journal_t *journal; 2987617ba13bSMingming Cao ext4_fsblk_t start; 2988617ba13bSMingming Cao ext4_fsblk_t len; 2989ac27a0ecSDave Kleikamp int hblock, blocksize; 2990617ba13bSMingming Cao ext4_fsblk_t sb_block; 2991ac27a0ecSDave Kleikamp unsigned long offset; 2992617ba13bSMingming Cao struct ext4_super_block *es; 2993ac27a0ecSDave Kleikamp struct block_device *bdev; 2994ac27a0ecSDave Kleikamp 29950390131bSFrank Mayhar BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 29960390131bSFrank Mayhar 2997617ba13bSMingming Cao bdev = ext4_blkdev_get(j_dev); 2998ac27a0ecSDave Kleikamp if (bdev == NULL) 2999ac27a0ecSDave Kleikamp return NULL; 3000ac27a0ecSDave Kleikamp 3001ac27a0ecSDave Kleikamp if (bd_claim(bdev, sb)) { 3002ac27a0ecSDave Kleikamp printk(KERN_ERR 3003abda1418STheodore Ts'o "EXT4-fs: failed to claim external journal device.\n"); 30049a1c3542SAl Viro blkdev_put(bdev, FMODE_READ|FMODE_WRITE); 3005ac27a0ecSDave Kleikamp return NULL; 3006ac27a0ecSDave Kleikamp } 3007ac27a0ecSDave Kleikamp 3008ac27a0ecSDave Kleikamp blocksize = sb->s_blocksize; 3009ac27a0ecSDave Kleikamp hblock = bdev_hardsect_size(bdev); 3010ac27a0ecSDave Kleikamp if (blocksize < hblock) { 3011ac27a0ecSDave Kleikamp printk(KERN_ERR 3012617ba13bSMingming Cao "EXT4-fs: blocksize too small for journal device.\n"); 3013ac27a0ecSDave Kleikamp goto out_bdev; 3014ac27a0ecSDave Kleikamp } 3015ac27a0ecSDave Kleikamp 3016617ba13bSMingming Cao sb_block = EXT4_MIN_BLOCK_SIZE / blocksize; 3017617ba13bSMingming Cao offset = EXT4_MIN_BLOCK_SIZE % blocksize; 3018ac27a0ecSDave Kleikamp set_blocksize(bdev, blocksize); 3019ac27a0ecSDave Kleikamp if (!(bh = __bread(bdev, sb_block, blocksize))) { 3020617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: couldn't read superblock of " 3021ac27a0ecSDave Kleikamp "external journal\n"); 3022ac27a0ecSDave Kleikamp goto out_bdev; 3023ac27a0ecSDave Kleikamp } 3024ac27a0ecSDave Kleikamp 3025617ba13bSMingming Cao es = (struct ext4_super_block *) (((char *)bh->b_data) + offset); 3026617ba13bSMingming Cao if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) || 3027ac27a0ecSDave Kleikamp !(le32_to_cpu(es->s_feature_incompat) & 3028617ba13bSMingming Cao EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) { 3029617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: external journal has " 3030ac27a0ecSDave Kleikamp "bad superblock\n"); 3031ac27a0ecSDave Kleikamp brelse(bh); 3032ac27a0ecSDave Kleikamp goto out_bdev; 3033ac27a0ecSDave Kleikamp } 3034ac27a0ecSDave Kleikamp 3035617ba13bSMingming Cao if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { 3036617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: journal UUID does not match\n"); 3037ac27a0ecSDave Kleikamp brelse(bh); 3038ac27a0ecSDave Kleikamp goto out_bdev; 3039ac27a0ecSDave Kleikamp } 3040ac27a0ecSDave Kleikamp 3041bd81d8eeSLaurent Vivier len = ext4_blocks_count(es); 3042ac27a0ecSDave Kleikamp start = sb_block + 1; 3043ac27a0ecSDave Kleikamp brelse(bh); /* we're done with the superblock */ 3044ac27a0ecSDave Kleikamp 3045dab291afSMingming Cao journal = jbd2_journal_init_dev(bdev, sb->s_bdev, 3046ac27a0ecSDave Kleikamp start, len, blocksize); 3047ac27a0ecSDave Kleikamp if (!journal) { 3048617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: failed to create device journal\n"); 3049ac27a0ecSDave Kleikamp goto out_bdev; 3050ac27a0ecSDave Kleikamp } 3051ac27a0ecSDave Kleikamp journal->j_private = sb; 3052ac27a0ecSDave Kleikamp ll_rw_block(READ, 1, &journal->j_sb_buffer); 3053ac27a0ecSDave Kleikamp wait_on_buffer(journal->j_sb_buffer); 3054ac27a0ecSDave Kleikamp if (!buffer_uptodate(journal->j_sb_buffer)) { 3055617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: I/O error on journal device\n"); 3056ac27a0ecSDave Kleikamp goto out_journal; 3057ac27a0ecSDave Kleikamp } 3058ac27a0ecSDave Kleikamp if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) { 3059617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: External journal has more than one " 3060ac27a0ecSDave Kleikamp "user (unsupported) - %d\n", 3061ac27a0ecSDave Kleikamp be32_to_cpu(journal->j_superblock->s_nr_users)); 3062ac27a0ecSDave Kleikamp goto out_journal; 3063ac27a0ecSDave Kleikamp } 3064617ba13bSMingming Cao EXT4_SB(sb)->journal_bdev = bdev; 3065617ba13bSMingming Cao ext4_init_journal_params(sb, journal); 3066ac27a0ecSDave Kleikamp return journal; 3067ac27a0ecSDave Kleikamp out_journal: 3068dab291afSMingming Cao jbd2_journal_destroy(journal); 3069ac27a0ecSDave Kleikamp out_bdev: 3070617ba13bSMingming Cao ext4_blkdev_put(bdev); 3071ac27a0ecSDave Kleikamp return NULL; 3072ac27a0ecSDave Kleikamp } 3073ac27a0ecSDave Kleikamp 3074617ba13bSMingming Cao static int ext4_load_journal(struct super_block *sb, 3075617ba13bSMingming Cao struct ext4_super_block *es, 3076ac27a0ecSDave Kleikamp unsigned long journal_devnum) 3077ac27a0ecSDave Kleikamp { 3078ac27a0ecSDave Kleikamp journal_t *journal; 3079ac27a0ecSDave Kleikamp unsigned int journal_inum = le32_to_cpu(es->s_journal_inum); 3080ac27a0ecSDave Kleikamp dev_t journal_dev; 3081ac27a0ecSDave Kleikamp int err = 0; 3082ac27a0ecSDave Kleikamp int really_read_only; 3083ac27a0ecSDave Kleikamp 30840390131bSFrank Mayhar BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 30850390131bSFrank Mayhar 3086ac27a0ecSDave Kleikamp if (journal_devnum && 3087ac27a0ecSDave Kleikamp journal_devnum != le32_to_cpu(es->s_journal_dev)) { 3088617ba13bSMingming Cao printk(KERN_INFO "EXT4-fs: external journal device major/minor " 3089ac27a0ecSDave Kleikamp "numbers have changed\n"); 3090ac27a0ecSDave Kleikamp journal_dev = new_decode_dev(journal_devnum); 3091ac27a0ecSDave Kleikamp } else 3092ac27a0ecSDave Kleikamp journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev)); 3093ac27a0ecSDave Kleikamp 3094ac27a0ecSDave Kleikamp really_read_only = bdev_read_only(sb->s_bdev); 3095ac27a0ecSDave Kleikamp 3096ac27a0ecSDave Kleikamp /* 3097ac27a0ecSDave Kleikamp * Are we loading a blank journal or performing recovery after a 3098ac27a0ecSDave Kleikamp * crash? For recovery, we need to check in advance whether we 3099ac27a0ecSDave Kleikamp * can get read-write access to the device. 3100ac27a0ecSDave Kleikamp */ 3101ac27a0ecSDave Kleikamp 3102617ba13bSMingming Cao if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { 3103ac27a0ecSDave Kleikamp if (sb->s_flags & MS_RDONLY) { 3104617ba13bSMingming Cao printk(KERN_INFO "EXT4-fs: INFO: recovery " 3105ac27a0ecSDave Kleikamp "required on readonly filesystem.\n"); 3106ac27a0ecSDave Kleikamp if (really_read_only) { 3107617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: write access " 3108ac27a0ecSDave Kleikamp "unavailable, cannot proceed.\n"); 3109ac27a0ecSDave Kleikamp return -EROFS; 3110ac27a0ecSDave Kleikamp } 3111617ba13bSMingming Cao printk(KERN_INFO "EXT4-fs: write access will " 3112ac27a0ecSDave Kleikamp "be enabled during recovery.\n"); 3113ac27a0ecSDave Kleikamp } 3114ac27a0ecSDave Kleikamp } 3115ac27a0ecSDave Kleikamp 3116ac27a0ecSDave Kleikamp if (journal_inum && journal_dev) { 3117617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: filesystem has both journal " 3118ac27a0ecSDave Kleikamp "and inode journals!\n"); 3119ac27a0ecSDave Kleikamp return -EINVAL; 3120ac27a0ecSDave Kleikamp } 3121ac27a0ecSDave Kleikamp 3122ac27a0ecSDave Kleikamp if (journal_inum) { 3123617ba13bSMingming Cao if (!(journal = ext4_get_journal(sb, journal_inum))) 3124ac27a0ecSDave Kleikamp return -EINVAL; 3125ac27a0ecSDave Kleikamp } else { 3126617ba13bSMingming Cao if (!(journal = ext4_get_dev_journal(sb, journal_dev))) 3127ac27a0ecSDave Kleikamp return -EINVAL; 3128ac27a0ecSDave Kleikamp } 3129ac27a0ecSDave Kleikamp 31304776004fSTheodore Ts'o if (journal->j_flags & JBD2_BARRIER) 31314776004fSTheodore Ts'o printk(KERN_INFO "EXT4-fs: barriers enabled\n"); 31324776004fSTheodore Ts'o else 31334776004fSTheodore Ts'o printk(KERN_INFO "EXT4-fs: barriers disabled\n"); 31344776004fSTheodore Ts'o 3135ac27a0ecSDave Kleikamp if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) { 3136dab291afSMingming Cao err = jbd2_journal_update_format(journal); 3137ac27a0ecSDave Kleikamp if (err) { 3138617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: error updating journal.\n"); 3139dab291afSMingming Cao jbd2_journal_destroy(journal); 3140ac27a0ecSDave Kleikamp return err; 3141ac27a0ecSDave Kleikamp } 3142ac27a0ecSDave Kleikamp } 3143ac27a0ecSDave Kleikamp 3144617ba13bSMingming Cao if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) 3145dab291afSMingming Cao err = jbd2_journal_wipe(journal, !really_read_only); 3146ac27a0ecSDave Kleikamp if (!err) 3147dab291afSMingming Cao err = jbd2_journal_load(journal); 3148ac27a0ecSDave Kleikamp 3149ac27a0ecSDave Kleikamp if (err) { 3150617ba13bSMingming Cao printk(KERN_ERR "EXT4-fs: error loading journal.\n"); 3151dab291afSMingming Cao jbd2_journal_destroy(journal); 3152ac27a0ecSDave Kleikamp return err; 3153ac27a0ecSDave Kleikamp } 3154ac27a0ecSDave Kleikamp 3155617ba13bSMingming Cao EXT4_SB(sb)->s_journal = journal; 3156617ba13bSMingming Cao ext4_clear_journal_err(sb, es); 3157ac27a0ecSDave Kleikamp 3158ac27a0ecSDave Kleikamp if (journal_devnum && 3159ac27a0ecSDave Kleikamp journal_devnum != le32_to_cpu(es->s_journal_dev)) { 3160ac27a0ecSDave Kleikamp es->s_journal_dev = cpu_to_le32(journal_devnum); 3161ac27a0ecSDave Kleikamp 3162ac27a0ecSDave Kleikamp /* Make sure we flush the recovery flag to disk. */ 3163e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 3164ac27a0ecSDave Kleikamp } 3165ac27a0ecSDave Kleikamp 3166ac27a0ecSDave Kleikamp return 0; 3167ac27a0ecSDave Kleikamp } 3168ac27a0ecSDave Kleikamp 3169e2d67052STheodore Ts'o static int ext4_commit_super(struct super_block *sb, int sync) 3170ac27a0ecSDave Kleikamp { 3171e2d67052STheodore Ts'o struct ext4_super_block *es = EXT4_SB(sb)->s_es; 3172617ba13bSMingming Cao struct buffer_head *sbh = EXT4_SB(sb)->s_sbh; 3173c4be0c1dSTakashi Sato int error = 0; 3174ac27a0ecSDave Kleikamp 3175ac27a0ecSDave Kleikamp if (!sbh) 3176c4be0c1dSTakashi Sato return error; 3177914258bfSTheodore Ts'o if (buffer_write_io_error(sbh)) { 3178914258bfSTheodore Ts'o /* 3179914258bfSTheodore Ts'o * Oh, dear. A previous attempt to write the 3180914258bfSTheodore Ts'o * superblock failed. This could happen because the 3181914258bfSTheodore Ts'o * USB device was yanked out. Or it could happen to 3182914258bfSTheodore Ts'o * be a transient write error and maybe the block will 3183914258bfSTheodore Ts'o * be remapped. Nothing we can do but to retry the 3184914258bfSTheodore Ts'o * write and hope for the best. 3185914258bfSTheodore Ts'o */ 3186abda1418STheodore Ts'o printk(KERN_ERR "EXT4-fs: previous I/O error to " 3187914258bfSTheodore Ts'o "superblock detected for %s.\n", sb->s_id); 3188914258bfSTheodore Ts'o clear_buffer_write_io_error(sbh); 3189914258bfSTheodore Ts'o set_buffer_uptodate(sbh); 3190914258bfSTheodore Ts'o } 3191ac27a0ecSDave Kleikamp es->s_wtime = cpu_to_le32(get_seconds()); 3192afc32f7eSTheodore Ts'o es->s_kbytes_written = 3193afc32f7eSTheodore Ts'o cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + 3194afc32f7eSTheodore Ts'o ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 3195afc32f7eSTheodore Ts'o EXT4_SB(sb)->s_sectors_written_start) >> 1)); 31965d1b1b3fSAneesh Kumar K.V ext4_free_blocks_count_set(es, percpu_counter_sum_positive( 31975d1b1b3fSAneesh Kumar K.V &EXT4_SB(sb)->s_freeblocks_counter)); 31985d1b1b3fSAneesh Kumar K.V es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive( 31995d1b1b3fSAneesh Kumar K.V &EXT4_SB(sb)->s_freeinodes_counter)); 32007234ab2aSTheodore Ts'o sb->s_dirt = 0; 3201ac27a0ecSDave Kleikamp BUFFER_TRACE(sbh, "marking dirty"); 3202ac27a0ecSDave Kleikamp mark_buffer_dirty(sbh); 3203914258bfSTheodore Ts'o if (sync) { 3204c4be0c1dSTakashi Sato error = sync_dirty_buffer(sbh); 3205c4be0c1dSTakashi Sato if (error) 3206c4be0c1dSTakashi Sato return error; 3207c4be0c1dSTakashi Sato 3208c4be0c1dSTakashi Sato error = buffer_write_io_error(sbh); 3209c4be0c1dSTakashi Sato if (error) { 3210abda1418STheodore Ts'o printk(KERN_ERR "EXT4-fs: I/O error while writing " 3211914258bfSTheodore Ts'o "superblock for %s.\n", sb->s_id); 3212914258bfSTheodore Ts'o clear_buffer_write_io_error(sbh); 3213914258bfSTheodore Ts'o set_buffer_uptodate(sbh); 3214914258bfSTheodore Ts'o } 3215914258bfSTheodore Ts'o } 3216c4be0c1dSTakashi Sato return error; 3217ac27a0ecSDave Kleikamp } 3218ac27a0ecSDave Kleikamp 3219ac27a0ecSDave Kleikamp 3220ac27a0ecSDave Kleikamp /* 3221ac27a0ecSDave Kleikamp * Have we just finished recovery? If so, and if we are mounting (or 3222ac27a0ecSDave Kleikamp * remounting) the filesystem readonly, then we will end up with a 3223ac27a0ecSDave Kleikamp * consistent fs on disk. Record that fact. 3224ac27a0ecSDave Kleikamp */ 3225617ba13bSMingming Cao static void ext4_mark_recovery_complete(struct super_block *sb, 3226617ba13bSMingming Cao struct ext4_super_block *es) 3227ac27a0ecSDave Kleikamp { 3228617ba13bSMingming Cao journal_t *journal = EXT4_SB(sb)->s_journal; 3229ac27a0ecSDave Kleikamp 32300390131bSFrank Mayhar if (!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) { 32310390131bSFrank Mayhar BUG_ON(journal != NULL); 32320390131bSFrank Mayhar return; 32330390131bSFrank Mayhar } 3234dab291afSMingming Cao jbd2_journal_lock_updates(journal); 32357ffe1ea8SHidehiro Kawai if (jbd2_journal_flush(journal) < 0) 32367ffe1ea8SHidehiro Kawai goto out; 32377ffe1ea8SHidehiro Kawai 3238617ba13bSMingming Cao if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) && 3239ac27a0ecSDave Kleikamp sb->s_flags & MS_RDONLY) { 3240617ba13bSMingming Cao EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3241e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 3242ac27a0ecSDave Kleikamp } 32437ffe1ea8SHidehiro Kawai 32447ffe1ea8SHidehiro Kawai out: 3245dab291afSMingming Cao jbd2_journal_unlock_updates(journal); 3246ac27a0ecSDave Kleikamp } 3247ac27a0ecSDave Kleikamp 3248ac27a0ecSDave Kleikamp /* 3249ac27a0ecSDave Kleikamp * If we are mounting (or read-write remounting) a filesystem whose journal 3250ac27a0ecSDave Kleikamp * has recorded an error from a previous lifetime, move that error to the 3251ac27a0ecSDave Kleikamp * main filesystem now. 3252ac27a0ecSDave Kleikamp */ 3253617ba13bSMingming Cao static void ext4_clear_journal_err(struct super_block *sb, 3254617ba13bSMingming Cao struct ext4_super_block *es) 3255ac27a0ecSDave Kleikamp { 3256ac27a0ecSDave Kleikamp journal_t *journal; 3257ac27a0ecSDave Kleikamp int j_errno; 3258ac27a0ecSDave Kleikamp const char *errstr; 3259ac27a0ecSDave Kleikamp 32600390131bSFrank Mayhar BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 32610390131bSFrank Mayhar 3262617ba13bSMingming Cao journal = EXT4_SB(sb)->s_journal; 3263ac27a0ecSDave Kleikamp 3264ac27a0ecSDave Kleikamp /* 3265ac27a0ecSDave Kleikamp * Now check for any error status which may have been recorded in the 3266617ba13bSMingming Cao * journal by a prior ext4_error() or ext4_abort() 3267ac27a0ecSDave Kleikamp */ 3268ac27a0ecSDave Kleikamp 3269dab291afSMingming Cao j_errno = jbd2_journal_errno(journal); 3270ac27a0ecSDave Kleikamp if (j_errno) { 3271ac27a0ecSDave Kleikamp char nbuf[16]; 3272ac27a0ecSDave Kleikamp 3273617ba13bSMingming Cao errstr = ext4_decode_error(sb, j_errno, nbuf); 327446e665e9SHarvey Harrison ext4_warning(sb, __func__, "Filesystem error recorded " 3275ac27a0ecSDave Kleikamp "from previous mount: %s", errstr); 327646e665e9SHarvey Harrison ext4_warning(sb, __func__, "Marking fs in need of " 3277ac27a0ecSDave Kleikamp "filesystem check."); 3278ac27a0ecSDave Kleikamp 3279617ba13bSMingming Cao EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 3280617ba13bSMingming Cao es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 3281e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 3282ac27a0ecSDave Kleikamp 3283dab291afSMingming Cao jbd2_journal_clear_err(journal); 3284ac27a0ecSDave Kleikamp } 3285ac27a0ecSDave Kleikamp } 3286ac27a0ecSDave Kleikamp 3287ac27a0ecSDave Kleikamp /* 3288ac27a0ecSDave Kleikamp * Force the running and committing transactions to commit, 3289ac27a0ecSDave Kleikamp * and wait on the commit. 3290ac27a0ecSDave Kleikamp */ 3291617ba13bSMingming Cao int ext4_force_commit(struct super_block *sb) 3292ac27a0ecSDave Kleikamp { 3293ac27a0ecSDave Kleikamp journal_t *journal; 32940390131bSFrank Mayhar int ret = 0; 3295ac27a0ecSDave Kleikamp 3296ac27a0ecSDave Kleikamp if (sb->s_flags & MS_RDONLY) 3297ac27a0ecSDave Kleikamp return 0; 3298ac27a0ecSDave Kleikamp 3299617ba13bSMingming Cao journal = EXT4_SB(sb)->s_journal; 33007234ab2aSTheodore Ts'o if (journal) 3301617ba13bSMingming Cao ret = ext4_journal_force_commit(journal); 33020390131bSFrank Mayhar 3303ac27a0ecSDave Kleikamp return ret; 3304ac27a0ecSDave Kleikamp } 3305ac27a0ecSDave Kleikamp 3306617ba13bSMingming Cao static void ext4_write_super(struct super_block *sb) 3307ac27a0ecSDave Kleikamp { 3308e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 33090390131bSFrank Mayhar } 3310ac27a0ecSDave Kleikamp 3311617ba13bSMingming Cao static int ext4_sync_fs(struct super_block *sb, int wait) 3312ac27a0ecSDave Kleikamp { 331314ce0cb4STheodore Ts'o int ret = 0; 33149eddacf9SJan Kara tid_t target; 3315ac27a0ecSDave Kleikamp 3316ede86cc4STheodore Ts'o trace_mark(ext4_sync_fs, "dev %s wait %d", sb->s_id, wait); 33179ca92389STheodore Ts'o if (jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, &target)) { 3318ac27a0ecSDave Kleikamp if (wait) 33199ca92389STheodore Ts'o jbd2_log_wait_commit(EXT4_SB(sb)->s_journal, target); 33200390131bSFrank Mayhar } 332114ce0cb4STheodore Ts'o return ret; 3322ac27a0ecSDave Kleikamp } 3323ac27a0ecSDave Kleikamp 3324ac27a0ecSDave Kleikamp /* 3325ac27a0ecSDave Kleikamp * LVM calls this function before a (read-only) snapshot is created. This 3326ac27a0ecSDave Kleikamp * gives us a chance to flush the journal completely and mark the fs clean. 3327ac27a0ecSDave Kleikamp */ 3328c4be0c1dSTakashi Sato static int ext4_freeze(struct super_block *sb) 3329ac27a0ecSDave Kleikamp { 3330c4be0c1dSTakashi Sato int error = 0; 3331c4be0c1dSTakashi Sato journal_t *journal; 3332ac27a0ecSDave Kleikamp 33339ca92389STheodore Ts'o if (sb->s_flags & MS_RDONLY) 33349ca92389STheodore Ts'o return 0; 33359ca92389STheodore Ts'o 3336c4be0c1dSTakashi Sato journal = EXT4_SB(sb)->s_journal; 3337ac27a0ecSDave Kleikamp 3338ac27a0ecSDave Kleikamp /* Now we set up the journal barrier. */ 3339dab291afSMingming Cao jbd2_journal_lock_updates(journal); 33407ffe1ea8SHidehiro Kawai 33417ffe1ea8SHidehiro Kawai /* 33429ca92389STheodore Ts'o * Don't clear the needs_recovery flag if we failed to flush 33439ca92389STheodore Ts'o * the journal. 33447ffe1ea8SHidehiro Kawai */ 3345c4be0c1dSTakashi Sato error = jbd2_journal_flush(journal); 33469ca92389STheodore Ts'o if (error < 0) { 33479ca92389STheodore Ts'o out: 33489ca92389STheodore Ts'o jbd2_journal_unlock_updates(journal); 33499ca92389STheodore Ts'o return error; 33500390131bSFrank Mayhar } 3351ac27a0ecSDave Kleikamp 3352ac27a0ecSDave Kleikamp /* Journal blocked and flushed, clear needs_recovery flag. */ 3353617ba13bSMingming Cao EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3354e2d67052STheodore Ts'o error = ext4_commit_super(sb, 1); 3355c4be0c1dSTakashi Sato if (error) 3356c4be0c1dSTakashi Sato goto out; 3357c4be0c1dSTakashi Sato return 0; 3358ac27a0ecSDave Kleikamp } 3359ac27a0ecSDave Kleikamp 3360ac27a0ecSDave Kleikamp /* 3361ac27a0ecSDave Kleikamp * Called by LVM after the snapshot is done. We need to reset the RECOVER 3362ac27a0ecSDave Kleikamp * flag here, even though the filesystem is not technically dirty yet. 3363ac27a0ecSDave Kleikamp */ 3364c4be0c1dSTakashi Sato static int ext4_unfreeze(struct super_block *sb) 3365ac27a0ecSDave Kleikamp { 33669ca92389STheodore Ts'o if (sb->s_flags & MS_RDONLY) 33679ca92389STheodore Ts'o return 0; 33689ca92389STheodore Ts'o 3369ac27a0ecSDave Kleikamp lock_super(sb); 33709ca92389STheodore Ts'o /* Reset the needs_recovery flag before the fs is unlocked. */ 3371617ba13bSMingming Cao EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3372e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 3373ac27a0ecSDave Kleikamp unlock_super(sb); 3374dab291afSMingming Cao jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 3375c4be0c1dSTakashi Sato return 0; 3376ac27a0ecSDave Kleikamp } 3377ac27a0ecSDave Kleikamp 3378617ba13bSMingming Cao static int ext4_remount(struct super_block *sb, int *flags, char *data) 3379ac27a0ecSDave Kleikamp { 3380617ba13bSMingming Cao struct ext4_super_block *es; 3381617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 3382617ba13bSMingming Cao ext4_fsblk_t n_blocks_count = 0; 3383ac27a0ecSDave Kleikamp unsigned long old_sb_flags; 3384617ba13bSMingming Cao struct ext4_mount_options old_opts; 33858a266467STheodore Ts'o ext4_group_t g; 3386b3881f74STheodore Ts'o unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; 3387ac27a0ecSDave Kleikamp int err; 3388ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 3389ac27a0ecSDave Kleikamp int i; 3390ac27a0ecSDave Kleikamp #endif 3391ac27a0ecSDave Kleikamp 3392ac27a0ecSDave Kleikamp /* Store the original options */ 3393ac27a0ecSDave Kleikamp old_sb_flags = sb->s_flags; 3394ac27a0ecSDave Kleikamp old_opts.s_mount_opt = sbi->s_mount_opt; 3395ac27a0ecSDave Kleikamp old_opts.s_resuid = sbi->s_resuid; 3396ac27a0ecSDave Kleikamp old_opts.s_resgid = sbi->s_resgid; 3397ac27a0ecSDave Kleikamp old_opts.s_commit_interval = sbi->s_commit_interval; 339830773840STheodore Ts'o old_opts.s_min_batch_time = sbi->s_min_batch_time; 339930773840STheodore Ts'o old_opts.s_max_batch_time = sbi->s_max_batch_time; 3400ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 3401ac27a0ecSDave Kleikamp old_opts.s_jquota_fmt = sbi->s_jquota_fmt; 3402ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) 3403ac27a0ecSDave Kleikamp old_opts.s_qf_names[i] = sbi->s_qf_names[i]; 3404ac27a0ecSDave Kleikamp #endif 3405b3881f74STheodore Ts'o if (sbi->s_journal && sbi->s_journal->j_task->io_context) 3406b3881f74STheodore Ts'o journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; 3407ac27a0ecSDave Kleikamp 3408ac27a0ecSDave Kleikamp /* 3409ac27a0ecSDave Kleikamp * Allow the "check" option to be passed as a remount option. 3410ac27a0ecSDave Kleikamp */ 3411b3881f74STheodore Ts'o if (!parse_options(data, sb, NULL, &journal_ioprio, 3412b3881f74STheodore Ts'o &n_blocks_count, 1)) { 3413ac27a0ecSDave Kleikamp err = -EINVAL; 3414ac27a0ecSDave Kleikamp goto restore_opts; 3415ac27a0ecSDave Kleikamp } 3416ac27a0ecSDave Kleikamp 3417617ba13bSMingming Cao if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) 341846e665e9SHarvey Harrison ext4_abort(sb, __func__, "Abort forced by user"); 3419ac27a0ecSDave Kleikamp 3420ac27a0ecSDave Kleikamp sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 3421617ba13bSMingming Cao ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); 3422ac27a0ecSDave Kleikamp 3423ac27a0ecSDave Kleikamp es = sbi->s_es; 3424ac27a0ecSDave Kleikamp 3425b3881f74STheodore Ts'o if (sbi->s_journal) { 3426617ba13bSMingming Cao ext4_init_journal_params(sb, sbi->s_journal); 3427b3881f74STheodore Ts'o set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); 3428b3881f74STheodore Ts'o } 3429ac27a0ecSDave Kleikamp 3430ac27a0ecSDave Kleikamp if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) || 3431bd81d8eeSLaurent Vivier n_blocks_count > ext4_blocks_count(es)) { 3432617ba13bSMingming Cao if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) { 3433ac27a0ecSDave Kleikamp err = -EROFS; 3434ac27a0ecSDave Kleikamp goto restore_opts; 3435ac27a0ecSDave Kleikamp } 3436ac27a0ecSDave Kleikamp 3437ac27a0ecSDave Kleikamp if (*flags & MS_RDONLY) { 3438ac27a0ecSDave Kleikamp /* 3439ac27a0ecSDave Kleikamp * First of all, the unconditional stuff we have to do 3440ac27a0ecSDave Kleikamp * to disable replay of the journal when we next remount 3441ac27a0ecSDave Kleikamp */ 3442ac27a0ecSDave Kleikamp sb->s_flags |= MS_RDONLY; 3443ac27a0ecSDave Kleikamp 3444ac27a0ecSDave Kleikamp /* 3445ac27a0ecSDave Kleikamp * OK, test if we are remounting a valid rw partition 3446ac27a0ecSDave Kleikamp * readonly, and if so set the rdonly flag and then 3447ac27a0ecSDave Kleikamp * mark the partition as valid again. 3448ac27a0ecSDave Kleikamp */ 3449617ba13bSMingming Cao if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) && 3450617ba13bSMingming Cao (sbi->s_mount_state & EXT4_VALID_FS)) 3451ac27a0ecSDave Kleikamp es->s_state = cpu_to_le16(sbi->s_mount_state); 3452ac27a0ecSDave Kleikamp 3453a63c9eb2STheodore Ts'o if (sbi->s_journal) 3454617ba13bSMingming Cao ext4_mark_recovery_complete(sb, es); 3455ac27a0ecSDave Kleikamp } else { 34563a06d778SAneesh Kumar K.V int ret; 3457617ba13bSMingming Cao if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb, 3458617ba13bSMingming Cao ~EXT4_FEATURE_RO_COMPAT_SUPP))) { 3459617ba13bSMingming Cao printk(KERN_WARNING "EXT4-fs: %s: couldn't " 3460ac27a0ecSDave Kleikamp "remount RDWR because of unsupported " 34613a06d778SAneesh Kumar K.V "optional features (%x).\n", sb->s_id, 34623a06d778SAneesh Kumar K.V (le32_to_cpu(sbi->s_es->s_feature_ro_compat) & 34633a06d778SAneesh Kumar K.V ~EXT4_FEATURE_RO_COMPAT_SUPP)); 3464ac27a0ecSDave Kleikamp err = -EROFS; 3465ac27a0ecSDave Kleikamp goto restore_opts; 3466ac27a0ecSDave Kleikamp } 3467ead6596bSEric Sandeen 3468ead6596bSEric Sandeen /* 34698a266467STheodore Ts'o * Make sure the group descriptor checksums 34708a266467STheodore Ts'o * are sane. If they aren't, refuse to 34718a266467STheodore Ts'o * remount r/w. 34728a266467STheodore Ts'o */ 34738a266467STheodore Ts'o for (g = 0; g < sbi->s_groups_count; g++) { 34748a266467STheodore Ts'o struct ext4_group_desc *gdp = 34758a266467STheodore Ts'o ext4_get_group_desc(sb, g, NULL); 34768a266467STheodore Ts'o 34778a266467STheodore Ts'o if (!ext4_group_desc_csum_verify(sbi, g, gdp)) { 34788a266467STheodore Ts'o printk(KERN_ERR 34798a266467STheodore Ts'o "EXT4-fs: ext4_remount: " 3480a9df9a49STheodore Ts'o "Checksum for group %u failed (%u!=%u)\n", 34818a266467STheodore Ts'o g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)), 34828a266467STheodore Ts'o le16_to_cpu(gdp->bg_checksum)); 34838a266467STheodore Ts'o err = -EINVAL; 34848a266467STheodore Ts'o goto restore_opts; 34858a266467STheodore Ts'o } 34868a266467STheodore Ts'o } 34878a266467STheodore Ts'o 34888a266467STheodore Ts'o /* 3489ead6596bSEric Sandeen * If we have an unprocessed orphan list hanging 3490ead6596bSEric Sandeen * around from a previously readonly bdev mount, 3491ead6596bSEric Sandeen * require a full umount/remount for now. 3492ead6596bSEric Sandeen */ 3493ead6596bSEric Sandeen if (es->s_last_orphan) { 3494ead6596bSEric Sandeen printk(KERN_WARNING "EXT4-fs: %s: couldn't " 3495ead6596bSEric Sandeen "remount RDWR because of unprocessed " 3496ead6596bSEric Sandeen "orphan inode list. Please " 3497ead6596bSEric Sandeen "umount/remount instead.\n", 3498ead6596bSEric Sandeen sb->s_id); 3499ead6596bSEric Sandeen err = -EINVAL; 3500ead6596bSEric Sandeen goto restore_opts; 3501ead6596bSEric Sandeen } 3502ead6596bSEric Sandeen 3503ac27a0ecSDave Kleikamp /* 3504ac27a0ecSDave Kleikamp * Mounting a RDONLY partition read-write, so reread 3505ac27a0ecSDave Kleikamp * and store the current valid flag. (It may have 3506ac27a0ecSDave Kleikamp * been changed by e2fsck since we originally mounted 3507ac27a0ecSDave Kleikamp * the partition.) 3508ac27a0ecSDave Kleikamp */ 35090390131bSFrank Mayhar if (sbi->s_journal) 3510617ba13bSMingming Cao ext4_clear_journal_err(sb, es); 3511ac27a0ecSDave Kleikamp sbi->s_mount_state = le16_to_cpu(es->s_state); 3512617ba13bSMingming Cao if ((err = ext4_group_extend(sb, es, n_blocks_count))) 3513ac27a0ecSDave Kleikamp goto restore_opts; 3514617ba13bSMingming Cao if (!ext4_setup_super(sb, es, 0)) 3515ac27a0ecSDave Kleikamp sb->s_flags &= ~MS_RDONLY; 3516ac27a0ecSDave Kleikamp } 3517ac27a0ecSDave Kleikamp } 35180390131bSFrank Mayhar if (sbi->s_journal == NULL) 3519e2d67052STheodore Ts'o ext4_commit_super(sb, 1); 35200390131bSFrank Mayhar 3521ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 3522ac27a0ecSDave Kleikamp /* Release old quota file names */ 3523ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) 3524ac27a0ecSDave Kleikamp if (old_opts.s_qf_names[i] && 3525ac27a0ecSDave Kleikamp old_opts.s_qf_names[i] != sbi->s_qf_names[i]) 3526ac27a0ecSDave Kleikamp kfree(old_opts.s_qf_names[i]); 3527ac27a0ecSDave Kleikamp #endif 3528ac27a0ecSDave Kleikamp return 0; 3529ac27a0ecSDave Kleikamp restore_opts: 3530ac27a0ecSDave Kleikamp sb->s_flags = old_sb_flags; 3531ac27a0ecSDave Kleikamp sbi->s_mount_opt = old_opts.s_mount_opt; 3532ac27a0ecSDave Kleikamp sbi->s_resuid = old_opts.s_resuid; 3533ac27a0ecSDave Kleikamp sbi->s_resgid = old_opts.s_resgid; 3534ac27a0ecSDave Kleikamp sbi->s_commit_interval = old_opts.s_commit_interval; 353530773840STheodore Ts'o sbi->s_min_batch_time = old_opts.s_min_batch_time; 353630773840STheodore Ts'o sbi->s_max_batch_time = old_opts.s_max_batch_time; 3537ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 3538ac27a0ecSDave Kleikamp sbi->s_jquota_fmt = old_opts.s_jquota_fmt; 3539ac27a0ecSDave Kleikamp for (i = 0; i < MAXQUOTAS; i++) { 3540ac27a0ecSDave Kleikamp if (sbi->s_qf_names[i] && 3541ac27a0ecSDave Kleikamp old_opts.s_qf_names[i] != sbi->s_qf_names[i]) 3542ac27a0ecSDave Kleikamp kfree(sbi->s_qf_names[i]); 3543ac27a0ecSDave Kleikamp sbi->s_qf_names[i] = old_opts.s_qf_names[i]; 3544ac27a0ecSDave Kleikamp } 3545ac27a0ecSDave Kleikamp #endif 3546ac27a0ecSDave Kleikamp return err; 3547ac27a0ecSDave Kleikamp } 3548ac27a0ecSDave Kleikamp 3549617ba13bSMingming Cao static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf) 3550ac27a0ecSDave Kleikamp { 3551ac27a0ecSDave Kleikamp struct super_block *sb = dentry->d_sb; 3552617ba13bSMingming Cao struct ext4_sb_info *sbi = EXT4_SB(sb); 3553617ba13bSMingming Cao struct ext4_super_block *es = sbi->s_es; 3554960cc398SPekka Enberg u64 fsid; 3555ac27a0ecSDave Kleikamp 35565e70030dSBadari Pulavarty if (test_opt(sb, MINIX_DF)) { 35575e70030dSBadari Pulavarty sbi->s_overhead_last = 0; 35586bc9feffSAneesh Kumar K.V } else if (sbi->s_blocks_last != ext4_blocks_count(es)) { 35598df9675fSTheodore Ts'o ext4_group_t i, ngroups = ext4_get_groups_count(sb); 35605e70030dSBadari Pulavarty ext4_fsblk_t overhead = 0; 3561ac27a0ecSDave Kleikamp 3562ac27a0ecSDave Kleikamp /* 35635e70030dSBadari Pulavarty * Compute the overhead (FS structures). This is constant 35645e70030dSBadari Pulavarty * for a given filesystem unless the number of block groups 35655e70030dSBadari Pulavarty * changes so we cache the previous value until it does. 3566ac27a0ecSDave Kleikamp */ 3567ac27a0ecSDave Kleikamp 3568ac27a0ecSDave Kleikamp /* 3569ac27a0ecSDave Kleikamp * All of the blocks before first_data_block are 3570ac27a0ecSDave Kleikamp * overhead 3571ac27a0ecSDave Kleikamp */ 3572ac27a0ecSDave Kleikamp overhead = le32_to_cpu(es->s_first_data_block); 3573ac27a0ecSDave Kleikamp 3574ac27a0ecSDave Kleikamp /* 3575ac27a0ecSDave Kleikamp * Add the overhead attributed to the superblock and 3576ac27a0ecSDave Kleikamp * block group descriptors. If the sparse superblocks 3577ac27a0ecSDave Kleikamp * feature is turned on, then not all groups have this. 3578ac27a0ecSDave Kleikamp */ 3579ac27a0ecSDave Kleikamp for (i = 0; i < ngroups; i++) { 3580617ba13bSMingming Cao overhead += ext4_bg_has_super(sb, i) + 3581617ba13bSMingming Cao ext4_bg_num_gdb(sb, i); 3582ac27a0ecSDave Kleikamp cond_resched(); 3583ac27a0ecSDave Kleikamp } 3584ac27a0ecSDave Kleikamp 3585ac27a0ecSDave Kleikamp /* 3586ac27a0ecSDave Kleikamp * Every block group has an inode bitmap, a block 3587ac27a0ecSDave Kleikamp * bitmap, and an inode table. 3588ac27a0ecSDave Kleikamp */ 35895e70030dSBadari Pulavarty overhead += ngroups * (2 + sbi->s_itb_per_group); 35905e70030dSBadari Pulavarty sbi->s_overhead_last = overhead; 35915e70030dSBadari Pulavarty smp_wmb(); 35926bc9feffSAneesh Kumar K.V sbi->s_blocks_last = ext4_blocks_count(es); 3593ac27a0ecSDave Kleikamp } 3594ac27a0ecSDave Kleikamp 3595617ba13bSMingming Cao buf->f_type = EXT4_SUPER_MAGIC; 3596ac27a0ecSDave Kleikamp buf->f_bsize = sb->s_blocksize; 35975e70030dSBadari Pulavarty buf->f_blocks = ext4_blocks_count(es) - sbi->s_overhead_last; 35986bc6e63fSAneesh Kumar K.V buf->f_bfree = percpu_counter_sum_positive(&sbi->s_freeblocks_counter) - 35996bc6e63fSAneesh Kumar K.V percpu_counter_sum_positive(&sbi->s_dirtyblocks_counter); 3600308ba3ecSAneesh Kumar K.V ext4_free_blocks_count_set(es, buf->f_bfree); 3601bd81d8eeSLaurent Vivier buf->f_bavail = buf->f_bfree - ext4_r_blocks_count(es); 3602bd81d8eeSLaurent Vivier if (buf->f_bfree < ext4_r_blocks_count(es)) 3603ac27a0ecSDave Kleikamp buf->f_bavail = 0; 3604ac27a0ecSDave Kleikamp buf->f_files = le32_to_cpu(es->s_inodes_count); 360552d9f3b4SPeter Zijlstra buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter); 36065e70030dSBadari Pulavarty es->s_free_inodes_count = cpu_to_le32(buf->f_ffree); 3607617ba13bSMingming Cao buf->f_namelen = EXT4_NAME_LEN; 3608960cc398SPekka Enberg fsid = le64_to_cpup((void *)es->s_uuid) ^ 3609960cc398SPekka Enberg le64_to_cpup((void *)es->s_uuid + sizeof(u64)); 3610960cc398SPekka Enberg buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL; 3611960cc398SPekka Enberg buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL; 3612ac27a0ecSDave Kleikamp return 0; 3613ac27a0ecSDave Kleikamp } 3614ac27a0ecSDave Kleikamp 3615ac27a0ecSDave Kleikamp /* Helper function for writing quotas on sync - we need to start transaction before quota file 3616ac27a0ecSDave Kleikamp * is locked for write. Otherwise the are possible deadlocks: 3617ac27a0ecSDave Kleikamp * Process 1 Process 2 3618617ba13bSMingming Cao * ext4_create() quota_sync() 3619dab291afSMingming Cao * jbd2_journal_start() write_dquot() 3620a269eb18SJan Kara * vfs_dq_init() down(dqio_mutex) 3621dab291afSMingming Cao * down(dqio_mutex) jbd2_journal_start() 3622ac27a0ecSDave Kleikamp * 3623ac27a0ecSDave Kleikamp */ 3624ac27a0ecSDave Kleikamp 3625ac27a0ecSDave Kleikamp #ifdef CONFIG_QUOTA 3626ac27a0ecSDave Kleikamp 3627ac27a0ecSDave Kleikamp static inline struct inode *dquot_to_inode(struct dquot *dquot) 3628ac27a0ecSDave Kleikamp { 3629ac27a0ecSDave Kleikamp return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type]; 3630ac27a0ecSDave Kleikamp } 3631ac27a0ecSDave Kleikamp 3632617ba13bSMingming Cao static int ext4_write_dquot(struct dquot *dquot) 3633ac27a0ecSDave Kleikamp { 3634ac27a0ecSDave Kleikamp int ret, err; 3635ac27a0ecSDave Kleikamp handle_t *handle; 3636ac27a0ecSDave Kleikamp struct inode *inode; 3637ac27a0ecSDave Kleikamp 3638ac27a0ecSDave Kleikamp inode = dquot_to_inode(dquot); 3639617ba13bSMingming Cao handle = ext4_journal_start(inode, 3640617ba13bSMingming Cao EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); 3641ac27a0ecSDave Kleikamp if (IS_ERR(handle)) 3642ac27a0ecSDave Kleikamp return PTR_ERR(handle); 3643ac27a0ecSDave Kleikamp ret = dquot_commit(dquot); 3644617ba13bSMingming Cao err = ext4_journal_stop(handle); 3645ac27a0ecSDave Kleikamp if (!ret) 3646ac27a0ecSDave Kleikamp ret = err; 3647ac27a0ecSDave Kleikamp return ret; 3648ac27a0ecSDave Kleikamp } 3649ac27a0ecSDave Kleikamp 3650617ba13bSMingming Cao static int ext4_acquire_dquot(struct dquot *dquot) 3651ac27a0ecSDave Kleikamp { 3652ac27a0ecSDave Kleikamp int ret, err; 3653ac27a0ecSDave Kleikamp handle_t *handle; 3654ac27a0ecSDave Kleikamp 3655617ba13bSMingming Cao handle = ext4_journal_start(dquot_to_inode(dquot), 3656617ba13bSMingming Cao EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb)); 3657ac27a0ecSDave Kleikamp if (IS_ERR(handle)) 3658ac27a0ecSDave Kleikamp return PTR_ERR(handle); 3659ac27a0ecSDave Kleikamp ret = dquot_acquire(dquot); 3660617ba13bSMingming Cao err = ext4_journal_stop(handle); 3661ac27a0ecSDave Kleikamp if (!ret) 3662ac27a0ecSDave Kleikamp ret = err; 3663ac27a0ecSDave Kleikamp return ret; 3664ac27a0ecSDave Kleikamp } 3665ac27a0ecSDave Kleikamp 3666617ba13bSMingming Cao static int ext4_release_dquot(struct dquot *dquot) 3667ac27a0ecSDave Kleikamp { 3668ac27a0ecSDave Kleikamp int ret, err; 3669ac27a0ecSDave Kleikamp handle_t *handle; 3670ac27a0ecSDave Kleikamp 3671617ba13bSMingming Cao handle = ext4_journal_start(dquot_to_inode(dquot), 3672617ba13bSMingming Cao EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb)); 36739c3013e9SJan Kara if (IS_ERR(handle)) { 36749c3013e9SJan Kara /* Release dquot anyway to avoid endless cycle in dqput() */ 36759c3013e9SJan Kara dquot_release(dquot); 3676ac27a0ecSDave Kleikamp return PTR_ERR(handle); 36779c3013e9SJan Kara } 3678ac27a0ecSDave Kleikamp ret = dquot_release(dquot); 3679617ba13bSMingming Cao err = ext4_journal_stop(handle); 3680ac27a0ecSDave Kleikamp if (!ret) 3681ac27a0ecSDave Kleikamp ret = err; 3682ac27a0ecSDave Kleikamp return ret; 3683ac27a0ecSDave Kleikamp } 3684ac27a0ecSDave Kleikamp 3685617ba13bSMingming Cao static int ext4_mark_dquot_dirty(struct dquot *dquot) 3686ac27a0ecSDave Kleikamp { 36872c8be6b2SJan Kara /* Are we journaling quotas? */ 3688617ba13bSMingming Cao if (EXT4_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] || 3689617ba13bSMingming Cao EXT4_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) { 3690ac27a0ecSDave Kleikamp dquot_mark_dquot_dirty(dquot); 3691617ba13bSMingming Cao return ext4_write_dquot(dquot); 3692ac27a0ecSDave Kleikamp } else { 3693ac27a0ecSDave Kleikamp return dquot_mark_dquot_dirty(dquot); 3694ac27a0ecSDave Kleikamp } 3695ac27a0ecSDave Kleikamp } 3696ac27a0ecSDave Kleikamp 3697617ba13bSMingming Cao static int ext4_write_info(struct super_block *sb, int type) 3698ac27a0ecSDave Kleikamp { 3699ac27a0ecSDave Kleikamp int ret, err; 3700ac27a0ecSDave Kleikamp handle_t *handle; 3701ac27a0ecSDave Kleikamp 3702ac27a0ecSDave Kleikamp /* Data block + inode block */ 3703617ba13bSMingming Cao handle = ext4_journal_start(sb->s_root->d_inode, 2); 3704ac27a0ecSDave Kleikamp if (IS_ERR(handle)) 3705ac27a0ecSDave Kleikamp return PTR_ERR(handle); 3706ac27a0ecSDave Kleikamp ret = dquot_commit_info(sb, type); 3707617ba13bSMingming Cao err = ext4_journal_stop(handle); 3708ac27a0ecSDave Kleikamp if (!ret) 3709ac27a0ecSDave Kleikamp ret = err; 3710ac27a0ecSDave Kleikamp return ret; 3711ac27a0ecSDave Kleikamp } 3712ac27a0ecSDave Kleikamp 3713ac27a0ecSDave Kleikamp /* 3714ac27a0ecSDave Kleikamp * Turn on quotas during mount time - we need to find 3715ac27a0ecSDave Kleikamp * the quota file and such... 3716ac27a0ecSDave Kleikamp */ 3717617ba13bSMingming Cao static int ext4_quota_on_mount(struct super_block *sb, int type) 3718ac27a0ecSDave Kleikamp { 3719617ba13bSMingming Cao return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type], 3720617ba13bSMingming Cao EXT4_SB(sb)->s_jquota_fmt, type); 3721ac27a0ecSDave Kleikamp } 3722ac27a0ecSDave Kleikamp 3723ac27a0ecSDave Kleikamp /* 3724ac27a0ecSDave Kleikamp * Standard function to be called on quota_on 3725ac27a0ecSDave Kleikamp */ 3726617ba13bSMingming Cao static int ext4_quota_on(struct super_block *sb, int type, int format_id, 37278264613dSAl Viro char *name, int remount) 3728ac27a0ecSDave Kleikamp { 3729ac27a0ecSDave Kleikamp int err; 37308264613dSAl Viro struct path path; 3731ac27a0ecSDave Kleikamp 3732ac27a0ecSDave Kleikamp if (!test_opt(sb, QUOTA)) 3733ac27a0ecSDave Kleikamp return -EINVAL; 37348264613dSAl Viro /* When remounting, no checks are needed and in fact, name is NULL */ 37350623543bSJan Kara if (remount) 37368264613dSAl Viro return vfs_quota_on(sb, type, format_id, name, remount); 37370623543bSJan Kara 37388264613dSAl Viro err = kern_path(name, LOOKUP_FOLLOW, &path); 3739ac27a0ecSDave Kleikamp if (err) 3740ac27a0ecSDave Kleikamp return err; 37410623543bSJan Kara 3742ac27a0ecSDave Kleikamp /* Quotafile not on the same filesystem? */ 37438264613dSAl Viro if (path.mnt->mnt_sb != sb) { 37448264613dSAl Viro path_put(&path); 3745ac27a0ecSDave Kleikamp return -EXDEV; 3746ac27a0ecSDave Kleikamp } 37470623543bSJan Kara /* Journaling quota? */ 37480623543bSJan Kara if (EXT4_SB(sb)->s_qf_names[type]) { 37492b2d6d01STheodore Ts'o /* Quotafile not in fs root? */ 37508264613dSAl Viro if (path.dentry->d_parent != sb->s_root) 3751ac27a0ecSDave Kleikamp printk(KERN_WARNING 3752617ba13bSMingming Cao "EXT4-fs: Quota file not on filesystem root. " 37530623543bSJan Kara "Journaled quota will not work.\n"); 37540623543bSJan Kara } 37550623543bSJan Kara 37560623543bSJan Kara /* 37570623543bSJan Kara * When we journal data on quota file, we have to flush journal to see 37580623543bSJan Kara * all updates to the file when we bypass pagecache... 37590623543bSJan Kara */ 37600390131bSFrank Mayhar if (EXT4_SB(sb)->s_journal && 37610390131bSFrank Mayhar ext4_should_journal_data(path.dentry->d_inode)) { 37620623543bSJan Kara /* 37630623543bSJan Kara * We don't need to lock updates but journal_flush() could 37640623543bSJan Kara * otherwise be livelocked... 37650623543bSJan Kara */ 37660623543bSJan Kara jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); 37677ffe1ea8SHidehiro Kawai err = jbd2_journal_flush(EXT4_SB(sb)->s_journal); 37680623543bSJan Kara jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 37697ffe1ea8SHidehiro Kawai if (err) { 37708264613dSAl Viro path_put(&path); 37717ffe1ea8SHidehiro Kawai return err; 37727ffe1ea8SHidehiro Kawai } 37730623543bSJan Kara } 37740623543bSJan Kara 37758264613dSAl Viro err = vfs_quota_on_path(sb, type, format_id, &path); 37768264613dSAl Viro path_put(&path); 377777e69dacSAl Viro return err; 3778ac27a0ecSDave Kleikamp } 3779ac27a0ecSDave Kleikamp 3780ac27a0ecSDave Kleikamp /* Read data from quotafile - avoid pagecache and such because we cannot afford 3781ac27a0ecSDave Kleikamp * acquiring the locks... As quota files are never truncated and quota code 3782ac27a0ecSDave Kleikamp * itself serializes the operations (and noone else should touch the files) 3783ac27a0ecSDave Kleikamp * we don't have to be afraid of races */ 3784617ba13bSMingming Cao static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, 3785ac27a0ecSDave Kleikamp size_t len, loff_t off) 3786ac27a0ecSDave Kleikamp { 3787ac27a0ecSDave Kleikamp struct inode *inode = sb_dqopt(sb)->files[type]; 3788725d26d3SAneesh Kumar K.V ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); 3789ac27a0ecSDave Kleikamp int err = 0; 3790ac27a0ecSDave Kleikamp int offset = off & (sb->s_blocksize - 1); 3791ac27a0ecSDave Kleikamp int tocopy; 3792ac27a0ecSDave Kleikamp size_t toread; 3793ac27a0ecSDave Kleikamp struct buffer_head *bh; 3794ac27a0ecSDave Kleikamp loff_t i_size = i_size_read(inode); 3795ac27a0ecSDave Kleikamp 3796ac27a0ecSDave Kleikamp if (off > i_size) 3797ac27a0ecSDave Kleikamp return 0; 3798ac27a0ecSDave Kleikamp if (off+len > i_size) 3799ac27a0ecSDave Kleikamp len = i_size-off; 3800ac27a0ecSDave Kleikamp toread = len; 3801ac27a0ecSDave Kleikamp while (toread > 0) { 3802ac27a0ecSDave Kleikamp tocopy = sb->s_blocksize - offset < toread ? 3803ac27a0ecSDave Kleikamp sb->s_blocksize - offset : toread; 3804617ba13bSMingming Cao bh = ext4_bread(NULL, inode, blk, 0, &err); 3805ac27a0ecSDave Kleikamp if (err) 3806ac27a0ecSDave Kleikamp return err; 3807ac27a0ecSDave Kleikamp if (!bh) /* A hole? */ 3808ac27a0ecSDave Kleikamp memset(data, 0, tocopy); 3809ac27a0ecSDave Kleikamp else 3810ac27a0ecSDave Kleikamp memcpy(data, bh->b_data+offset, tocopy); 3811ac27a0ecSDave Kleikamp brelse(bh); 3812ac27a0ecSDave Kleikamp offset = 0; 3813ac27a0ecSDave Kleikamp toread -= tocopy; 3814ac27a0ecSDave Kleikamp data += tocopy; 3815ac27a0ecSDave Kleikamp blk++; 3816ac27a0ecSDave Kleikamp } 3817ac27a0ecSDave Kleikamp return len; 3818ac27a0ecSDave Kleikamp } 3819ac27a0ecSDave Kleikamp 3820ac27a0ecSDave Kleikamp /* Write to quotafile (we know the transaction is already started and has 3821ac27a0ecSDave Kleikamp * enough credits) */ 3822617ba13bSMingming Cao static ssize_t ext4_quota_write(struct super_block *sb, int type, 3823ac27a0ecSDave Kleikamp const char *data, size_t len, loff_t off) 3824ac27a0ecSDave Kleikamp { 3825ac27a0ecSDave Kleikamp struct inode *inode = sb_dqopt(sb)->files[type]; 3826725d26d3SAneesh Kumar K.V ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); 3827ac27a0ecSDave Kleikamp int err = 0; 3828ac27a0ecSDave Kleikamp int offset = off & (sb->s_blocksize - 1); 3829ac27a0ecSDave Kleikamp int tocopy; 3830617ba13bSMingming Cao int journal_quota = EXT4_SB(sb)->s_qf_names[type] != NULL; 3831ac27a0ecSDave Kleikamp size_t towrite = len; 3832ac27a0ecSDave Kleikamp struct buffer_head *bh; 3833ac27a0ecSDave Kleikamp handle_t *handle = journal_current_handle(); 3834ac27a0ecSDave Kleikamp 38350390131bSFrank Mayhar if (EXT4_SB(sb)->s_journal && !handle) { 3836e5f8eab8STheodore Ts'o printk(KERN_WARNING "EXT4-fs: Quota write (off=%llu, len=%llu)" 38379c3013e9SJan Kara " cancelled because transaction is not started.\n", 38389c3013e9SJan Kara (unsigned long long)off, (unsigned long long)len); 38399c3013e9SJan Kara return -EIO; 38409c3013e9SJan Kara } 3841ac27a0ecSDave Kleikamp mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); 3842ac27a0ecSDave Kleikamp while (towrite > 0) { 3843ac27a0ecSDave Kleikamp tocopy = sb->s_blocksize - offset < towrite ? 3844ac27a0ecSDave Kleikamp sb->s_blocksize - offset : towrite; 3845617ba13bSMingming Cao bh = ext4_bread(handle, inode, blk, 1, &err); 3846ac27a0ecSDave Kleikamp if (!bh) 3847ac27a0ecSDave Kleikamp goto out; 3848ac27a0ecSDave Kleikamp if (journal_quota) { 3849617ba13bSMingming Cao err = ext4_journal_get_write_access(handle, bh); 3850ac27a0ecSDave Kleikamp if (err) { 3851ac27a0ecSDave Kleikamp brelse(bh); 3852ac27a0ecSDave Kleikamp goto out; 3853ac27a0ecSDave Kleikamp } 3854ac27a0ecSDave Kleikamp } 3855ac27a0ecSDave Kleikamp lock_buffer(bh); 3856ac27a0ecSDave Kleikamp memcpy(bh->b_data+offset, data, tocopy); 3857ac27a0ecSDave Kleikamp flush_dcache_page(bh->b_page); 3858ac27a0ecSDave Kleikamp unlock_buffer(bh); 3859ac27a0ecSDave Kleikamp if (journal_quota) 38600390131bSFrank Mayhar err = ext4_handle_dirty_metadata(handle, NULL, bh); 3861ac27a0ecSDave Kleikamp else { 3862ac27a0ecSDave Kleikamp /* Always do at least ordered writes for quotas */ 3863678aaf48SJan Kara err = ext4_jbd2_file_inode(handle, inode); 3864ac27a0ecSDave Kleikamp mark_buffer_dirty(bh); 3865ac27a0ecSDave Kleikamp } 3866ac27a0ecSDave Kleikamp brelse(bh); 3867ac27a0ecSDave Kleikamp if (err) 3868ac27a0ecSDave Kleikamp goto out; 3869ac27a0ecSDave Kleikamp offset = 0; 3870ac27a0ecSDave Kleikamp towrite -= tocopy; 3871ac27a0ecSDave Kleikamp data += tocopy; 3872ac27a0ecSDave Kleikamp blk++; 3873ac27a0ecSDave Kleikamp } 3874ac27a0ecSDave Kleikamp out: 38754d04e4fbSJan Kara if (len == towrite) { 38764d04e4fbSJan Kara mutex_unlock(&inode->i_mutex); 3877ac27a0ecSDave Kleikamp return err; 38784d04e4fbSJan Kara } 3879ac27a0ecSDave Kleikamp if (inode->i_size < off+len-towrite) { 3880ac27a0ecSDave Kleikamp i_size_write(inode, off+len-towrite); 3881617ba13bSMingming Cao EXT4_I(inode)->i_disksize = inode->i_size; 3882ac27a0ecSDave Kleikamp } 3883ac27a0ecSDave Kleikamp inode->i_mtime = inode->i_ctime = CURRENT_TIME; 3884617ba13bSMingming Cao ext4_mark_inode_dirty(handle, inode); 3885ac27a0ecSDave Kleikamp mutex_unlock(&inode->i_mutex); 3886ac27a0ecSDave Kleikamp return len - towrite; 3887ac27a0ecSDave Kleikamp } 3888ac27a0ecSDave Kleikamp 3889ac27a0ecSDave Kleikamp #endif 3890ac27a0ecSDave Kleikamp 3891617ba13bSMingming Cao static int ext4_get_sb(struct file_system_type *fs_type, 3892ac27a0ecSDave Kleikamp int flags, const char *dev_name, void *data, struct vfsmount *mnt) 3893ac27a0ecSDave Kleikamp { 3894617ba13bSMingming Cao return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt); 3895ac27a0ecSDave Kleikamp } 3896ac27a0ecSDave Kleikamp 389703010a33STheodore Ts'o static struct file_system_type ext4_fs_type = { 3898ac27a0ecSDave Kleikamp .owner = THIS_MODULE, 389903010a33STheodore Ts'o .name = "ext4", 3900617ba13bSMingming Cao .get_sb = ext4_get_sb, 3901ac27a0ecSDave Kleikamp .kill_sb = kill_block_super, 3902ac27a0ecSDave Kleikamp .fs_flags = FS_REQUIRES_DEV, 3903ac27a0ecSDave Kleikamp }; 3904ac27a0ecSDave Kleikamp 390503010a33STheodore Ts'o #ifdef CONFIG_EXT4DEV_COMPAT 390603010a33STheodore Ts'o static int ext4dev_get_sb(struct file_system_type *fs_type, 390703010a33STheodore Ts'o int flags, const char *dev_name, void *data, struct vfsmount *mnt) 390803010a33STheodore Ts'o { 390903010a33STheodore Ts'o printk(KERN_WARNING "EXT4-fs: Update your userspace programs " 391003010a33STheodore Ts'o "to mount using ext4\n"); 391103010a33STheodore Ts'o printk(KERN_WARNING "EXT4-fs: ext4dev backwards compatibility " 391203010a33STheodore Ts'o "will go away by 2.6.31\n"); 391303010a33STheodore Ts'o return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt); 391403010a33STheodore Ts'o } 391503010a33STheodore Ts'o 391603010a33STheodore Ts'o static struct file_system_type ext4dev_fs_type = { 391703010a33STheodore Ts'o .owner = THIS_MODULE, 391803010a33STheodore Ts'o .name = "ext4dev", 391903010a33STheodore Ts'o .get_sb = ext4dev_get_sb, 392003010a33STheodore Ts'o .kill_sb = kill_block_super, 392103010a33STheodore Ts'o .fs_flags = FS_REQUIRES_DEV, 392203010a33STheodore Ts'o }; 392303010a33STheodore Ts'o MODULE_ALIAS("ext4dev"); 392403010a33STheodore Ts'o #endif 392503010a33STheodore Ts'o 3926617ba13bSMingming Cao static int __init init_ext4_fs(void) 3927ac27a0ecSDave Kleikamp { 3928c9de560dSAlex Tomas int err; 3929c9de560dSAlex Tomas 39303197ebdbSTheodore Ts'o ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj); 39313197ebdbSTheodore Ts'o if (!ext4_kset) 39323197ebdbSTheodore Ts'o return -ENOMEM; 39339f6200bbSTheodore Ts'o ext4_proc_root = proc_mkdir("fs/ext4", NULL); 3934c9de560dSAlex Tomas err = init_ext4_mballoc(); 3935ac27a0ecSDave Kleikamp if (err) 3936ac27a0ecSDave Kleikamp return err; 3937c9de560dSAlex Tomas 3938c9de560dSAlex Tomas err = init_ext4_xattr(); 3939c9de560dSAlex Tomas if (err) 3940c9de560dSAlex Tomas goto out2; 3941ac27a0ecSDave Kleikamp err = init_inodecache(); 3942ac27a0ecSDave Kleikamp if (err) 3943ac27a0ecSDave Kleikamp goto out1; 394403010a33STheodore Ts'o err = register_filesystem(&ext4_fs_type); 3945ac27a0ecSDave Kleikamp if (err) 3946ac27a0ecSDave Kleikamp goto out; 394703010a33STheodore Ts'o #ifdef CONFIG_EXT4DEV_COMPAT 394803010a33STheodore Ts'o err = register_filesystem(&ext4dev_fs_type); 394903010a33STheodore Ts'o if (err) { 395003010a33STheodore Ts'o unregister_filesystem(&ext4_fs_type); 395103010a33STheodore Ts'o goto out; 395203010a33STheodore Ts'o } 395303010a33STheodore Ts'o #endif 3954ac27a0ecSDave Kleikamp return 0; 3955ac27a0ecSDave Kleikamp out: 3956ac27a0ecSDave Kleikamp destroy_inodecache(); 3957ac27a0ecSDave Kleikamp out1: 3958617ba13bSMingming Cao exit_ext4_xattr(); 3959c9de560dSAlex Tomas out2: 3960c9de560dSAlex Tomas exit_ext4_mballoc(); 3961ac27a0ecSDave Kleikamp return err; 3962ac27a0ecSDave Kleikamp } 3963ac27a0ecSDave Kleikamp 3964617ba13bSMingming Cao static void __exit exit_ext4_fs(void) 3965ac27a0ecSDave Kleikamp { 396603010a33STheodore Ts'o unregister_filesystem(&ext4_fs_type); 396703010a33STheodore Ts'o #ifdef CONFIG_EXT4DEV_COMPAT 3968617ba13bSMingming Cao unregister_filesystem(&ext4dev_fs_type); 396903010a33STheodore Ts'o #endif 3970ac27a0ecSDave Kleikamp destroy_inodecache(); 3971617ba13bSMingming Cao exit_ext4_xattr(); 3972c9de560dSAlex Tomas exit_ext4_mballoc(); 39739f6200bbSTheodore Ts'o remove_proc_entry("fs/ext4", NULL); 39743197ebdbSTheodore Ts'o kset_unregister(ext4_kset); 3975ac27a0ecSDave Kleikamp } 3976ac27a0ecSDave Kleikamp 3977ac27a0ecSDave Kleikamp MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); 397883982b6fSTheodore Ts'o MODULE_DESCRIPTION("Fourth Extended Filesystem"); 3979ac27a0ecSDave Kleikamp MODULE_LICENSE("GPL"); 3980617ba13bSMingming Cao module_init(init_ext4_fs) 3981617ba13bSMingming Cao module_exit(exit_ext4_fs) 3982