Lines Matching +full:es +full:- +full:enable
1 // SPDX-License-Identifier: GPL-2.0
7 * Laboratoire MASI - Institut Blaise Pascal
16 * Big-endian to little-endian byte-swapping/bitmaps by
28 #include <linux/backing-dev.h>
70 struct ext4_super_block *es);
72 struct ext4_super_block *es);
92 * Note the difference between i_mmap_sem (EXT4_I(inode)->i_mmap_sem) and
93 * i_mmap_rwsem (inode->i_mmap_rwsem)!
96 * mmap_lock -> sb_start_pagefault -> i_mmap_sem (r) -> transaction start ->
97 * page lock -> i_data_sem (rw)
100 * sb_start_write -> i_mutex -> mmap_lock
101 * sb_start_write -> i_mutex -> transaction start -> page lock ->
105 * sb_start_write -> i_mutex -> i_mmap_sem (w) -> i_mmap_rwsem (w) -> page lock
106 * sb_start_write -> i_mutex -> i_mmap_sem (w) -> transaction start ->
110 * sb_start_write -> i_mutex -> mmap_lock
111 * sb_start_write -> i_mutex -> transaction start -> i_data_sem (rw)
114 * transaction start -> page lock(s) -> i_data_sem (rw)
127 #define IS_EXT2_SB(sb) ((sb)->s_bdev->bd_holder == &ext2_fs_type)
142 #define IS_EXT3_SB(sb) ((sb)->s_bdev->bd_holder == &ext3_fs_type)
155 bh->b_end_io = end_io ? end_io : end_buffer_read_sync; in __ext4_read_bh()
186 return -EIO; in ext4_read_bh()
214 return ERR_PTR(-ENOMEM); in __ext4_sb_bread_gfp()
250 struct ext4_super_block *es) in ext4_verify_csum_type() argument
255 return es->s_checksum_type == EXT4_CRC32C_CHKSUM; in ext4_verify_csum_type()
259 struct ext4_super_block *es) in ext4_superblock_csum() argument
265 csum = ext4_chksum(sbi, ~0, (char *)es, offset); in ext4_superblock_csum()
271 struct ext4_super_block *es) in ext4_superblock_csum_verify() argument
276 return es->s_checksum == ext4_superblock_csum(sb, es); in ext4_superblock_csum_verify()
281 struct ext4_super_block *es = EXT4_SB(sb)->s_es; in ext4_superblock_csum_set() local
286 es->s_checksum = ext4_superblock_csum(sb, es); in ext4_superblock_csum_set()
292 return le32_to_cpu(bg->bg_block_bitmap_lo) | in ext4_block_bitmap()
294 (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0); in ext4_block_bitmap()
300 return le32_to_cpu(bg->bg_inode_bitmap_lo) | in ext4_inode_bitmap()
302 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0); in ext4_inode_bitmap()
308 return le32_to_cpu(bg->bg_inode_table_lo) | in ext4_inode_table()
310 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0); in ext4_inode_table()
316 return le16_to_cpu(bg->bg_free_blocks_count_lo) | in ext4_free_group_clusters()
318 (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0); in ext4_free_group_clusters()
324 return le16_to_cpu(bg->bg_free_inodes_count_lo) | in ext4_free_inodes_count()
326 (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0); in ext4_free_inodes_count()
332 return le16_to_cpu(bg->bg_used_dirs_count_lo) | in ext4_used_dirs_count()
334 (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0); in ext4_used_dirs_count()
340 return le16_to_cpu(bg->bg_itable_unused_lo) | in ext4_itable_unused_count()
342 (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0); in ext4_itable_unused_count()
348 bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk); in ext4_block_bitmap_set()
350 bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32); in ext4_block_bitmap_set()
356 bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk); in ext4_inode_bitmap_set()
358 bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32); in ext4_inode_bitmap_set()
364 bg->bg_inode_table_lo = cpu_to_le32((u32)blk); in ext4_inode_table_set()
366 bg->bg_inode_table_hi = cpu_to_le32(blk >> 32); in ext4_inode_table_set()
372 bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count); in ext4_free_group_clusters_set()
374 bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16); in ext4_free_group_clusters_set()
380 bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count); in ext4_free_inodes_set()
382 bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16); in ext4_free_inodes_set()
388 bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count); in ext4_used_dirs_set()
390 bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16); in ext4_used_dirs_set()
396 bg->bg_itable_unused_lo = cpu_to_le16((__u16)count); in ext4_itable_unused_set()
398 bg->bg_itable_unused_hi = cpu_to_le16(count >> 16); in ext4_itable_unused_set()
405 now = clamp_val(now, 0, (1ull << 40) - 1); in __ext4_update_tstamp()
415 #define ext4_update_tstamp(es, tstamp) \ argument
416 __ext4_update_tstamp(&(es)->tstamp, &(es)->tstamp ## _hi)
417 #define ext4_get_tstamp(es, tstamp) \ argument
418 __ext4_get_tstamp(&(es)->tstamp, &(es)->tstamp ## _hi)
424 struct ext4_super_block *es = EXT4_SB(sb)->s_es; in __save_error_info() local
427 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; in __save_error_info()
428 if (bdev_read_only(sb->s_bdev)) in __save_error_info()
430 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); in __save_error_info()
431 ext4_update_tstamp(es, s_last_error_time); in __save_error_info()
432 strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func)); in __save_error_info()
433 es->s_last_error_line = cpu_to_le32(line); in __save_error_info()
434 es->s_last_error_ino = cpu_to_le32(ino); in __save_error_info()
435 es->s_last_error_block = cpu_to_le64(block); in __save_error_info()
489 es->s_last_error_errcode = err; in __save_error_info()
490 if (!es->s_first_error_time) { in __save_error_info()
491 es->s_first_error_time = es->s_last_error_time; in __save_error_info()
492 es->s_first_error_time_hi = es->s_last_error_time_hi; in __save_error_info()
493 strncpy(es->s_first_error_func, func, in __save_error_info()
494 sizeof(es->s_first_error_func)); in __save_error_info()
495 es->s_first_error_line = cpu_to_le32(line); in __save_error_info()
496 es->s_first_error_ino = es->s_last_error_ino; in __save_error_info()
497 es->s_first_error_block = es->s_last_error_block; in __save_error_info()
498 es->s_first_error_errcode = es->s_last_error_errcode; in __save_error_info()
504 if (!es->s_error_count) in __save_error_info()
505 mod_timer(&EXT4_SB(sb)->s_err_report, jiffies + 24*60*60*HZ); in __save_error_info()
506 le32_add_cpu(&es->s_error_count, 1); in __save_error_info()
514 if (!bdev_read_only(sb->s_bdev)) in save_error_info()
519 * The del_gendisk() function uninitializes the disk-specific data
528 struct inode *bd_inode = sb->s_bdev->bd_inode; in block_device_ejected()
531 return bdi->dev == NULL; in block_device_ejected()
536 struct super_block *sb = journal->j_private; in ext4_journal_commit_callback()
541 BUG_ON(txn->t_state == T_FINISHED); in ext4_journal_commit_callback()
543 ext4_process_freed_data(sb, txn->t_tid); in ext4_journal_commit_callback()
545 spin_lock(&sbi->s_md_lock); in ext4_journal_commit_callback()
546 while (!list_empty(&txn->t_private_list)) { in ext4_journal_commit_callback()
547 jce = list_entry(txn->t_private_list.next, in ext4_journal_commit_callback()
549 list_del_init(&jce->jce_list); in ext4_journal_commit_callback()
550 spin_unlock(&sbi->s_md_lock); in ext4_journal_commit_callback()
551 jce->jce_func(sb, jce, error); in ext4_journal_commit_callback()
552 spin_lock(&sbi->s_md_lock); in ext4_journal_commit_callback()
554 spin_unlock(&sbi->s_md_lock); in ext4_journal_commit_callback()
592 (jh && (jh->b_transaction != transaction || in ext4_journalled_writepage_callback()
593 jh->b_next_transaction))) { in ext4_journalled_writepage_callback()
597 } while ((bh = bh->b_this_page) != head); in ext4_journalled_writepage_callback()
605 struct address_space *mapping = jinode->i_vfs_inode->i_mapping; in ext4_journalled_submit_inode_data_buffers()
609 .range_start = jinode->i_dirty_start, in ext4_journalled_submit_inode_data_buffers()
610 .range_end = jinode->i_dirty_end, in ext4_journalled_submit_inode_data_buffers()
615 jinode->i_transaction); in ext4_journalled_submit_inode_data_buffers()
622 if (ext4_should_journal_data(jinode->i_vfs_inode)) in ext4_journal_submit_inode_data_buffers()
634 if (!ext4_should_journal_data(jinode->i_vfs_inode)) in ext4_journal_finish_inode_data_buffers()
663 journal_t *journal = EXT4_SB(sb)->s_journal; in ext4_handle_error()
673 jbd2_journal_abort(journal, -EIO); in ext4_handle_error()
676 * could panic during 'reboot -f' as the underlying device got already in ext4_handle_error()
680 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only"); in ext4_handle_error()
682 * Make sure updated value of ->s_mount_flags will be visible in ext4_handle_error()
683 * before ->s_flags update in ext4_handle_error()
686 sb->s_flags |= SB_RDONLY; in ext4_handle_error()
688 panic("EXT4-fs (device %s): panic forced after error\n", in ext4_handle_error()
689 sb->s_id); in ext4_handle_error()
694 ___ratelimit(&(EXT4_SB(sb)->s_err_ratelimit_state), \
695 "EXT4-fs error")
713 "EXT4-fs error (device %s): %s:%d: comm %s: %pV\n", in __ext4_error()
714 sb->s_id, function, line, current->comm, &vaf); in __ext4_error()
728 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) in __ext4_error_inode()
731 trace_ext4_error(inode->i_sb, function, line); in __ext4_error_inode()
732 if (ext4_error_ratelimit(inode->i_sb)) { in __ext4_error_inode()
737 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: " in __ext4_error_inode()
739 inode->i_sb->s_id, function, line, inode->i_ino, in __ext4_error_inode()
740 block, current->comm, &vaf); in __ext4_error_inode()
742 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: " in __ext4_error_inode()
744 inode->i_sb->s_id, function, line, inode->i_ino, in __ext4_error_inode()
745 current->comm, &vaf); in __ext4_error_inode()
748 save_error_info(inode->i_sb, error, inode->i_ino, block, in __ext4_error_inode()
750 ext4_handle_error(inode->i_sb); in __ext4_error_inode()
762 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) in __ext4_error_file()
765 trace_ext4_error(inode->i_sb, function, line); in __ext4_error_file()
766 if (ext4_error_ratelimit(inode->i_sb)) { in __ext4_error_file()
775 "EXT4-fs error (device %s): %s:%d: inode #%lu: " in __ext4_error_file()
777 inode->i_sb->s_id, function, line, inode->i_ino, in __ext4_error_file()
778 block, current->comm, path, &vaf); in __ext4_error_file()
781 "EXT4-fs error (device %s): %s:%d: inode #%lu: " in __ext4_error_file()
783 inode->i_sb->s_id, function, line, inode->i_ino, in __ext4_error_file()
784 current->comm, path, &vaf); in __ext4_error_file()
787 save_error_info(inode->i_sb, EFSCORRUPTED, inode->i_ino, block, in __ext4_error_file()
789 ext4_handle_error(inode->i_sb); in __ext4_error_file()
798 case -EFSCORRUPTED: in ext4_decode_error()
801 case -EFSBADCRC: in ext4_decode_error()
804 case -EIO: in ext4_decode_error()
807 case -ENOMEM: in ext4_decode_error()
810 case -EROFS: in ext4_decode_error()
811 if (!sb || (EXT4_SB(sb)->s_journal && in ext4_decode_error()
812 EXT4_SB(sb)->s_journal->j_flags & JBD2_ABORT)) in ext4_decode_error()
823 if (snprintf(nbuf, 16, "error %d", -errno) >= 0) in ext4_decode_error()
847 if (errno == -EROFS && journal_current_handle() == NULL && sb_rdonly(sb)) in __ext4_std_error()
852 printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n", in __ext4_std_error()
853 sb->s_id, function, line, errstr); in __ext4_std_error()
856 save_error_info(sb, -errno, 0, 0, function, line); in __ext4_std_error()
883 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: %pV\n", in __ext4_abort()
884 sb->s_id, function, line, &vaf); in __ext4_abort()
889 if (EXT4_SB(sb)->s_journal) in __ext4_abort()
890 jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO); in __ext4_abort()
892 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only"); in __ext4_abort()
894 * Make sure updated value of ->s_mount_flags will be visible in __ext4_abort()
895 * before ->s_flags update in __ext4_abort()
898 sb->s_flags |= SB_RDONLY; in __ext4_abort()
901 panic("EXT4-fs panic from previous error\n"); in __ext4_abort()
910 atomic_inc(&EXT4_SB(sb)->s_msg_count); in __ext4_msg()
911 if (!___ratelimit(&(EXT4_SB(sb)->s_msg_ratelimit_state), "EXT4-fs")) in __ext4_msg()
917 printk("%sEXT4-fs (%s): %pV\n", prefix, sb->s_id, &vaf); in __ext4_msg()
923 atomic_inc(&EXT4_SB(sb)->s_warning_count); in ext4_warning_ratelimit()
924 return ___ratelimit(&(EXT4_SB(sb)->s_warning_ratelimit_state), in ext4_warning_ratelimit()
925 "EXT4-fs warning"); in ext4_warning_ratelimit()
940 printk(KERN_WARNING "EXT4-fs warning (device %s): %s:%d: %pV\n", in __ext4_warning()
941 sb->s_id, function, line, &vaf); in __ext4_warning()
951 if (!ext4_warning_ratelimit(inode->i_sb)) in __ext4_warning_inode()
957 printk(KERN_WARNING "EXT4-fs warning (device %s): %s:%d: " in __ext4_warning_inode()
958 "inode #%lu: comm %s: %pV\n", inode->i_sb->s_id, in __ext4_warning_inode()
959 function, line, inode->i_ino, current->comm, &vaf); in __ext4_warning_inode()
983 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: group %u, ", in __ext4_grp_locked_error()
984 sb->s_id, function, line, grp); in __ext4_grp_locked_error()
1031 &grp->bb_state); in ext4_mark_group_bitmap_corrupted()
1033 percpu_counter_sub(&sbi->s_freeclusters_counter, in ext4_mark_group_bitmap_corrupted()
1034 grp->bb_free); in ext4_mark_group_bitmap_corrupted()
1039 &grp->bb_state); in ext4_mark_group_bitmap_corrupted()
1044 percpu_counter_sub(&sbi->s_freeinodes_counter, in ext4_mark_group_bitmap_corrupted()
1052 struct ext4_super_block *es = EXT4_SB(sb)->s_es; in ext4_update_dynamic_rev() local
1054 if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV) in ext4_update_dynamic_rev()
1062 es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO); in ext4_update_dynamic_rev()
1063 es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE); in ext4_update_dynamic_rev()
1064 es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV); in ext4_update_dynamic_rev()
1065 /* leave es->s_feature_*compat flags alone */ in ext4_update_dynamic_rev()
1066 /* es->s_uuid will be set by e2fsck if empty */ in ext4_update_dynamic_rev()
1089 "failed to open journal device unknown-block(%u,%u) %ld", in ext4_blkdev_get()
1105 bdev = sbi->s_journal_bdev; in ext4_blkdev_remove()
1108 sbi->s_journal_bdev = NULL; in ext4_blkdev_remove()
1114 return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode; in orphan_list_entry()
1122 le32_to_cpu(sbi->s_es->s_last_orphan)); in dump_orphan_list()
1125 list_for_each(l, &sbi->s_orphan) { in dump_orphan_list()
1129 inode->i_sb->s_id, inode->i_ino, inode, in dump_orphan_list()
1130 inode->i_mode, inode->i_nlink, in dump_orphan_list()
1155 return rcu_dereference_protected(sbi->s_qf_names[type], in get_qf_name()
1156 lockdep_is_held(&sb->s_umount)); in get_qf_name()
1167 struct ext4_super_block *es = sbi->s_es; in ext4_put_super() local
1176 * path which could have sbi->s_journal->j_task as NULL in ext4_put_super()
1177 * Unregister sysfs before flush sbi->s_error_work. in ext4_put_super()
1188 destroy_workqueue(sbi->rsv_conversion_wq); in ext4_put_super()
1190 if (sbi->s_journal) { in ext4_put_super()
1191 aborted = is_journal_aborted(sbi->s_journal); in ext4_put_super()
1192 err = jbd2_journal_destroy(sbi->s_journal); in ext4_put_super()
1193 sbi->s_journal = NULL; in ext4_put_super()
1195 ext4_abort(sb, -err, "Couldn't clean up the journal"); in ext4_put_super()
1200 del_timer_sync(&sbi->s_err_report); in ext4_put_super()
1207 es->s_state = cpu_to_le16(sbi->s_mount_state); in ext4_put_super()
1213 group_desc = rcu_dereference(sbi->s_group_desc); in ext4_put_super()
1214 for (i = 0; i < sbi->s_gdb_count; i++) in ext4_put_super()
1217 flex_groups = rcu_dereference(sbi->s_flex_groups); in ext4_put_super()
1219 for (i = 0; i < sbi->s_flex_groups_allocated; i++) in ext4_put_super()
1224 percpu_counter_destroy(&sbi->s_freeclusters_counter); in ext4_put_super()
1225 percpu_counter_destroy(&sbi->s_freeinodes_counter); in ext4_put_super()
1226 percpu_counter_destroy(&sbi->s_dirs_counter); in ext4_put_super()
1227 percpu_counter_destroy(&sbi->s_dirtyclusters_counter); in ext4_put_super()
1228 percpu_counter_destroy(&sbi->s_sra_exceeded_retry_limit); in ext4_put_super()
1229 percpu_free_rwsem(&sbi->s_writepages_rwsem); in ext4_put_super()
1235 /* Debugging code just in case the in-memory inode orphan list in ext4_put_super()
1236 * isn't empty. The on-disk one can be non-empty if we've in ext4_put_super()
1238 * in-memory list had better be clean by this point. */ in ext4_put_super()
1239 if (!list_empty(&sbi->s_orphan)) in ext4_put_super()
1241 J_ASSERT(list_empty(&sbi->s_orphan)); in ext4_put_super()
1243 sync_blockdev(sb->s_bdev); in ext4_put_super()
1244 invalidate_bdev(sb->s_bdev); in ext4_put_super()
1245 if (sbi->s_journal_bdev && sbi->s_journal_bdev != sb->s_bdev) { in ext4_put_super()
1248 * floating about in memory - the physical journal device may in ext4_put_super()
1249 * hotswapped, and it breaks the `ro-after' testing code. in ext4_put_super()
1251 sync_blockdev(sbi->s_journal_bdev); in ext4_put_super()
1252 invalidate_bdev(sbi->s_journal_bdev); in ext4_put_super()
1256 ext4_xattr_destroy_cache(sbi->s_ea_inode_cache); in ext4_put_super()
1257 sbi->s_ea_inode_cache = NULL; in ext4_put_super()
1259 ext4_xattr_destroy_cache(sbi->s_ea_block_cache); in ext4_put_super()
1260 sbi->s_ea_block_cache = NULL; in ext4_put_super()
1264 brelse(sbi->s_sbh); in ext4_put_super()
1265 sb->s_fs_info = NULL; in ext4_put_super()
1270 kobject_put(&sbi->s_kobj); in ext4_put_super()
1271 wait_for_completion(&sbi->s_kobj_unregister); in ext4_put_super()
1272 if (sbi->s_chksum_driver) in ext4_put_super()
1273 crypto_free_shash(sbi->s_chksum_driver); in ext4_put_super()
1274 kfree(sbi->s_blockgroup_lock); in ext4_put_super()
1275 fs_put_dax(sbi->s_daxdev); in ext4_put_super()
1276 fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy); in ext4_put_super()
1278 utf8_unload(sb->s_encoding); in ext4_put_super()
1296 inode_set_iversion(&ei->vfs_inode, 1); in ext4_alloc_inode()
1297 spin_lock_init(&ei->i_raw_lock); in ext4_alloc_inode()
1298 INIT_LIST_HEAD(&ei->i_prealloc_list); in ext4_alloc_inode()
1299 atomic_set(&ei->i_prealloc_active, 0); in ext4_alloc_inode()
1300 spin_lock_init(&ei->i_prealloc_lock); in ext4_alloc_inode()
1301 ext4_es_init_tree(&ei->i_es_tree); in ext4_alloc_inode()
1302 rwlock_init(&ei->i_es_lock); in ext4_alloc_inode()
1303 INIT_LIST_HEAD(&ei->i_es_list); in ext4_alloc_inode()
1304 ei->i_es_all_nr = 0; in ext4_alloc_inode()
1305 ei->i_es_shk_nr = 0; in ext4_alloc_inode()
1306 ei->i_es_shrink_lblk = 0; in ext4_alloc_inode()
1307 ei->i_reserved_data_blocks = 0; in ext4_alloc_inode()
1308 spin_lock_init(&(ei->i_block_reservation_lock)); in ext4_alloc_inode()
1309 ext4_init_pending_tree(&ei->i_pending_tree); in ext4_alloc_inode()
1311 ei->i_reserved_quota = 0; in ext4_alloc_inode()
1312 memset(&ei->i_dquot, 0, sizeof(ei->i_dquot)); in ext4_alloc_inode()
1314 ei->jinode = NULL; in ext4_alloc_inode()
1315 INIT_LIST_HEAD(&ei->i_rsv_conversion_list); in ext4_alloc_inode()
1316 spin_lock_init(&ei->i_completed_io_lock); in ext4_alloc_inode()
1317 ei->i_sync_tid = 0; in ext4_alloc_inode()
1318 ei->i_datasync_tid = 0; in ext4_alloc_inode()
1319 atomic_set(&ei->i_unwritten, 0); in ext4_alloc_inode()
1320 INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work); in ext4_alloc_inode()
1321 ext4_fc_init_inode(&ei->vfs_inode); in ext4_alloc_inode()
1322 mutex_init(&ei->i_fc_lock); in ext4_alloc_inode()
1323 return &ei->vfs_inode; in ext4_alloc_inode()
1340 if (!list_empty(&(EXT4_I(inode)->i_fc_list))) { in ext4_free_in_core_inode()
1342 __func__, inode->i_ino); in ext4_free_in_core_inode()
1349 if (!list_empty(&(EXT4_I(inode)->i_orphan))) { in ext4_destroy_inode()
1350 ext4_msg(inode->i_sb, KERN_ERR, in ext4_destroy_inode()
1352 inode->i_ino, EXT4_I(inode)); in ext4_destroy_inode()
1359 if (EXT4_I(inode)->i_reserved_data_blocks) in ext4_destroy_inode()
1360 ext4_msg(inode->i_sb, KERN_ERR, in ext4_destroy_inode()
1362 inode->i_ino, EXT4_I(inode), in ext4_destroy_inode()
1363 EXT4_I(inode)->i_reserved_data_blocks); in ext4_destroy_inode()
1370 INIT_LIST_HEAD(&ei->i_orphan); in init_once()
1371 init_rwsem(&ei->xattr_sem); in init_once()
1372 init_rwsem(&ei->i_data_sem); in init_once()
1373 init_rwsem(&ei->i_mmap_sem); in init_once()
1374 inode_init_once(&ei->vfs_inode); in init_once()
1375 ext4_fc_init_inode(&ei->vfs_inode); in init_once()
1388 return -ENOMEM; in init_inodecache()
1410 if (EXT4_I(inode)->jinode) { in ext4_clear_inode()
1412 EXT4_I(inode)->jinode); in ext4_clear_inode()
1413 jbd2_free_inode(EXT4_I(inode)->jinode); in ext4_clear_inode()
1414 EXT4_I(inode)->jinode = NULL; in ext4_clear_inode()
1432 if (generation && inode->i_generation != generation) { in ext4_nfs_get_inode()
1434 return ERR_PTR(-ESTALE); in ext4_nfs_get_inode()
1473 journal_t *journal = EXT4_SB(sb)->s_journal; in bdev_try_to_free_page()
1503 if (inode->i_ino == EXT4_ROOT_INO) in ext4_set_context()
1504 return -EPERM; in ext4_set_context()
1507 return -EINVAL; in ext4_set_context()
1510 return -EOPNOTSUPP; in ext4_set_context()
1534 * Update inode->i_flags - S_ENCRYPTED will be enabled, in ext4_set_context()
1561 * Update inode->i_flags - S_ENCRYPTED will be enabled, in ext4_set_context()
1571 if (res == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) in ext4_set_context()
1580 return EXT4_SB(sb)->s_dummy_enc_policy.policy; in ext4_get_dummy_policy()
1591 *ino_bits_ret = 8 * sizeof(EXT4_SB(sb)->s_es->s_inodes_count); in ext4_get_ino_and_lblk_bits()
1629 return EXT4_I(inode)->i_dquot; in ext4_get_dquots()
1730 {Opt_err_ro, "errors=remount-ro"},
1833 printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n", in get_sb_block()
1847 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
1854 int ret = -1; in set_qf_name()
1860 return -1; in set_qf_name()
1871 return -1; in set_qf_name()
1887 rcu_assign_pointer(sbi->s_qf_names[qtype], qname); in set_qf_name()
1904 return -1; in clear_qf_name()
1906 rcu_assign_pointer(sbi->s_qf_names[qtype], NULL); in clear_qf_name()
2051 static int ext4_sb_read_encoding(const struct ext4_super_block *es, in ext4_sb_read_encoding() argument
2055 __u16 magic = le16_to_cpu(es->s_encoding); in ext4_sb_read_encoding()
2063 return -EINVAL; in ext4_sb_read_encoding()
2066 *flags = le16_to_cpu(es->s_encoding_flags); in ext4_sb_read_encoding()
2084 return -1; in ext4_set_test_dummy_encryption()
2093 if (is_remount && !sbi->s_dummy_enc_policy.policy) { in ext4_set_test_dummy_encryption()
2096 return -1; in ext4_set_test_dummy_encryption()
2098 err = fscrypt_set_test_dummy_encryption(sb, arg->from, in ext4_set_test_dummy_encryption()
2099 &sbi->s_dummy_enc_policy); in ext4_set_test_dummy_encryption()
2101 if (err == -EEXIST) in ext4_set_test_dummy_encryption()
2104 else if (err == -EINVAL) in ext4_set_test_dummy_encryption()
2111 return -1; in ext4_set_test_dummy_encryption()
2118 return -1; in ext4_set_test_dummy_encryption()
2157 sb->s_flags |= SB_I_VERSION; in handle_mount_opt()
2160 sb->s_flags |= SB_LAZYTIME; in handle_mount_opt()
2163 sb->s_flags &= ~SB_LAZYTIME; in handle_mount_opt()
2167 sb->s_flags |= SB_INLINECRYPT; in handle_mount_opt()
2174 for (m = ext4_mount_opts; m->token != Opt_err; m++) in handle_mount_opt()
2175 if (token == m->token) in handle_mount_opt()
2178 if (m->token == Opt_err) { in handle_mount_opt()
2181 return -1; in handle_mount_opt()
2184 if ((m->flags & MOPT_NO_EXT2) && IS_EXT2_SB(sb)) { in handle_mount_opt()
2187 return -1; in handle_mount_opt()
2189 if ((m->flags & MOPT_NO_EXT3) && IS_EXT3_SB(sb)) { in handle_mount_opt()
2192 return -1; in handle_mount_opt()
2195 if (args->from && !(m->flags & MOPT_STRING) && match_int(args, &arg)) in handle_mount_opt()
2196 return -1; in handle_mount_opt()
2197 if (args->from && (m->flags & MOPT_GTE0) && (arg < 0)) in handle_mount_opt()
2198 return -1; in handle_mount_opt()
2199 if (m->flags & MOPT_EXPLICIT) { in handle_mount_opt()
2200 if (m->mount_opt & EXT4_MOUNT_DELALLOC) { in handle_mount_opt()
2202 } else if (m->mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) { in handle_mount_opt()
2205 return -1; in handle_mount_opt()
2207 if (m->flags & MOPT_CLEAR_ERR) in handle_mount_opt()
2212 return -1; in handle_mount_opt()
2215 if (m->flags & MOPT_NOSUPPORT) { in handle_mount_opt()
2225 return -1; in handle_mount_opt()
2227 sbi->s_commit_interval = HZ * arg; in handle_mount_opt()
2231 (arg > (sbi->s_inode_size - EXT4_GOOD_OLD_INODE_SIZE))) { in handle_mount_opt()
2234 return -1; in handle_mount_opt()
2236 sbi->s_want_extra_isize = arg; in handle_mount_opt()
2238 sbi->s_max_batch_time = arg; in handle_mount_opt()
2240 sbi->s_min_batch_time = arg; in handle_mount_opt()
2244 "EXT4-fs: inode_readahead_blks must be " in handle_mount_opt()
2246 return -1; in handle_mount_opt()
2248 sbi->s_inode_readahead_blks = arg; in handle_mount_opt()
2251 if (!args->from) in handle_mount_opt()
2253 sbi->s_li_wait_mult = arg; in handle_mount_opt()
2255 sbi->s_max_dir_size_kb = arg; in handle_mount_opt()
2258 sbi->s_fc_debug_max_replay = arg; in handle_mount_opt()
2261 sbi->s_stripe = arg; in handle_mount_opt()
2266 return -1; in handle_mount_opt()
2268 sbi->s_resuid = uid; in handle_mount_opt()
2273 return -1; in handle_mount_opt()
2275 sbi->s_resgid = gid; in handle_mount_opt()
2280 return -1; in handle_mount_opt()
2292 return -1; in handle_mount_opt()
2298 return -1; in handle_mount_opt()
2306 return -1; in handle_mount_opt()
2310 if (!S_ISBLK(journal_inode->i_mode)) { in handle_mount_opt()
2315 return -1; in handle_mount_opt()
2318 *journal_devnum = new_encode_dev(journal_inode->i_rdev); in handle_mount_opt()
2324 " (must be 0-7)"); in handle_mount_opt()
2325 return -1; in handle_mount_opt()
2332 } else if (m->flags & MOPT_DATAJ) { in handle_mount_opt()
2334 if (!sbi->s_journal) in handle_mount_opt()
2336 else if (test_opt(sb, DATA_FLAGS) != m->mount_opt) { in handle_mount_opt()
2339 return -1; in handle_mount_opt()
2343 sbi->s_mount_opt |= m->mount_opt; in handle_mount_opt()
2346 } else if (m->flags & MOPT_QFMT) { in handle_mount_opt()
2348 sbi->s_jquota_fmt != m->mount_opt) { in handle_mount_opt()
2351 return -1; in handle_mount_opt()
2359 sbi->s_jquota_fmt = m->mount_opt; in handle_mount_opt()
2368 (!(sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) || in handle_mount_opt()
2369 (sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER))) { in handle_mount_opt()
2373 return -1; in handle_mount_opt()
2380 return -1; in handle_mount_opt()
2384 sbi->s_mount_opt |= EXT4_MOUNT_DAX_ALWAYS; in handle_mount_opt()
2385 sbi->s_mount_opt2 &= ~EXT4_MOUNT2_DAX_NEVER; in handle_mount_opt()
2389 (!(sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER) || in handle_mount_opt()
2390 (sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS))) in handle_mount_opt()
2392 sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_NEVER; in handle_mount_opt()
2393 sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS; in handle_mount_opt()
2397 ((sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) || in handle_mount_opt()
2398 (sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER) || in handle_mount_opt()
2399 !(sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_INODE))) in handle_mount_opt()
2401 sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS; in handle_mount_opt()
2402 sbi->s_mount_opt2 &= ~EXT4_MOUNT2_DAX_NEVER; in handle_mount_opt()
2404 sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_INODE; in handle_mount_opt()
2409 sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_NEVER; in handle_mount_opt()
2410 sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS; in handle_mount_opt()
2411 return -1; in handle_mount_opt()
2414 sbi->s_mount_opt |= m->mount_opt; in handle_mount_opt()
2416 sbi->s_mount_opt &= ~m->mount_opt; in handle_mount_opt()
2418 if (!args->from) in handle_mount_opt()
2420 if (m->flags & MOPT_CLEAR) in handle_mount_opt()
2422 else if (unlikely(!(m->flags & MOPT_SET))) { in handle_mount_opt()
2426 return -1; in handle_mount_opt()
2428 if (m->flags & MOPT_2) { in handle_mount_opt()
2430 sbi->s_mount_opt2 |= m->mount_opt; in handle_mount_opt()
2432 sbi->s_mount_opt2 &= ~m->mount_opt; in handle_mount_opt()
2435 sbi->s_mount_opt |= m->mount_opt; in handle_mount_opt()
2437 sbi->s_mount_opt &= ~m->mount_opt; in handle_mount_opt()
2477 "Cannot enable project quota enforcement."); in parse_options()
2495 if (!sbi->s_jquota_fmt) { in parse_options()
2504 BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size); in parse_options()
2520 if (sbi->s_jquota_fmt) { in ext4_show_quota_options()
2523 switch (sbi->s_jquota_fmt) { in ext4_show_quota_options()
2538 usr_qf_name = rcu_dereference(sbi->s_qf_names[USRQUOTA]); in ext4_show_quota_options()
2539 grp_qf_name = rcu_dereference(sbi->s_qf_names[GRPQUOTA]); in ext4_show_quota_options()
2552 for (t = tokens; t->token != Opt_err; t++) in token2str()
2553 if (t->token == token && !strchr(t->pattern, '=')) in token2str()
2555 return t->pattern; in token2str()
2560 * - it's set to a non-default value OR
2561 * - if the per-sb default is different from the global default
2567 struct ext4_super_block *es = sbi->s_es; in _ext4_show_options() local
2568 int def_errors, def_mount_opt = sbi->s_def_mount_opt; in _ext4_show_options()
2575 if (sbi->s_sb_block != 1) in _ext4_show_options()
2576 SEQ_OPTS_PRINT("sb=%llu", sbi->s_sb_block); in _ext4_show_options()
2578 for (m = ext4_mount_opts; m->token != Opt_err; m++) { in _ext4_show_options()
2579 int want_set = m->flags & MOPT_SET; in _ext4_show_options()
2580 if (((m->flags & (MOPT_SET|MOPT_CLEAR)) == 0) || in _ext4_show_options()
2581 (m->flags & MOPT_CLEAR_ERR) || m->flags & MOPT_SKIP) in _ext4_show_options()
2583 if (!nodefs && !(m->mount_opt & (sbi->s_mount_opt ^ def_mount_opt))) in _ext4_show_options()
2586 (sbi->s_mount_opt & m->mount_opt) != m->mount_opt) || in _ext4_show_options()
2587 (!want_set && (sbi->s_mount_opt & m->mount_opt))) in _ext4_show_options()
2589 SEQ_OPTS_PRINT("%s", token2str(m->token)); in _ext4_show_options()
2592 if (nodefs || !uid_eq(sbi->s_resuid, make_kuid(&init_user_ns, EXT4_DEF_RESUID)) || in _ext4_show_options()
2593 le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID) in _ext4_show_options()
2595 from_kuid_munged(&init_user_ns, sbi->s_resuid)); in _ext4_show_options()
2596 if (nodefs || !gid_eq(sbi->s_resgid, make_kgid(&init_user_ns, EXT4_DEF_RESGID)) || in _ext4_show_options()
2597 le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID) in _ext4_show_options()
2599 from_kgid_munged(&init_user_ns, sbi->s_resgid)); in _ext4_show_options()
2600 def_errors = nodefs ? -1 : le16_to_cpu(es->s_errors); in _ext4_show_options()
2602 SEQ_OPTS_PUTS("errors=remount-ro"); in _ext4_show_options()
2607 if (nodefs || sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) in _ext4_show_options()
2608 SEQ_OPTS_PRINT("commit=%lu", sbi->s_commit_interval / HZ); in _ext4_show_options()
2609 if (nodefs || sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME) in _ext4_show_options()
2610 SEQ_OPTS_PRINT("min_batch_time=%u", sbi->s_min_batch_time); in _ext4_show_options()
2611 if (nodefs || sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME) in _ext4_show_options()
2612 SEQ_OPTS_PRINT("max_batch_time=%u", sbi->s_max_batch_time); in _ext4_show_options()
2613 if (sb->s_flags & SB_I_VERSION) in _ext4_show_options()
2615 if (nodefs || sbi->s_stripe) in _ext4_show_options()
2616 SEQ_OPTS_PRINT("stripe=%lu", sbi->s_stripe); in _ext4_show_options()
2618 (sbi->s_mount_opt ^ def_mount_opt)) { in _ext4_show_options()
2627 sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS) in _ext4_show_options()
2629 sbi->s_inode_readahead_blks); in _ext4_show_options()
2632 (sbi->s_li_wait_mult != EXT4_DEF_LI_WAIT_MULT))) in _ext4_show_options()
2633 SEQ_OPTS_PRINT("init_itable=%u", sbi->s_li_wait_mult); in _ext4_show_options()
2634 if (nodefs || sbi->s_max_dir_size_kb) in _ext4_show_options()
2635 SEQ_OPTS_PRINT("max_dir_size_kb=%u", sbi->s_max_dir_size_kb); in _ext4_show_options()
2641 if (sb->s_flags & SB_INLINECRYPT) in _ext4_show_options()
2660 return _ext4_show_options(seq, root->d_sb, 0); in ext4_show_options()
2665 struct super_block *sb = seq->private; in ext4_seq_options_show()
2674 static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, in ext4_setup_super() argument
2680 if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) { in ext4_setup_super()
2682 "forcing read-only mode"); in ext4_setup_super()
2683 err = -EROFS; in ext4_setup_super()
2688 if (!(sbi->s_mount_state & EXT4_VALID_FS)) in ext4_setup_super()
2691 else if (sbi->s_mount_state & EXT4_ERROR_FS) in ext4_setup_super()
2695 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) > 0 && in ext4_setup_super()
2696 le16_to_cpu(es->s_mnt_count) >= in ext4_setup_super()
2697 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count)) in ext4_setup_super()
2701 else if (le32_to_cpu(es->s_checkinterval) && in ext4_setup_super()
2702 (ext4_get_tstamp(es, s_lastcheck) + in ext4_setup_super()
2703 le32_to_cpu(es->s_checkinterval) <= ktime_get_real_seconds())) in ext4_setup_super()
2707 if (!sbi->s_journal) in ext4_setup_super()
2708 es->s_state &= cpu_to_le16(~EXT4_VALID_FS); in ext4_setup_super()
2709 if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) in ext4_setup_super()
2710 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); in ext4_setup_super()
2711 le16_add_cpu(&es->s_mnt_count, 1); in ext4_setup_super()
2712 ext4_update_tstamp(es, s_mtime); in ext4_setup_super()
2713 if (sbi->s_journal) in ext4_setup_super()
2721 sb->s_blocksize, in ext4_setup_super()
2722 sbi->s_groups_count, in ext4_setup_super()
2725 sbi->s_mount_opt, sbi->s_mount_opt2); in ext4_setup_super()
2737 if (!sbi->s_log_groups_per_flex) in ext4_alloc_flex_bg_array()
2740 size = ext4_flex_group(sbi, ngroup - 1) + 1; in ext4_alloc_flex_bg_array()
2741 if (size <= sbi->s_flex_groups_allocated) in ext4_alloc_flex_bg_array()
2745 sizeof(*sbi->s_flex_groups)), GFP_KERNEL); in ext4_alloc_flex_bg_array()
2749 return -ENOMEM; in ext4_alloc_flex_bg_array()
2751 for (i = sbi->s_flex_groups_allocated; i < size; i++) { in ext4_alloc_flex_bg_array()
2756 for (j = sbi->s_flex_groups_allocated; j < i; j++) in ext4_alloc_flex_bg_array()
2761 return -ENOMEM; in ext4_alloc_flex_bg_array()
2765 old_groups = rcu_dereference(sbi->s_flex_groups); in ext4_alloc_flex_bg_array()
2768 (sbi->s_flex_groups_allocated * in ext4_alloc_flex_bg_array()
2771 rcu_assign_pointer(sbi->s_flex_groups, new_groups); in ext4_alloc_flex_bg_array()
2772 sbi->s_flex_groups_allocated = size; in ext4_alloc_flex_bg_array()
2786 sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex; in ext4_fill_flex_info()
2787 if (sbi->s_log_groups_per_flex < 1 || sbi->s_log_groups_per_flex > 31) { in ext4_fill_flex_info()
2788 sbi->s_log_groups_per_flex = 0; in ext4_fill_flex_info()
2792 err = ext4_alloc_flex_bg_array(sb, sbi->s_groups_count); in ext4_fill_flex_info()
2796 for (i = 0; i < sbi->s_groups_count; i++) { in ext4_fill_flex_info()
2801 atomic_add(ext4_free_inodes_count(sb, gdp), &fg->free_inodes); in ext4_fill_flex_info()
2803 &fg->free_clusters); in ext4_fill_flex_info()
2804 atomic_add(ext4_used_dirs_count(sb, gdp), &fg->used_dirs); in ext4_fill_flex_info()
2820 if (ext4_has_metadata_csum(sbi->s_sb)) { in ext4_group_desc_csum()
2825 csum32 = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&le_group, in ext4_group_desc_csum()
2831 if (offset < sbi->s_desc_size) in ext4_group_desc_csum()
2833 sbi->s_desc_size - offset); in ext4_group_desc_csum()
2843 crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid)); in ext4_group_desc_csum()
2846 offset += sizeof(gdp->bg_checksum); /* skip checksum */ in ext4_group_desc_csum()
2849 offset < le16_to_cpu(sbi->s_es->s_desc_size)) in ext4_group_desc_csum()
2851 le16_to_cpu(sbi->s_es->s_desc_size) - in ext4_group_desc_csum()
2862 (gdp->bg_checksum != ext4_group_desc_csum(sb, block_group, gdp))) in ext4_group_desc_csum_verify()
2873 gdp->bg_checksum = ext4_group_desc_csum(sb, block_group, gdp); in ext4_group_desc_csum_set()
2876 /* Called at mount-time, super-block is locked */
2882 ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block); in ext4_check_descriptors()
2889 ext4_group_t i, grp = sbi->s_groups_count; in ext4_check_descriptors()
2896 for (i = 0; i < sbi->s_groups_count; i++) { in ext4_check_descriptors()
2899 if (i == sbi->s_groups_count - 1 || flexbg_flag) in ext4_check_descriptors()
2900 last_block = ext4_blocks_count(sbi->s_es) - 1; in ext4_check_descriptors()
2903 (EXT4_BLOCKS_PER_GROUP(sb) - 1); in ext4_check_descriptors()
2905 if ((grp == sbi->s_groups_count) && in ext4_check_descriptors()
2906 !(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED))) in ext4_check_descriptors()
2970 inode_table + sbi->s_itb_per_group - 1 > last_block) { in ext4_check_descriptors()
2981 gdp)), le16_to_cpu(gdp->bg_checksum)); in ext4_check_descriptors()
2996 /* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at
2999 * inodes at recovery time (only with a read-write filesystem).
3007 * accidentally point at an in-use or already deleted inode. The worst that
3014 struct ext4_super_block *es) in ext4_orphan_cleanup() argument
3016 unsigned int s_flags = sb->s_flags; in ext4_orphan_cleanup()
3022 if (!es->s_last_orphan) { in ext4_orphan_cleanup()
3027 if (bdev_read_only(sb->s_bdev)) { in ext4_orphan_cleanup()
3040 if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) { in ext4_orphan_cleanup()
3042 if (es->s_last_orphan && !(s_flags & SB_RDONLY)) { in ext4_orphan_cleanup()
3045 es->s_last_orphan = 0; in ext4_orphan_cleanup()
3053 sb->s_flags &= ~SB_RDONLY; in ext4_orphan_cleanup()
3057 * Turn on quotas which were not enabled for read-only mounts if in ext4_orphan_cleanup()
3072 if (EXT4_SB(sb)->s_qf_names[i]) { in ext4_orphan_cleanup()
3085 while (es->s_last_orphan) { in ext4_orphan_cleanup()
3092 if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) { in ext4_orphan_cleanup()
3094 es->s_last_orphan = 0; in ext4_orphan_cleanup()
3098 inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan)); in ext4_orphan_cleanup()
3100 es->s_last_orphan = 0; in ext4_orphan_cleanup()
3104 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan); in ext4_orphan_cleanup()
3106 if (inode->i_nlink) { in ext4_orphan_cleanup()
3110 __func__, inode->i_ino, inode->i_size); in ext4_orphan_cleanup()
3112 inode->i_ino, inode->i_size); in ext4_orphan_cleanup()
3114 truncate_inode_pages(inode->i_mapping, inode->i_size); in ext4_orphan_cleanup()
3118 * We need to clean up the in-core orphan list in ext4_orphan_cleanup()
3123 ext4_std_error(inode->i_sb, ret); in ext4_orphan_cleanup()
3131 __func__, inode->i_ino); in ext4_orphan_cleanup()
3133 inode->i_ino); in ext4_orphan_cleanup()
3151 if (sb_dqopt(sb)->files[i]) in ext4_orphan_cleanup()
3156 sb->s_flags = s_flags; /* Restore SB_RDONLY status */ in ext4_orphan_cleanup()
3161 * Resulting logical blkno at s_maxbytes must fit in our on-disk
3168 * covering maximum file size must fit into on-disk format containers as
3182 upper_limit = (1LL << 32) - 1; in ext4_max_size()
3185 upper_limit >>= (blkbits - 9); in ext4_max_size()
3190 * 32-bit extent-start container, ee_block. We lower the maxbytes in ext4_max_size()
3194 res = (1LL << 32) - 1; in ext4_max_size()
3197 /* Sanity check against vm- & vfs- imposed limits */ in ext4_max_size()
3205 * Maximal bitmap file size. There is a direct, and {,double-,triple-}indirect
3206 * block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks.
3216 * mapped file such that the file's total number of 512-byte sectors, in ext4_max_bitmap_size()
3217 * including data and all indirect blocks, does not exceed (2^48 - 1). in ext4_max_bitmap_size()
3220 * number of 512-byte sectors of the file. in ext4_max_bitmap_size()
3225 * represents total file blocks in 2^32 512-byte sectors == in ext4_max_bitmap_size()
3228 upper_limit = (1LL << 32) - 1; in ext4_max_bitmap_size()
3231 upper_limit >>= (bits - 9); in ext4_max_bitmap_size()
3240 upper_limit = (1LL << 48) - 1; in ext4_max_bitmap_size()
3247 meta_blocks += 1 + (1LL << (bits-2)); in ext4_max_bitmap_size()
3249 meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2))); in ext4_max_bitmap_size()
3251 upper_limit -= meta_blocks; in ext4_max_bitmap_size()
3254 res += 1LL << (bits-2); in ext4_max_bitmap_size()
3255 res += 1LL << (2*(bits-2)); in ext4_max_bitmap_size()
3256 res += 1LL << (3*(bits-2)); in ext4_max_bitmap_size()
3274 first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg); in descriptor_loc()
3278 bg = sbi->s_desc_per_block * nr; in descriptor_loc()
3288 if (sb->s_blocksize == 1024 && nr == 0 && in descriptor_loc()
3289 le32_to_cpu(sbi->s_es->s_first_data_block) == 0) in descriptor_loc()
3308 unsigned long stride = le16_to_cpu(sbi->s_es->s_raid_stride); in ext4_get_stripe_size()
3310 le32_to_cpu(sbi->s_es->s_raid_stripe_width); in ext4_get_stripe_size()
3313 if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group) in ext4_get_stripe_size()
3314 ret = sbi->s_stripe; in ext4_get_stripe_size()
3315 else if (stripe_width && stripe_width <= sbi->s_blocks_per_group) in ext4_get_stripe_size()
3317 else if (stride && stride <= sbi->s_blocks_per_group) in ext4_get_stripe_size()
3344 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) & in ext4_feature_set_ok()
3362 ext4_msg(sb, KERN_INFO, "filesystem is read-only"); in ext4_feature_set_ok()
3363 sb->s_flags |= SB_RDONLY; in ext4_feature_set_ok()
3367 /* Check that feature set is OK for a read-write mount */ in ext4_feature_set_ok()
3371 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) & in ext4_feature_set_ok()
3400 struct super_block *sb = sbi->s_sb; in print_daily_error_info()
3401 struct ext4_super_block *es = sbi->s_es; in print_daily_error_info() local
3403 if (es->s_error_count) in print_daily_error_info()
3406 le32_to_cpu(es->s_error_count)); in print_daily_error_info()
3407 if (es->s_first_error_time) { in print_daily_error_info()
3408 printk(KERN_NOTICE "EXT4-fs (%s): initial error at time %llu: %.*s:%d", in print_daily_error_info()
3409 sb->s_id, in print_daily_error_info()
3410 ext4_get_tstamp(es, s_first_error_time), in print_daily_error_info()
3411 (int) sizeof(es->s_first_error_func), in print_daily_error_info()
3412 es->s_first_error_func, in print_daily_error_info()
3413 le32_to_cpu(es->s_first_error_line)); in print_daily_error_info()
3414 if (es->s_first_error_ino) in print_daily_error_info()
3416 le32_to_cpu(es->s_first_error_ino)); in print_daily_error_info()
3417 if (es->s_first_error_block) in print_daily_error_info()
3419 le64_to_cpu(es->s_first_error_block)); in print_daily_error_info()
3422 if (es->s_last_error_time) { in print_daily_error_info()
3423 printk(KERN_NOTICE "EXT4-fs (%s): last error at time %llu: %.*s:%d", in print_daily_error_info()
3424 sb->s_id, in print_daily_error_info()
3425 ext4_get_tstamp(es, s_last_error_time), in print_daily_error_info()
3426 (int) sizeof(es->s_last_error_func), in print_daily_error_info()
3427 es->s_last_error_func, in print_daily_error_info()
3428 le32_to_cpu(es->s_last_error_line)); in print_daily_error_info()
3429 if (es->s_last_error_ino) in print_daily_error_info()
3431 le32_to_cpu(es->s_last_error_ino)); in print_daily_error_info()
3432 if (es->s_last_error_block) in print_daily_error_info()
3434 le64_to_cpu(es->s_last_error_block)); in print_daily_error_info()
3437 mod_timer(&sbi->s_err_report, jiffies + 24*60*60*HZ); /* Once a day */ in print_daily_error_info()
3444 struct super_block *sb = elr->lr_super; in ext4_run_li_request()
3445 ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count; in ext4_run_li_request()
3446 ext4_group_t group = elr->lr_next_group; in ext4_run_li_request()
3451 if (elr->lr_mode == EXT4_LI_MODE_PREFETCH_BBITMAP) { in ext4_run_li_request()
3452 elr->lr_next_group = ext4_mb_prefetch(sb, group, in ext4_run_li_request()
3453 EXT4_SB(sb)->s_mb_prefetch, &prefetch_ios); in ext4_run_li_request()
3455 ext4_mb_prefetch_fini(sb, elr->lr_next_group, in ext4_run_li_request()
3457 trace_ext4_prefetch_bitmaps(sb, group, elr->lr_next_group, in ext4_run_li_request()
3459 if (group >= elr->lr_next_group) { in ext4_run_li_request()
3461 if (elr->lr_first_not_zeroed != ngroups && in ext4_run_li_request()
3463 elr->lr_next_group = elr->lr_first_not_zeroed; in ext4_run_li_request()
3464 elr->lr_mode = EXT4_LI_MODE_ITABLE; in ext4_run_li_request()
3478 if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED))) in ext4_run_li_request()
3488 elr->lr_timeout ? 0 : 1); in ext4_run_li_request()
3490 if (elr->lr_timeout == 0) { in ext4_run_li_request()
3491 elr->lr_timeout = nsecs_to_jiffies((ktime_get_real_ns() - start_time) * in ext4_run_li_request()
3492 EXT4_SB(elr->lr_super)->s_li_wait_mult); in ext4_run_li_request()
3494 elr->lr_next_sched = jiffies + elr->lr_timeout; in ext4_run_li_request()
3495 elr->lr_next_group = group + 1; in ext4_run_li_request()
3509 list_del(&elr->lr_request); in ext4_remove_li_request()
3510 EXT4_SB(elr->lr_super)->s_li_request = NULL; in ext4_remove_li_request()
3522 mutex_lock(&ext4_li_info->li_list_mtx); in ext4_unregister_li_request()
3523 ext4_remove_li_request(EXT4_SB(sb)->s_li_request); in ext4_unregister_li_request()
3524 mutex_unlock(&ext4_li_info->li_list_mtx); in ext4_unregister_li_request()
3553 mutex_lock(&eli->li_list_mtx); in ext4_lazyinit_thread()
3554 if (list_empty(&eli->li_request_list)) { in ext4_lazyinit_thread()
3555 mutex_unlock(&eli->li_list_mtx); in ext4_lazyinit_thread()
3558 list_for_each_safe(pos, n, &eli->li_request_list) { in ext4_lazyinit_thread()
3564 if (time_before(jiffies, elr->lr_next_sched)) { in ext4_lazyinit_thread()
3565 if (time_before(elr->lr_next_sched, next_wakeup)) in ext4_lazyinit_thread()
3566 next_wakeup = elr->lr_next_sched; in ext4_lazyinit_thread()
3569 if (down_read_trylock(&elr->lr_super->s_umount)) { in ext4_lazyinit_thread()
3570 if (sb_start_write_trylock(elr->lr_super)) { in ext4_lazyinit_thread()
3573 * We hold sb->s_umount, sb can not in ext4_lazyinit_thread()
3577 mutex_unlock(&eli->li_list_mtx); in ext4_lazyinit_thread()
3579 sb_end_write(elr->lr_super); in ext4_lazyinit_thread()
3580 mutex_lock(&eli->li_list_mtx); in ext4_lazyinit_thread()
3581 n = pos->next; in ext4_lazyinit_thread()
3583 up_read((&elr->lr_super->s_umount)); in ext4_lazyinit_thread()
3591 elr->lr_next_sched = jiffies + in ext4_lazyinit_thread()
3595 if (time_before(elr->lr_next_sched, next_wakeup)) in ext4_lazyinit_thread()
3596 next_wakeup = elr->lr_next_sched; in ext4_lazyinit_thread()
3598 mutex_unlock(&eli->li_list_mtx); in ext4_lazyinit_thread()
3609 schedule_timeout_interruptible(next_wakeup - cur); in ext4_lazyinit_thread()
3627 mutex_lock(&eli->li_list_mtx); in ext4_lazyinit_thread()
3628 if (!list_empty(&eli->li_request_list)) { in ext4_lazyinit_thread()
3629 mutex_unlock(&eli->li_list_mtx); in ext4_lazyinit_thread()
3633 mutex_unlock(&eli->li_list_mtx); in ext4_lazyinit_thread()
3646 mutex_lock(&ext4_li_info->li_list_mtx); in ext4_clear_request_list()
3647 list_for_each_safe(pos, n, &ext4_li_info->li_request_list) { in ext4_clear_request_list()
3652 mutex_unlock(&ext4_li_info->li_list_mtx); in ext4_clear_request_list()
3664 printk(KERN_CRIT "EXT4-fs: error %d creating inode table " in ext4_run_lazyinit_thread()
3669 ext4_li_info->li_state |= EXT4_LAZYINIT_RUNNING; in ext4_run_lazyinit_thread()
3681 ext4_group_t group, ngroups = EXT4_SB(sb)->s_groups_count; in ext4_has_uninit_itable()
3692 if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED))) in ext4_has_uninit_itable()
3705 return -ENOMEM; in ext4_li_info_new()
3707 INIT_LIST_HEAD(&eli->li_request_list); in ext4_li_info_new()
3708 mutex_init(&eli->li_list_mtx); in ext4_li_info_new()
3710 eli->li_state |= EXT4_LAZYINIT_QUIT; in ext4_li_info_new()
3726 elr->lr_super = sb; in ext4_li_request_new()
3727 elr->lr_first_not_zeroed = start; in ext4_li_request_new()
3729 elr->lr_mode = EXT4_LI_MODE_PREFETCH_BBITMAP; in ext4_li_request_new()
3731 elr->lr_mode = EXT4_LI_MODE_ITABLE; in ext4_li_request_new()
3732 elr->lr_next_group = start; in ext4_li_request_new()
3740 elr->lr_next_sched = jiffies + (prandom_u32() % in ext4_li_request_new()
3750 ext4_group_t ngroups = sbi->s_groups_count; in ext4_register_li_request()
3754 if (sbi->s_li_request != NULL) { in ext4_register_li_request()
3759 sbi->s_li_request->lr_timeout = 0; in ext4_register_li_request()
3770 ret = -ENOMEM; in ext4_register_li_request()
3780 mutex_lock(&ext4_li_info->li_list_mtx); in ext4_register_li_request()
3781 list_add(&elr->lr_request, &ext4_li_info->li_request_list); in ext4_register_li_request()
3782 mutex_unlock(&ext4_li_info->li_list_mtx); in ext4_register_li_request()
3784 sbi->s_li_request = elr; in ext4_register_li_request()
3792 if (!(ext4_li_info->li_state & EXT4_LAZYINIT_RUNNING)) { in ext4_register_li_request()
3836 jbd2_journal_clear_features(sbi->s_journal, in set_journal_csum_feature_set()
3841 ret = jbd2_journal_set_features(sbi->s_journal, in set_journal_csum_feature_set()
3846 ret = jbd2_journal_set_features(sbi->s_journal, in set_journal_csum_feature_set()
3849 jbd2_journal_clear_features(sbi->s_journal, 0, 0, in set_journal_csum_feature_set()
3852 jbd2_journal_clear_features(sbi->s_journal, 0, 0, in set_journal_csum_feature_set()
3867 * older file systems --- and if we come across with a bigalloc file
3869 * correct especially for very large cluster sizes --- but for newer
3872 * present (even for non-bigalloc file systems), we will use it.
3886 (has_super ? le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) : 0) + in count_overhead()
3887 sbi->s_itb_per_group + 2); in count_overhead()
3889 first_block = le32_to_cpu(sbi->s_es->s_first_data_block) + in count_overhead()
3891 last_block = first_block + EXT4_BLOCKS_PER_GROUP(sb) - 1; in count_overhead()
3896 ext4_set_bit(EXT4_B2C(sbi, b - first_block), buf); in count_overhead()
3901 ext4_set_bit(EXT4_B2C(sbi, b - first_block), buf); in count_overhead()
3905 if (b >= first_block && b + sbi->s_itb_per_group <= last_block) in count_overhead()
3906 for (j = 0; j < sbi->s_itb_per_group; j++, b++) { in count_overhead()
3907 int c = EXT4_B2C(sbi, b - first_block); in count_overhead()
3922 j = EXT4_BLOCKS_PER_GROUP(sb) - s; in count_overhead()
3925 for (; j > 0; j--) in count_overhead()
3930 return EXT4_CLUSTERS_PER_GROUP(sb) - in count_overhead()
3935 * Compute the overhead and stash it in sbi->s_overhead
3940 struct ext4_super_block *es = sbi->s_es; in ext4_calculate_overhead() local
3942 unsigned int j_blocks, j_inum = le32_to_cpu(es->s_journal_inum); in ext4_calculate_overhead()
3948 return -ENOMEM; in ext4_calculate_overhead()
3959 overhead = EXT4_B2C(sbi, le32_to_cpu(es->s_first_data_block)); in ext4_calculate_overhead()
3978 if (sbi->s_journal && !sbi->s_journal_bdev) in ext4_calculate_overhead()
3979 overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len); in ext4_calculate_overhead()
3980 else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) { in ext4_calculate_overhead()
3981 /* j_inum for internal journal is non-zero */ in ext4_calculate_overhead()
3984 j_blocks = j_inode->i_size >> sb->s_blocksize_bits; in ext4_calculate_overhead()
3991 sbi->s_overhead = overhead; in ext4_calculate_overhead()
4018 resv_clusters = (ext4_blocks_count(sbi->s_es) >> in ext4_set_resv_clusters()
4019 sbi->s_cluster_bits); in ext4_set_resv_clusters()
4024 atomic64_set(&sbi->s_resv_clusters, resv_clusters); in ext4_set_resv_clusters()
4029 struct dax_device *dax_dev = fs_dax_get_by_bdev(sb->s_bdev); in ext4_fill_super()
4032 struct ext4_super_block *es = NULL; in ext4_fill_super() local
4043 int ret = -ENOMEM; in ext4_fill_super()
4056 sbi->s_daxdev = dax_dev; in ext4_fill_super()
4057 sbi->s_blockgroup_lock = in ext4_fill_super()
4059 if (!sbi->s_blockgroup_lock) in ext4_fill_super()
4062 sb->s_fs_info = sbi; in ext4_fill_super()
4063 sbi->s_sb = sb; in ext4_fill_super()
4064 sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; in ext4_fill_super()
4065 sbi->s_sb_block = sb_block; in ext4_fill_super()
4066 if (sb->s_bdev->bd_part) in ext4_fill_super()
4067 sbi->s_sectors_written_start = in ext4_fill_super()
4068 part_stat_read(sb->s_bdev->bd_part, sectors[STAT_WRITE]); in ext4_fill_super()
4071 strreplace(sb->s_id, '/', '!'); in ext4_fill_super()
4073 /* -EINVAL is default */ in ext4_fill_super()
4074 ret = -EINVAL; in ext4_fill_super()
4101 * some ext4 macro-instructions depend on its value in ext4_fill_super()
4103 es = (struct ext4_super_block *) (bh->b_data + offset); in ext4_fill_super()
4104 sbi->s_es = es; in ext4_fill_super()
4105 sb->s_magic = le16_to_cpu(es->s_magic); in ext4_fill_super()
4106 if (sb->s_magic != EXT4_SUPER_MAGIC) in ext4_fill_super()
4108 sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written); in ext4_fill_super()
4117 if (!ext4_verify_csum_type(sb, es)) { in ext4_fill_super()
4125 sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0); in ext4_fill_super()
4126 if (IS_ERR(sbi->s_chksum_driver)) { in ext4_fill_super()
4128 ret = PTR_ERR(sbi->s_chksum_driver); in ext4_fill_super()
4129 sbi->s_chksum_driver = NULL; in ext4_fill_super()
4134 if (!ext4_superblock_csum_verify(sb, es)) { in ext4_fill_super()
4138 ret = -EFSBADCRC; in ext4_fill_super()
4144 sbi->s_csum_seed = le32_to_cpu(es->s_checksum_seed); in ext4_fill_super()
4146 sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid, in ext4_fill_super()
4147 sizeof(es->s_uuid)); in ext4_fill_super()
4150 def_mount_opts = le32_to_cpu(es->s_default_mount_opts); in ext4_fill_super()
4165 /* don't forget to enable journal_csum when metadata_csum is enabled. */ in ext4_fill_super()
4176 if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC) in ext4_fill_super()
4178 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE) in ext4_fill_super()
4187 sbi->s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid)); in ext4_fill_super()
4188 sbi->s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid)); in ext4_fill_super()
4189 sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ; in ext4_fill_super()
4190 sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME; in ext4_fill_super()
4191 sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME; in ext4_fill_super()
4197 * enable delayed allocation by default in ext4_fill_super()
4198 * Use -o nodelalloc to turn it off in ext4_fill_super()
4208 sbi->s_li_wait_mult = EXT4_DEF_LI_WAIT_MULT; in ext4_fill_super()
4210 if (le32_to_cpu(es->s_log_block_size) > in ext4_fill_super()
4211 (EXT4_MAX_BLOCK_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) { in ext4_fill_super()
4214 le32_to_cpu(es->s_log_block_size)); in ext4_fill_super()
4217 if (le32_to_cpu(es->s_log_cluster_size) > in ext4_fill_super()
4218 (EXT4_MAX_CLUSTER_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) { in ext4_fill_super()
4221 le32_to_cpu(es->s_log_cluster_size)); in ext4_fill_super()
4225 blocksize = EXT4_MIN_BLOCK_SIZE << le32_to_cpu(es->s_log_block_size); in ext4_fill_super()
4230 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) { in ext4_fill_super()
4231 sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE; in ext4_fill_super()
4232 sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO; in ext4_fill_super()
4234 sbi->s_inode_size = le16_to_cpu(es->s_inode_size); in ext4_fill_super()
4235 sbi->s_first_ino = le32_to_cpu(es->s_first_ino); in ext4_fill_super()
4236 if (sbi->s_first_ino < EXT4_GOOD_OLD_FIRST_INO) { in ext4_fill_super()
4238 sbi->s_first_ino); in ext4_fill_super()
4241 if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) || in ext4_fill_super()
4242 (!is_power_of_2(sbi->s_inode_size)) || in ext4_fill_super()
4243 (sbi->s_inode_size > blocksize)) { in ext4_fill_super()
4246 sbi->s_inode_size); in ext4_fill_super()
4256 if (sbi->s_inode_size >= offsetof(struct ext4_inode, i_atime_extra) + in ext4_fill_super()
4257 sizeof(((struct ext4_inode *)0)->i_atime_extra)) { in ext4_fill_super()
4258 sb->s_time_gran = 1; in ext4_fill_super()
4259 sb->s_time_max = EXT4_EXTRA_TIMESTAMP_MAX; in ext4_fill_super()
4261 sb->s_time_gran = NSEC_PER_SEC; in ext4_fill_super()
4262 sb->s_time_max = EXT4_NON_EXTRA_TIMESTAMP_MAX; in ext4_fill_super()
4264 sb->s_time_min = EXT4_TIMESTAMP_MIN; in ext4_fill_super()
4266 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) { in ext4_fill_super()
4267 sbi->s_want_extra_isize = sizeof(struct ext4_inode) - in ext4_fill_super()
4270 unsigned v, max = (sbi->s_inode_size - in ext4_fill_super()
4273 v = le16_to_cpu(es->s_want_extra_isize); in ext4_fill_super()
4279 if (sbi->s_want_extra_isize < v) in ext4_fill_super()
4280 sbi->s_want_extra_isize = v; in ext4_fill_super()
4282 v = le16_to_cpu(es->s_min_extra_isize); in ext4_fill_super()
4288 if (sbi->s_want_extra_isize < v) in ext4_fill_super()
4289 sbi->s_want_extra_isize = v; in ext4_fill_super()
4293 if (sbi->s_es->s_mount_opts[0]) { in ext4_fill_super()
4294 char *s_mount_opts = kstrndup(sbi->s_es->s_mount_opts, in ext4_fill_super()
4295 sizeof(sbi->s_es->s_mount_opts), in ext4_fill_super()
4307 sbi->s_def_mount_opt = sbi->s_mount_opt; in ext4_fill_super()
4313 if (ext4_has_feature_casefold(sb) && !sb->s_encoding) { in ext4_fill_super()
4318 if (ext4_sb_read_encoding(es, &encoding_info, in ext4_fill_super()
4325 encoding = utf8_load(encoding_info->version); in ext4_fill_super()
4328 "can't mount with superblock charset: %s-%s " in ext4_fill_super()
4330 encoding_info->name, encoding_info->version, in ext4_fill_super()
4335 "%s-%s with flags 0x%hx", encoding_info->name, in ext4_fill_super()
4336 encoding_info->version?:"\b", encoding_flags); in ext4_fill_super()
4338 sb->s_encoding = encoding; in ext4_fill_super()
4339 sb->s_encoding_flags = encoding_flags; in ext4_fill_super()
4344 …printk_once(KERN_WARNING "EXT4-fs: Warning: mounting with data=journal disables delayed allocation… in ext4_fill_super()
4366 sb->s_iflags |= SB_I_CGROUPWB; in ext4_fill_super()
4369 sb->s_flags = (sb->s_flags & ~SB_POSIXACL) | in ext4_fill_super()
4372 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV && in ext4_fill_super()
4380 if (es->s_creator_os == cpu_to_le32(EXT4_OS_HURD)) { in ext4_fill_super()
4384 "The Hurd can't support 64-bit file systems"); in ext4_fill_super()
4441 if (le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) > (blocksize / 4)) { in ext4_fill_super()
4444 le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks)); in ext4_fill_super()
4448 if (bdev_dax_supported(sb->s_bdev, blocksize)) in ext4_fill_super()
4449 set_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags); in ext4_fill_super()
4451 if (sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) { in ext4_fill_super()
4457 if (!test_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags)) { in ext4_fill_super()
4464 if (ext4_has_feature_encrypt(sb) && es->s_encryption_level) { in ext4_fill_super()
4466 es->s_encryption_level); in ext4_fill_super()
4470 if (sb->s_blocksize != blocksize) { in ext4_fill_super()
4495 es = (struct ext4_super_block *)(bh->b_data + offset); in ext4_fill_super()
4496 sbi->s_es = es; in ext4_fill_super()
4497 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) { in ext4_fill_super()
4505 sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits, in ext4_fill_super()
4507 sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files); in ext4_fill_super()
4509 sbi->s_desc_size = le16_to_cpu(es->s_desc_size); in ext4_fill_super()
4511 if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT || in ext4_fill_super()
4512 sbi->s_desc_size > EXT4_MAX_DESC_SIZE || in ext4_fill_super()
4513 !is_power_of_2(sbi->s_desc_size)) { in ext4_fill_super()
4516 sbi->s_desc_size); in ext4_fill_super()
4520 sbi->s_desc_size = EXT4_MIN_DESC_SIZE; in ext4_fill_super()
4522 sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); in ext4_fill_super()
4523 sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); in ext4_fill_super()
4525 sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb); in ext4_fill_super()
4526 if (sbi->s_inodes_per_block == 0) in ext4_fill_super()
4528 if (sbi->s_inodes_per_group < sbi->s_inodes_per_block || in ext4_fill_super()
4529 sbi->s_inodes_per_group > blocksize * 8) { in ext4_fill_super()
4531 sbi->s_inodes_per_group); in ext4_fill_super()
4534 sbi->s_itb_per_group = sbi->s_inodes_per_group / in ext4_fill_super()
4535 sbi->s_inodes_per_block; in ext4_fill_super()
4536 sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb); in ext4_fill_super()
4537 sbi->s_sbh = bh; in ext4_fill_super()
4538 sbi->s_mount_state = le16_to_cpu(es->s_state) & ~EXT4_FC_REPLAY; in ext4_fill_super()
4539 sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb)); in ext4_fill_super()
4540 sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb)); in ext4_fill_super()
4543 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); in ext4_fill_super()
4544 sbi->s_def_hash_version = es->s_def_hash_version; in ext4_fill_super()
4546 i = le32_to_cpu(es->s_flags); in ext4_fill_super()
4548 sbi->s_hash_unsigned = 3; in ext4_fill_super()
4552 es->s_flags |= in ext4_fill_super()
4554 sbi->s_hash_unsigned = 3; in ext4_fill_super()
4557 es->s_flags |= in ext4_fill_super()
4564 clustersize = BLOCK_SIZE << le32_to_cpu(es->s_log_cluster_size); in ext4_fill_super()
4572 sbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) - in ext4_fill_super()
4573 le32_to_cpu(es->s_log_block_size); in ext4_fill_super()
4574 sbi->s_clusters_per_group = in ext4_fill_super()
4575 le32_to_cpu(es->s_clusters_per_group); in ext4_fill_super()
4576 if (sbi->s_clusters_per_group > blocksize * 8) { in ext4_fill_super()
4579 sbi->s_clusters_per_group); in ext4_fill_super()
4582 if (sbi->s_blocks_per_group != in ext4_fill_super()
4583 (sbi->s_clusters_per_group * (clustersize / blocksize))) { in ext4_fill_super()
4586 sbi->s_blocks_per_group, in ext4_fill_super()
4587 sbi->s_clusters_per_group); in ext4_fill_super()
4597 if (sbi->s_blocks_per_group > blocksize * 8) { in ext4_fill_super()
4600 sbi->s_blocks_per_group); in ext4_fill_super()
4603 sbi->s_clusters_per_group = sbi->s_blocks_per_group; in ext4_fill_super()
4604 sbi->s_cluster_bits = 0; in ext4_fill_super()
4606 sbi->s_cluster_ratio = clustersize / blocksize; in ext4_fill_super()
4609 if (sbi->s_blocks_per_group == clustersize << 3) in ext4_fill_super()
4616 err = generic_check_addressable(sb->s_blocksize_bits, in ext4_fill_super()
4617 ext4_blocks_count(es)); in ext4_fill_super()
4628 blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits; in ext4_fill_super()
4629 if (blocks_count && ext4_blocks_count(es) > blocks_count) { in ext4_fill_super()
4632 ext4_blocks_count(es), blocks_count); in ext4_fill_super()
4640 if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) { in ext4_fill_super()
4643 le32_to_cpu(es->s_first_data_block), in ext4_fill_super()
4644 ext4_blocks_count(es)); in ext4_fill_super()
4647 if ((es->s_first_data_block == 0) && (es->s_log_block_size == 0) && in ext4_fill_super()
4648 (sbi->s_cluster_ratio == 1)) { in ext4_fill_super()
4654 blocks_count = (ext4_blocks_count(es) - in ext4_fill_super()
4655 le32_to_cpu(es->s_first_data_block) + in ext4_fill_super()
4656 EXT4_BLOCKS_PER_GROUP(sb) - 1); in ext4_fill_super()
4658 if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) { in ext4_fill_super()
4662 ext4_blocks_count(es), in ext4_fill_super()
4663 le32_to_cpu(es->s_first_data_block), in ext4_fill_super()
4667 sbi->s_groups_count = blocks_count; in ext4_fill_super()
4668 sbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count, in ext4_fill_super()
4670 if (((u64)sbi->s_groups_count * sbi->s_inodes_per_group) != in ext4_fill_super()
4671 le32_to_cpu(es->s_inodes_count)) { in ext4_fill_super()
4673 le32_to_cpu(es->s_inodes_count), in ext4_fill_super()
4674 ((u64)sbi->s_groups_count * sbi->s_inodes_per_group)); in ext4_fill_super()
4675 ret = -EINVAL; in ext4_fill_super()
4678 db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) / in ext4_fill_super()
4681 if (le32_to_cpu(es->s_first_meta_bg) > db_count) { in ext4_fill_super()
4685 le32_to_cpu(es->s_first_meta_bg), db_count); in ext4_fill_super()
4689 rcu_assign_pointer(sbi->s_group_desc, in ext4_fill_super()
4693 if (sbi->s_group_desc == NULL) { in ext4_fill_super()
4695 ret = -ENOMEM; in ext4_fill_super()
4699 bgl_lock_init(sbi->s_blockgroup_lock); in ext4_fill_super()
4701 /* Pre-read the descriptors into the buffer cache */ in ext4_fill_super()
4721 rcu_dereference(sbi->s_group_desc)[i] = bh; in ext4_fill_super()
4724 sbi->s_gdb_count = db_count; in ext4_fill_super()
4727 ret = -EFSCORRUPTED; in ext4_fill_super()
4731 timer_setup(&sbi->s_err_report, print_daily_error_info, 0); in ext4_fill_super()
4737 sbi->s_stripe = ext4_get_stripe_size(sbi); in ext4_fill_super()
4738 sbi->s_extent_max_zeroout_kb = 32; in ext4_fill_super()
4743 sb->s_op = &ext4_sops; in ext4_fill_super()
4744 sb->s_export_op = &ext4_export_ops; in ext4_fill_super()
4745 sb->s_xattr = ext4_xattr_handlers; in ext4_fill_super()
4747 sb->s_cop = &ext4_cryptops; in ext4_fill_super()
4750 sb->s_vop = &ext4_verityops; in ext4_fill_super()
4753 sb->dq_op = &ext4_quota_operations; in ext4_fill_super()
4755 sb->s_qcop = &dquot_quotactl_sysfile_ops; in ext4_fill_super()
4757 sb->s_qcop = &ext4_qctl_operations; in ext4_fill_super()
4758 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ; in ext4_fill_super()
4760 memcpy(&sb->s_uuid, es->s_uuid, sizeof(es->s_uuid)); in ext4_fill_super()
4762 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ in ext4_fill_super()
4763 mutex_init(&sbi->s_orphan_lock); in ext4_fill_super()
4766 atomic_set(&sbi->s_fc_subtid, 0); in ext4_fill_super()
4767 atomic_set(&sbi->s_fc_ineligible_updates, 0); in ext4_fill_super()
4768 INIT_LIST_HEAD(&sbi->s_fc_q[FC_Q_MAIN]); in ext4_fill_super()
4769 INIT_LIST_HEAD(&sbi->s_fc_q[FC_Q_STAGING]); in ext4_fill_super()
4770 INIT_LIST_HEAD(&sbi->s_fc_dentry_q[FC_Q_MAIN]); in ext4_fill_super()
4771 INIT_LIST_HEAD(&sbi->s_fc_dentry_q[FC_Q_STAGING]); in ext4_fill_super()
4772 sbi->s_fc_bytes = 0; in ext4_fill_super()
4775 spin_lock_init(&sbi->s_fc_lock); in ext4_fill_super()
4776 memset(&sbi->s_fc_stats, 0, sizeof(sbi->s_fc_stats)); in ext4_fill_super()
4777 sbi->s_fc_replay_state.fc_regions = NULL; in ext4_fill_super()
4778 sbi->s_fc_replay_state.fc_regions_size = 0; in ext4_fill_super()
4779 sbi->s_fc_replay_state.fc_regions_used = 0; in ext4_fill_super()
4780 sbi->s_fc_replay_state.fc_regions_valid = 0; in ext4_fill_super()
4781 sbi->s_fc_replay_state.fc_modified_inodes = NULL; in ext4_fill_super()
4782 sbi->s_fc_replay_state.fc_modified_inodes_size = 0; in ext4_fill_super()
4783 sbi->s_fc_replay_state.fc_modified_inodes_used = 0; in ext4_fill_super()
4785 sb->s_root = NULL; in ext4_fill_super()
4787 needs_recovery = (es->s_last_orphan != 0 || in ext4_fill_super()
4791 if (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block))) in ext4_fill_super()
4799 err = ext4_load_journal(sb, es, journal_devnum); in ext4_fill_super()
4805 "suppressed and not mounted read-only"); in ext4_fill_super()
4819 if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) { in ext4_fill_super()
4822 sbi->s_commit_interval / HZ); in ext4_fill_super()
4826 (sbi->s_mount_opt ^ sbi->s_def_mount_opt)) { in ext4_fill_super()
4831 sbi->s_def_mount_opt &= ~EXT4_MOUNT_JOURNAL_CHECKSUM; in ext4_fill_super()
4835 sbi->s_journal = NULL; in ext4_fill_super()
4841 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0, in ext4_fill_super()
4843 ext4_msg(sb, KERN_ERR, "Failed to set 64-bit journal feature"); in ext4_fill_super()
4854 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0, in ext4_fill_super()
4870 (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) { in ext4_fill_super()
4872 sbi->s_def_mount_opt |= EXT4_MOUNT_ORDERED_DATA; in ext4_fill_super()
4875 sbi->s_def_mount_opt |= EXT4_MOUNT_JOURNAL_DATA; in ext4_fill_super()
4882 (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) { in ext4_fill_super()
4898 set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); in ext4_fill_super()
4900 sbi->s_journal->j_submit_inode_data_buffers = in ext4_fill_super()
4902 sbi->s_journal->j_finish_inode_data_buffers = in ext4_fill_super()
4907 sbi->s_ea_block_cache = ext4_xattr_create_cache(); in ext4_fill_super()
4908 if (!sbi->s_ea_block_cache) { in ext4_fill_super()
4915 sbi->s_ea_inode_cache = ext4_xattr_create_cache(); in ext4_fill_super()
4916 if (!sbi->s_ea_inode_cache) { in ext4_fill_super()
4925 ext4_msg(sb, KERN_ERR, "Unsupported blocksize for fs-verity"); in ext4_fill_super()
4933 sbi->s_overhead = le32_to_cpu(es->s_overhead_clusters); in ext4_fill_super()
4935 if (sbi->s_overhead > ext4_blocks_count(es)) in ext4_fill_super()
4936 sbi->s_overhead = 0; in ext4_fill_super()
4943 sbi->s_overhead = 0; in ext4_fill_super()
4944 if (sbi->s_overhead == 0) { in ext4_fill_super()
4954 EXT4_SB(sb)->rsv_conversion_wq = in ext4_fill_super()
4955 alloc_workqueue("ext4-rsv-conversion", WQ_MEM_RECLAIM | WQ_UNBOUND, 1); in ext4_fill_super()
4956 if (!EXT4_SB(sb)->rsv_conversion_wq) { in ext4_fill_super()
4957 printk(KERN_ERR "EXT4-fs: failed to create workqueue\n"); in ext4_fill_super()
4958 ret = -ENOMEM; in ext4_fill_super()
4974 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { in ext4_fill_super()
4980 sb->s_root = d_make_root(root); in ext4_fill_super()
4981 if (!sb->s_root) { in ext4_fill_super()
4983 ret = -ENOMEM; in ext4_fill_super()
4987 ret = ext4_setup_super(sb, es, sb_rdonly(sb)); in ext4_fill_super()
4988 if (ret == -EROFS) { in ext4_fill_super()
4989 sb->s_flags |= SB_RDONLY; in ext4_fill_super()
5018 if (sbi->s_journal) in ext4_fill_super()
5019 sbi->s_journal->j_commit_callback = in ext4_fill_super()
5023 ext4_free_blocks_count_set(sbi->s_es, in ext4_fill_super()
5026 err = percpu_counter_init(&sbi->s_freeclusters_counter, block, in ext4_fill_super()
5030 sbi->s_es->s_free_inodes_count = cpu_to_le32(freei); in ext4_fill_super()
5032 err = percpu_counter_init(&sbi->s_freeinodes_counter, freei, in ext4_fill_super()
5036 err = percpu_counter_init(&sbi->s_dirs_counter, in ext4_fill_super()
5039 err = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0, in ext4_fill_super()
5042 err = percpu_counter_init(&sbi->s_sra_exceeded_retry_limit, 0, in ext4_fill_super()
5045 err = percpu_init_rwsem(&sbi->s_writepages_rwsem); in ext4_fill_super()
5057 ret = -ENOMEM; in ext4_fill_super()
5070 /* Enable quota usage during mount. */ in ext4_fill_super()
5082 spin_lock_init(&sbi->s_bdev_wb_lock); in ext4_fill_super()
5083 errseq_check_and_advance(&sb->s_bdev->bd_inode->i_mapping->wb_err, in ext4_fill_super()
5084 &sbi->s_bdev_wb_err); in ext4_fill_super()
5085 sb->s_bdev->bd_super = sb; in ext4_fill_super()
5086 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; in ext4_fill_super()
5087 ext4_orphan_cleanup(sb, es); in ext4_fill_super()
5088 EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS; in ext4_fill_super()
5091 err = ext4_mark_recovery_complete(sb, es); in ext4_fill_super()
5095 if (EXT4_SB(sb)->s_journal) { in ext4_fill_super()
5106 struct request_queue *q = bdev_get_queue(sb->s_bdev); in ext4_fill_super()
5113 if (___ratelimit(&ext4_mount_msg_ratelimit, "EXT4-fs mount")) in ext4_fill_super()
5116 (int) sizeof(sbi->s_es->s_mount_opts), in ext4_fill_super()
5117 sbi->s_es->s_mount_opts, in ext4_fill_super()
5118 *sbi->s_es->s_mount_opts ? "; " : "", orig_data); in ext4_fill_super()
5120 if (es->s_error_count) in ext4_fill_super()
5121 mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */ in ext4_fill_super()
5123 /* Enable message ratelimiting. Default is 10 messages per 5 secs. */ in ext4_fill_super()
5124 ratelimit_state_init(&sbi->s_err_ratelimit_state, 5 * HZ, 10); in ext4_fill_super()
5125 ratelimit_state_init(&sbi->s_warning_ratelimit_state, 5 * HZ, 10); in ext4_fill_super()
5126 ratelimit_state_init(&sbi->s_msg_ratelimit_state, 5 * HZ, 10); in ext4_fill_super()
5127 atomic_set(&sbi->s_warning_count, 0); in ext4_fill_super()
5128 atomic_set(&sbi->s_msg_count, 0); in ext4_fill_super()
5140 kobject_put(&sbi->s_kobj); in ext4_fill_super()
5146 flex_groups = rcu_dereference(sbi->s_flex_groups); in ext4_fill_super()
5148 for (i = 0; i < sbi->s_flex_groups_allocated; i++) in ext4_fill_super()
5153 percpu_counter_destroy(&sbi->s_freeclusters_counter); in ext4_fill_super()
5154 percpu_counter_destroy(&sbi->s_freeinodes_counter); in ext4_fill_super()
5155 percpu_counter_destroy(&sbi->s_dirs_counter); in ext4_fill_super()
5156 percpu_counter_destroy(&sbi->s_dirtyclusters_counter); in ext4_fill_super()
5157 percpu_counter_destroy(&sbi->s_sra_exceeded_retry_limit); in ext4_fill_super()
5158 percpu_free_rwsem(&sbi->s_writepages_rwsem); in ext4_fill_super()
5163 dput(sb->s_root); in ext4_fill_super()
5164 sb->s_root = NULL; in ext4_fill_super()
5167 if (EXT4_SB(sb)->rsv_conversion_wq) in ext4_fill_super()
5168 destroy_workqueue(EXT4_SB(sb)->rsv_conversion_wq); in ext4_fill_super()
5170 ext4_xattr_destroy_cache(sbi->s_ea_inode_cache); in ext4_fill_super()
5171 sbi->s_ea_inode_cache = NULL; in ext4_fill_super()
5173 ext4_xattr_destroy_cache(sbi->s_ea_block_cache); in ext4_fill_super()
5174 sbi->s_ea_block_cache = NULL; in ext4_fill_super()
5176 if (sbi->s_journal) { in ext4_fill_super()
5177 jbd2_journal_destroy(sbi->s_journal); in ext4_fill_super()
5178 sbi->s_journal = NULL; in ext4_fill_super()
5183 del_timer_sync(&sbi->s_err_report); in ext4_fill_super()
5187 group_desc = rcu_dereference(sbi->s_group_desc); in ext4_fill_super()
5193 if (sbi->s_chksum_driver) in ext4_fill_super()
5194 crypto_free_shash(sbi->s_chksum_driver); in ext4_fill_super()
5197 utf8_unload(sb->s_encoding); in ext4_fill_super()
5204 fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy); in ext4_fill_super()
5209 sb->s_fs_info = NULL; in ext4_fill_super()
5210 kfree(sbi->s_blockgroup_lock); in ext4_fill_super()
5219 * Setup any per-fs journal parameters now. We'll do this both on
5227 journal->j_commit_interval = sbi->s_commit_interval; in ext4_init_journal_params()
5228 journal->j_min_batch_time = sbi->s_min_batch_time; in ext4_init_journal_params()
5229 journal->j_max_batch_time = sbi->s_max_batch_time; in ext4_init_journal_params()
5232 write_lock(&journal->j_state_lock); in ext4_init_journal_params()
5234 journal->j_flags |= JBD2_BARRIER; in ext4_init_journal_params()
5236 journal->j_flags &= ~JBD2_BARRIER; in ext4_init_journal_params()
5238 journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR; in ext4_init_journal_params()
5240 journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR; in ext4_init_journal_params()
5241 write_unlock(&journal->j_state_lock); in ext4_init_journal_params()
5259 if (!journal_inode->i_nlink) { in ext4_get_journal_inode()
5267 journal_inode, journal_inode->i_size); in ext4_get_journal_inode()
5268 if (!S_ISREG(journal_inode->i_mode)) { in ext4_get_journal_inode()
5295 journal->j_private = sb; in ext4_get_journal()
5310 struct ext4_super_block *es; in ext4_get_dev_journal() local
5320 blocksize = sb->s_blocksize; in ext4_get_dev_journal()
5337 es = (struct ext4_super_block *) (bh->b_data + offset); in ext4_get_dev_journal()
5338 if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) || in ext4_get_dev_journal()
5339 !(le32_to_cpu(es->s_feature_incompat) & in ext4_get_dev_journal()
5347 if ((le32_to_cpu(es->s_feature_ro_compat) & in ext4_get_dev_journal()
5349 es->s_checksum != ext4_superblock_csum(sb, es)) { in ext4_get_dev_journal()
5356 if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { in ext4_get_dev_journal()
5362 len = ext4_blocks_count(es); in ext4_get_dev_journal()
5366 journal = jbd2_journal_init_dev(bdev, sb->s_bdev, in ext4_get_dev_journal()
5372 journal->j_private = sb; in ext4_get_dev_journal()
5373 if (ext4_read_bh_lock(journal->j_sb_buffer, REQ_META | REQ_PRIO, true)) { in ext4_get_dev_journal()
5377 if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) { in ext4_get_dev_journal()
5379 "user (unsupported) - %d", in ext4_get_dev_journal()
5380 be32_to_cpu(journal->j_superblock->s_nr_users)); in ext4_get_dev_journal()
5383 EXT4_SB(sb)->s_journal_bdev = bdev; in ext4_get_dev_journal()
5395 struct ext4_super_block *es, in ext4_load_journal() argument
5399 unsigned int journal_inum = le32_to_cpu(es->s_journal_inum); in ext4_load_journal()
5406 return -EFSCORRUPTED; in ext4_load_journal()
5409 journal_devnum != le32_to_cpu(es->s_journal_dev)) { in ext4_load_journal()
5414 journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev)); in ext4_load_journal()
5419 return -EINVAL; in ext4_load_journal()
5425 return -EINVAL; in ext4_load_journal()
5429 return -EINVAL; in ext4_load_journal()
5432 journal_dev_ro = bdev_read_only(journal->j_dev); in ext4_load_journal()
5433 really_read_only = bdev_read_only(sb->s_bdev) | journal_dev_ro; in ext4_load_journal()
5437 "journal device read-only, try mounting with '-o ro'"); in ext4_load_journal()
5438 err = -EROFS; in ext4_load_journal()
5445 * can get read-write access to the device. in ext4_load_journal()
5455 err = -EROFS; in ext4_load_journal()
5463 if (!(journal->j_flags & JBD2_BARRIER)) in ext4_load_journal()
5471 memcpy(save, ((char *) es) + in ext4_load_journal()
5475 memcpy(((char *) es) + EXT4_S_ERR_START, in ext4_load_journal()
5485 EXT4_SB(sb)->s_journal = journal; in ext4_load_journal()
5486 err = ext4_clear_journal_err(sb, es); in ext4_load_journal()
5488 EXT4_SB(sb)->s_journal = NULL; in ext4_load_journal()
5494 journal_devnum != le32_to_cpu(es->s_journal_dev)) { in ext4_load_journal()
5495 es->s_journal_dev = cpu_to_le32(journal_devnum); in ext4_load_journal()
5510 struct ext4_super_block *es = EXT4_SB(sb)->s_es; in ext4_commit_super() local
5511 struct buffer_head *sbh = EXT4_SB(sb)->s_sbh; in ext4_commit_super()
5515 return -EINVAL; in ext4_commit_super()
5517 return -ENODEV; in ext4_commit_super()
5520 * If the file system is mounted read-only, don't update the in ext4_commit_super()
5525 * tick in localtime for Windows bug-for-bug compatibility, in ext4_commit_super()
5529 if (!(sb->s_flags & SB_RDONLY)) in ext4_commit_super()
5530 ext4_update_tstamp(es, s_wtime); in ext4_commit_super()
5531 if (sb->s_bdev->bd_part) in ext4_commit_super()
5532 es->s_kbytes_written = in ext4_commit_super()
5533 cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + in ext4_commit_super()
5534 ((part_stat_read(sb->s_bdev->bd_part, in ext4_commit_super()
5535 sectors[STAT_WRITE]) - in ext4_commit_super()
5536 EXT4_SB(sb)->s_sectors_written_start) >> 1)); in ext4_commit_super()
5538 es->s_kbytes_written = in ext4_commit_super()
5539 cpu_to_le64(EXT4_SB(sb)->s_kbytes_written); in ext4_commit_super()
5540 if (percpu_counter_initialized(&EXT4_SB(sb)->s_freeclusters_counter)) in ext4_commit_super()
5541 ext4_free_blocks_count_set(es, in ext4_commit_super()
5543 &EXT4_SB(sb)->s_freeclusters_counter))); in ext4_commit_super()
5544 if (percpu_counter_initialized(&EXT4_SB(sb)->s_freeinodes_counter)) in ext4_commit_super()
5545 es->s_free_inodes_count = in ext4_commit_super()
5547 &EXT4_SB(sb)->s_freeinodes_counter)); in ext4_commit_super()
5587 struct ext4_super_block *es) in ext4_mark_recovery_complete() argument
5590 journal_t *journal = EXT4_SB(sb)->s_journal; in ext4_mark_recovery_complete()
5596 return -EFSCORRUPTED; in ext4_mark_recovery_complete()
5615 * If we are mounting (or read-write remounting) a filesystem whose journal
5620 struct ext4_super_block *es) in ext4_clear_journal_err() argument
5628 return -EFSCORRUPTED; in ext4_clear_journal_err()
5631 journal = EXT4_SB(sb)->s_journal; in ext4_clear_journal_err()
5647 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; in ext4_clear_journal_err()
5648 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); in ext4_clear_journal_err()
5668 journal = EXT4_SB(sb)->s_journal; in ext4_force_commit()
5683 flush_workqueue(sbi->rsv_conversion_wq); in ext4_sync_fs()
5685 * Writeback quota in non-journalled quota case - journalled quota has in ext4_sync_fs()
5688 dquot_writeback_dquots(sb, -1); in ext4_sync_fs()
5694 if (sbi->s_journal) { in ext4_sync_fs()
5695 target = jbd2_get_latest_transaction(sbi->s_journal); in ext4_sync_fs()
5696 if (wait && sbi->s_journal->j_flags & JBD2_BARRIER && in ext4_sync_fs()
5697 !jbd2_trans_will_send_data_barrier(sbi->s_journal, target)) in ext4_sync_fs()
5700 if (jbd2_journal_start_commit(sbi->s_journal, &target)) { in ext4_sync_fs()
5702 ret = jbd2_log_wait_commit(sbi->s_journal, in ext4_sync_fs()
5709 err = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL); in ext4_sync_fs()
5718 * LVM calls this function before a (read-only) snapshot is created. This
5733 journal = EXT4_SB(sb)->s_journal; in ext4_freeze()
5768 if (EXT4_SB(sb)->s_journal) { in ext4_unfreeze()
5795 struct ext4_super_block *es; in ext4_remount() local
5810 return -ENOMEM; in ext4_remount()
5813 old_sb_flags = sb->s_flags; in ext4_remount()
5814 old_opts.s_mount_opt = sbi->s_mount_opt; in ext4_remount()
5815 old_opts.s_mount_opt2 = sbi->s_mount_opt2; in ext4_remount()
5816 old_opts.s_resuid = sbi->s_resuid; in ext4_remount()
5817 old_opts.s_resgid = sbi->s_resgid; in ext4_remount()
5818 old_opts.s_commit_interval = sbi->s_commit_interval; in ext4_remount()
5819 old_opts.s_min_batch_time = sbi->s_min_batch_time; in ext4_remount()
5820 old_opts.s_max_batch_time = sbi->s_max_batch_time; in ext4_remount()
5822 old_opts.s_jquota_fmt = sbi->s_jquota_fmt; in ext4_remount()
5824 if (sbi->s_qf_names[i]) { in ext4_remount()
5832 return -ENOMEM; in ext4_remount()
5837 if (sbi->s_journal && sbi->s_journal->j_task->io_context) in ext4_remount()
5838 journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; in ext4_remount()
5846 sb->s_flags = (sb->s_flags & ~vfs_flags) | (*flags & vfs_flags); in ext4_remount()
5849 err = -EINVAL; in ext4_remount()
5857 sbi->s_mount_opt ^= EXT4_MOUNT_JOURNAL_CHECKSUM; in ext4_remount()
5864 err = -EINVAL; in ext4_remount()
5870 err = -EINVAL; in ext4_remount()
5877 err = -EINVAL; in ext4_remount()
5882 if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) & EXT4_MOUNT_NO_MBCACHE) { in ext4_remount()
5883 ext4_msg(sb, KERN_ERR, "can't enable nombcache during remount"); in ext4_remount()
5884 err = -EINVAL; in ext4_remount()
5891 sb->s_flags = (sb->s_flags & ~SB_POSIXACL) | in ext4_remount()
5894 es = sbi->s_es; in ext4_remount()
5896 if (sbi->s_journal) { in ext4_remount()
5897 ext4_init_journal_params(sb, sbi->s_journal); in ext4_remount()
5898 set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); in ext4_remount()
5903 err = -EROFS; in ext4_remount()
5911 err = dquot_suspend(sb, -1); in ext4_remount()
5919 sb->s_flags |= SB_RDONLY; in ext4_remount()
5926 if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) && in ext4_remount()
5927 (sbi->s_mount_state & EXT4_VALID_FS)) in ext4_remount()
5928 es->s_state = cpu_to_le16(sbi->s_mount_state); in ext4_remount()
5930 if (sbi->s_journal) { in ext4_remount()
5932 * We let remount-ro finish even if marking fs in ext4_remount()
5935 ext4_mark_recovery_complete(sb, es); in ext4_remount()
5941 err = -EROFS; in ext4_remount()
5948 for (g = 0; g < sbi->s_groups_count; g++) { in ext4_remount()
5956 le16_to_cpu(gdp->bg_checksum)); in ext4_remount()
5957 err = -EFSBADCRC; in ext4_remount()
5967 if (es->s_last_orphan) { in ext4_remount()
5972 err = -EINVAL; in ext4_remount()
5977 * Mounting a RDONLY partition read-write, so reread in ext4_remount()
5982 if (sbi->s_journal) { in ext4_remount()
5983 err = ext4_clear_journal_err(sb, es); in ext4_remount()
5987 sbi->s_mount_state = (le16_to_cpu(es->s_state) & in ext4_remount()
5990 err = ext4_setup_super(sb, es, 0); in ext4_remount()
5994 sb->s_flags &= ~SB_RDONLY; in ext4_remount()
5997 le64_to_cpu(es->s_mmp_block))) { in ext4_remount()
5998 err = -EROFS; in ext4_remount()
6022 if (test_opt(sb, BLOCK_VALIDITY) && !sbi->s_system_blks) { in ext4_remount()
6028 if (sbi->s_journal == NULL && !(old_sb_flags & SB_RDONLY)) { in ext4_remount()
6040 dquot_resume(sb, -1); in ext4_remount()
6048 if (!test_opt(sb, BLOCK_VALIDITY) && sbi->s_system_blks) in ext4_remount()
6059 *flags = (*flags & ~vfs_flags) | (sb->s_flags & vfs_flags); in ext4_remount()
6061 ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s", orig_data); in ext4_remount()
6066 sb->s_flags = old_sb_flags; in ext4_remount()
6067 sbi->s_mount_opt = old_opts.s_mount_opt; in ext4_remount()
6068 sbi->s_mount_opt2 = old_opts.s_mount_opt2; in ext4_remount()
6069 sbi->s_resuid = old_opts.s_resuid; in ext4_remount()
6070 sbi->s_resgid = old_opts.s_resgid; in ext4_remount()
6071 sbi->s_commit_interval = old_opts.s_commit_interval; in ext4_remount()
6072 sbi->s_min_batch_time = old_opts.s_min_batch_time; in ext4_remount()
6073 sbi->s_max_batch_time = old_opts.s_max_batch_time; in ext4_remount()
6074 if (!test_opt(sb, BLOCK_VALIDITY) && sbi->s_system_blks) in ext4_remount()
6077 sbi->s_jquota_fmt = old_opts.s_jquota_fmt; in ext4_remount()
6080 rcu_assign_pointer(sbi->s_qf_names[i], old_opts.s_qf_names[i]); in ext4_remount()
6105 spin_lock(&dquot->dq_dqb_lock); in ext4_statfs_project()
6107 limit = min_not_zero(dquot->dq_dqb.dqb_bsoftlimit, in ext4_statfs_project()
6108 dquot->dq_dqb.dqb_bhardlimit); in ext4_statfs_project()
6109 limit >>= sb->s_blocksize_bits; in ext4_statfs_project()
6111 if (limit && buf->f_blocks > limit) { in ext4_statfs_project()
6112 curblock = (dquot->dq_dqb.dqb_curspace + in ext4_statfs_project()
6113 dquot->dq_dqb.dqb_rsvspace) >> sb->s_blocksize_bits; in ext4_statfs_project()
6114 buf->f_blocks = limit; in ext4_statfs_project()
6115 buf->f_bfree = buf->f_bavail = in ext4_statfs_project()
6116 (buf->f_blocks > curblock) ? in ext4_statfs_project()
6117 (buf->f_blocks - curblock) : 0; in ext4_statfs_project()
6120 limit = min_not_zero(dquot->dq_dqb.dqb_isoftlimit, in ext4_statfs_project()
6121 dquot->dq_dqb.dqb_ihardlimit); in ext4_statfs_project()
6122 if (limit && buf->f_files > limit) { in ext4_statfs_project()
6123 buf->f_files = limit; in ext4_statfs_project()
6124 buf->f_ffree = in ext4_statfs_project()
6125 (buf->f_files > dquot->dq_dqb.dqb_curinodes) ? in ext4_statfs_project()
6126 (buf->f_files - dquot->dq_dqb.dqb_curinodes) : 0; in ext4_statfs_project()
6129 spin_unlock(&dquot->dq_dqb_lock); in ext4_statfs_project()
6137 struct super_block *sb = dentry->d_sb; in ext4_statfs()
6139 struct ext4_super_block *es = sbi->s_es; in ext4_statfs() local
6143 resv_blocks = EXT4_C2B(sbi, atomic64_read(&sbi->s_resv_clusters)); in ext4_statfs()
6146 overhead = sbi->s_overhead; in ext4_statfs()
6148 buf->f_type = EXT4_SUPER_MAGIC; in ext4_statfs()
6149 buf->f_bsize = sb->s_blocksize; in ext4_statfs()
6150 buf->f_blocks = ext4_blocks_count(es) - EXT4_C2B(sbi, overhead); in ext4_statfs()
6151 bfree = percpu_counter_sum_positive(&sbi->s_freeclusters_counter) - in ext4_statfs()
6152 percpu_counter_sum_positive(&sbi->s_dirtyclusters_counter); in ext4_statfs()
6154 buf->f_bfree = EXT4_C2B(sbi, max_t(s64, bfree, 0)); in ext4_statfs()
6155 buf->f_bavail = buf->f_bfree - in ext4_statfs()
6156 (ext4_r_blocks_count(es) + resv_blocks); in ext4_statfs()
6157 if (buf->f_bfree < (ext4_r_blocks_count(es) + resv_blocks)) in ext4_statfs()
6158 buf->f_bavail = 0; in ext4_statfs()
6159 buf->f_files = le32_to_cpu(es->s_inodes_count); in ext4_statfs()
6160 buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter); in ext4_statfs()
6161 buf->f_namelen = EXT4_NAME_LEN; in ext4_statfs()
6162 fsid = le64_to_cpup((void *)es->s_uuid) ^ in ext4_statfs()
6163 le64_to_cpup((void *)es->s_uuid + sizeof(u64)); in ext4_statfs()
6164 buf->f_fsid = u64_to_fsid(fsid); in ext4_statfs()
6167 if (ext4_test_inode_flag(dentry->d_inode, EXT4_INODE_PROJINHERIT) && in ext4_statfs()
6169 ext4_statfs_project(sb, EXT4_I(dentry->d_inode)->i_projid, buf); in ext4_statfs()
6183 return sb_dqopt(dquot->dq_sb)->files[dquot->dq_id.type]; in dquot_to_inode()
6194 EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); in ext4_write_dquot()
6210 EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb)); in ext4_acquire_dquot()
6226 EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb)); in ext4_release_dquot()
6241 struct super_block *sb = dquot->dq_sb; in ext4_mark_dquot_dirty()
6246 sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { in ext4_mark_dquot_dirty()
6271 * Turn on quotas during mount time - we need to find
6277 EXT4_SB(sb)->s_jquota_fmt, type); in ext4_quota_on_mount()
6285 * *exactly* the same as the argument to init_rwsem() --- in in lockdep_set_quota_inode()
6286 * this case, in init_once() --- or lockdep gets unhappy in lockdep_set_quota_inode()
6291 lockdep_set_subclass(&ei->i_data_sem, subclass); in lockdep_set_quota_inode()
6303 return -EINVAL; in ext4_quota_on()
6306 if (path->dentry->d_sb != sb) in ext4_quota_on()
6307 return -EXDEV; in ext4_quota_on()
6310 if (IS_NOQUOTA(d_inode(path->dentry))) in ext4_quota_on()
6311 return -EBUSY; in ext4_quota_on()
6314 if (EXT4_SB(sb)->s_qf_names[type]) { in ext4_quota_on()
6316 if (path->dentry->d_parent != sb->s_root) in ext4_quota_on()
6320 sb_dqopt(sb)->flags |= DQUOT_NOLIST_DIRTY; in ext4_quota_on()
6326 sb_dqopt(sb)->flags &= ~DQUOT_NOLIST_DIRTY; in ext4_quota_on()
6333 if (EXT4_SB(sb)->s_journal && in ext4_quota_on()
6334 ext4_should_journal_data(d_inode(path->dentry))) { in ext4_quota_on()
6339 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); in ext4_quota_on()
6340 err = jbd2_journal_flush(EXT4_SB(sb)->s_journal); in ext4_quota_on()
6341 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); in ext4_quota_on()
6346 lockdep_set_quota_inode(path->dentry->d_inode, I_DATA_SEM_QUOTA); in ext4_quota_on()
6349 struct inode *inode = d_inode(path->dentry); in ext4_quota_on()
6361 EXT4_I(inode)->i_flags |= EXT4_NOATIME_FL | EXT4_IMMUTABLE_FL; in ext4_quota_on()
6372 lockdep_set_quota_inode(path->dentry->d_inode, in ext4_quota_on()
6383 le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum), in ext4_quota_enable()
6384 le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum), in ext4_quota_enable()
6385 le32_to_cpu(EXT4_SB(sb)->s_es->s_prj_quota_inum) in ext4_quota_enable()
6391 return -EPERM; in ext4_quota_enable()
6400 qf_inode->i_flags |= S_NOQUOTA; in ext4_quota_enable()
6410 /* Enable usage tracking for all quota types. */
6415 le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum), in ext4_enable_quotas()
6416 le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum), in ext4_enable_quotas()
6417 le32_to_cpu(EXT4_SB(sb)->s_es->s_prj_quota_inum) in ext4_enable_quotas()
6425 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NOLIST_DIRTY; in ext4_enable_quotas()
6433 "Failed to enable quota tracking " in ext4_enable_quotas()
6436 for (type--; type >= 0; type--) { in ext4_enable_quotas()
6439 inode = sb_dqopt(sb)->files[type]; in ext4_enable_quotas()
6459 struct inode *inode = sb_dqopt(sb)->files[type]; in ext4_quota_off()
6486 EXT4_I(inode)->i_flags &= ~(EXT4_NOATIME_FL | EXT4_IMMUTABLE_FL); in ext4_quota_off()
6488 inode->i_mtime = inode->i_ctime = current_time(inode); in ext4_quota_off()
6501 /* Read data from quotafile - avoid pagecache and such because we cannot afford
6508 struct inode *inode = sb_dqopt(sb)->files[type]; in ext4_quota_read()
6510 int offset = off & (sb->s_blocksize - 1); in ext4_quota_read()
6519 len = i_size-off; in ext4_quota_read()
6522 tocopy = sb->s_blocksize - offset < toread ? in ext4_quota_read()
6523 sb->s_blocksize - offset : toread; in ext4_quota_read()
6530 memcpy(data, bh->b_data+offset, tocopy); in ext4_quota_read()
6533 toread -= tocopy; in ext4_quota_read()
6545 struct inode *inode = sb_dqopt(sb)->files[type]; in ext4_quota_write()
6547 int err = 0, err2 = 0, offset = off & (sb->s_blocksize - 1); in ext4_quota_write()
6556 return -EIO; in ext4_quota_write()
6562 if (sb->s_blocksize - offset < len) { in ext4_quota_write()
6566 return -EIO; in ext4_quota_write()
6573 } while (PTR_ERR(bh) == -ENOSPC && in ext4_quota_write()
6574 ext4_should_retry_alloc(inode->i_sb, &retries)); in ext4_quota_write()
6586 memcpy(bh->b_data+offset, data, len); in ext4_quota_write()
6587 flush_dcache_page(bh->b_page); in ext4_quota_write()
6592 if (inode->i_size < off + len) { in ext4_quota_write()
6594 EXT4_I(inode)->i_disksize = inode->i_size; in ext4_quota_write()
6615 "EXT4-fs: Unable to register as ext2 (%d)\n", err); in register_as_ext2()
6644 "EXT4-fs: Unable to register as ext3 (%d)\n", err); in register_as_ext3()
6685 /* Build-time check for flags consistency */ in ext4_init_fs()