Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  linux/fs/ext4/super.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (C) 1992, 1993, 1994, 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Remy Card (card@masi.ibp.fr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Laboratoire MASI - Institut Blaise Pascal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Universite Pierre et Marie Curie (Paris VI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *  from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *  linux/fs/minix/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *  Copyright (C) 1991, 1992  Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *  Big-endian to little-endian byte-swapping/bitmaps by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *        David S. Miller (davem@caip.rutgers.edu), 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/backing-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/exportfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/quotaops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/log2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/crc16.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/dax.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/cleancache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <linux/iversion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <linux/unicode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <linux/part_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <linux/freezer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include "ext4.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include "ext4_extents.h"	/* Needed for trace points definition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include "ext4_jbd2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include "acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include "mballoc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include "fsmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #define CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include <trace/events/ext4.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) static struct ext4_lazy_init *ext4_li_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) static struct mutex ext4_li_mtx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) static struct ratelimit_state ext4_mount_msg_ratelimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) static int ext4_load_journal(struct super_block *, struct ext4_super_block *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 			     unsigned long journal_devnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) static int ext4_show_options(struct seq_file *seq, struct dentry *root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) static int ext4_commit_super(struct super_block *sb, int sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) static int ext4_mark_recovery_complete(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 					struct ext4_super_block *es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) static int ext4_clear_journal_err(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 				  struct ext4_super_block *es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) static int ext4_sync_fs(struct super_block *sb, int wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) static int ext4_remount(struct super_block *sb, int *flags, char *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) static int ext4_unfreeze(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) static int ext4_freeze(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 		       const char *dev_name, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) static inline int ext2_feature_set_ok(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) static inline int ext3_feature_set_ok(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) static int ext4_feature_set_ok(struct super_block *sb, int readonly);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) static void ext4_destroy_lazyinit_thread(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) static void ext4_unregister_li_request(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) static void ext4_clear_request_list(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) static struct inode *ext4_get_journal_inode(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 					    unsigned int journal_inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  * Lock ordering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  * Note the difference between i_mmap_sem (EXT4_I(inode)->i_mmap_sem) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  * i_mmap_rwsem (inode->i_mmap_rwsem)!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)  * page fault path:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)  * mmap_lock -> sb_start_pagefault -> i_mmap_sem (r) -> transaction start ->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)  *   page lock -> i_data_sem (rw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)  * buffered write path:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)  * sb_start_write -> i_mutex -> mmap_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101)  * sb_start_write -> i_mutex -> transaction start -> page lock ->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102)  *   i_data_sem (rw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  * truncate:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)  * sb_start_write -> i_mutex -> i_mmap_sem (w) -> i_mmap_rwsem (w) -> page lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)  * sb_start_write -> i_mutex -> i_mmap_sem (w) -> transaction start ->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  *   i_data_sem (rw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)  * direct IO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)  * sb_start_write -> i_mutex -> mmap_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  * sb_start_write -> i_mutex -> transaction start -> i_data_sem (rw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  * writepages:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)  * transaction start -> page lock(s) -> i_data_sem (rw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) #if !defined(CONFIG_EXT2_FS) && !defined(CONFIG_EXT2_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) static struct file_system_type ext2_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	.name		= "ext2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	.mount		= ext4_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	.kill_sb	= kill_block_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	.fs_flags	= FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) MODULE_ALIAS_FS("ext2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) MODULE_ALIAS("ext2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) #define IS_EXT2_SB(sb) ((sb)->s_bdev->bd_holder == &ext2_fs_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) #define IS_EXT2_SB(sb) (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) static struct file_system_type ext3_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	.name		= "ext3",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	.mount		= ext4_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	.kill_sb	= kill_block_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	.fs_flags	= FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) MODULE_ALIAS_FS("ext3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) MODULE_ALIAS("ext3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) #define IS_EXT3_SB(sb) ((sb)->s_bdev->bd_holder == &ext3_fs_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) static inline void __ext4_read_bh(struct buffer_head *bh, int op_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 				  bh_end_io_t *end_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	 * buffer's verified bit is no longer valid after reading from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	 * disk again due to write out error, clear it to make sure we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	 * recheck the buffer contents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	clear_buffer_verified(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	bh->b_end_io = end_io ? end_io : end_buffer_read_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	get_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	submit_bh(REQ_OP_READ, op_flags, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) void ext4_read_bh_nowait(struct buffer_head *bh, int op_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 			 bh_end_io_t *end_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	BUG_ON(!buffer_locked(bh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	if (ext4_buffer_uptodate(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 		unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	__ext4_read_bh(bh, op_flags, end_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) int ext4_read_bh(struct buffer_head *bh, int op_flags, bh_end_io_t *end_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	BUG_ON(!buffer_locked(bh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	if (ext4_buffer_uptodate(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	__ext4_read_bh(bh, op_flags, end_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	wait_on_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	if (buffer_uptodate(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) int ext4_read_bh_lock(struct buffer_head *bh, int op_flags, bool wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	if (trylock_buffer(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 		if (wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 			return ext4_read_bh(bh, op_flags, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 		ext4_read_bh_nowait(bh, op_flags, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	if (wait) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 		wait_on_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 		if (buffer_uptodate(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207)  * This works like __bread_gfp() except it uses ERR_PTR for error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208)  * returns.  Currently with sb_bread it's impossible to distinguish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209)  * between ENOMEM and EIO situations (since both result in a NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210)  * return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) static struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 					       sector_t block, int op_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 					       gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	bh = sb_getblk_gfp(sb, block, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	if (bh == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	if (ext4_buffer_uptodate(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		return bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	ret = ext4_read_bh_lock(bh, REQ_META | op_flags, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	return bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 				   int op_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	return __ext4_sb_bread_gfp(sb, block, op_flags, __GFP_MOVABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 					    sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	return __ext4_sb_bread_gfp(sb, block, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	struct buffer_head *bh = sb_getblk_gfp(sb, block, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	if (likely(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		ext4_read_bh_lock(bh, REQ_RAHEAD, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) static int ext4_verify_csum_type(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 				 struct ext4_super_block *es)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	if (!ext4_has_feature_metadata_csum(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	return es->s_checksum_type == EXT4_CRC32C_CHKSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) static __le32 ext4_superblock_csum(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 				   struct ext4_super_block *es)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	int offset = offsetof(struct ext4_super_block, s_checksum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	__u32 csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	csum = ext4_chksum(sbi, ~0, (char *)es, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	return cpu_to_le32(csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) static int ext4_superblock_csum_verify(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 				       struct ext4_super_block *es)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	if (!ext4_has_metadata_csum(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	return es->s_checksum == ext4_superblock_csum(sb, es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) void ext4_superblock_csum_set(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	struct ext4_super_block *es = EXT4_SB(sb)->s_es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	if (!ext4_has_metadata_csum(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	es->s_checksum = ext4_superblock_csum(sb, es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 			       struct ext4_group_desc *bg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	return le32_to_cpu(bg->bg_block_bitmap_lo) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 		 (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 			       struct ext4_group_desc *bg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	return le32_to_cpu(bg->bg_inode_bitmap_lo) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 		 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) ext4_fsblk_t ext4_inode_table(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 			      struct ext4_group_desc *bg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	return le32_to_cpu(bg->bg_inode_table_lo) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) __u32 ext4_free_group_clusters(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 			       struct ext4_group_desc *bg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	return le16_to_cpu(bg->bg_free_blocks_count_lo) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		 (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) __u32 ext4_free_inodes_count(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 			      struct ext4_group_desc *bg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	return le16_to_cpu(bg->bg_free_inodes_count_lo) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		 (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) __u32 ext4_used_dirs_count(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 			      struct ext4_group_desc *bg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	return le16_to_cpu(bg->bg_used_dirs_count_lo) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		 (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) __u32 ext4_itable_unused_count(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 			      struct ext4_group_desc *bg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	return le16_to_cpu(bg->bg_itable_unused_lo) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 		 (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) void ext4_block_bitmap_set(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 			   struct ext4_group_desc *bg, ext4_fsblk_t blk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) void ext4_inode_bitmap_set(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 			   struct ext4_group_desc *bg, ext4_fsblk_t blk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	bg->bg_inode_bitmap_lo  = cpu_to_le32((u32)blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) void ext4_inode_table_set(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 			  struct ext4_group_desc *bg, ext4_fsblk_t blk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	bg->bg_inode_table_lo = cpu_to_le32((u32)blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		bg->bg_inode_table_hi = cpu_to_le32(blk >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) void ext4_free_group_clusters_set(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 				  struct ext4_group_desc *bg, __u32 count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) void ext4_free_inodes_set(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 			  struct ext4_group_desc *bg, __u32 count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) void ext4_used_dirs_set(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 			  struct ext4_group_desc *bg, __u32 count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) void ext4_itable_unused_set(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 			  struct ext4_group_desc *bg, __u32 count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	bg->bg_itable_unused_lo = cpu_to_le16((__u16)count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		bg->bg_itable_unused_hi = cpu_to_le16(count >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) static void __ext4_update_tstamp(__le32 *lo, __u8 *hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	time64_t now = ktime_get_real_seconds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	now = clamp_val(now, 0, (1ull << 40) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	*lo = cpu_to_le32(lower_32_bits(now));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	*hi = upper_32_bits(now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) static time64_t __ext4_get_tstamp(__le32 *lo, __u8 *hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	return ((time64_t)(*hi) << 32) + le32_to_cpu(*lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) #define ext4_update_tstamp(es, tstamp) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	__ext4_update_tstamp(&(es)->tstamp, &(es)->tstamp ## _hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) #define ext4_get_tstamp(es, tstamp) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	__ext4_get_tstamp(&(es)->tstamp, &(es)->tstamp ## _hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) static void __save_error_info(struct super_block *sb, int error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 			      __u32 ino, __u64 block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 			      const char *func, unsigned int line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	struct ext4_super_block *es = EXT4_SB(sb)->s_es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	if (bdev_read_only(sb->s_bdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	ext4_update_tstamp(es, s_last_error_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	es->s_last_error_line = cpu_to_le32(line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	es->s_last_error_ino = cpu_to_le32(ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	es->s_last_error_block = cpu_to_le64(block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	switch (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	case EIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		err = EXT4_ERR_EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	case ENOMEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		err = EXT4_ERR_ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	case EFSBADCRC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		err = EXT4_ERR_EFSBADCRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	case EFSCORRUPTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		err = EXT4_ERR_EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	case ENOSPC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		err = EXT4_ERR_ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	case ENOKEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		err = EXT4_ERR_ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	case EROFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		err = EXT4_ERR_EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	case EFBIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		err = EXT4_ERR_EFBIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	case EEXIST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 		err = EXT4_ERR_EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	case ERANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		err = EXT4_ERR_ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	case EOVERFLOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		err = EXT4_ERR_EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	case EBUSY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		err = EXT4_ERR_EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	case ENOTDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		err = EXT4_ERR_ENOTDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	case ENOTEMPTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		err = EXT4_ERR_ENOTEMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	case ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		err = EXT4_ERR_ESHUTDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	case EFAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		err = EXT4_ERR_EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		err = EXT4_ERR_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	es->s_last_error_errcode = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	if (!es->s_first_error_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		es->s_first_error_time = es->s_last_error_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		es->s_first_error_time_hi = es->s_last_error_time_hi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		strncpy(es->s_first_error_func, func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			sizeof(es->s_first_error_func));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		es->s_first_error_line = cpu_to_le32(line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		es->s_first_error_ino = es->s_last_error_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		es->s_first_error_block = es->s_last_error_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		es->s_first_error_errcode = es->s_last_error_errcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	 * Start the daily error reporting function if it hasn't been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	 * started already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	if (!es->s_error_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		mod_timer(&EXT4_SB(sb)->s_err_report, jiffies + 24*60*60*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	le32_add_cpu(&es->s_error_count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) static void save_error_info(struct super_block *sb, int error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 			    __u32 ino, __u64 block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 			    const char *func, unsigned int line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	__save_error_info(sb, error, ino, block, func, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	if (!bdev_read_only(sb->s_bdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		ext4_commit_super(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525)  * The del_gendisk() function uninitializes the disk-specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526)  * structures, including the bdi structure, without telling anyone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527)  * else.  Once this happens, any attempt to call mark_buffer_dirty()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528)  * (for example, by ext4_commit_super), will cause a kernel OOPS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529)  * This is a kludge to prevent these oops until we can put in a proper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530)  * hook in del_gendisk() to inform the VFS and file system layers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) static int block_device_ejected(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	struct inode *bd_inode = sb->s_bdev->bd_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	struct backing_dev_info *bdi = inode_to_bdi(bd_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	return bdi->dev == NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) static void ext4_journal_commit_callback(journal_t *journal, transaction_t *txn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	struct super_block		*sb = journal->j_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	struct ext4_sb_info		*sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	int				error = is_journal_aborted(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	struct ext4_journal_cb_entry	*jce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	BUG_ON(txn->t_state == T_FINISHED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	ext4_process_freed_data(sb, txn->t_tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	spin_lock(&sbi->s_md_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	while (!list_empty(&txn->t_private_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		jce = list_entry(txn->t_private_list.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 				 struct ext4_journal_cb_entry, jce_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		list_del_init(&jce->jce_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		spin_unlock(&sbi->s_md_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		jce->jce_func(sb, jce, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		spin_lock(&sbi->s_md_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	spin_unlock(&sbi->s_md_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564)  * This writepage callback for write_cache_pages()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565)  * takes care of a few cases after page cleaning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567)  * write_cache_pages() already checks for dirty pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568)  * and calls clear_page_dirty_for_io(), which we want,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569)  * to write protect the pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571)  * However, we may have to redirty a page (see below.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) static int ext4_journalled_writepage_callback(struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 					      struct writeback_control *wbc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 					      void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	transaction_t *transaction = (transaction_t *) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	struct buffer_head *bh, *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	struct journal_head *jh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	bh = head = page_buffers(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		 * We have to redirty a page in these cases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		 * 1) If buffer is dirty, it means the page was dirty because it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		 * contains a buffer that needs checkpointing. So the dirty bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		 * needs to be preserved so that checkpointing writes the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		 * properly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		 * 2) If buffer is not part of the committing transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		 * (we may have just accidentally come across this buffer because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		 * inode range tracking is not exact) or if the currently running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		 * transaction already contains this buffer as well, dirty bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		 * needs to be preserved so that the buffer gets writeprotected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		 * properly on running transaction's commit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		jh = bh2jh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		if (buffer_dirty(bh) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 		    (jh && (jh->b_transaction != transaction ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 			    jh->b_next_transaction))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 			redirty_page_for_writepage(wbc, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	} while ((bh = bh->b_this_page) != head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	return AOP_WRITEPAGE_ACTIVATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) static int ext4_journalled_submit_inode_data_buffers(struct jbd2_inode *jinode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	struct address_space *mapping = jinode->i_vfs_inode->i_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	struct writeback_control wbc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		.sync_mode =  WB_SYNC_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		.nr_to_write = LONG_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		.range_start = jinode->i_dirty_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		.range_end = jinode->i_dirty_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617)         };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	return write_cache_pages(mapping, &wbc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 				 ext4_journalled_writepage_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 				 jinode->i_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) static int ext4_journal_submit_inode_data_buffers(struct jbd2_inode *jinode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	if (ext4_should_journal_data(jinode->i_vfs_inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		ret = ext4_journalled_submit_inode_data_buffers(jinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		ret = jbd2_journal_submit_inode_data_buffers(jinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) static int ext4_journal_finish_inode_data_buffers(struct jbd2_inode *jinode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	if (!ext4_should_journal_data(jinode->i_vfs_inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		ret = jbd2_journal_finish_inode_data_buffers(jinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) static bool system_going_down(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		|| system_state == SYSTEM_RESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) /* Deal with the reporting of failure conditions on a filesystem such as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653)  * inconsistencies detected or read IO failures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655)  * On ext2, we can store the error state of the filesystem in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656)  * superblock.  That is not possible on ext4, because we may have other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657)  * write ordering constraints on the superblock which prevent us from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658)  * writing it out straight away; and given that the journal is about to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659)  * be aborted, we can't rely on the current, or future, transactions to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660)  * write out the superblock safely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662)  * We'll just use the jbd2_journal_abort() error code to record an error in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663)  * the journal instead.  On recovery, the journal will complain about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664)  * that error until we've noted it down and cleared it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) static void ext4_handle_error(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	journal_t *journal = EXT4_SB(sb)->s_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	if (test_opt(sb, WARN_ON_ERROR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	if (sb_rdonly(sb) || test_opt(sb, ERRORS_CONT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	ext4_set_mount_flag(sb, EXT4_MF_FS_ABORTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	if (journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		jbd2_journal_abort(journal, -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	 * We force ERRORS_RO behavior when system is rebooting. Otherwise we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	 * could panic during 'reboot -f' as the underlying device got already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	 * disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	if (test_opt(sb, ERRORS_RO) || system_going_down()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		 * Make sure updated value of ->s_mount_flags will be visible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		 * before ->s_flags update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	} else if (test_opt(sb, ERRORS_PANIC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		panic("EXT4-fs (device %s): panic forced after error\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 			sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) #define ext4_error_ratelimit(sb)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		___ratelimit(&(EXT4_SB(sb)->s_err_ratelimit_state),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 			     "EXT4-fs error")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) void __ext4_error(struct super_block *sb, const char *function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		  unsigned int line, int error, __u64 block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		  const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	if (unlikely(ext4_forced_shutdown(EXT4_SB(sb))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	trace_ext4_error(sb, function, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	if (ext4_error_ratelimit(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		printk(KERN_CRIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		       "EXT4-fs error (device %s): %s:%d: comm %s: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		       sb->s_id, function, line, current->comm, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	save_error_info(sb, error, 0, block, function, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	ext4_handle_error(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) void __ext4_error_inode(struct inode *inode, const char *function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 			unsigned int line, ext4_fsblk_t block, int error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 			const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	trace_ext4_error(inode->i_sb, function, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	if (ext4_error_ratelimit(inode->i_sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		if (block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 			printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 			       "inode #%lu: block %llu: comm %s: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 			       inode->i_sb->s_id, function, line, inode->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			       block, current->comm, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 			printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 			       "inode #%lu: comm %s: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 			       inode->i_sb->s_id, function, line, inode->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 			       current->comm, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	save_error_info(inode->i_sb, error, inode->i_ino, block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 			function, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	ext4_handle_error(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) void __ext4_error_file(struct file *file, const char *function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		       unsigned int line, ext4_fsblk_t block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		       const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	char pathname[80], *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	trace_ext4_error(inode->i_sb, function, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	if (ext4_error_ratelimit(inode->i_sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		path = file_path(file, pathname, sizeof(pathname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		if (IS_ERR(path))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 			path = "(unknown)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		if (block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 			printk(KERN_CRIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 			       "EXT4-fs error (device %s): %s:%d: inode #%lu: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 			       "block %llu: comm %s: path %s: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 			       inode->i_sb->s_id, function, line, inode->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 			       block, current->comm, path, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 			printk(KERN_CRIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 			       "EXT4-fs error (device %s): %s:%d: inode #%lu: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 			       "comm %s: path %s: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 			       inode->i_sb->s_id, function, line, inode->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 			       current->comm, path, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	save_error_info(inode->i_sb, EFSCORRUPTED, inode->i_ino, block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 			function, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	ext4_handle_error(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) const char *ext4_decode_error(struct super_block *sb, int errno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 			      char nbuf[16])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	char *errstr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	switch (errno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	case -EFSCORRUPTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		errstr = "Corrupt filesystem";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	case -EFSBADCRC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		errstr = "Filesystem failed CRC";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	case -EIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		errstr = "IO failure";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	case -ENOMEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		errstr = "Out of memory";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	case -EROFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		if (!sb || (EXT4_SB(sb)->s_journal &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			    EXT4_SB(sb)->s_journal->j_flags & JBD2_ABORT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 			errstr = "Journal has aborted";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 			errstr = "Readonly filesystem";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		/* If the caller passed in an extra buffer for unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		 * errors, textualise them now.  Else we just return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		 * NULL. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		if (nbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 			/* Check for truncated error codes... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 			if (snprintf(nbuf, 16, "error %d", -errno) >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 				errstr = nbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	return errstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) /* __ext4_std_error decodes expected errors from journaling functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839)  * automatically and invokes the appropriate error response.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) void __ext4_std_error(struct super_block *sb, const char *function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		      unsigned int line, int errno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	char nbuf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	const char *errstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	if (unlikely(ext4_forced_shutdown(EXT4_SB(sb))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	/* Special case: if the error is EROFS, and we're not already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	 * inside a transaction, then there's really no point in logging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	 * an error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	if (errno == -EROFS && journal_current_handle() == NULL && sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	if (ext4_error_ratelimit(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		errstr = ext4_decode_error(sb, errno, nbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 		printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		       sb->s_id, function, line, errstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	save_error_info(sb, -errno, 0, 0, function, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	ext4_handle_error(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867)  * ext4_abort is a much stronger failure handler than ext4_error.  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868)  * abort function may be used to deal with unrecoverable failures such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869)  * as journal IO errors or ENOMEM at a critical moment in log management.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871)  * We unconditionally force the filesystem into an ABORT|READONLY state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872)  * unless the error response on the fs has been set to panic in which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873)  * case we take the easy way out and panic immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) void __ext4_abort(struct super_block *sb, const char *function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		  unsigned int line, int error, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	if (unlikely(ext4_forced_shutdown(EXT4_SB(sb))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	save_error_info(sb, error, 0, 0, function, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	       sb->s_id, function, line, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	if (sb_rdonly(sb) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		ext4_set_mount_flag(sb, EXT4_MF_FS_ABORTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		if (EXT4_SB(sb)->s_journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 			jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		 * Make sure updated value of ->s_mount_flags will be visible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		 * before ->s_flags update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	if (test_opt(sb, ERRORS_PANIC) && !system_going_down())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		panic("EXT4-fs panic from previous error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) void __ext4_msg(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		const char *prefix, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	atomic_inc(&EXT4_SB(sb)->s_msg_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	if (!___ratelimit(&(EXT4_SB(sb)->s_msg_ratelimit_state), "EXT4-fs"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	printk("%sEXT4-fs (%s): %pV\n", prefix, sb->s_id, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) static int ext4_warning_ratelimit(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	atomic_inc(&EXT4_SB(sb)->s_warning_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	return ___ratelimit(&(EXT4_SB(sb)->s_warning_ratelimit_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 			    "EXT4-fs warning");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) void __ext4_warning(struct super_block *sb, const char *function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		    unsigned int line, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	if (!ext4_warning_ratelimit(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	printk(KERN_WARNING "EXT4-fs warning (device %s): %s:%d: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	       sb->s_id, function, line, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) void __ext4_warning_inode(const struct inode *inode, const char *function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 			  unsigned int line, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	if (!ext4_warning_ratelimit(inode->i_sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	printk(KERN_WARNING "EXT4-fs warning (device %s): %s:%d: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	       "inode #%lu: comm %s: %pV\n", inode->i_sb->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	       function, line, inode->i_ino, current->comm, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) void __ext4_grp_locked_error(const char *function, unsigned int line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 			     struct super_block *sb, ext4_group_t grp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 			     unsigned long ino, ext4_fsblk_t block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 			     const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) __releases(bitlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) __acquires(bitlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	if (unlikely(ext4_forced_shutdown(EXT4_SB(sb))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	trace_ext4_error(sb, function, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	__save_error_info(sb, EFSCORRUPTED, ino, block, function, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	if (ext4_error_ratelimit(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: group %u, ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 		       sb->s_id, function, line, grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		if (ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 			printk(KERN_CONT "inode %lu: ", ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		if (block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 			printk(KERN_CONT "block %llu:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 			       (unsigned long long) block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		printk(KERN_CONT "%pV\n", &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	if (test_opt(sb, WARN_ON_ERROR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	if (test_opt(sb, ERRORS_CONT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		ext4_commit_super(sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	ext4_unlock_group(sb, grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	ext4_commit_super(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	ext4_handle_error(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	 * We only get here in the ERRORS_RO case; relocking the group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	 * may be dangerous, but nothing bad will happen since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	 * filesystem will have already been marked read/only and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	 * journal has been aborted.  We return 1 as a hint to callers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	 * who might what to use the return value from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	 * ext4_grp_locked_error() to distinguish between the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	 * ERRORS_CONT and ERRORS_RO case, and perhaps return more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	 * aggressively from the ext4 function in question, with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	 * more appropriate error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	ext4_lock_group(sb, grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) void ext4_mark_group_bitmap_corrupted(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 				     ext4_group_t group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 				     unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	struct ext4_group_info *grp = ext4_get_group_info(sb, group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	struct ext4_group_desc *gdp = ext4_get_group_desc(sb, group, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	if (flags & EXT4_GROUP_INFO_BBITMAP_CORRUPT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		ret = ext4_test_and_set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 					    &grp->bb_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 			percpu_counter_sub(&sbi->s_freeclusters_counter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 					   grp->bb_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	if (flags & EXT4_GROUP_INFO_IBITMAP_CORRUPT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		ret = ext4_test_and_set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 					    &grp->bb_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		if (!ret && gdp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 			int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 			count = ext4_free_inodes_count(sb, gdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 			percpu_counter_sub(&sbi->s_freeinodes_counter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 					   count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) void ext4_update_dynamic_rev(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	struct ext4_super_block *es = EXT4_SB(sb)->s_es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	ext4_warning(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		     "updating to rev %d because of new feature flag, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		     "running e2fsck is recommended",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		     EXT4_DYNAMIC_REV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	/* leave es->s_feature_*compat flags alone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	/* es->s_uuid will be set by e2fsck if empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	 * The rest of the superblock fields should be zero, and if not it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	 * means they are likely already in use, so leave them alone.  We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	 * can leave it up to e2fsck to clean up any inconsistencies there.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)  * Open the external journal device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	struct block_device *bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	if (IS_ERR(bdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	return bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		 "failed to open journal device unknown-block(%u,%u) %ld",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		 MAJOR(dev), MINOR(dev), PTR_ERR(bdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)  * Release the journal device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) static void ext4_blkdev_put(struct block_device *bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) static void ext4_blkdev_remove(struct ext4_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	struct block_device *bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	bdev = sbi->s_journal_bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	if (bdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		ext4_blkdev_put(bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		sbi->s_journal_bdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) static inline struct inode *orphan_list_entry(struct list_head *l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	struct list_head *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	ext4_msg(sb, KERN_ERR, "sb orphan head is %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		 le32_to_cpu(sbi->s_es->s_last_orphan));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	printk(KERN_ERR "sb_info orphan list:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	list_for_each(l, &sbi->s_orphan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		struct inode *inode = orphan_list_entry(l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 		printk(KERN_ERR "  "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		       "inode %s:%lu at %p: mode %o, nlink %d, next %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 		       inode->i_sb->s_id, inode->i_ino, inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		       inode->i_mode, inode->i_nlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		       NEXT_ORPHAN(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) static int ext4_quota_off(struct super_block *sb, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) static inline void ext4_quota_off_umount(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	/* Use our quota_off function to clear inode flags etc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	for (type = 0; type < EXT4_MAXQUOTAS; type++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		ext4_quota_off(sb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)  * This is a helper function which is used in the mount/remount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)  * codepaths (which holds s_umount) to fetch the quota file name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) static inline char *get_qf_name(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 				struct ext4_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 				int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	return rcu_dereference_protected(sbi->s_qf_names[type],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 					 lockdep_is_held(&sb->s_umount));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) static inline void ext4_quota_off_umount(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) static void ext4_put_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	struct ext4_super_block *es = sbi->s_es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	struct buffer_head **group_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	struct flex_groups **flex_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	int aborted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	ext4_unregister_li_request(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	ext4_quota_off_umount(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	destroy_workqueue(sbi->rsv_conversion_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	 * Unregister sysfs before destroying jbd2 journal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	 * Since we could still access attr_journal_task attribute via sysfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	 * path which could have sbi->s_journal->j_task as NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	ext4_unregister_sysfs(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	if (sbi->s_journal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		aborted = is_journal_aborted(sbi->s_journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		err = jbd2_journal_destroy(sbi->s_journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 		sbi->s_journal = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		if ((err < 0) && !aborted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 			ext4_abort(sb, -err, "Couldn't clean up the journal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	ext4_es_unregister_shrinker(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	del_timer_sync(&sbi->s_err_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	ext4_release_system_zone(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	ext4_mb_release(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	ext4_ext_release(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	if (!sb_rdonly(sb) && !aborted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 		ext4_clear_feature_journal_needs_recovery(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		es->s_state = cpu_to_le16(sbi->s_mount_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		ext4_commit_super(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	group_desc = rcu_dereference(sbi->s_group_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	for (i = 0; i < sbi->s_gdb_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 		brelse(group_desc[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	kvfree(group_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	flex_groups = rcu_dereference(sbi->s_flex_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	if (flex_groups) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		for (i = 0; i < sbi->s_flex_groups_allocated; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 			kvfree(flex_groups[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 		kvfree(flex_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	percpu_counter_destroy(&sbi->s_freeclusters_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	percpu_counter_destroy(&sbi->s_freeinodes_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	percpu_counter_destroy(&sbi->s_dirs_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	percpu_counter_destroy(&sbi->s_sra_exceeded_retry_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	percpu_free_rwsem(&sbi->s_writepages_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	for (i = 0; i < EXT4_MAXQUOTAS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 		kfree(get_qf_name(sb, sbi, i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	/* Debugging code just in case the in-memory inode orphan list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	 * isn't empty.  The on-disk one can be non-empty if we've
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	 * detected an error and taken the fs readonly, but the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	 * in-memory list had better be clean by this point. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	if (!list_empty(&sbi->s_orphan))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 		dump_orphan_list(sb, sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	J_ASSERT(list_empty(&sbi->s_orphan));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	sync_blockdev(sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	invalidate_bdev(sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	if (sbi->s_journal_bdev && sbi->s_journal_bdev != sb->s_bdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		 * Invalidate the journal device's buffers.  We don't want them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 		 * floating about in memory - the physical journal device may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		 * hotswapped, and it breaks the `ro-after' testing code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		sync_blockdev(sbi->s_journal_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 		invalidate_bdev(sbi->s_journal_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 		ext4_blkdev_remove(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	sbi->s_ea_inode_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	ext4_xattr_destroy_cache(sbi->s_ea_block_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	sbi->s_ea_block_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	ext4_stop_mmpd(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	brelse(sbi->s_sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	 * Now that we are completely done shutting down the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	 * superblock, we need to actually destroy the kobject.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	kobject_put(&sbi->s_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	wait_for_completion(&sbi->s_kobj_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	if (sbi->s_chksum_driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		crypto_free_shash(sbi->s_chksum_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	kfree(sbi->s_blockgroup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	fs_put_dax(sbi->s_daxdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) #ifdef CONFIG_UNICODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	utf8_unload(sb->s_encoding);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) static struct kmem_cache *ext4_inode_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)  * Called inside transaction, so use GFP_NOFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) static struct inode *ext4_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	struct ext4_inode_info *ei;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	if (!ei)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	inode_set_iversion(&ei->vfs_inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	spin_lock_init(&ei->i_raw_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	INIT_LIST_HEAD(&ei->i_prealloc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	atomic_set(&ei->i_prealloc_active, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	spin_lock_init(&ei->i_prealloc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	ext4_es_init_tree(&ei->i_es_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	rwlock_init(&ei->i_es_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	INIT_LIST_HEAD(&ei->i_es_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	ei->i_es_all_nr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	ei->i_es_shk_nr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	ei->i_es_shrink_lblk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	ei->i_reserved_data_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	spin_lock_init(&(ei->i_block_reservation_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	ext4_init_pending_tree(&ei->i_pending_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	ei->i_reserved_quota = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	memset(&ei->i_dquot, 0, sizeof(ei->i_dquot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	ei->jinode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	INIT_LIST_HEAD(&ei->i_rsv_conversion_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	spin_lock_init(&ei->i_completed_io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	ei->i_sync_tid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	ei->i_datasync_tid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	atomic_set(&ei->i_unwritten, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	ext4_fc_init_inode(&ei->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	mutex_init(&ei->i_fc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	return &ei->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) static int ext4_drop_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	int drop = generic_drop_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	if (!drop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		drop = fscrypt_drop_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	trace_ext4_drop_inode(inode, drop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	return drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) static void ext4_free_in_core_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	fscrypt_free_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	if (!list_empty(&(EXT4_I(inode)->i_fc_list))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		pr_warn("%s: inode %ld still in fc list",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 			__func__, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	kmem_cache_free(ext4_inode_cachep, EXT4_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) static void ext4_destroy_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	if (!list_empty(&(EXT4_I(inode)->i_orphan))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		ext4_msg(inode->i_sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 			 "Inode %lu (%p): orphan list check failed!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 			 inode->i_ino, EXT4_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 		print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 				EXT4_I(inode), sizeof(struct ext4_inode_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 				true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 		dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	if (EXT4_I(inode)->i_reserved_data_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 		ext4_msg(inode->i_sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 			 "Inode %lu (%p): i_reserved_data_blocks (%u) not cleared!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 			 inode->i_ino, EXT4_I(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 			 EXT4_I(inode)->i_reserved_data_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) static void init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	struct ext4_inode_info *ei = (struct ext4_inode_info *) foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	INIT_LIST_HEAD(&ei->i_orphan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	init_rwsem(&ei->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	init_rwsem(&ei->i_data_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	init_rwsem(&ei->i_mmap_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	inode_init_once(&ei->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 	ext4_fc_init_inode(&ei->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) static int __init init_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	ext4_inode_cachep = kmem_cache_create_usercopy("ext4_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 				sizeof(struct ext4_inode_info), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 				(SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 					SLAB_ACCOUNT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 				offsetof(struct ext4_inode_info, i_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 				sizeof_field(struct ext4_inode_info, i_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 				init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	if (ext4_inode_cachep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) static void destroy_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	 * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	 * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	kmem_cache_destroy(ext4_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) void ext4_clear_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	ext4_fc_del(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	invalidate_inode_buffers(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	ext4_discard_preallocations(inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	dquot_drop(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	if (EXT4_I(inode)->jinode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		jbd2_journal_release_jbd_inode(EXT4_JOURNAL(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 					       EXT4_I(inode)->jinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 		jbd2_free_inode(EXT4_I(inode)->jinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		EXT4_I(inode)->jinode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	fscrypt_put_encryption_info(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	fsverity_cleanup_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) static struct inode *ext4_nfs_get_inode(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 					u64 ino, u32 generation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	 * Currently we don't know the generation for parent directory, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	 * a generation of 0 means "accept any"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	inode = ext4_iget(sb, ino, EXT4_IGET_HANDLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 		return ERR_CAST(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	if (generation && inode->i_generation != generation) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 					int fh_len, int fh_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 				    ext4_nfs_get_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 					int fh_len, int fh_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	return generic_fh_to_parent(sb, fid, fh_len, fh_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 				    ext4_nfs_get_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) static int ext4_nfs_commit_metadata(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	struct writeback_control wbc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 		.sync_mode = WB_SYNC_ALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	trace_ext4_nfs_commit_metadata(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	return ext4_write_inode(inode, &wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466)  * Try to release metadata pages (indirect blocks, directories) which are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)  * mapped via the block device.  Since these pages could have journal heads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468)  * which would prevent try_to_free_buffers() from freeing them, we must use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)  * jbd2 layer's try_to_free_buffers() function to release them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) static int bdev_try_to_free_page(struct super_block *sb, struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 				 gfp_t wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	journal_t *journal = EXT4_SB(sb)->s_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	WARN_ON(PageChecked(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 	if (!page_has_buffers(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	if (journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 		return jbd2_journal_try_to_free_buffers(journal, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	return try_to_free_buffers(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) #ifdef CONFIG_FS_ENCRYPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) static int ext4_get_context(struct inode *inode, void *ctx, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	return ext4_xattr_get(inode, EXT4_XATTR_INDEX_ENCRYPTION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 				 EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, ctx, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 							void *fs_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 	handle_t *handle = fs_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	int res, res2, credits, retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	 * Encrypting the root directory is not allowed because e2fsck expects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	 * lost+found to exist and be unencrypted, and encrypting the root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	 * directory would imply encrypting the lost+found directory as well as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	 * the filename "lost+found" itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	if (inode->i_ino == EXT4_ROOT_INO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	if (WARN_ON_ONCE(IS_DAX(inode) && i_size_read(inode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	if (ext4_test_inode_flag(inode, EXT4_INODE_DAX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	res = ext4_convert_inline_data(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	 * If a journal handle was specified, then the encryption context is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	 * being set on a new inode via inheritance and is part of a larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	 * transaction to create the inode.  Otherwise the encryption context is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	 * being set on an existing inode in its own transaction.  Only in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	 * latter case should the "retry on ENOSPC" logic be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	if (handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 		res = ext4_xattr_set_handle(handle, inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 					    EXT4_XATTR_INDEX_ENCRYPTION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 					    EXT4_XATTR_NAME_ENCRYPTION_CONTEXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 					    ctx, len, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 		if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 			ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 			ext4_clear_inode_state(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 					EXT4_STATE_MAY_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 			 * Update inode->i_flags - S_ENCRYPTED will be enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 			 * S_DAX may be disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 			ext4_set_inode_flags(inode, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	res = dquot_initialize(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	res = ext4_xattr_set_credits(inode, len, false /* is_create */,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 				     &credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	handle = ext4_journal_start(inode, EXT4_HT_MISC, credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	if (IS_ERR(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 		return PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	res = ext4_xattr_set_handle(handle, inode, EXT4_XATTR_INDEX_ENCRYPTION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 				    EXT4_XATTR_NAME_ENCRYPTION_CONTEXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 				    ctx, len, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 		ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 		 * Update inode->i_flags - S_ENCRYPTED will be enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 		 * S_DAX may be disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 		ext4_set_inode_flags(inode, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 		res = ext4_mark_inode_dirty(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 		if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 			EXT4_ERROR_INODE(inode, "Failed to mark inode dirty");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	res2 = ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	if (res == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	if (!res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		res = res2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) static const union fscrypt_policy *ext4_get_dummy_policy(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	return EXT4_SB(sb)->s_dummy_enc_policy.policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) static bool ext4_has_stable_inodes(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	return ext4_has_feature_stable_inodes(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) static void ext4_get_ino_and_lblk_bits(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 				       int *ino_bits_ret, int *lblk_bits_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	*ino_bits_ret = 8 * sizeof(EXT4_SB(sb)->s_es->s_inodes_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	*lblk_bits_ret = 8 * sizeof(ext4_lblk_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) static const struct fscrypt_operations ext4_cryptops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	.key_prefix		= "ext4:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 	.get_context		= ext4_get_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	.set_context		= ext4_set_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	.get_dummy_policy	= ext4_get_dummy_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 	.empty_dir		= ext4_empty_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	.max_namelen		= EXT4_NAME_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	.has_stable_inodes	= ext4_has_stable_inodes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 	.get_ino_and_lblk_bits	= ext4_get_ino_and_lblk_bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) static const char * const quotatypes[] = INITQFNAMES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) #define QTYPE2NAME(t) (quotatypes[t])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) static int ext4_write_dquot(struct dquot *dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) static int ext4_acquire_dquot(struct dquot *dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) static int ext4_release_dquot(struct dquot *dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) static int ext4_mark_dquot_dirty(struct dquot *dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) static int ext4_write_info(struct super_block *sb, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) static int ext4_quota_on(struct super_block *sb, int type, int format_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 			 const struct path *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) static int ext4_quota_on_mount(struct super_block *sb, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 			       size_t len, loff_t off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) static ssize_t ext4_quota_write(struct super_block *sb, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 				const char *data, size_t len, loff_t off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) static int ext4_quota_enable(struct super_block *sb, int type, int format_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 			     unsigned int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) static int ext4_enable_quotas(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) static struct dquot **ext4_get_dquots(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	return EXT4_I(inode)->i_dquot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) static const struct dquot_operations ext4_quota_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	.get_reserved_space	= ext4_get_reserved_space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	.write_dquot		= ext4_write_dquot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	.acquire_dquot		= ext4_acquire_dquot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	.release_dquot		= ext4_release_dquot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	.mark_dirty		= ext4_mark_dquot_dirty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	.write_info		= ext4_write_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	.alloc_dquot		= dquot_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	.destroy_dquot		= dquot_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	.get_projid		= ext4_get_projid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	.get_inode_usage	= ext4_get_inode_usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	.get_next_id		= dquot_get_next_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) static const struct quotactl_ops ext4_qctl_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 	.quota_on	= ext4_quota_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	.quota_off	= ext4_quota_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 	.quota_sync	= dquot_quota_sync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	.get_state	= dquot_get_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	.set_info	= dquot_set_dqinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 	.get_dqblk	= dquot_get_dqblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 	.set_dqblk	= dquot_set_dqblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	.get_nextdqblk	= dquot_get_next_dqblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) static const struct super_operations ext4_sops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	.alloc_inode	= ext4_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	.free_inode	= ext4_free_in_core_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	.destroy_inode	= ext4_destroy_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	.write_inode	= ext4_write_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	.dirty_inode	= ext4_dirty_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	.drop_inode	= ext4_drop_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	.evict_inode	= ext4_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	.put_super	= ext4_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	.sync_fs	= ext4_sync_fs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	.freeze_fs	= ext4_freeze,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	.unfreeze_fs	= ext4_unfreeze,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	.statfs		= ext4_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	.remount_fs	= ext4_remount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	.show_options	= ext4_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 	.quota_read	= ext4_quota_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	.quota_write	= ext4_quota_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	.get_dquots	= ext4_get_dquots,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	.bdev_try_to_free_page = bdev_try_to_free_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) static const struct export_operations ext4_export_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 	.fh_to_dentry = ext4_fh_to_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	.fh_to_parent = ext4_fh_to_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 	.get_parent = ext4_get_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 	.commit_metadata = ext4_nfs_commit_metadata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 	Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	Opt_nouid32, Opt_debug, Opt_removed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 	Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	Opt_auto_da_alloc, Opt_noauto_da_alloc, Opt_noload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	Opt_commit, Opt_min_batch_time, Opt_max_batch_time, Opt_journal_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	Opt_journal_path, Opt_journal_checksum, Opt_journal_async_commit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	Opt_data_err_abort, Opt_data_err_ignore, Opt_test_dummy_encryption,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 	Opt_inlinecrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	Opt_noquota, Opt_barrier, Opt_nobarrier, Opt_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	Opt_usrquota, Opt_grpquota, Opt_prjquota, Opt_i_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	Opt_dax, Opt_dax_always, Opt_dax_inode, Opt_dax_never,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	Opt_stripe, Opt_delalloc, Opt_nodelalloc, Opt_warn_on_error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	Opt_nowarn_on_error, Opt_mblk_io_submit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	Opt_lazytime, Opt_nolazytime, Opt_debug_want_extra_isize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 	Opt_nomblk_io_submit, Opt_block_validity, Opt_noblock_validity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 	Opt_inode_readahead_blks, Opt_journal_ioprio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	Opt_dioread_nolock, Opt_dioread_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	Opt_prefetch_block_bitmaps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) #ifdef CONFIG_EXT4_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	Opt_fc_debug_max_replay, Opt_fc_debug_force
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) static const match_table_t tokens = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	{Opt_bsd_df, "bsddf"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	{Opt_minix_df, "minixdf"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	{Opt_grpid, "grpid"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	{Opt_grpid, "bsdgroups"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	{Opt_nogrpid, "nogrpid"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	{Opt_nogrpid, "sysvgroups"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	{Opt_resgid, "resgid=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	{Opt_resuid, "resuid=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	{Opt_sb, "sb=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	{Opt_err_cont, "errors=continue"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	{Opt_err_panic, "errors=panic"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 	{Opt_err_ro, "errors=remount-ro"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	{Opt_nouid32, "nouid32"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	{Opt_debug, "debug"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	{Opt_removed, "oldalloc"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	{Opt_removed, "orlov"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 	{Opt_user_xattr, "user_xattr"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	{Opt_nouser_xattr, "nouser_xattr"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 	{Opt_acl, "acl"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 	{Opt_noacl, "noacl"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 	{Opt_noload, "norecovery"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	{Opt_noload, "noload"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	{Opt_removed, "nobh"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 	{Opt_removed, "bh"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	{Opt_commit, "commit=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	{Opt_min_batch_time, "min_batch_time=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 	{Opt_max_batch_time, "max_batch_time=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	{Opt_journal_dev, "journal_dev=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	{Opt_journal_path, "journal_path=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 	{Opt_journal_checksum, "journal_checksum"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	{Opt_nojournal_checksum, "nojournal_checksum"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	{Opt_journal_async_commit, "journal_async_commit"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	{Opt_abort, "abort"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 	{Opt_data_journal, "data=journal"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 	{Opt_data_ordered, "data=ordered"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	{Opt_data_writeback, "data=writeback"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	{Opt_data_err_abort, "data_err=abort"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	{Opt_data_err_ignore, "data_err=ignore"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 	{Opt_offusrjquota, "usrjquota="},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 	{Opt_usrjquota, "usrjquota=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	{Opt_offgrpjquota, "grpjquota="},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	{Opt_grpjquota, "grpjquota=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	{Opt_jqfmt_vfsold, "jqfmt=vfsold"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	{Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	{Opt_jqfmt_vfsv1, "jqfmt=vfsv1"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	{Opt_grpquota, "grpquota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	{Opt_noquota, "noquota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	{Opt_quota, "quota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	{Opt_usrquota, "usrquota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	{Opt_prjquota, "prjquota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	{Opt_barrier, "barrier=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	{Opt_barrier, "barrier"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 	{Opt_nobarrier, "nobarrier"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	{Opt_i_version, "i_version"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	{Opt_dax, "dax"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	{Opt_dax_always, "dax=always"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 	{Opt_dax_inode, "dax=inode"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	{Opt_dax_never, "dax=never"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	{Opt_stripe, "stripe=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	{Opt_delalloc, "delalloc"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	{Opt_warn_on_error, "warn_on_error"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	{Opt_nowarn_on_error, "nowarn_on_error"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	{Opt_lazytime, "lazytime"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	{Opt_nolazytime, "nolazytime"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	{Opt_debug_want_extra_isize, "debug_want_extra_isize=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	{Opt_nodelalloc, "nodelalloc"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	{Opt_removed, "mblk_io_submit"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	{Opt_removed, "nomblk_io_submit"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	{Opt_block_validity, "block_validity"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	{Opt_noblock_validity, "noblock_validity"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 	{Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 	{Opt_journal_ioprio, "journal_ioprio=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 	{Opt_auto_da_alloc, "auto_da_alloc=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	{Opt_auto_da_alloc, "auto_da_alloc"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	{Opt_noauto_da_alloc, "noauto_da_alloc"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	{Opt_dioread_nolock, "dioread_nolock"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	{Opt_dioread_lock, "nodioread_nolock"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	{Opt_dioread_lock, "dioread_lock"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	{Opt_discard, "discard"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 	{Opt_nodiscard, "nodiscard"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	{Opt_init_itable, "init_itable=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	{Opt_init_itable, "init_itable"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	{Opt_noinit_itable, "noinit_itable"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) #ifdef CONFIG_EXT4_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	{Opt_fc_debug_force, "fc_debug_force"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	{Opt_fc_debug_max_replay, "fc_debug_max_replay=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	{Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	{Opt_test_dummy_encryption, "test_dummy_encryption=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	{Opt_test_dummy_encryption, "test_dummy_encryption"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	{Opt_inlinecrypt, "inlinecrypt"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	{Opt_nombcache, "nombcache"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	{Opt_nombcache, "no_mbcache"},	/* for backward compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	{Opt_prefetch_block_bitmaps, "prefetch_block_bitmaps"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	{Opt_removed, "check=none"},	/* mount option from ext2/3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	{Opt_removed, "nocheck"},	/* mount option from ext2/3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	{Opt_removed, "reservation"},	/* mount option from ext2/3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	{Opt_removed, "noreservation"}, /* mount option from ext2/3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 	{Opt_removed, "journal=%u"},	/* mount option from ext2/3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	{Opt_err, NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) static ext4_fsblk_t get_sb_block(void **data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	ext4_fsblk_t	sb_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	char		*options = (char *) *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	if (!options || strncmp(options, "sb=", 3) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 		return 1;	/* Default location */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	options += 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	/* TODO: use simple_strtoll with >32bit ext4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	sb_block = simple_strtoul(options, &options, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	if (*options && *options != ',') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 		printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 		       (char *) *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	if (*options == ',')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 		options++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 	*data = (void *) options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	return sb_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) static const char deprecated_msg[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	"Mount option \"%s\" will be removed by %s\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	"Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	char *qname, *old_qname = get_qf_name(sb, sbi, qtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 	int ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 	if (sb_any_quota_loaded(sb) && !old_qname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 			"Cannot change journaled "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 			"quota options when quota turned on");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	if (ext4_has_feature_quota(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 		ext4_msg(sb, KERN_INFO, "Journaled quota options "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 			 "ignored when QUOTA feature is enabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	qname = match_strdup(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	if (!qname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 			"Not enough memory for storing quotafile name");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	if (old_qname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 		if (strcmp(old_qname, qname) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 			ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 				 "%s quota file already specified",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 				 QTYPE2NAME(qtype));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 	if (strchr(qname, '/')) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 			"quotafile must be on filesystem root");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 	rcu_assign_pointer(sbi->s_qf_names[qtype], qname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	set_opt(sb, QUOTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 	kfree(qname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) static int clear_qf_name(struct super_block *sb, int qtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 	char *old_qname = get_qf_name(sb, sbi, qtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 	if (sb_any_quota_loaded(sb) && old_qname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 		ext4_msg(sb, KERN_ERR, "Cannot change journaled quota options"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 			" when quota turned on");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	rcu_assign_pointer(sbi->s_qf_names[qtype], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 	synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 	kfree(old_qname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) #define MOPT_SET	0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) #define MOPT_CLEAR	0x0002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) #define MOPT_NOSUPPORT	0x0004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) #define MOPT_EXPLICIT	0x0008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) #define MOPT_CLEAR_ERR	0x0010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) #define MOPT_GTE0	0x0020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) #define MOPT_Q		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) #define MOPT_QFMT	0x0040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) #define MOPT_Q		MOPT_NOSUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) #define MOPT_QFMT	MOPT_NOSUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) #define MOPT_DATAJ	0x0080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) #define MOPT_NO_EXT2	0x0100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) #define MOPT_NO_EXT3	0x0200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) #define MOPT_EXT4_ONLY	(MOPT_NO_EXT2 | MOPT_NO_EXT3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) #define MOPT_STRING	0x0400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) #define MOPT_SKIP	0x0800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) #define	MOPT_2		0x1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) static const struct mount_opts {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 	int	token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 	int	mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 	int	flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) } ext4_mount_opts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 	{Opt_minix_df, EXT4_MOUNT_MINIX_DF, MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 	{Opt_bsd_df, EXT4_MOUNT_MINIX_DF, MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 	{Opt_grpid, EXT4_MOUNT_GRPID, MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	{Opt_nogrpid, EXT4_MOUNT_GRPID, MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 	{Opt_block_validity, EXT4_MOUNT_BLOCK_VALIDITY, MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 	{Opt_noblock_validity, EXT4_MOUNT_BLOCK_VALIDITY, MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 	{Opt_dioread_nolock, EXT4_MOUNT_DIOREAD_NOLOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	 MOPT_EXT4_ONLY | MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 	{Opt_dioread_lock, EXT4_MOUNT_DIOREAD_NOLOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	 MOPT_EXT4_ONLY | MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 	{Opt_discard, EXT4_MOUNT_DISCARD, MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 	{Opt_nodiscard, EXT4_MOUNT_DISCARD, MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 	{Opt_delalloc, EXT4_MOUNT_DELALLOC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 	 MOPT_EXT4_ONLY | MOPT_SET | MOPT_EXPLICIT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 	{Opt_nodelalloc, EXT4_MOUNT_DELALLOC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 	 MOPT_EXT4_ONLY | MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 	{Opt_warn_on_error, EXT4_MOUNT_WARN_ON_ERROR, MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 	{Opt_nowarn_on_error, EXT4_MOUNT_WARN_ON_ERROR, MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	{Opt_nojournal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 	 MOPT_EXT4_ONLY | MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 	{Opt_journal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 	 MOPT_EXT4_ONLY | MOPT_SET | MOPT_EXPLICIT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 	{Opt_journal_async_commit, (EXT4_MOUNT_JOURNAL_ASYNC_COMMIT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 				    EXT4_MOUNT_JOURNAL_CHECKSUM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	 MOPT_EXT4_ONLY | MOPT_SET | MOPT_EXPLICIT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	{Opt_noload, EXT4_MOUNT_NOLOAD, MOPT_NO_EXT2 | MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 	{Opt_err_panic, EXT4_MOUNT_ERRORS_PANIC, MOPT_SET | MOPT_CLEAR_ERR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	{Opt_err_ro, EXT4_MOUNT_ERRORS_RO, MOPT_SET | MOPT_CLEAR_ERR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 	{Opt_err_cont, EXT4_MOUNT_ERRORS_CONT, MOPT_SET | MOPT_CLEAR_ERR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 	{Opt_data_err_abort, EXT4_MOUNT_DATA_ERR_ABORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 	 MOPT_NO_EXT2},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 	{Opt_data_err_ignore, EXT4_MOUNT_DATA_ERR_ABORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 	 MOPT_NO_EXT2},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 	{Opt_barrier, EXT4_MOUNT_BARRIER, MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 	{Opt_nobarrier, EXT4_MOUNT_BARRIER, MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 	{Opt_noauto_da_alloc, EXT4_MOUNT_NO_AUTO_DA_ALLOC, MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 	{Opt_auto_da_alloc, EXT4_MOUNT_NO_AUTO_DA_ALLOC, MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 	{Opt_noinit_itable, EXT4_MOUNT_INIT_INODE_TABLE, MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 	{Opt_commit, 0, MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 	{Opt_max_batch_time, 0, MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 	{Opt_min_batch_time, 0, MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 	{Opt_inode_readahead_blks, 0, MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 	{Opt_init_itable, 0, MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 	{Opt_dax, EXT4_MOUNT_DAX_ALWAYS, MOPT_SET | MOPT_SKIP},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	{Opt_dax_always, EXT4_MOUNT_DAX_ALWAYS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 		MOPT_EXT4_ONLY | MOPT_SET | MOPT_SKIP},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 	{Opt_dax_inode, EXT4_MOUNT2_DAX_INODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 		MOPT_EXT4_ONLY | MOPT_SET | MOPT_SKIP},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 	{Opt_dax_never, EXT4_MOUNT2_DAX_NEVER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 		MOPT_EXT4_ONLY | MOPT_SET | MOPT_SKIP},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 	{Opt_stripe, 0, MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 	{Opt_resuid, 0, MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 	{Opt_resgid, 0, MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 	{Opt_journal_dev, 0, MOPT_NO_EXT2 | MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 	{Opt_journal_path, 0, MOPT_NO_EXT2 | MOPT_STRING},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 	{Opt_journal_ioprio, 0, MOPT_NO_EXT2 | MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 	{Opt_data_journal, EXT4_MOUNT_JOURNAL_DATA, MOPT_NO_EXT2 | MOPT_DATAJ},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 	{Opt_data_ordered, EXT4_MOUNT_ORDERED_DATA, MOPT_NO_EXT2 | MOPT_DATAJ},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 	{Opt_data_writeback, EXT4_MOUNT_WRITEBACK_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 	 MOPT_NO_EXT2 | MOPT_DATAJ},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 	{Opt_user_xattr, EXT4_MOUNT_XATTR_USER, MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 	{Opt_nouser_xattr, EXT4_MOUNT_XATTR_USER, MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) #ifdef CONFIG_EXT4_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 	{Opt_acl, EXT4_MOUNT_POSIX_ACL, MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 	{Opt_noacl, EXT4_MOUNT_POSIX_ACL, MOPT_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 	{Opt_acl, 0, MOPT_NOSUPPORT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	{Opt_noacl, 0, MOPT_NOSUPPORT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 	{Opt_nouid32, EXT4_MOUNT_NO_UID32, MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 	{Opt_debug, EXT4_MOUNT_DEBUG, MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 	{Opt_debug_want_extra_isize, 0, MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 	{Opt_quota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA, MOPT_SET | MOPT_Q},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 	{Opt_usrquota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 							MOPT_SET | MOPT_Q},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	{Opt_grpquota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_GRPQUOTA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 							MOPT_SET | MOPT_Q},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 	{Opt_prjquota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_PRJQUOTA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 							MOPT_SET | MOPT_Q},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 	{Opt_noquota, (EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 		       EXT4_MOUNT_GRPQUOTA | EXT4_MOUNT_PRJQUOTA),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 							MOPT_CLEAR | MOPT_Q},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	{Opt_usrjquota, 0, MOPT_Q | MOPT_STRING},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 	{Opt_grpjquota, 0, MOPT_Q | MOPT_STRING},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 	{Opt_offusrjquota, 0, MOPT_Q},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 	{Opt_offgrpjquota, 0, MOPT_Q},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 	{Opt_jqfmt_vfsold, QFMT_VFS_OLD, MOPT_QFMT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 	{Opt_jqfmt_vfsv0, QFMT_VFS_V0, MOPT_QFMT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 	{Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 	{Opt_max_dir_size_kb, 0, MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 	{Opt_test_dummy_encryption, 0, MOPT_STRING},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 	{Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 	{Opt_prefetch_block_bitmaps, EXT4_MOUNT_PREFETCH_BLOCK_BITMAPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	 MOPT_SET},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) #ifdef CONFIG_EXT4_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 	{Opt_fc_debug_force, EXT4_MOUNT2_JOURNAL_FAST_COMMIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 	 MOPT_SET | MOPT_2 | MOPT_EXT4_ONLY},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 	{Opt_fc_debug_max_replay, 0, MOPT_GTE0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 	{Opt_err, 0, 0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) #ifdef CONFIG_UNICODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) static const struct ext4_sb_encodings {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 	__u16 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 	char *version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) } ext4_sb_encoding_map[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 	{EXT4_ENC_UTF8_12_1, "utf8", "12.1.0"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) static int ext4_sb_read_encoding(const struct ext4_super_block *es,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 				 const struct ext4_sb_encodings **encoding,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 				 __u16 *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 	__u16 magic = le16_to_cpu(es->s_encoding);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 	for (i = 0; i < ARRAY_SIZE(ext4_sb_encoding_map); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 		if (magic == ext4_sb_encoding_map[i].magic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 	if (i >= ARRAY_SIZE(ext4_sb_encoding_map))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 	*encoding = &ext4_sb_encoding_map[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 	*flags = le16_to_cpu(es->s_encoding_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) static int ext4_set_test_dummy_encryption(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 					  const char *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 					  const substring_t *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 					  bool is_remount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) #ifdef CONFIG_FS_ENCRYPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	 * This mount option is just for testing, and it's not worthwhile to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 	 * implement the extra complexity (e.g. RCU protection) that would be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 	 * needed to allow it to be set or changed during remount.  We do allow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 	 * it to be specified during remount, but only if there is no change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 	if (is_remount && !sbi->s_dummy_enc_policy.policy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 		ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 			 "Can't set test_dummy_encryption on remount");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 	err = fscrypt_set_test_dummy_encryption(sb, arg->from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 						&sbi->s_dummy_enc_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 		if (err == -EEXIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 			ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 				 "Can't change test_dummy_encryption on remount");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 		else if (err == -EINVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 			ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 				 "Value of option \"%s\" is unrecognized", opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 			ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 				 "Error processing option \"%s\" [%d]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 				 opt, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 	ext4_msg(sb, KERN_WARNING, "Test dummy encryption mode enabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 	ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 		 "Test dummy encryption mount option ignored");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) static int handle_mount_opt(struct super_block *sb, char *opt, int token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 			    substring_t *args, unsigned long *journal_devnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 			    unsigned int *journal_ioprio, int is_remount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 	const struct mount_opts *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 	kuid_t uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 	kgid_t gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 	int arg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 	if (token == Opt_usrjquota)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 		return set_qf_name(sb, USRQUOTA, &args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 	else if (token == Opt_grpjquota)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 		return set_qf_name(sb, GRPQUOTA, &args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 	else if (token == Opt_offusrjquota)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 		return clear_qf_name(sb, USRQUOTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 	else if (token == Opt_offgrpjquota)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 		return clear_qf_name(sb, GRPQUOTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 	switch (token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 	case Opt_noacl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 	case Opt_nouser_xattr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 		ext4_msg(sb, KERN_WARNING, deprecated_msg, opt, "3.5");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 	case Opt_sb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 		return 1;	/* handled by get_sb_block() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 	case Opt_removed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 		ext4_msg(sb, KERN_WARNING, "Ignoring removed %s option", opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 	case Opt_abort:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 		ext4_set_mount_flag(sb, EXT4_MF_FS_ABORTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 	case Opt_i_version:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 		sb->s_flags |= SB_I_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 	case Opt_lazytime:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 		sb->s_flags |= SB_LAZYTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	case Opt_nolazytime:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 		sb->s_flags &= ~SB_LAZYTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 	case Opt_inlinecrypt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) #ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 		sb->s_flags |= SB_INLINECRYPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 		ext4_msg(sb, KERN_ERR, "inline encryption not supported");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 	for (m = ext4_mount_opts; m->token != Opt_err; m++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 		if (token == m->token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 	if (m->token == Opt_err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 		ext4_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 			 "or missing value", opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 	if ((m->flags & MOPT_NO_EXT2) && IS_EXT2_SB(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 			 "Mount option \"%s\" incompatible with ext2", opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 	if ((m->flags & MOPT_NO_EXT3) && IS_EXT3_SB(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 			 "Mount option \"%s\" incompatible with ext3", opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 	if (args->from && !(m->flags & MOPT_STRING) && match_int(args, &arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 	if (args->from && (m->flags & MOPT_GTE0) && (arg < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 	if (m->flags & MOPT_EXPLICIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 		if (m->mount_opt & EXT4_MOUNT_DELALLOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 			set_opt2(sb, EXPLICIT_DELALLOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 		} else if (m->mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 			set_opt2(sb, EXPLICIT_JOURNAL_CHECKSUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 	if (m->flags & MOPT_CLEAR_ERR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 		clear_opt(sb, ERRORS_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 	if (token == Opt_noquota && sb_any_quota_loaded(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 		ext4_msg(sb, KERN_ERR, "Cannot change quota "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 			 "options when quota turned on");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 	if (m->flags & MOPT_NOSUPPORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 		ext4_msg(sb, KERN_ERR, "%s option not supported", opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	} else if (token == Opt_commit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 		if (arg == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 			arg = JBD2_DEFAULT_MAX_COMMIT_AGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 		else if (arg > INT_MAX / HZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 				 "Invalid commit interval %d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 				 "must be smaller than %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 				 arg, INT_MAX / HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 		sbi->s_commit_interval = HZ * arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 	} else if (token == Opt_debug_want_extra_isize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 		if ((arg & 1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 		    (arg < 4) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 		    (arg > (sbi->s_inode_size - EXT4_GOOD_OLD_INODE_SIZE))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 				 "Invalid want_extra_isize %d", arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 		sbi->s_want_extra_isize = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 	} else if (token == Opt_max_batch_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 		sbi->s_max_batch_time = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 	} else if (token == Opt_min_batch_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 		sbi->s_min_batch_time = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 	} else if (token == Opt_inode_readahead_blks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 		if (arg && (arg > (1 << 30) || !is_power_of_2(arg))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 				 "EXT4-fs: inode_readahead_blks must be "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 				 "0 or a power of 2 smaller than 2^31");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 		sbi->s_inode_readahead_blks = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 	} else if (token == Opt_init_itable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 		set_opt(sb, INIT_INODE_TABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 		if (!args->from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 			arg = EXT4_DEF_LI_WAIT_MULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 		sbi->s_li_wait_mult = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 	} else if (token == Opt_max_dir_size_kb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 		sbi->s_max_dir_size_kb = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) #ifdef CONFIG_EXT4_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 	} else if (token == Opt_fc_debug_max_replay) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 		sbi->s_fc_debug_max_replay = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 	} else if (token == Opt_stripe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 		sbi->s_stripe = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 	} else if (token == Opt_resuid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 		uid = make_kuid(current_user_ns(), arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 		if (!uid_valid(uid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 			ext4_msg(sb, KERN_ERR, "Invalid uid value %d", arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 		sbi->s_resuid = uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 	} else if (token == Opt_resgid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 		gid = make_kgid(current_user_ns(), arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 		if (!gid_valid(gid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 			ext4_msg(sb, KERN_ERR, "Invalid gid value %d", arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 		sbi->s_resgid = gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 	} else if (token == Opt_journal_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 		if (is_remount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 				 "Cannot specify journal on remount");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 		*journal_devnum = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 	} else if (token == Opt_journal_path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 		char *journal_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 		struct inode *journal_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 		struct path path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 		int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 		if (is_remount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 				 "Cannot specify journal on remount");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 		journal_path = match_strdup(&args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 		if (!journal_path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 			ext4_msg(sb, KERN_ERR, "error: could not dup "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 				"journal device string");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 		error = kern_path(journal_path, LOOKUP_FOLLOW, &path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 			ext4_msg(sb, KERN_ERR, "error: could not find "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 				"journal device path: error %d", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 			kfree(journal_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 		journal_inode = d_inode(path.dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 		if (!S_ISBLK(journal_inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 			ext4_msg(sb, KERN_ERR, "error: journal path %s "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 				"is not a block device", journal_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 			path_put(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 			kfree(journal_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 		*journal_devnum = new_encode_dev(journal_inode->i_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 		path_put(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 		kfree(journal_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 	} else if (token == Opt_journal_ioprio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 		if (arg > 7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 			ext4_msg(sb, KERN_ERR, "Invalid journal IO priority"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 				 " (must be 0-7)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 		*journal_ioprio =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 			IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 	} else if (token == Opt_test_dummy_encryption) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 		return ext4_set_test_dummy_encryption(sb, opt, &args[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 						      is_remount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 	} else if (m->flags & MOPT_DATAJ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 		if (is_remount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 			if (!sbi->s_journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 				ext4_msg(sb, KERN_WARNING, "Remounting file system with no journal so ignoring journalled data option");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 			else if (test_opt(sb, DATA_FLAGS) != m->mount_opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 				ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 					 "Cannot change data mode on remount");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 			clear_opt(sb, DATA_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 			sbi->s_mount_opt |= m->mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 	} else if (m->flags & MOPT_QFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 		if (sb_any_quota_loaded(sb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 		    sbi->s_jquota_fmt != m->mount_opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 			ext4_msg(sb, KERN_ERR, "Cannot change journaled "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 				 "quota options when quota turned on");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 		if (ext4_has_feature_quota(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 			ext4_msg(sb, KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 				 "Quota format mount options ignored "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 				 "when QUOTA feature is enabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 		sbi->s_jquota_fmt = m->mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 	} else if (token == Opt_dax || token == Opt_dax_always ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 		   token == Opt_dax_inode || token == Opt_dax_never) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) #ifdef CONFIG_FS_DAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 		switch (token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 		case Opt_dax:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 		case Opt_dax_always:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 			if (is_remount &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 			    (!(sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 			     (sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 			fail_dax_change_remount:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 				ext4_msg(sb, KERN_ERR, "can't change "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 					 "dax mount option while remounting");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 			if (is_remount &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 			    (test_opt(sb, DATA_FLAGS) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 			     EXT4_MOUNT_JOURNAL_DATA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 				    ext4_msg(sb, KERN_ERR, "can't mount with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 					     "both data=journal and dax");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 				    return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 			ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 				"DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 			sbi->s_mount_opt |= EXT4_MOUNT_DAX_ALWAYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 			sbi->s_mount_opt2 &= ~EXT4_MOUNT2_DAX_NEVER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 		case Opt_dax_never:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 			if (is_remount &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 			    (!(sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 			     (sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 				goto fail_dax_change_remount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 			sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_NEVER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 			sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 		case Opt_dax_inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 			if (is_remount &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 			    ((sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 			     (sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 			     !(sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_INODE)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 				goto fail_dax_change_remount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 			sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 			sbi->s_mount_opt2 &= ~EXT4_MOUNT2_DAX_NEVER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 			/* Strictly for printing options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 			sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_INODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 		ext4_msg(sb, KERN_INFO, "dax option not supported");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 		sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_NEVER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 		sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 	} else if (token == Opt_data_err_abort) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 		sbi->s_mount_opt |= m->mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 	} else if (token == Opt_data_err_ignore) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 		sbi->s_mount_opt &= ~m->mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 		if (!args->from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 			arg = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 		if (m->flags & MOPT_CLEAR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 			arg = !arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 		else if (unlikely(!(m->flags & MOPT_SET))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 			ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 				 "buggy handling of option %s", opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 			WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 		if (m->flags & MOPT_2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 			if (arg != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 				sbi->s_mount_opt2 |= m->mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 				sbi->s_mount_opt2 &= ~m->mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 			if (arg != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 				sbi->s_mount_opt |= m->mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 				sbi->s_mount_opt &= ~m->mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) static int parse_options(char *options, struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 			 unsigned long *journal_devnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 			 unsigned int *journal_ioprio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 			 int is_remount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 	struct ext4_sb_info __maybe_unused *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 	char *p, __maybe_unused *usr_qf_name, __maybe_unused *grp_qf_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 	substring_t args[MAX_OPT_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 	int token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 	if (!options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 	while ((p = strsep(&options, ",")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 		if (!*p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 		 * Initialize args struct so we know whether arg was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 		 * found; some options take optional arguments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 		args[0].to = args[0].from = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 		token = match_token(p, tokens, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 		if (handle_mount_opt(sb, p, token, args, journal_devnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 				     journal_ioprio, is_remount) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 	 * We do the test below only for project quotas. 'usrquota' and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 	 * 'grpquota' mount options are allowed even without quota feature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 	 * to support legacy quotas in quota files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 	if (test_opt(sb, PRJQUOTA) && !ext4_has_feature_project(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 		ext4_msg(sb, KERN_ERR, "Project quota feature not enabled. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 			 "Cannot enable project quota enforcement.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 	usr_qf_name = get_qf_name(sb, sbi, USRQUOTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 	grp_qf_name = get_qf_name(sb, sbi, GRPQUOTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 	if (usr_qf_name || grp_qf_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 		if (test_opt(sb, USRQUOTA) && usr_qf_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 			clear_opt(sb, USRQUOTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 		if (test_opt(sb, GRPQUOTA) && grp_qf_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 			clear_opt(sb, GRPQUOTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 		if (test_opt(sb, GRPQUOTA) || test_opt(sb, USRQUOTA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 			ext4_msg(sb, KERN_ERR, "old and new quota "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 					"format mixing");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 		if (!sbi->s_jquota_fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 			ext4_msg(sb, KERN_ERR, "journaled quota format "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 					"not specified");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 	if (test_opt(sb, DIOREAD_NOLOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 		int blocksize =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 			BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 		if (blocksize < PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 			ext4_msg(sb, KERN_WARNING, "Warning: mounting with an "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 				 "experimental mount option 'dioread_nolock' "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 				 "for blocksize < PAGE_SIZE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) static inline void ext4_show_quota_options(struct seq_file *seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 					   struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) #if defined(CONFIG_QUOTA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 	char *usr_qf_name, *grp_qf_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 	if (sbi->s_jquota_fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 		char *fmtname = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 		switch (sbi->s_jquota_fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 		case QFMT_VFS_OLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 			fmtname = "vfsold";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 		case QFMT_VFS_V0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 			fmtname = "vfsv0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 		case QFMT_VFS_V1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 			fmtname = "vfsv1";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 		seq_printf(seq, ",jqfmt=%s", fmtname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 	usr_qf_name = rcu_dereference(sbi->s_qf_names[USRQUOTA]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 	grp_qf_name = rcu_dereference(sbi->s_qf_names[GRPQUOTA]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 	if (usr_qf_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 		seq_show_option(seq, "usrjquota", usr_qf_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 	if (grp_qf_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 		seq_show_option(seq, "grpjquota", grp_qf_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) static const char *token2str(int token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 	const struct match_token *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 	for (t = tokens; t->token != Opt_err; t++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 		if (t->token == token && !strchr(t->pattern, '='))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 	return t->pattern;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551)  * Show an option if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552)  *  - it's set to a non-default value OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553)  *  - if the per-sb default is different from the global default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) static int _ext4_show_options(struct seq_file *seq, struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 			      int nodefs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 	struct ext4_super_block *es = sbi->s_es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 	int def_errors, def_mount_opt = sbi->s_def_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 	const struct mount_opts *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 	char sep = nodefs ? '\n' : ',';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) #define SEQ_OPTS_PUTS(str) seq_printf(seq, "%c" str, sep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) #define SEQ_OPTS_PRINT(str, arg) seq_printf(seq, "%c" str, sep, arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 	if (sbi->s_sb_block != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 		SEQ_OPTS_PRINT("sb=%llu", sbi->s_sb_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 	for (m = ext4_mount_opts; m->token != Opt_err; m++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 		int want_set = m->flags & MOPT_SET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 		if (((m->flags & (MOPT_SET|MOPT_CLEAR)) == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 		    (m->flags & MOPT_CLEAR_ERR) || m->flags & MOPT_SKIP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 		if (!nodefs && !(m->mount_opt & (sbi->s_mount_opt ^ def_mount_opt)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 			continue; /* skip if same as the default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 		if ((want_set &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 		     (sbi->s_mount_opt & m->mount_opt) != m->mount_opt) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 		    (!want_set && (sbi->s_mount_opt & m->mount_opt)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 			continue; /* select Opt_noFoo vs Opt_Foo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 		SEQ_OPTS_PRINT("%s", token2str(m->token));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 	if (nodefs || !uid_eq(sbi->s_resuid, make_kuid(&init_user_ns, EXT4_DEF_RESUID)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 	    le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 		SEQ_OPTS_PRINT("resuid=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 				from_kuid_munged(&init_user_ns, sbi->s_resuid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 	if (nodefs || !gid_eq(sbi->s_resgid, make_kgid(&init_user_ns, EXT4_DEF_RESGID)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 	    le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 		SEQ_OPTS_PRINT("resgid=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 				from_kgid_munged(&init_user_ns, sbi->s_resgid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 	def_errors = nodefs ? -1 : le16_to_cpu(es->s_errors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 	if (test_opt(sb, ERRORS_RO) && def_errors != EXT4_ERRORS_RO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 		SEQ_OPTS_PUTS("errors=remount-ro");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 	if (test_opt(sb, ERRORS_CONT) && def_errors != EXT4_ERRORS_CONTINUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 		SEQ_OPTS_PUTS("errors=continue");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 	if (test_opt(sb, ERRORS_PANIC) && def_errors != EXT4_ERRORS_PANIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 		SEQ_OPTS_PUTS("errors=panic");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 	if (nodefs || sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 		SEQ_OPTS_PRINT("commit=%lu", sbi->s_commit_interval / HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 	if (nodefs || sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 		SEQ_OPTS_PRINT("min_batch_time=%u", sbi->s_min_batch_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 	if (nodefs || sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 		SEQ_OPTS_PRINT("max_batch_time=%u", sbi->s_max_batch_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 	if (sb->s_flags & SB_I_VERSION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 		SEQ_OPTS_PUTS("i_version");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 	if (nodefs || sbi->s_stripe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 		SEQ_OPTS_PRINT("stripe=%lu", sbi->s_stripe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 	if (nodefs || EXT4_MOUNT_DATA_FLAGS &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 			(sbi->s_mount_opt ^ def_mount_opt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 		if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 			SEQ_OPTS_PUTS("data=journal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 		else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 			SEQ_OPTS_PUTS("data=ordered");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 		else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 			SEQ_OPTS_PUTS("data=writeback");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 	if (nodefs ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 	    sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 		SEQ_OPTS_PRINT("inode_readahead_blks=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 			       sbi->s_inode_readahead_blks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 	if (test_opt(sb, INIT_INODE_TABLE) && (nodefs ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 		       (sbi->s_li_wait_mult != EXT4_DEF_LI_WAIT_MULT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 		SEQ_OPTS_PRINT("init_itable=%u", sbi->s_li_wait_mult);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 	if (nodefs || sbi->s_max_dir_size_kb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 		SEQ_OPTS_PRINT("max_dir_size_kb=%u", sbi->s_max_dir_size_kb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 	if (test_opt(sb, DATA_ERR_ABORT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 		SEQ_OPTS_PUTS("data_err=abort");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 	fscrypt_show_test_dummy_encryption(seq, sep, sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 	if (sb->s_flags & SB_INLINECRYPT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 		SEQ_OPTS_PUTS("inlinecrypt");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 	if (test_opt(sb, DAX_ALWAYS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 		if (IS_EXT2_SB(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 			SEQ_OPTS_PUTS("dax");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) 			SEQ_OPTS_PUTS("dax=always");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 	} else if (test_opt2(sb, DAX_NEVER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) 		SEQ_OPTS_PUTS("dax=never");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 	} else if (test_opt2(sb, DAX_INODE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 		SEQ_OPTS_PUTS("dax=inode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 	ext4_show_quota_options(seq, sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) static int ext4_show_options(struct seq_file *seq, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 	return _ext4_show_options(seq, root->d_sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) int ext4_seq_options_show(struct seq_file *seq, void *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 	struct super_block *sb = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 	seq_puts(seq, sb_rdonly(sb) ? "ro" : "rw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 	rc = _ext4_show_options(seq, sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 	seq_puts(seq, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 			    int read_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 	if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 		ext4_msg(sb, KERN_ERR, "revision level too high, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 			 "forcing read-only mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 		err = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 	if (read_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 	if (!(sbi->s_mount_state & EXT4_VALID_FS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 		ext4_msg(sb, KERN_WARNING, "warning: mounting unchecked fs, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 			 "running e2fsck is recommended");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 	else if (sbi->s_mount_state & EXT4_ERROR_FS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 		ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 			 "warning: mounting fs with errors, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 			 "running e2fsck is recommended");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 	else if ((__s16) le16_to_cpu(es->s_max_mnt_count) > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 		 le16_to_cpu(es->s_mnt_count) >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 		 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 		ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 			 "warning: maximal mount count reached, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 			 "running e2fsck is recommended");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 	else if (le32_to_cpu(es->s_checkinterval) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 		 (ext4_get_tstamp(es, s_lastcheck) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 		  le32_to_cpu(es->s_checkinterval) <= ktime_get_real_seconds()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 		ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 			 "warning: checktime reached, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 			 "running e2fsck is recommended");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 	if (!sbi->s_journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 		es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 	if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 		es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 	le16_add_cpu(&es->s_mnt_count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 	ext4_update_tstamp(es, s_mtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 	if (sbi->s_journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 		ext4_set_feature_journal_needs_recovery(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 	err = ext4_commit_super(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 	if (test_opt(sb, DEBUG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 		printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 				"bpg=%lu, ipg=%lu, mo=%04x, mo2=%04x]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 			sb->s_blocksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 			sbi->s_groups_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 			EXT4_BLOCKS_PER_GROUP(sb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 			EXT4_INODES_PER_GROUP(sb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 			sbi->s_mount_opt, sbi->s_mount_opt2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 	cleancache_init_fs(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) int ext4_alloc_flex_bg_array(struct super_block *sb, ext4_group_t ngroup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 	struct flex_groups **old_groups, **new_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 	int size, i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 	if (!sbi->s_log_groups_per_flex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 	size = ext4_flex_group(sbi, ngroup - 1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 	if (size <= sbi->s_flex_groups_allocated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 	new_groups = kvzalloc(roundup_pow_of_two(size *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 			      sizeof(*sbi->s_flex_groups)), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 	if (!new_groups) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 			 "not enough memory for %d flex group pointers", size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 	for (i = sbi->s_flex_groups_allocated; i < size; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 		new_groups[i] = kvzalloc(roundup_pow_of_two(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 					 sizeof(struct flex_groups)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 					 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 		if (!new_groups[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 			for (j = sbi->s_flex_groups_allocated; j < i; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 				kvfree(new_groups[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 			kvfree(new_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 				 "not enough memory for %d flex groups", size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 	old_groups = rcu_dereference(sbi->s_flex_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 	if (old_groups)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 		memcpy(new_groups, old_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 		       (sbi->s_flex_groups_allocated *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 			sizeof(struct flex_groups *)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 	rcu_assign_pointer(sbi->s_flex_groups, new_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 	sbi->s_flex_groups_allocated = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 	if (old_groups)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 		ext4_kvfree_array_rcu(old_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) static int ext4_fill_flex_info(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 	struct ext4_group_desc *gdp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 	struct flex_groups *fg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 	ext4_group_t flex_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 	sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 	if (sbi->s_log_groups_per_flex < 1 || sbi->s_log_groups_per_flex > 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 		sbi->s_log_groups_per_flex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 	err = ext4_alloc_flex_bg_array(sb, sbi->s_groups_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 	for (i = 0; i < sbi->s_groups_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 		gdp = ext4_get_group_desc(sb, i, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 		flex_group = ext4_flex_group(sbi, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 		fg = sbi_array_rcu_deref(sbi, s_flex_groups, flex_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 		atomic_add(ext4_free_inodes_count(sb, gdp), &fg->free_inodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 		atomic64_add(ext4_free_group_clusters(sb, gdp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 			     &fg->free_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 		atomic_add(ext4_used_dirs_count(sb, gdp), &fg->used_dirs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) static __le16 ext4_group_desc_csum(struct super_block *sb, __u32 block_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 				   struct ext4_group_desc *gdp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 	int offset = offsetof(struct ext4_group_desc, bg_checksum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 	__u16 crc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 	__le32 le_group = cpu_to_le32(block_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 	if (ext4_has_metadata_csum(sbi->s_sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 		/* Use new metadata_csum algorithm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 		__u32 csum32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 		__u16 dummy_csum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 		csum32 = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&le_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 				     sizeof(le_group));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 		csum32 = ext4_chksum(sbi, csum32, (__u8 *)gdp, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 		csum32 = ext4_chksum(sbi, csum32, (__u8 *)&dummy_csum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 				     sizeof(dummy_csum));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 		offset += sizeof(dummy_csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 		if (offset < sbi->s_desc_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 			csum32 = ext4_chksum(sbi, csum32, (__u8 *)gdp + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 					     sbi->s_desc_size - offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 		crc = csum32 & 0xFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 	/* old crc16 code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 	if (!ext4_has_feature_gdt_csum(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 	crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 	crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 	crc = crc16(crc, (__u8 *)gdp, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) 	offset += sizeof(gdp->bg_checksum); /* skip checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 	/* for checksum of struct ext4_group_desc do the rest...*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) 	if (ext4_has_feature_64bit(sb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 	    offset < le16_to_cpu(sbi->s_es->s_desc_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 		crc = crc16(crc, (__u8 *)gdp + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 			    le16_to_cpu(sbi->s_es->s_desc_size) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 				offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) 	return cpu_to_le16(crc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) int ext4_group_desc_csum_verify(struct super_block *sb, __u32 block_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) 				struct ext4_group_desc *gdp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) 	if (ext4_has_group_desc_csum(sb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 	    (gdp->bg_checksum != ext4_group_desc_csum(sb, block_group, gdp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) void ext4_group_desc_csum_set(struct super_block *sb, __u32 block_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 			      struct ext4_group_desc *gdp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) 	if (!ext4_has_group_desc_csum(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) 	gdp->bg_checksum = ext4_group_desc_csum(sb, block_group, gdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) /* Called at mount-time, super-block is locked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) static int ext4_check_descriptors(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) 				  ext4_fsblk_t sb_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 				  ext4_group_t *first_not_zeroed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) 	ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 	ext4_fsblk_t last_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 	ext4_fsblk_t last_bg_block = sb_block + ext4_bg_num_gdb(sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) 	ext4_fsblk_t block_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 	ext4_fsblk_t inode_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) 	ext4_fsblk_t inode_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) 	int flexbg_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 	ext4_group_t i, grp = sbi->s_groups_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 	if (ext4_has_feature_flex_bg(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) 		flexbg_flag = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 	ext4_debug("Checking group descriptors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 	for (i = 0; i < sbi->s_groups_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 		struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 		if (i == sbi->s_groups_count - 1 || flexbg_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 			last_block = ext4_blocks_count(sbi->s_es) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 			last_block = first_block +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 				(EXT4_BLOCKS_PER_GROUP(sb) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 		if ((grp == sbi->s_groups_count) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 		   !(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 			grp = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) 		block_bitmap = ext4_block_bitmap(sb, gdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) 		if (block_bitmap == sb_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 			ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) 				 "Block bitmap for group %u overlaps "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) 				 "superblock", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 			if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 		if (block_bitmap >= sb_block + 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) 		    block_bitmap <= last_bg_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 			ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) 				 "Block bitmap for group %u overlaps "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) 				 "block group descriptors", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) 			if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) 		if (block_bitmap < first_block || block_bitmap > last_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) 			ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) 			       "Block bitmap for group %u not in group "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 			       "(block %llu)!", i, block_bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 		inode_bitmap = ext4_inode_bitmap(sb, gdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 		if (inode_bitmap == sb_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 			ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 				 "Inode bitmap for group %u overlaps "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 				 "superblock", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 			if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 		if (inode_bitmap >= sb_block + 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 		    inode_bitmap <= last_bg_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 			ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 				 "Inode bitmap for group %u overlaps "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 				 "block group descriptors", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 			if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 		if (inode_bitmap < first_block || inode_bitmap > last_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 			ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 			       "Inode bitmap for group %u not in group "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 			       "(block %llu)!", i, inode_bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 		inode_table = ext4_inode_table(sb, gdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 		if (inode_table == sb_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 			ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 				 "Inode table for group %u overlaps "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 				 "superblock", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 			if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 		if (inode_table >= sb_block + 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 		    inode_table <= last_bg_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) 			ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) 				 "Inode table for group %u overlaps "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 				 "block group descriptors", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 			if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 		if (inode_table < first_block ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 		    inode_table + sbi->s_itb_per_group - 1 > last_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 			ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) 			       "Inode table for group %u not in group "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 			       "(block %llu)!", i, inode_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 		ext4_lock_group(sb, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 		if (!ext4_group_desc_csum_verify(sb, i, gdp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 			ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 				 "Checksum for group %u failed (%u!=%u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) 				 i, le16_to_cpu(ext4_group_desc_csum(sb, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) 				     gdp)), le16_to_cpu(gdp->bg_checksum));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) 			if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) 				ext4_unlock_group(sb, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) 		ext4_unlock_group(sb, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 		if (!flexbg_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) 			first_block += EXT4_BLOCKS_PER_GROUP(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) 	if (NULL != first_not_zeroed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 		*first_not_zeroed = grp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) /* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989)  * the superblock) which were deleted from all directories, but held open by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990)  * a process at the time of a crash.  We walk the list and try to delete these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991)  * inodes at recovery time (only with a read-write filesystem).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993)  * In order to keep the orphan inode chain consistent during traversal (in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994)  * case of crash during recovery), we link each inode into the superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995)  * orphan list_head and handle it the same way as an inode deletion during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996)  * normal operation (which journals the operations for us).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998)  * We only do an iget() and an iput() on each inode, which is very safe if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999)  * accidentally point at an in-use or already deleted inode.  The worst that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000)  * can happen in this case is that we get a "bit already cleared" message from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001)  * ext4_free_inode().  The only reason we would point at a wrong inode is if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002)  * e2fsck was run on this filesystem, and it must have already done the orphan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003)  * inode cleanup for us, so we can safely abort without any further action.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) static void ext4_orphan_cleanup(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 				struct ext4_super_block *es)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 	unsigned int s_flags = sb->s_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) 	int ret, nr_orphans = 0, nr_truncates = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 	int quota_update = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) 	if (!es->s_last_orphan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 		jbd_debug(4, "no orphan inodes to clean up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 	if (bdev_read_only(sb->s_bdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) 		ext4_msg(sb, KERN_ERR, "write access "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 			"unavailable, skipping orphan cleanup");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 	/* Check if feature set would not allow a r/w mount */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 	if (!ext4_feature_set_ok(sb, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 		ext4_msg(sb, KERN_INFO, "Skipping orphan cleanup due to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 			 "unknown ROCOMPAT features");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) 	if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 		/* don't clear list on RO mount w/ errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) 		if (es->s_last_orphan && !(s_flags & SB_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) 			ext4_msg(sb, KERN_INFO, "Errors on filesystem, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 				  "clearing orphan list.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) 			es->s_last_orphan = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) 		jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) 	if (s_flags & SB_RDONLY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) 		ext4_msg(sb, KERN_INFO, "orphan cleanup on readonly fs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) 		sb->s_flags &= ~SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) 	 * Turn on quotas which were not enabled for read-only mounts if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) 	 * filesystem has quota feature, so that they are updated correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) 	if (ext4_has_feature_quota(sb) && (s_flags & SB_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) 		int ret = ext4_enable_quotas(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) 			quota_update = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) 				"Cannot turn on quotas: error %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 	/* Turn on journaled quotas used for old sytle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 	for (i = 0; i < EXT4_MAXQUOTAS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) 		if (EXT4_SB(sb)->s_qf_names[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 			int ret = ext4_quota_on_mount(sb, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 			if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 				quota_update = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 				ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 					"Cannot turn on journaled "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 					"quota: type %d: error %d", i, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 	while (es->s_last_orphan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 		struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 		 * We may have encountered an error during cleanup; if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 		 * so, skip the rest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) 		if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 			jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) 			es->s_last_orphan = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) 		inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 		if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 			es->s_last_orphan = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) 		list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) 		dquot_initialize(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) 		if (inode->i_nlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) 			if (test_opt(sb, DEBUG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) 				ext4_msg(sb, KERN_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) 					"%s: truncating inode %lu to %lld bytes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) 					__func__, inode->i_ino, inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) 			jbd_debug(2, "truncating inode %lu to %lld bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) 				  inode->i_ino, inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) 			inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) 			truncate_inode_pages(inode->i_mapping, inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) 			ret = ext4_truncate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) 				 * We need to clean up the in-core orphan list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) 				 * manually if ext4_truncate() failed to get a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) 				 * transaction handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) 				ext4_orphan_del(NULL, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) 				ext4_std_error(inode->i_sb, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 			inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 			nr_truncates++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) 			if (test_opt(sb, DEBUG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) 				ext4_msg(sb, KERN_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) 					"%s: deleting unreferenced inode %lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) 					__func__, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) 			jbd_debug(2, "deleting unreferenced inode %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 				  inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) 			nr_orphans++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 		iput(inode);  /* The delete magic happens here! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) #define PLURAL(x) (x), ((x) == 1) ? "" : "s"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) 	if (nr_orphans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) 		ext4_msg(sb, KERN_INFO, "%d orphan inode%s deleted",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 		       PLURAL(nr_orphans));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 	if (nr_truncates)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 		ext4_msg(sb, KERN_INFO, "%d truncate%s cleaned up",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) 		       PLURAL(nr_truncates));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 	/* Turn off quotas if they were enabled for orphan cleanup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) 	if (quota_update) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 		for (i = 0; i < EXT4_MAXQUOTAS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) 			if (sb_dqopt(sb)->files[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) 				dquot_quota_off(sb, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) 	sb->s_flags = s_flags; /* Restore SB_RDONLY status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152)  * Maximal extent format file size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153)  * Resulting logical blkno at s_maxbytes must fit in our on-disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154)  * extent format containers, within a sector_t, and within i_blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155)  * in the vfs.  ext4 inode has 48 bits of i_block in fsblock units,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156)  * so that won't be a limiting factor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158)  * However there is other limiting factor. We do store extents in the form
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159)  * of starting block and length, hence the resulting length of the extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160)  * covering maximum file size must fit into on-disk format containers as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161)  * well. Given that length is always by 1 unit bigger than max unit (because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162)  * we count 0 as well) we have to lower the s_maxbytes by one fs block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164)  * Note, this does *not* consider any metadata overhead for vfs i_blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) static loff_t ext4_max_size(int blkbits, int has_huge_files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) 	loff_t res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) 	loff_t upper_limit = MAX_LFS_FILESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) 	BUILD_BUG_ON(sizeof(blkcnt_t) < sizeof(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) 	if (!has_huge_files) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) 		upper_limit = (1LL << 32) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) 		/* total blocks in file system block size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) 		upper_limit >>= (blkbits - 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) 		upper_limit <<= blkbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) 	 * 32-bit extent-start container, ee_block. We lower the maxbytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) 	 * by one fs block, so ee_len can cover the extent of maximum file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) 	 * size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) 	res = (1LL << 32) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) 	res <<= blkbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) 	/* Sanity check against vm- & vfs- imposed limits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) 	if (res > upper_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) 		res = upper_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197)  * Maximal bitmap file size.  There is a direct, and {,double-,triple-}indirect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198)  * block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199)  * We need to be 1 filesystem block less than the 2^48 sector limit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) 	unsigned long long upper_limit, res = EXT4_NDIR_BLOCKS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) 	int meta_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) 	 * This is calculated to be the largest file size for a dense, block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) 	 * mapped file such that the file's total number of 512-byte sectors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) 	 * including data and all indirect blocks, does not exceed (2^48 - 1).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) 	 * __u32 i_blocks_lo and _u16 i_blocks_high represent the total
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) 	 * number of 512-byte sectors of the file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) 	if (!has_huge_files) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) 		 * !has_huge_files or implies that the inode i_block field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) 		 * represents total file blocks in 2^32 512-byte sectors ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) 		 * size of vfs inode i_blocks * 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) 		upper_limit = (1LL << 32) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) 		/* total blocks in file system block size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) 		upper_limit >>= (bits - 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) 		 * We use 48 bit ext4_inode i_blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) 		 * With EXT4_HUGE_FILE_FL set the i_blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) 		 * represent total number of blocks in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) 		 * file system block size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) 		upper_limit = (1LL << 48) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) 	/* indirect blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) 	meta_blocks = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) 	/* double indirect blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) 	meta_blocks += 1 + (1LL << (bits-2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) 	/* tripple indirect blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) 	meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) 	upper_limit -= meta_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) 	upper_limit <<= bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) 	res += 1LL << (bits-2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) 	res += 1LL << (2*(bits-2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) 	res += 1LL << (3*(bits-2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 	res <<= bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) 	if (res > upper_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 		res = upper_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) 	if (res > MAX_LFS_FILESIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) 		res = MAX_LFS_FILESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) 	return (loff_t)res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) static ext4_fsblk_t descriptor_loc(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) 				   ext4_fsblk_t logical_sb_block, int nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) 	ext4_group_t bg, first_meta_bg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) 	int has_super = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) 	first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) 	if (!ext4_has_feature_meta_bg(sb) || nr < first_meta_bg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) 		return logical_sb_block + nr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) 	bg = sbi->s_desc_per_block * nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) 	if (ext4_bg_has_super(sb, bg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) 		has_super = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) 	 * If we have a meta_bg fs with 1k blocks, group 0's GDT is at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) 	 * block 2, not 1.  If s_first_data_block == 0 (bigalloc is enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) 	 * on modern mke2fs or blksize > 1k on older mke2fs) then we must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) 	 * compensate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) 	if (sb->s_blocksize == 1024 && nr == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 	    le32_to_cpu(sbi->s_es->s_first_data_block) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) 		has_super++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) 	return (has_super + ext4_group_first_block_no(sb, bg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288)  * ext4_get_stripe_size: Get the stripe size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289)  * @sbi: In memory super block info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291)  * If we have specified it via mount option, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292)  * use the mount option value. If the value specified at mount time is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293)  * greater than the blocks per group use the super block value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294)  * If the super block value is greater than blocks per group return 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295)  * Allocator needs it be less than blocks per group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) 	unsigned long stride = le16_to_cpu(sbi->s_es->s_raid_stride);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) 	unsigned long stripe_width =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) 			le32_to_cpu(sbi->s_es->s_raid_stripe_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) 	if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) 		ret = sbi->s_stripe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) 	else if (stripe_width && stripe_width <= sbi->s_blocks_per_group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) 		ret = stripe_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) 	else if (stride && stride <= sbi->s_blocks_per_group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) 		ret = stride;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) 	 * If the stripe width is 1, this makes no sense and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) 	 * we set it to 0 to turn off stripe handling code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) 	if (ret <= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325)  * Check whether this filesystem can be mounted based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326)  * the features present and the RDONLY/RDWR mount requested.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327)  * Returns 1 if this filesystem can be mounted as requested,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328)  * 0 if it cannot be.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) static int ext4_feature_set_ok(struct super_block *sb, int readonly)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) 	if (ext4_has_unknown_ext4_incompat_features(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) 			"Couldn't mount because of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) 			"unsupported optional features (%x)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) 			(le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) 			~EXT4_FEATURE_INCOMPAT_SUPP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) #ifndef CONFIG_UNICODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) 	if (ext4_has_feature_casefold(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) 			 "Filesystem with casefold feature cannot be "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) 			 "mounted without CONFIG_UNICODE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) 	if (readonly)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) 	if (ext4_has_feature_readonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) 		ext4_msg(sb, KERN_INFO, "filesystem is read-only");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) 		sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) 	/* Check that feature set is OK for a read-write mount */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) 	if (ext4_has_unknown_ext4_ro_compat_features(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) 		ext4_msg(sb, KERN_ERR, "couldn't mount RDWR because of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) 			 "unsupported optional features (%x)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) 			 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) 				~EXT4_FEATURE_RO_COMPAT_SUPP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) 	if (ext4_has_feature_bigalloc(sb) && !ext4_has_feature_extents(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) 			 "Can't support bigalloc feature without "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) 			 "extents feature\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) #if !IS_ENABLED(CONFIG_QUOTA) || !IS_ENABLED(CONFIG_QFMT_V2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) 	if (!readonly && (ext4_has_feature_quota(sb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) 			  ext4_has_feature_project(sb))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) 			 "The kernel was not built with CONFIG_QUOTA and CONFIG_QFMT_V2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) #endif  /* CONFIG_QUOTA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386)  * This function is called once a day if we have errors logged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387)  * on the file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) static void print_daily_error_info(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) 	struct ext4_sb_info *sbi = from_timer(sbi, t, s_err_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) 	struct super_block *sb = sbi->s_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) 	struct ext4_super_block *es = sbi->s_es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) 	if (es->s_error_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) 		/* fsck newer than v1.41.13 is needed to clean this condition. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) 		ext4_msg(sb, KERN_NOTICE, "error count since last fsck: %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) 			 le32_to_cpu(es->s_error_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) 	if (es->s_first_error_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) 		printk(KERN_NOTICE "EXT4-fs (%s): initial error at time %llu: %.*s:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) 		       sb->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) 		       ext4_get_tstamp(es, s_first_error_time),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) 		       (int) sizeof(es->s_first_error_func),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) 		       es->s_first_error_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) 		       le32_to_cpu(es->s_first_error_line));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) 		if (es->s_first_error_ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) 			printk(KERN_CONT ": inode %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) 			       le32_to_cpu(es->s_first_error_ino));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) 		if (es->s_first_error_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) 			printk(KERN_CONT ": block %llu", (unsigned long long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) 			       le64_to_cpu(es->s_first_error_block));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) 		printk(KERN_CONT "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) 	if (es->s_last_error_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) 		printk(KERN_NOTICE "EXT4-fs (%s): last error at time %llu: %.*s:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) 		       sb->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) 		       ext4_get_tstamp(es, s_last_error_time),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) 		       (int) sizeof(es->s_last_error_func),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) 		       es->s_last_error_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) 		       le32_to_cpu(es->s_last_error_line));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) 		if (es->s_last_error_ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) 			printk(KERN_CONT ": inode %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) 			       le32_to_cpu(es->s_last_error_ino));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) 		if (es->s_last_error_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) 			printk(KERN_CONT ": block %llu", (unsigned long long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) 			       le64_to_cpu(es->s_last_error_block));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) 		printk(KERN_CONT "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) 	mod_timer(&sbi->s_err_report, jiffies + 24*60*60*HZ);  /* Once a day */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) /* Find next suitable group and run ext4_init_inode_table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) static int ext4_run_li_request(struct ext4_li_request *elr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) 	struct ext4_group_desc *gdp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) 	struct super_block *sb = elr->lr_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) 	ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) 	ext4_group_t group = elr->lr_next_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) 	unsigned int prefetch_ios = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) 	u64 start_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) 	if (elr->lr_mode == EXT4_LI_MODE_PREFETCH_BBITMAP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) 		elr->lr_next_group = ext4_mb_prefetch(sb, group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) 				EXT4_SB(sb)->s_mb_prefetch, &prefetch_ios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) 		if (prefetch_ios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) 			ext4_mb_prefetch_fini(sb, elr->lr_next_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) 					      prefetch_ios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) 		trace_ext4_prefetch_bitmaps(sb, group, elr->lr_next_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) 					    prefetch_ios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) 		if (group >= elr->lr_next_group) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) 			ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) 			if (elr->lr_first_not_zeroed != ngroups &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) 			    !sb_rdonly(sb) && test_opt(sb, INIT_INODE_TABLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) 				elr->lr_next_group = elr->lr_first_not_zeroed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) 				elr->lr_mode = EXT4_LI_MODE_ITABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) 				ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) 	for (; group < ngroups; group++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) 		gdp = ext4_get_group_desc(sb, group, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) 		if (!gdp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) 			ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) 		if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) 	if (group >= ngroups)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) 		ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) 	if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) 		start_time = ktime_get_real_ns();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) 		ret = ext4_init_inode_table(sb, group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) 					    elr->lr_timeout ? 0 : 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) 		trace_ext4_lazy_itable_init(sb, group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) 		if (elr->lr_timeout == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) 			elr->lr_timeout = nsecs_to_jiffies((ktime_get_real_ns() - start_time) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) 				EXT4_SB(elr->lr_super)->s_li_wait_mult);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) 		elr->lr_next_sched = jiffies + elr->lr_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) 		elr->lr_next_group = group + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493)  * Remove lr_request from the list_request and free the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494)  * request structure. Should be called with li_list_mtx held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) static void ext4_remove_li_request(struct ext4_li_request *elr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) 	if (!elr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) 	list_del(&elr->lr_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) 	EXT4_SB(elr->lr_super)->s_li_request = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) 	kfree(elr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) static void ext4_unregister_li_request(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) 	mutex_lock(&ext4_li_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) 	if (!ext4_li_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) 		mutex_unlock(&ext4_li_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) 	mutex_lock(&ext4_li_info->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) 	ext4_remove_li_request(EXT4_SB(sb)->s_li_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) 	mutex_unlock(&ext4_li_info->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) 	mutex_unlock(&ext4_li_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) static struct task_struct *ext4_lazyinit_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523)  * This is the function where ext4lazyinit thread lives. It walks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524)  * through the request list searching for next scheduled filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525)  * When such a fs is found, run the lazy initialization request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526)  * (ext4_rn_li_request) and keep track of the time spend in this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527)  * function. Based on that time we compute next schedule time of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528)  * the request. When walking through the list is complete, compute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529)  * next waking time and put itself into sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) static int ext4_lazyinit_thread(void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) 	struct ext4_lazy_init *eli = (struct ext4_lazy_init *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) 	struct list_head *pos, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) 	struct ext4_li_request *elr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) 	unsigned long next_wakeup, cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) 	BUG_ON(NULL == eli);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) cont_thread:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) 	while (true) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) 		next_wakeup = MAX_JIFFY_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) 		mutex_lock(&eli->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) 		if (list_empty(&eli->li_request_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) 			mutex_unlock(&eli->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) 			goto exit_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) 		list_for_each_safe(pos, n, &eli->li_request_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) 			int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) 			int progress = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) 			elr = list_entry(pos, struct ext4_li_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) 					 lr_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) 			if (time_before(jiffies, elr->lr_next_sched)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) 				if (time_before(elr->lr_next_sched, next_wakeup))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) 					next_wakeup = elr->lr_next_sched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) 			if (down_read_trylock(&elr->lr_super->s_umount)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) 				if (sb_start_write_trylock(elr->lr_super)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) 					progress = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) 					/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) 					 * We hold sb->s_umount, sb can not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) 					 * be removed from the list, it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) 					 * now safe to drop li_list_mtx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) 					mutex_unlock(&eli->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) 					err = ext4_run_li_request(elr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) 					sb_end_write(elr->lr_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) 					mutex_lock(&eli->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) 					n = pos->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) 				up_read((&elr->lr_super->s_umount));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) 			/* error, remove the lazy_init job */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) 			if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) 				ext4_remove_li_request(elr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) 			if (!progress) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) 				elr->lr_next_sched = jiffies +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) 					(prandom_u32()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) 					 % (EXT4_DEF_LI_MAX_START_DELAY * HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) 			if (time_before(elr->lr_next_sched, next_wakeup))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) 				next_wakeup = elr->lr_next_sched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) 		mutex_unlock(&eli->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) 		try_to_freeze();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) 		cur = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) 		if ((time_after_eq(cur, next_wakeup)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) 		    (MAX_JIFFY_OFFSET == next_wakeup)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) 			cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) 		schedule_timeout_interruptible(next_wakeup - cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) 		if (kthread_should_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) 			ext4_clear_request_list();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) 			goto exit_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) exit_thread:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) 	 * It looks like the request list is empty, but we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) 	 * to check it under the li_list_mtx lock, to prevent any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) 	 * additions into it, and of course we should lock ext4_li_mtx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) 	 * to atomically free the list and ext4_li_info, because at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) 	 * this point another ext4 filesystem could be registering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) 	 * new one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) 	mutex_lock(&ext4_li_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) 	mutex_lock(&eli->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) 	if (!list_empty(&eli->li_request_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) 		mutex_unlock(&eli->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) 		mutex_unlock(&ext4_li_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 		goto cont_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) 	mutex_unlock(&eli->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) 	kfree(ext4_li_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) 	ext4_li_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) 	mutex_unlock(&ext4_li_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) static void ext4_clear_request_list(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) 	struct list_head *pos, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) 	struct ext4_li_request *elr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 	mutex_lock(&ext4_li_info->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) 	list_for_each_safe(pos, n, &ext4_li_info->li_request_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) 		elr = list_entry(pos, struct ext4_li_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) 				 lr_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) 		ext4_remove_li_request(elr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) 	mutex_unlock(&ext4_li_info->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) static int ext4_run_lazyinit_thread(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) 	ext4_lazyinit_task = kthread_run(ext4_lazyinit_thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) 					 ext4_li_info, "ext4lazyinit");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) 	if (IS_ERR(ext4_lazyinit_task)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) 		int err = PTR_ERR(ext4_lazyinit_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) 		ext4_clear_request_list();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) 		kfree(ext4_li_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) 		ext4_li_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) 		printk(KERN_CRIT "EXT4-fs: error %d creating inode table "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) 				 "initialization thread\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) 				 err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) 	ext4_li_info->li_state |= EXT4_LAZYINIT_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665)  * Check whether it make sense to run itable init. thread or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666)  * If there is at least one uninitialized inode table, return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667)  * corresponding group number, else the loop goes through all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668)  * groups and return total number of groups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) static ext4_group_t ext4_has_uninit_itable(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) 	ext4_group_t group, ngroups = EXT4_SB(sb)->s_groups_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) 	struct ext4_group_desc *gdp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) 	if (!ext4_has_group_desc_csum(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) 		return ngroups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) 	for (group = 0; group < ngroups; group++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) 		gdp = ext4_get_group_desc(sb, group, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) 		if (!gdp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) 		if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) 	return group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) static int ext4_li_info_new(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) 	struct ext4_lazy_init *eli = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) 	eli = kzalloc(sizeof(*eli), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) 	if (!eli)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) 	INIT_LIST_HEAD(&eli->li_request_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) 	mutex_init(&eli->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) 	eli->li_state |= EXT4_LAZYINIT_QUIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) 	ext4_li_info = eli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) static struct ext4_li_request *ext4_li_request_new(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) 					    ext4_group_t start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) 	struct ext4_li_request *elr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) 	elr = kzalloc(sizeof(*elr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) 	if (!elr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) 	elr->lr_super = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) 	elr->lr_first_not_zeroed = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) 	if (test_opt(sb, PREFETCH_BLOCK_BITMAPS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) 		elr->lr_mode = EXT4_LI_MODE_PREFETCH_BBITMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) 		elr->lr_mode = EXT4_LI_MODE_ITABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) 		elr->lr_next_group = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) 	 * Randomize first schedule time of the request to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) 	 * spread the inode table initialization requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) 	 * better.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) 	elr->lr_next_sched = jiffies + (prandom_u32() %
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) 				(EXT4_DEF_LI_MAX_START_DELAY * HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 	return elr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) int ext4_register_li_request(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) 			     ext4_group_t first_not_zeroed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) 	struct ext4_li_request *elr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) 	ext4_group_t ngroups = sbi->s_groups_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) 	mutex_lock(&ext4_li_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) 	if (sbi->s_li_request != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) 		 * Reset timeout so it can be computed again, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) 		 * s_li_wait_mult might have changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) 		sbi->s_li_request->lr_timeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) 	if (!test_opt(sb, PREFETCH_BLOCK_BITMAPS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) 	    (first_not_zeroed == ngroups || sb_rdonly(sb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) 	     !test_opt(sb, INIT_INODE_TABLE)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) 	elr = ext4_li_request_new(sb, first_not_zeroed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) 	if (!elr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) 	if (NULL == ext4_li_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) 		ret = ext4_li_info_new();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) 	mutex_lock(&ext4_li_info->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) 	list_add(&elr->lr_request, &ext4_li_info->li_request_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) 	mutex_unlock(&ext4_li_info->li_list_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) 	sbi->s_li_request = elr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) 	 * set elr to NULL here since it has been inserted to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) 	 * the request_list and the removal and free of it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) 	 * handled by ext4_clear_request_list from now on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) 	elr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) 	if (!(ext4_li_info->li_state & EXT4_LAZYINIT_RUNNING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) 		ret = ext4_run_lazyinit_thread();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) 	mutex_unlock(&ext4_li_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) 		kfree(elr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796)  * We do not need to lock anything since this is called on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797)  * module unload.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) static void ext4_destroy_lazyinit_thread(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) 	 * If thread exited earlier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) 	 * there's nothing to be done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) 	if (!ext4_li_info || !ext4_lazyinit_task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) 	kthread_stop(ext4_lazyinit_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) static int set_journal_csum_feature_set(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) 	int ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) 	int compat, incompat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) 	if (ext4_has_metadata_csum(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) 		/* journal checksum v3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) 		compat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) 		incompat = JBD2_FEATURE_INCOMPAT_CSUM_V3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) 		/* journal checksum v1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) 		compat = JBD2_FEATURE_COMPAT_CHECKSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) 		incompat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) 	jbd2_journal_clear_features(sbi->s_journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) 			JBD2_FEATURE_COMPAT_CHECKSUM, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) 			JBD2_FEATURE_INCOMPAT_CSUM_V3 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) 			JBD2_FEATURE_INCOMPAT_CSUM_V2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) 	if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) 		ret = jbd2_journal_set_features(sbi->s_journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) 				compat, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) 				JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) 				incompat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) 	} else if (test_opt(sb, JOURNAL_CHECKSUM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) 		ret = jbd2_journal_set_features(sbi->s_journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) 				compat, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) 				incompat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) 		jbd2_journal_clear_features(sbi->s_journal, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) 				JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) 		jbd2_journal_clear_features(sbi->s_journal, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) 				JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851)  * Note: calculating the overhead so we can be compatible with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852)  * historical BSD practice is quite difficult in the face of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853)  * clusters/bigalloc.  This is because multiple metadata blocks from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854)  * different block group can end up in the same allocation cluster.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855)  * Calculating the exact overhead in the face of clustered allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856)  * requires either O(all block bitmaps) in memory or O(number of block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857)  * groups**2) in time.  We will still calculate the superblock for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858)  * older file systems --- and if we come across with a bigalloc file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859)  * system with zero in s_overhead_clusters the estimate will be close to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860)  * correct especially for very large cluster sizes --- but for newer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861)  * file systems, it's better to calculate this figure once at mkfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862)  * time, and store it in the superblock.  If the superblock value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863)  * present (even for non-bigalloc file systems), we will use it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) static int count_overhead(struct super_block *sb, ext4_group_t grp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) 			  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) 	struct ext4_sb_info	*sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) 	struct ext4_group_desc	*gdp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) 	ext4_fsblk_t		first_block, last_block, b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) 	ext4_group_t		i, ngroups = ext4_get_groups_count(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) 	int			s, j, count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) 	if (!ext4_has_feature_bigalloc(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) 		return (ext4_bg_has_super(sb, grp) + ext4_bg_num_gdb(sb, grp) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) 			sbi->s_itb_per_group + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) 	first_block = le32_to_cpu(sbi->s_es->s_first_data_block) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) 		(grp * EXT4_BLOCKS_PER_GROUP(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) 	last_block = first_block + EXT4_BLOCKS_PER_GROUP(sb) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) 	for (i = 0; i < ngroups; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) 		gdp = ext4_get_group_desc(sb, i, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) 		b = ext4_block_bitmap(sb, gdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) 		if (b >= first_block && b <= last_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) 			ext4_set_bit(EXT4_B2C(sbi, b - first_block), buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) 			count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) 		b = ext4_inode_bitmap(sb, gdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) 		if (b >= first_block && b <= last_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) 			ext4_set_bit(EXT4_B2C(sbi, b - first_block), buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) 			count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) 		b = ext4_inode_table(sb, gdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) 		if (b >= first_block && b + sbi->s_itb_per_group <= last_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) 			for (j = 0; j < sbi->s_itb_per_group; j++, b++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) 				int c = EXT4_B2C(sbi, b - first_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) 				ext4_set_bit(c, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) 				count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) 		if (i != grp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) 		s = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) 		if (ext4_bg_has_super(sb, grp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) 			ext4_set_bit(s++, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) 			count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) 		j = ext4_bg_num_gdb(sb, grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) 		if (s + j > EXT4_BLOCKS_PER_GROUP(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) 			ext4_error(sb, "Invalid number of block group "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) 				   "descriptor blocks: %d", j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) 			j = EXT4_BLOCKS_PER_GROUP(sb) - s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) 		count += j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) 		for (; j > 0; j--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) 			ext4_set_bit(EXT4_B2C(sbi, s++), buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) 	if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) 	return EXT4_CLUSTERS_PER_GROUP(sb) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) 		ext4_count_free(buf, EXT4_CLUSTERS_PER_GROUP(sb) / 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924)  * Compute the overhead and stash it in sbi->s_overhead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) int ext4_calculate_overhead(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) 	struct ext4_super_block *es = sbi->s_es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) 	struct inode *j_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) 	unsigned int j_blocks, j_inum = le32_to_cpu(es->s_journal_inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) 	ext4_group_t i, ngroups = ext4_get_groups_count(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) 	ext4_fsblk_t overhead = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) 	char *buf = (char *) get_zeroed_page(GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) 	 * Compute the overhead (FS structures).  This is constant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) 	 * for a given filesystem unless the number of block groups
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) 	 * changes so we cache the previous value until it does.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) 	 * All of the blocks before first_data_block are overhead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) 	overhead = EXT4_B2C(sbi, le32_to_cpu(es->s_first_data_block));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) 	 * Add the overhead found in each block group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) 	for (i = 0; i < ngroups; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) 		int blks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) 		blks = count_overhead(sb, i, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) 		overhead += blks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) 		if (blks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) 			memset(buf, 0, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) 	 * Add the internal journal blocks whether the journal has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) 	 * loaded or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) 	if (sbi->s_journal && !sbi->s_journal_bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) 		overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) 	else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) 		/* j_inum for internal journal is non-zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) 		j_inode = ext4_get_journal_inode(sb, j_inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) 		if (j_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) 			j_blocks = j_inode->i_size >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) 			overhead += EXT4_NUM_B2C(sbi, j_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) 			iput(j_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) 			ext4_msg(sb, KERN_ERR, "can't get journal size");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) 	sbi->s_overhead = overhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) 	smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) 	free_page((unsigned long) buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) static void ext4_set_resv_clusters(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) 	ext4_fsblk_t resv_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) 	 * There's no need to reserve anything when we aren't using extents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) 	 * The space estimates are exact, there are no unwritten extents,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) 	 * hole punching doesn't need new metadata... This is needed especially
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) 	 * to keep ext2/3 backward compatibility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) 	if (!ext4_has_feature_extents(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) 	 * By default we reserve 2% or 4096 clusters, whichever is smaller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) 	 * This should cover the situations where we can not afford to run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) 	 * out of space like for example punch hole, or converting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) 	 * unwritten extents in delalloc path. In most cases such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) 	 * allocation would require 1, or 2 blocks, higher numbers are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) 	 * very rare.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) 	resv_clusters = (ext4_blocks_count(sbi->s_es) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) 			 sbi->s_cluster_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) 	do_div(resv_clusters, 50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) 	resv_clusters = min_t(ext4_fsblk_t, resv_clusters, 4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) 	atomic64_set(&sbi->s_resv_clusters, resv_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) static int ext4_fill_super(struct super_block *sb, void *data, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) 	struct dax_device *dax_dev = fs_dax_get_by_bdev(sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) 	char *orig_data = kstrdup(data, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) 	struct buffer_head *bh, **group_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) 	struct ext4_super_block *es = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) 	struct ext4_sb_info *sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) 	struct flex_groups **flex_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) 	ext4_fsblk_t block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) 	ext4_fsblk_t sb_block = get_sb_block(&data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) 	ext4_fsblk_t logical_sb_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) 	unsigned long offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) 	unsigned long journal_devnum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) 	unsigned long def_mount_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) 	struct inode *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) 	const char *descr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) 	int blocksize, clustersize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) 	unsigned int db_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) 	int needs_recovery, has_huge_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) 	__u64 blocks_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) 	unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) 	ext4_group_t first_not_zeroed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) 	if ((data && !orig_data) || !sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) 		goto out_free_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) 	sbi->s_daxdev = dax_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) 	sbi->s_blockgroup_lock =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) 		kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) 	if (!sbi->s_blockgroup_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) 		goto out_free_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) 	sb->s_fs_info = sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) 	sbi->s_sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) 	sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) 	sbi->s_sb_block = sb_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) 	if (sb->s_bdev->bd_part)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) 		sbi->s_sectors_written_start =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) 			part_stat_read(sb->s_bdev->bd_part, sectors[STAT_WRITE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) 	/* Cleanup superblock name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) 	strreplace(sb->s_id, '/', '!');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) 	/* -EINVAL is default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) 	ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) 	blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) 	if (!blocksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) 		ext4_msg(sb, KERN_ERR, "unable to set blocksize");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) 		goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) 	 * The ext4 superblock will not be buffer aligned for other than 1kB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) 	 * block sizes.  We need to calculate the offset from buffer start.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) 	if (blocksize != EXT4_MIN_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) 		logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) 		offset = do_div(logical_sb_block, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) 		logical_sb_block = sb_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) 	bh = ext4_sb_bread_unmovable(sb, logical_sb_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) 	if (IS_ERR(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) 		ext4_msg(sb, KERN_ERR, "unable to read superblock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) 		ret = PTR_ERR(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) 		bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) 		goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) 	 * Note: s_es must be initialized as soon as possible because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) 	 *       some ext4 macro-instructions depend on its value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) 	es = (struct ext4_super_block *) (bh->b_data + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) 	sbi->s_es = es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) 	sb->s_magic = le16_to_cpu(es->s_magic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) 	if (sb->s_magic != EXT4_SUPER_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) 		goto cantfind_ext4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) 	sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) 	/* Warn if metadata_csum and gdt_csum are both set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) 	if (ext4_has_feature_metadata_csum(sb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) 	    ext4_has_feature_gdt_csum(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) 		ext4_warning(sb, "metadata_csum and uninit_bg are "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) 			     "redundant flags; please run fsck.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) 	/* Check for a known checksum algorithm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) 	if (!ext4_verify_csum_type(sb, es)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) 		ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) 			 "unknown checksum algorithm.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) 		silent = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) 		goto cantfind_ext4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) 	/* Load the checksum driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) 	sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) 	if (IS_ERR(sbi->s_chksum_driver)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) 		ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) 		ret = PTR_ERR(sbi->s_chksum_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) 		sbi->s_chksum_driver = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) 	/* Check superblock checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) 	if (!ext4_superblock_csum_verify(sb, es)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) 		ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) 			 "invalid superblock checksum.  Run e2fsck?");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) 		silent = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) 		ret = -EFSBADCRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) 		goto cantfind_ext4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) 	/* Precompute checksum seed for all metadata */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) 	if (ext4_has_feature_csum_seed(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) 		sbi->s_csum_seed = le32_to_cpu(es->s_checksum_seed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) 	else if (ext4_has_metadata_csum(sb) || ext4_has_feature_ea_inode(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) 		sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) 					       sizeof(es->s_uuid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) 	/* Set defaults before we parse the mount options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) 	def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) 	set_opt(sb, INIT_INODE_TABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) 	if (def_mount_opts & EXT4_DEFM_DEBUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) 		set_opt(sb, DEBUG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) 	if (def_mount_opts & EXT4_DEFM_BSDGROUPS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) 		set_opt(sb, GRPID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) 	if (def_mount_opts & EXT4_DEFM_UID16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) 		set_opt(sb, NO_UID32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) 	/* xattr user namespace & acls are now defaulted on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) 	set_opt(sb, XATTR_USER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) #ifdef CONFIG_EXT4_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) 	set_opt(sb, POSIX_ACL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) 	if (ext4_has_feature_fast_commit(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) 		set_opt2(sb, JOURNAL_FAST_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) 	/* don't forget to enable journal_csum when metadata_csum is enabled. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) 	if (ext4_has_metadata_csum(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) 		set_opt(sb, JOURNAL_CHECKSUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) 	if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) 		set_opt(sb, JOURNAL_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) 	else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) 		set_opt(sb, ORDERED_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) 	else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) 		set_opt(sb, WRITEBACK_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) 	if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) 		set_opt(sb, ERRORS_PANIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) 	else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) 		set_opt(sb, ERRORS_CONT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) 		set_opt(sb, ERRORS_RO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) 	/* block_validity enabled by default; disable with noblock_validity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) 	set_opt(sb, BLOCK_VALIDITY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) 	if (def_mount_opts & EXT4_DEFM_DISCARD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) 		set_opt(sb, DISCARD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) 	sbi->s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) 	sbi->s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) 	sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) 	sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) 	sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) 	if ((def_mount_opts & EXT4_DEFM_NOBARRIER) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) 		set_opt(sb, BARRIER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) 	 * enable delayed allocation by default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) 	 * Use -o nodelalloc to turn it off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) 	if (!IS_EXT3_SB(sb) && !IS_EXT2_SB(sb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) 	    ((def_mount_opts & EXT4_DEFM_NODELALLOC) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) 		set_opt(sb, DELALLOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) 	 * set default s_li_wait_mult for lazyinit, for the case there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) 	 * no mount option specified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) 	sbi->s_li_wait_mult = EXT4_DEF_LI_WAIT_MULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) 	if (le32_to_cpu(es->s_log_block_size) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) 	    (EXT4_MAX_BLOCK_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) 			 "Invalid log block size: %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) 			 le32_to_cpu(es->s_log_block_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) 	if (le32_to_cpu(es->s_log_cluster_size) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) 	    (EXT4_MAX_CLUSTER_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) 			 "Invalid log cluster size: %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) 			 le32_to_cpu(es->s_log_cluster_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) 	blocksize = EXT4_MIN_BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) 	if (blocksize == PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) 		set_opt(sb, DIOREAD_NOLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) 	if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) 		sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) 		sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) 		sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) 		sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225) 		if (sbi->s_first_ino < EXT4_GOOD_OLD_FIRST_INO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) 			ext4_msg(sb, KERN_ERR, "invalid first ino: %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) 				 sbi->s_first_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) 		if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) 		    (!is_power_of_2(sbi->s_inode_size)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) 		    (sbi->s_inode_size > blocksize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) 			       "unsupported inode size: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) 			       sbi->s_inode_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) 			ext4_msg(sb, KERN_ERR, "blocksize: %d", blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) 		 * i_atime_extra is the last extra field available for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) 		 * [acm]times in struct ext4_inode. Checking for that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) 		 * field should suffice to ensure we have extra space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) 		 * for all three.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) 		if (sbi->s_inode_size >= offsetof(struct ext4_inode, i_atime_extra) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) 			sizeof(((struct ext4_inode *)0)->i_atime_extra)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) 			sb->s_time_gran = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) 			sb->s_time_max = EXT4_EXTRA_TIMESTAMP_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) 			sb->s_time_gran = NSEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) 			sb->s_time_max = EXT4_NON_EXTRA_TIMESTAMP_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) 		sb->s_time_min = EXT4_TIMESTAMP_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) 	if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) 		sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) 			EXT4_GOOD_OLD_INODE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) 		if (ext4_has_feature_extra_isize(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) 			unsigned v, max = (sbi->s_inode_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) 					   EXT4_GOOD_OLD_INODE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) 			v = le16_to_cpu(es->s_want_extra_isize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) 			if (v > max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) 				ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) 					 "bad s_want_extra_isize: %d", v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) 				goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) 			if (sbi->s_want_extra_isize < v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) 				sbi->s_want_extra_isize = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) 			v = le16_to_cpu(es->s_min_extra_isize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) 			if (v > max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) 				ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) 					 "bad s_min_extra_isize: %d", v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) 				goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) 			if (sbi->s_want_extra_isize < v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) 				sbi->s_want_extra_isize = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) 	if (sbi->s_es->s_mount_opts[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) 		char *s_mount_opts = kstrndup(sbi->s_es->s_mount_opts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) 					      sizeof(sbi->s_es->s_mount_opts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) 					      GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) 		if (!s_mount_opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) 		if (!parse_options(s_mount_opts, sb, &journal_devnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) 				   &journal_ioprio, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) 			ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) 				 "failed to parse options in superblock: %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) 				 s_mount_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) 		kfree(s_mount_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) 	sbi->s_def_mount_opt = sbi->s_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) 	if (!parse_options((char *) data, sb, &journal_devnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) 			   &journal_ioprio, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) #ifdef CONFIG_UNICODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) 	if (ext4_has_feature_casefold(sb) && !sb->s_encoding) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) 		const struct ext4_sb_encodings *encoding_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) 		struct unicode_map *encoding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) 		__u16 encoding_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) 		if (ext4_sb_read_encoding(es, &encoding_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) 					  &encoding_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) 				 "Encoding requested by superblock is unknown");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) 		encoding = utf8_load(encoding_info->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) 		if (IS_ERR(encoding)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) 				 "can't mount with superblock charset: %s-%s "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) 				 "not supported by the kernel. flags: 0x%x.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) 				 encoding_info->name, encoding_info->version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) 				 encoding_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) 		ext4_msg(sb, KERN_INFO,"Using encoding defined by superblock: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) 			 "%s-%s with flags 0x%hx", encoding_info->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) 			 encoding_info->version?:"\b", encoding_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) 		sb->s_encoding = encoding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) 		sb->s_encoding_flags = encoding_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) 	if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) 		printk_once(KERN_WARNING "EXT4-fs: Warning: mounting with data=journal disables delayed allocation, dioread_nolock, O_DIRECT and fast_commit support!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) 		/* can't mount with both data=journal and dioread_nolock. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) 		clear_opt(sb, DIOREAD_NOLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) 		clear_opt2(sb, JOURNAL_FAST_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) 		if (test_opt2(sb, EXPLICIT_DELALLOC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) 			ext4_msg(sb, KERN_ERR, "can't mount with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) 				 "both data=journal and delalloc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) 		if (test_opt(sb, DAX_ALWAYS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) 			ext4_msg(sb, KERN_ERR, "can't mount with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) 				 "both data=journal and dax");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) 		if (ext4_has_feature_encrypt(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) 			ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) 				 "encrypted files will use data=ordered "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) 				 "instead of data journaling mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) 		if (test_opt(sb, DELALLOC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) 			clear_opt(sb, DELALLOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) 		sb->s_iflags |= SB_I_CGROUPWB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) 	sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) 		(test_opt(sb, POSIX_ACL) ? SB_POSIXACL : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) 	if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) 	    (ext4_has_compat_features(sb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) 	     ext4_has_ro_compat_features(sb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) 	     ext4_has_incompat_features(sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) 		ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) 		       "feature flags set on rev 0 fs, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) 		       "running e2fsck is recommended");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) 	if (es->s_creator_os == cpu_to_le32(EXT4_OS_HURD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) 		set_opt2(sb, HURD_COMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) 		if (ext4_has_feature_64bit(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) 				 "The Hurd can't support 64-bit file systems");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) 		 * ea_inode feature uses l_i_version field which is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) 		 * available in HURD_COMPAT mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) 		if (ext4_has_feature_ea_inode(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) 				 "ea_inode feature is not supported for Hurd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) 	if (IS_EXT2_SB(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) 		if (ext2_feature_set_ok(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) 			ext4_msg(sb, KERN_INFO, "mounting ext2 file system "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) 				 "using the ext4 subsystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) 			 * If we're probing be silent, if this looks like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) 			 * it's actually an ext[34] filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) 			if (silent && ext4_feature_set_ok(sb, sb_rdonly(sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) 				goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) 			ext4_msg(sb, KERN_ERR, "couldn't mount as ext2 due "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) 				 "to feature incompatibilities");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) 	if (IS_EXT3_SB(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) 		if (ext3_feature_set_ok(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) 			ext4_msg(sb, KERN_INFO, "mounting ext3 file system "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) 				 "using the ext4 subsystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) 			 * If we're probing be silent, if this looks like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) 			 * it's actually an ext4 filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) 			if (silent && ext4_feature_set_ok(sb, sb_rdonly(sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) 				goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) 			ext4_msg(sb, KERN_ERR, "couldn't mount as ext3 due "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) 				 "to feature incompatibilities");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) 	 * Check feature flags regardless of the revision level, since we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) 	 * previously didn't change the revision level when setting the flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) 	 * so there is a chance incompat flags are set on a rev 0 filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) 	if (!ext4_feature_set_ok(sb, (sb_rdonly(sb))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) 	if (le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) > (blocksize / 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) 			 "Number of reserved GDT blocks insanely large: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) 			 le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) 	if (bdev_dax_supported(sb->s_bdev, blocksize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) 		set_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) 	if (sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) 		if (ext4_has_feature_inline_data(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) 			ext4_msg(sb, KERN_ERR, "Cannot use DAX on a filesystem"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) 					" that may contain inline data");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) 		if (!test_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) 				"DAX unsupported by block device.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) 	if (ext4_has_feature_encrypt(sb) && es->s_encryption_level) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) 		ext4_msg(sb, KERN_ERR, "Unsupported encryption level %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) 			 es->s_encryption_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) 	if (sb->s_blocksize != blocksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) 		 * bh must be released before kill_bdev(), otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) 		 * it won't be freed and its page also. kill_bdev()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) 		 * is called by sb_set_blocksize().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) 		/* Validate the filesystem blocksize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) 		if (!sb_set_blocksize(sb, blocksize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) 			ext4_msg(sb, KERN_ERR, "bad block size %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) 					blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) 			bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474) 		logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) 		offset = do_div(logical_sb_block, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) 		bh = ext4_sb_bread_unmovable(sb, logical_sb_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) 		if (IS_ERR(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479) 			       "Can't read superblock on 2nd try");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) 			ret = PTR_ERR(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) 			bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) 		es = (struct ext4_super_block *)(bh->b_data + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) 		sbi->s_es = es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) 		if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) 			       "Magic mismatch, very weird!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) 	has_huge_files = ext4_has_feature_huge_file(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) 	sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) 						      has_huge_files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) 	sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) 	sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) 	if (ext4_has_feature_64bit(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) 		if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) 		    sbi->s_desc_size > EXT4_MAX_DESC_SIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) 		    !is_power_of_2(sbi->s_desc_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) 			       "unsupported descriptor size %lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) 			       sbi->s_desc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) 		sbi->s_desc_size = EXT4_MIN_DESC_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) 	sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) 	sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) 	sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) 	if (sbi->s_inodes_per_block == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) 		goto cantfind_ext4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) 	if (sbi->s_inodes_per_group < sbi->s_inodes_per_block ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) 	    sbi->s_inodes_per_group > blocksize * 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) 		ext4_msg(sb, KERN_ERR, "invalid inodes per group: %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520) 			 sbi->s_inodes_per_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) 	sbi->s_itb_per_group = sbi->s_inodes_per_group /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) 					sbi->s_inodes_per_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) 	sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) 	sbi->s_sbh = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) 	sbi->s_mount_state = le16_to_cpu(es->s_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528) 	sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) 	sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) 	for (i = 0; i < 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) 		sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) 	sbi->s_def_hash_version = es->s_def_hash_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) 	if (ext4_has_feature_dir_index(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535) 		i = le32_to_cpu(es->s_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) 		if (i & EXT2_FLAGS_UNSIGNED_HASH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) 			sbi->s_hash_unsigned = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) 		else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) #ifdef __CHAR_UNSIGNED__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) 			if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) 				es->s_flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) 					cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) 			sbi->s_hash_unsigned = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) 			if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) 				es->s_flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) 					cpu_to_le32(EXT2_FLAGS_SIGNED_HASH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) 	/* Handle clustersize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) 	clustersize = BLOCK_SIZE << le32_to_cpu(es->s_log_cluster_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) 	if (ext4_has_feature_bigalloc(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) 		if (clustersize < blocksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) 				 "cluster size (%d) smaller than "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) 				 "block size (%d)", clustersize, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) 		sbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) 			le32_to_cpu(es->s_log_block_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) 		sbi->s_clusters_per_group =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) 			le32_to_cpu(es->s_clusters_per_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) 		if (sbi->s_clusters_per_group > blocksize * 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) 				 "#clusters per group too big: %lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) 				 sbi->s_clusters_per_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) 		if (sbi->s_blocks_per_group !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572) 		    (sbi->s_clusters_per_group * (clustersize / blocksize))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) 			ext4_msg(sb, KERN_ERR, "blocks per group (%lu) and "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) 				 "clusters per group (%lu) inconsistent",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) 				 sbi->s_blocks_per_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) 				 sbi->s_clusters_per_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) 		if (clustersize != blocksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) 				 "fragment/cluster size (%d) != "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) 				 "block size (%d)", clustersize, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) 		if (sbi->s_blocks_per_group > blocksize * 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) 				 "#blocks per group too big: %lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) 				 sbi->s_blocks_per_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) 		sbi->s_clusters_per_group = sbi->s_blocks_per_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) 		sbi->s_cluster_bits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) 	sbi->s_cluster_ratio = clustersize / blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) 	/* Do we have standard group size of clustersize * 8 blocks ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) 	if (sbi->s_blocks_per_group == clustersize << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) 		set_opt2(sb, STD_GROUP_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) 	 * Test whether we have more sectors than will fit in sector_t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) 	 * and whether the max offset is addressable by the page cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) 	err = generic_check_addressable(sb->s_blocksize_bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) 					ext4_blocks_count(es));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) 		ext4_msg(sb, KERN_ERR, "filesystem"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) 			 " too large to mount safely on this system");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) 	if (EXT4_BLOCKS_PER_GROUP(sb) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) 		goto cantfind_ext4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) 	/* check blocks count against device size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) 	blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) 	if (blocks_count && ext4_blocks_count(es) > blocks_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) 		ext4_msg(sb, KERN_WARNING, "bad geometry: block count %llu "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) 		       "exceeds size of device (%llu blocks)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) 		       ext4_blocks_count(es), blocks_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) 	 * It makes no sense for the first data block to be beyond the end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) 	 * of the filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) 	if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) 		ext4_msg(sb, KERN_WARNING, "bad geometry: first data "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) 			 "block %u is beyond end of filesystem (%llu)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) 			 le32_to_cpu(es->s_first_data_block),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) 			 ext4_blocks_count(es));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) 	if ((es->s_first_data_block == 0) && (es->s_log_block_size == 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) 	    (sbi->s_cluster_ratio == 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) 		ext4_msg(sb, KERN_WARNING, "bad geometry: first data "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) 			 "block is 0 with a 1k block and cluster size");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) 	blocks_count = (ext4_blocks_count(es) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) 			le32_to_cpu(es->s_first_data_block) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) 			EXT4_BLOCKS_PER_GROUP(sb) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) 	do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) 	if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648) 		ext4_msg(sb, KERN_WARNING, "groups count too large: %llu "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) 		       "(block count %llu, first data block %u, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) 		       "blocks per group %lu)", blocks_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) 		       ext4_blocks_count(es),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) 		       le32_to_cpu(es->s_first_data_block),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) 		       EXT4_BLOCKS_PER_GROUP(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) 	sbi->s_groups_count = blocks_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) 	sbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) 			(EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) 	if (((u64)sbi->s_groups_count * sbi->s_inodes_per_group) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) 	    le32_to_cpu(es->s_inodes_count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) 		ext4_msg(sb, KERN_ERR, "inodes count not valid: %u vs %llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) 			 le32_to_cpu(es->s_inodes_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) 			 ((u64)sbi->s_groups_count * sbi->s_inodes_per_group));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) 	db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) 		   EXT4_DESC_PER_BLOCK(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) 	if (ext4_has_feature_meta_bg(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) 		if (le32_to_cpu(es->s_first_meta_bg) > db_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) 			ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) 				 "first meta block group too large: %u "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) 				 "(group descriptor block count %u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) 				 le32_to_cpu(es->s_first_meta_bg), db_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) 			goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) 	rcu_assign_pointer(sbi->s_group_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) 			   kvmalloc_array(db_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) 					  sizeof(struct buffer_head *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) 					  GFP_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) 	if (sbi->s_group_desc == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) 		ext4_msg(sb, KERN_ERR, "not enough memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) 		goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) 	bgl_lock_init(sbi->s_blockgroup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690) 	/* Pre-read the descriptors into the buffer cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691) 	for (i = 0; i < db_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) 		block = descriptor_loc(sb, logical_sb_block, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693) 		ext4_sb_breadahead_unmovable(sb, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696) 	for (i = 0; i < db_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697) 		struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) 		block = descriptor_loc(sb, logical_sb_block, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) 		bh = ext4_sb_bread_unmovable(sb, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701) 		if (IS_ERR(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) 			       "can't read group descriptor %d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) 			db_count = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) 			ret = PTR_ERR(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706) 			bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) 			goto failed_mount2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) 		rcu_dereference(sbi->s_group_desc)[i] = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) 	sbi->s_gdb_count = db_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) 	if (!ext4_check_descriptors(sb, logical_sb_block, &first_not_zeroed)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715) 		ext4_msg(sb, KERN_ERR, "group descriptors corrupted!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) 		ret = -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) 		goto failed_mount2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720) 	timer_setup(&sbi->s_err_report, print_daily_error_info, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722) 	/* Register extent status tree shrinker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) 	if (ext4_es_register_shrinker(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) 		goto failed_mount3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) 	sbi->s_stripe = ext4_get_stripe_size(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) 	sbi->s_extent_max_zeroout_kb = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) 	 * set up enough so that it can read an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) 	sb->s_op = &ext4_sops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) 	sb->s_export_op = &ext4_export_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) 	sb->s_xattr = ext4_xattr_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) #ifdef CONFIG_FS_ENCRYPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) 	sb->s_cop = &ext4_cryptops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) #ifdef CONFIG_FS_VERITY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) 	sb->s_vop = &ext4_verityops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) 	sb->dq_op = &ext4_quota_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) 	if (ext4_has_feature_quota(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) 		sb->s_qcop = &dquot_quotactl_sysfile_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) 		sb->s_qcop = &ext4_qctl_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) 	sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) 	memcpy(&sb->s_uuid, es->s_uuid, sizeof(es->s_uuid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) 	INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752) 	mutex_init(&sbi->s_orphan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) 	/* Initialize fast commit stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) 	atomic_set(&sbi->s_fc_subtid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) 	atomic_set(&sbi->s_fc_ineligible_updates, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757) 	INIT_LIST_HEAD(&sbi->s_fc_q[FC_Q_MAIN]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) 	INIT_LIST_HEAD(&sbi->s_fc_q[FC_Q_STAGING]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) 	INIT_LIST_HEAD(&sbi->s_fc_dentry_q[FC_Q_MAIN]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) 	INIT_LIST_HEAD(&sbi->s_fc_dentry_q[FC_Q_STAGING]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761) 	sbi->s_fc_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762) 	ext4_clear_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) 	ext4_clear_mount_flag(sb, EXT4_MF_FC_COMMITTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) 	spin_lock_init(&sbi->s_fc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765) 	memset(&sbi->s_fc_stats, 0, sizeof(sbi->s_fc_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766) 	sbi->s_fc_replay_state.fc_regions = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) 	sbi->s_fc_replay_state.fc_regions_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) 	sbi->s_fc_replay_state.fc_regions_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) 	sbi->s_fc_replay_state.fc_regions_valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) 	sbi->s_fc_replay_state.fc_modified_inodes = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771) 	sbi->s_fc_replay_state.fc_modified_inodes_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772) 	sbi->s_fc_replay_state.fc_modified_inodes_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) 	sb->s_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) 	needs_recovery = (es->s_last_orphan != 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) 			  ext4_has_feature_journal_needs_recovery(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) 	if (ext4_has_feature_mmp(sb) && !sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) 		if (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) 			goto failed_mount3a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) 	 * The first inode we look at is the journal inode.  Don't try
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) 	 * root first: it may be modified in the journal!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) 	if (!test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) 		err = ext4_load_journal(sb, es, journal_devnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) 			goto failed_mount3a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) 	} else if (test_opt(sb, NOLOAD) && !sb_rdonly(sb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792) 		   ext4_has_feature_journal_needs_recovery(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) 		ext4_msg(sb, KERN_ERR, "required journal recovery "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794) 		       "suppressed and not mounted read-only");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795) 		goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) 		/* Nojournal mode, all journal mount options are illegal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) 		if (test_opt2(sb, EXPLICIT_JOURNAL_CHECKSUM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) 			ext4_msg(sb, KERN_ERR, "can't mount with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800) 				 "journal_checksum, fs mounted w/o journal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) 			goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) 		if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804) 			ext4_msg(sb, KERN_ERR, "can't mount with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) 				 "journal_async_commit, fs mounted w/o journal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) 			goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) 		if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) 			ext4_msg(sb, KERN_ERR, "can't mount with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810) 				 "commit=%lu, fs mounted w/o journal",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811) 				 sbi->s_commit_interval / HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812) 			goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) 		if (EXT4_MOUNT_DATA_FLAGS &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) 		    (sbi->s_mount_opt ^ sbi->s_def_mount_opt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816) 			ext4_msg(sb, KERN_ERR, "can't mount with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) 				 "data=, fs mounted w/o journal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) 			goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) 		sbi->s_def_mount_opt &= ~EXT4_MOUNT_JOURNAL_CHECKSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821) 		clear_opt(sb, JOURNAL_CHECKSUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822) 		clear_opt(sb, DATA_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) 		clear_opt2(sb, JOURNAL_FAST_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824) 		sbi->s_journal = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825) 		needs_recovery = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826) 		goto no_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) 	if (ext4_has_feature_64bit(sb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830) 	    !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) 				       JBD2_FEATURE_INCOMPAT_64BIT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832) 		ext4_msg(sb, KERN_ERR, "Failed to set 64-bit journal feature");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) 		goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836) 	if (!set_journal_csum_feature_set(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837) 		ext4_msg(sb, KERN_ERR, "Failed to set journal checksum "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) 			 "feature set");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839) 		goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842) 	if (test_opt2(sb, JOURNAL_FAST_COMMIT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843) 		!jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844) 					  JBD2_FEATURE_INCOMPAT_FAST_COMMIT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846) 			"Failed to set fast commit journal feature");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847) 		goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) 	/* We have now updated the journal if required, so we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851) 	 * validate the data journaling mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852) 	switch (test_opt(sb, DATA_FLAGS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) 		/* No mode set, assume a default based on the journal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855) 		 * capabilities: ORDERED_DATA if the journal can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856) 		 * cope, else JOURNAL_DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858) 		if (jbd2_journal_check_available_features
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859) 		    (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860) 			set_opt(sb, ORDERED_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) 			sbi->s_def_mount_opt |= EXT4_MOUNT_ORDERED_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) 			set_opt(sb, JOURNAL_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) 			sbi->s_def_mount_opt |= EXT4_MOUNT_JOURNAL_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) 	case EXT4_MOUNT_ORDERED_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) 	case EXT4_MOUNT_WRITEBACK_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) 		if (!jbd2_journal_check_available_features
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) 		    (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872) 			ext4_msg(sb, KERN_ERR, "Journal does not support "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) 			       "requested data journaling mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) 			goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) 	if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) 	    test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) 		ext4_msg(sb, KERN_ERR, "can't mount with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) 			"journal_async_commit in data=ordered mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) 		goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) 	set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889) 	sbi->s_journal->j_submit_inode_data_buffers =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) 		ext4_journal_submit_inode_data_buffers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) 	sbi->s_journal->j_finish_inode_data_buffers =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) 		ext4_journal_finish_inode_data_buffers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) no_journal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) 	if (!test_opt(sb, NO_MBCACHE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) 		sbi->s_ea_block_cache = ext4_xattr_create_cache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897) 		if (!sbi->s_ea_block_cache) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) 				 "Failed to create ea_block_cache");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) 			goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) 		if (ext4_has_feature_ea_inode(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) 			sbi->s_ea_inode_cache = ext4_xattr_create_cache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) 			if (!sbi->s_ea_inode_cache) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) 				ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) 					 "Failed to create ea_inode_cache");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) 				goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913) 	if (ext4_has_feature_verity(sb) && blocksize != PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) 		ext4_msg(sb, KERN_ERR, "Unsupported blocksize for fs-verity");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) 		goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918) 	if (DUMMY_ENCRYPTION_ENABLED(sbi) && !sb_rdonly(sb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919) 	    !ext4_has_feature_encrypt(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) 		ext4_set_feature_encrypt(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921) 		ext4_commit_super(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925) 	 * Get the # of file system overhead blocks from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926) 	 * superblock if present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928) 	if (es->s_overhead_clusters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929) 		sbi->s_overhead = le32_to_cpu(es->s_overhead_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931) 		err = ext4_calculate_overhead(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933) 			goto failed_mount_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937) 	 * The maximum number of concurrent works can be high and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938) 	 * concurrency isn't really necessary.  Limit it to 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940) 	EXT4_SB(sb)->rsv_conversion_wq =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941) 		alloc_workqueue("ext4-rsv-conversion", WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942) 	if (!EXT4_SB(sb)->rsv_conversion_wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943) 		printk(KERN_ERR "EXT4-fs: failed to create workqueue\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945) 		goto failed_mount4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949) 	 * The jbd2_journal_load will have done any necessary log recovery,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950) 	 * so we can safely mount the rest of the filesystem now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953) 	root = ext4_iget(sb, EXT4_ROOT_INO, EXT4_IGET_SPECIAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954) 	if (IS_ERR(root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955) 		ext4_msg(sb, KERN_ERR, "get root inode failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956) 		ret = PTR_ERR(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957) 		root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958) 		goto failed_mount4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960) 	if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961) 		ext4_msg(sb, KERN_ERR, "corrupt root inode, run e2fsck");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962) 		iput(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963) 		goto failed_mount4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966) 	sb->s_root = d_make_root(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967) 	if (!sb->s_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968) 		ext4_msg(sb, KERN_ERR, "get root dentry failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970) 		goto failed_mount4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973) 	ret = ext4_setup_super(sb, es, sb_rdonly(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974) 	if (ret == -EROFS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) 		sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) 	} else if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978) 		goto failed_mount4a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) 	ext4_set_resv_clusters(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) 	if (test_opt(sb, BLOCK_VALIDITY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983) 		err = ext4_setup_system_zone(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985) 			ext4_msg(sb, KERN_ERR, "failed to initialize system "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986) 				 "zone (%d)", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987) 			goto failed_mount4a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990) 	ext4_fc_replay_cleanup(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992) 	ext4_ext_init(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993) 	err = ext4_mb_init(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995) 		ext4_msg(sb, KERN_ERR, "failed to initialize mballoc (%d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996) 			 err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997) 		goto failed_mount5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001) 	 * We can only set up the journal commit callback once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002) 	 * mballoc is initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004) 	if (sbi->s_journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005) 		sbi->s_journal->j_commit_callback =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006) 			ext4_journal_commit_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008) 	block = ext4_count_free_clusters(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009) 	ext4_free_blocks_count_set(sbi->s_es, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010) 				   EXT4_C2B(sbi, block));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011) 	ext4_superblock_csum_set(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012) 	err = percpu_counter_init(&sbi->s_freeclusters_counter, block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013) 				  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015) 		unsigned long freei = ext4_count_free_inodes(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016) 		sbi->s_es->s_free_inodes_count = cpu_to_le32(freei);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) 		ext4_superblock_csum_set(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018) 		err = percpu_counter_init(&sbi->s_freeinodes_counter, freei,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) 					  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022) 		err = percpu_counter_init(&sbi->s_dirs_counter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) 					  ext4_count_dirs(sb), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) 		err = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) 					  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028) 		err = percpu_counter_init(&sbi->s_sra_exceeded_retry_limit, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029) 					  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) 		err = percpu_init_rwsem(&sbi->s_writepages_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034) 		ext4_msg(sb, KERN_ERR, "insufficient memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) 		goto failed_mount6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) 	if (ext4_has_feature_flex_bg(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039) 		if (!ext4_fill_flex_info(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) 			ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041) 			       "unable to initialize "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042) 			       "flex_bg meta info!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043) 			ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) 			goto failed_mount6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047) 	err = ext4_register_li_request(sb, first_not_zeroed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049) 		goto failed_mount6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051) 	err = ext4_register_sysfs(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053) 		goto failed_mount7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056) 	/* Enable quota usage during mount. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057) 	if (ext4_has_feature_quota(sb) && !sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058) 		err = ext4_enable_quotas(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060) 			goto failed_mount8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062) #endif  /* CONFIG_QUOTA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065) 	 * Save the original bdev mapping's wb_err value which could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066) 	 * used to detect the metadata async write error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068) 	spin_lock_init(&sbi->s_bdev_wb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069) 	errseq_check_and_advance(&sb->s_bdev->bd_inode->i_mapping->wb_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070) 				 &sbi->s_bdev_wb_err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) 	sb->s_bdev->bd_super = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072) 	EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) 	ext4_orphan_cleanup(sb, es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5074) 	EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5075) 	if (needs_recovery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5076) 		ext4_msg(sb, KERN_INFO, "recovery complete");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5077) 		err = ext4_mark_recovery_complete(sb, es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5078) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5079) 			goto failed_mount8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5080) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5081) 	if (EXT4_SB(sb)->s_journal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5082) 		if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5083) 			descr = " journalled data mode";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5084) 		else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5085) 			descr = " ordered data mode";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5086) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5087) 			descr = " writeback data mode";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5088) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5089) 		descr = "out journal";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5091) 	if (test_opt(sb, DISCARD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5092) 		struct request_queue *q = bdev_get_queue(sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5093) 		if (!blk_queue_discard(q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5094) 			ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5095) 				 "mounting with \"discard\" option, but "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5096) 				 "the device does not support discard");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5097) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5099) 	if (___ratelimit(&ext4_mount_msg_ratelimit, "EXT4-fs mount"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5100) 		ext4_msg(sb, KERN_INFO, "mounted filesystem with%s. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5101) 			 "Opts: %.*s%s%s", descr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5102) 			 (int) sizeof(sbi->s_es->s_mount_opts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5103) 			 sbi->s_es->s_mount_opts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5104) 			 *sbi->s_es->s_mount_opts ? "; " : "", orig_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5106) 	if (es->s_error_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5107) 		mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5109) 	/* Enable message ratelimiting. Default is 10 messages per 5 secs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5110) 	ratelimit_state_init(&sbi->s_err_ratelimit_state, 5 * HZ, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5111) 	ratelimit_state_init(&sbi->s_warning_ratelimit_state, 5 * HZ, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5112) 	ratelimit_state_init(&sbi->s_msg_ratelimit_state, 5 * HZ, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5113) 	atomic_set(&sbi->s_warning_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5114) 	atomic_set(&sbi->s_msg_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5116) 	kfree(orig_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5117) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5119) cantfind_ext4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5120) 	if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5121) 		ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5122) 	goto failed_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5124) failed_mount8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5125) 	ext4_unregister_sysfs(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5126) 	kobject_put(&sbi->s_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5127) failed_mount7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5128) 	ext4_unregister_li_request(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5129) failed_mount6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5130) 	ext4_mb_release(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5131) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5132) 	flex_groups = rcu_dereference(sbi->s_flex_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5133) 	if (flex_groups) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5134) 		for (i = 0; i < sbi->s_flex_groups_allocated; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5135) 			kvfree(flex_groups[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5136) 		kvfree(flex_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5138) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5139) 	percpu_counter_destroy(&sbi->s_freeclusters_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5140) 	percpu_counter_destroy(&sbi->s_freeinodes_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5141) 	percpu_counter_destroy(&sbi->s_dirs_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5142) 	percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5143) 	percpu_counter_destroy(&sbi->s_sra_exceeded_retry_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5144) 	percpu_free_rwsem(&sbi->s_writepages_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5145) failed_mount5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5146) 	ext4_ext_release(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5147) 	ext4_release_system_zone(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5148) failed_mount4a:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5149) 	dput(sb->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5150) 	sb->s_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5151) failed_mount4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5152) 	ext4_msg(sb, KERN_ERR, "mount failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5153) 	if (EXT4_SB(sb)->rsv_conversion_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5154) 		destroy_workqueue(EXT4_SB(sb)->rsv_conversion_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5155) failed_mount_wq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5156) 	ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5157) 	sbi->s_ea_inode_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5159) 	ext4_xattr_destroy_cache(sbi->s_ea_block_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5160) 	sbi->s_ea_block_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5162) 	if (sbi->s_journal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5163) 		jbd2_journal_destroy(sbi->s_journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5164) 		sbi->s_journal = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5166) failed_mount3a:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5167) 	ext4_es_unregister_shrinker(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5168) failed_mount3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5169) 	del_timer_sync(&sbi->s_err_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5170) 	ext4_stop_mmpd(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5171) failed_mount2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5172) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5173) 	group_desc = rcu_dereference(sbi->s_group_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5174) 	for (i = 0; i < db_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5175) 		brelse(group_desc[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5176) 	kvfree(group_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5177) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5178) failed_mount:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5179) 	if (sbi->s_chksum_driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5180) 		crypto_free_shash(sbi->s_chksum_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5182) #ifdef CONFIG_UNICODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5183) 	utf8_unload(sb->s_encoding);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5184) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5186) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5187) 	for (i = 0; i < EXT4_MAXQUOTAS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5188) 		kfree(get_qf_name(sb, sbi, i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5189) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5190) 	fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5191) 	/* ext4_blkdev_remove() calls kill_bdev(), release bh before it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5192) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5193) 	ext4_blkdev_remove(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5194) out_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5195) 	sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5196) 	kfree(sbi->s_blockgroup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5197) out_free_base:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5198) 	kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5199) 	kfree(orig_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5200) 	fs_put_dax(dax_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5201) 	return err ? err : ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5204) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5205)  * Setup any per-fs journal parameters now.  We'll do this both on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5206)  * initial mount, once the journal has been initialised but before we've
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5207)  * done any recovery; and again on any subsequent remount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5208)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5209) static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5211) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5213) 	journal->j_commit_interval = sbi->s_commit_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5214) 	journal->j_min_batch_time = sbi->s_min_batch_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5215) 	journal->j_max_batch_time = sbi->s_max_batch_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5216) 	ext4_fc_init(sb, journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5218) 	write_lock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5219) 	if (test_opt(sb, BARRIER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5220) 		journal->j_flags |= JBD2_BARRIER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5221) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5222) 		journal->j_flags &= ~JBD2_BARRIER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5223) 	if (test_opt(sb, DATA_ERR_ABORT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5224) 		journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5225) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5226) 		journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5227) 	write_unlock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5230) static struct inode *ext4_get_journal_inode(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5231) 					     unsigned int journal_inum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5233) 	struct inode *journal_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5235) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5236) 	 * Test for the existence of a valid inode on disk.  Bad things
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5237) 	 * happen if we iget() an unused inode, as the subsequent iput()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5238) 	 * will try to delete it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5239) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5240) 	journal_inode = ext4_iget(sb, journal_inum, EXT4_IGET_SPECIAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5241) 	if (IS_ERR(journal_inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5242) 		ext4_msg(sb, KERN_ERR, "no journal found");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5243) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5245) 	if (!journal_inode->i_nlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5246) 		make_bad_inode(journal_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5247) 		iput(journal_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5248) 		ext4_msg(sb, KERN_ERR, "journal inode is deleted");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5249) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5250) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5252) 	jbd_debug(2, "Journal inode found at %p: %lld bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5253) 		  journal_inode, journal_inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5254) 	if (!S_ISREG(journal_inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5255) 		ext4_msg(sb, KERN_ERR, "invalid journal inode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5256) 		iput(journal_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5257) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5259) 	return journal_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5262) static journal_t *ext4_get_journal(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5263) 				   unsigned int journal_inum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5265) 	struct inode *journal_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5266) 	journal_t *journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5268) 	if (WARN_ON_ONCE(!ext4_has_feature_journal(sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5269) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5271) 	journal_inode = ext4_get_journal_inode(sb, journal_inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5272) 	if (!journal_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5273) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5275) 	journal = jbd2_journal_init_inode(journal_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5276) 	if (!journal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5277) 		ext4_msg(sb, KERN_ERR, "Could not load journal inode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5278) 		iput(journal_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5279) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5281) 	journal->j_private = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5282) 	ext4_init_journal_params(sb, journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5283) 	return journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5286) static journal_t *ext4_get_dev_journal(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5287) 				       dev_t j_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5289) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5290) 	journal_t *journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5291) 	ext4_fsblk_t start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5292) 	ext4_fsblk_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5293) 	int hblock, blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5294) 	ext4_fsblk_t sb_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5295) 	unsigned long offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5296) 	struct ext4_super_block *es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5297) 	struct block_device *bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5299) 	if (WARN_ON_ONCE(!ext4_has_feature_journal(sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5300) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5302) 	bdev = ext4_blkdev_get(j_dev, sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5303) 	if (bdev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5304) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5306) 	blocksize = sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5307) 	hblock = bdev_logical_block_size(bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5308) 	if (blocksize < hblock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5309) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5310) 			"blocksize too small for journal device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5311) 		goto out_bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5314) 	sb_block = EXT4_MIN_BLOCK_SIZE / blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5315) 	offset = EXT4_MIN_BLOCK_SIZE % blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5316) 	set_blocksize(bdev, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5317) 	if (!(bh = __bread(bdev, sb_block, blocksize))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5318) 		ext4_msg(sb, KERN_ERR, "couldn't read superblock of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5319) 		       "external journal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5320) 		goto out_bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5323) 	es = (struct ext4_super_block *) (bh->b_data + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5324) 	if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5325) 	    !(le32_to_cpu(es->s_feature_incompat) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5326) 	      EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5327) 		ext4_msg(sb, KERN_ERR, "external journal has "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5328) 					"bad superblock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5329) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5330) 		goto out_bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5333) 	if ((le32_to_cpu(es->s_feature_ro_compat) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5334) 	     EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5335) 	    es->s_checksum != ext4_superblock_csum(sb, es)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5336) 		ext4_msg(sb, KERN_ERR, "external journal has "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5337) 				       "corrupt superblock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5338) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5339) 		goto out_bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5342) 	if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5343) 		ext4_msg(sb, KERN_ERR, "journal UUID does not match");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5344) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5345) 		goto out_bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5348) 	len = ext4_blocks_count(es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5349) 	start = sb_block + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5350) 	brelse(bh);	/* we're done with the superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5352) 	journal = jbd2_journal_init_dev(bdev, sb->s_bdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5353) 					start, len, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5354) 	if (!journal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5355) 		ext4_msg(sb, KERN_ERR, "failed to create device journal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5356) 		goto out_bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5358) 	journal->j_private = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5359) 	if (ext4_read_bh_lock(journal->j_sb_buffer, REQ_META | REQ_PRIO, true)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5360) 		ext4_msg(sb, KERN_ERR, "I/O error on journal device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5361) 		goto out_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5363) 	if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5364) 		ext4_msg(sb, KERN_ERR, "External journal has more than one "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5365) 					"user (unsupported) - %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5366) 			be32_to_cpu(journal->j_superblock->s_nr_users));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5367) 		goto out_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5368) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5369) 	EXT4_SB(sb)->s_journal_bdev = bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5370) 	ext4_init_journal_params(sb, journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5371) 	return journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5373) out_journal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5374) 	jbd2_journal_destroy(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5375) out_bdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5376) 	ext4_blkdev_put(bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5377) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5380) static int ext4_load_journal(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5381) 			     struct ext4_super_block *es,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5382) 			     unsigned long journal_devnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5384) 	journal_t *journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5385) 	unsigned int journal_inum = le32_to_cpu(es->s_journal_inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5386) 	dev_t journal_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5387) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5388) 	int really_read_only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5389) 	int journal_dev_ro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5391) 	if (WARN_ON_ONCE(!ext4_has_feature_journal(sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5392) 		return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5394) 	if (journal_devnum &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5395) 	    journal_devnum != le32_to_cpu(es->s_journal_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5396) 		ext4_msg(sb, KERN_INFO, "external journal device major/minor "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5397) 			"numbers have changed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5398) 		journal_dev = new_decode_dev(journal_devnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5399) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5400) 		journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5402) 	if (journal_inum && journal_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5403) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5404) 			 "filesystem has both journal inode and journal device!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5405) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5408) 	if (journal_inum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5409) 		journal = ext4_get_journal(sb, journal_inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5410) 		if (!journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5411) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5412) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5413) 		journal = ext4_get_dev_journal(sb, journal_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5414) 		if (!journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5415) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5418) 	journal_dev_ro = bdev_read_only(journal->j_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5419) 	really_read_only = bdev_read_only(sb->s_bdev) | journal_dev_ro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5421) 	if (journal_dev_ro && !sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5422) 		ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5423) 			 "journal device read-only, try mounting with '-o ro'");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5424) 		err = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5425) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5428) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5429) 	 * Are we loading a blank journal or performing recovery after a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5430) 	 * crash?  For recovery, we need to check in advance whether we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5431) 	 * can get read-write access to the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5432) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5433) 	if (ext4_has_feature_journal_needs_recovery(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5434) 		if (sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5435) 			ext4_msg(sb, KERN_INFO, "INFO: recovery "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5436) 					"required on readonly filesystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5437) 			if (really_read_only) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5438) 				ext4_msg(sb, KERN_ERR, "write access "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5439) 					"unavailable, cannot proceed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5440) 					"(try mounting with noload)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5441) 				err = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5442) 				goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5443) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5444) 			ext4_msg(sb, KERN_INFO, "write access will "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5445) 			       "be enabled during recovery");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5446) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5449) 	if (!(journal->j_flags & JBD2_BARRIER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5450) 		ext4_msg(sb, KERN_INFO, "barriers disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5452) 	if (!ext4_has_feature_journal_needs_recovery(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5453) 		err = jbd2_journal_wipe(journal, !really_read_only);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5454) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5455) 		char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5456) 		if (save)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5457) 			memcpy(save, ((char *) es) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5458) 			       EXT4_S_ERR_START, EXT4_S_ERR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5459) 		err = jbd2_journal_load(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5460) 		if (save)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5461) 			memcpy(((char *) es) + EXT4_S_ERR_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5462) 			       save, EXT4_S_ERR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5463) 		kfree(save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5464) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5466) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5467) 		ext4_msg(sb, KERN_ERR, "error loading journal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5468) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5469) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5471) 	EXT4_SB(sb)->s_journal = journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5472) 	err = ext4_clear_journal_err(sb, es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5473) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5474) 		EXT4_SB(sb)->s_journal = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5475) 		jbd2_journal_destroy(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5476) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5477) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5479) 	if (!really_read_only && journal_devnum &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5480) 	    journal_devnum != le32_to_cpu(es->s_journal_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5481) 		es->s_journal_dev = cpu_to_le32(journal_devnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5483) 		/* Make sure we flush the recovery flag to disk. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5484) 		ext4_commit_super(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5485) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5487) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5489) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5490) 	jbd2_journal_destroy(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5491) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5494) static int ext4_commit_super(struct super_block *sb, int sync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5496) 	struct ext4_super_block *es = EXT4_SB(sb)->s_es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5497) 	struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5498) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5500) 	if (!sbh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5501) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5502) 	if (block_device_ejected(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5503) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5505) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5506) 	 * If the file system is mounted read-only, don't update the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5507) 	 * superblock write time.  This avoids updating the superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5508) 	 * write time when we are mounting the root file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5509) 	 * read/only but we need to replay the journal; at that point,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5510) 	 * for people who are east of GMT and who make their clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5511) 	 * tick in localtime for Windows bug-for-bug compatibility,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5512) 	 * the clock is set in the future, and this will cause e2fsck
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5513) 	 * to complain and force a full file system check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5514) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5515) 	if (!(sb->s_flags & SB_RDONLY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5516) 		ext4_update_tstamp(es, s_wtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5517) 	if (sb->s_bdev->bd_part)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5518) 		es->s_kbytes_written =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5519) 			cpu_to_le64(EXT4_SB(sb)->s_kbytes_written +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5520) 			    ((part_stat_read(sb->s_bdev->bd_part,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5521) 					     sectors[STAT_WRITE]) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5522) 			      EXT4_SB(sb)->s_sectors_written_start) >> 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5523) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5524) 		es->s_kbytes_written =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5525) 			cpu_to_le64(EXT4_SB(sb)->s_kbytes_written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5526) 	if (percpu_counter_initialized(&EXT4_SB(sb)->s_freeclusters_counter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5527) 		ext4_free_blocks_count_set(es,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5528) 			EXT4_C2B(EXT4_SB(sb), percpu_counter_sum_positive(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5529) 				&EXT4_SB(sb)->s_freeclusters_counter)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5530) 	if (percpu_counter_initialized(&EXT4_SB(sb)->s_freeinodes_counter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5531) 		es->s_free_inodes_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5532) 			cpu_to_le32(percpu_counter_sum_positive(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5533) 				&EXT4_SB(sb)->s_freeinodes_counter));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5534) 	BUFFER_TRACE(sbh, "marking dirty");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5535) 	ext4_superblock_csum_set(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5536) 	if (sync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5537) 		lock_buffer(sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5538) 	if (buffer_write_io_error(sbh) || !buffer_uptodate(sbh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5539) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5540) 		 * Oh, dear.  A previous attempt to write the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5541) 		 * superblock failed.  This could happen because the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5542) 		 * USB device was yanked out.  Or it could happen to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5543) 		 * be a transient write error and maybe the block will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5544) 		 * be remapped.  Nothing we can do but to retry the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5545) 		 * write and hope for the best.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5546) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5547) 		ext4_msg(sb, KERN_ERR, "previous I/O error to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5548) 		       "superblock detected");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5549) 		clear_buffer_write_io_error(sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5550) 		set_buffer_uptodate(sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5551) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5552) 	mark_buffer_dirty(sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5553) 	if (sync) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5554) 		unlock_buffer(sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5555) 		error = __sync_dirty_buffer(sbh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5556) 			REQ_SYNC | (test_opt(sb, BARRIER) ? REQ_FUA : 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5557) 		if (buffer_write_io_error(sbh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5558) 			ext4_msg(sb, KERN_ERR, "I/O error while writing "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5559) 			       "superblock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5560) 			clear_buffer_write_io_error(sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5561) 			set_buffer_uptodate(sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5562) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5563) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5564) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5567) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5568)  * Have we just finished recovery?  If so, and if we are mounting (or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5569)  * remounting) the filesystem readonly, then we will end up with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5570)  * consistent fs on disk.  Record that fact.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5571)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5572) static int ext4_mark_recovery_complete(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5573) 				       struct ext4_super_block *es)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5575) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5576) 	journal_t *journal = EXT4_SB(sb)->s_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5578) 	if (!ext4_has_feature_journal(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5579) 		if (journal != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5580) 			ext4_error(sb, "Journal got removed while the fs was "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5581) 				   "mounted!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5582) 			return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5583) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5584) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5585) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5586) 	jbd2_journal_lock_updates(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5587) 	err = jbd2_journal_flush(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5588) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5589) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5591) 	if (ext4_has_feature_journal_needs_recovery(sb) && sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5592) 		ext4_clear_feature_journal_needs_recovery(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5593) 		ext4_commit_super(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5594) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5595) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5596) 	jbd2_journal_unlock_updates(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5597) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5600) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5601)  * If we are mounting (or read-write remounting) a filesystem whose journal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5602)  * has recorded an error from a previous lifetime, move that error to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5603)  * main filesystem now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5604)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5605) static int ext4_clear_journal_err(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5606) 				   struct ext4_super_block *es)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5608) 	journal_t *journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5609) 	int j_errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5610) 	const char *errstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5612) 	if (!ext4_has_feature_journal(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5613) 		ext4_error(sb, "Journal got removed while the fs was mounted!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5614) 		return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5615) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5617) 	journal = EXT4_SB(sb)->s_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5619) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5620) 	 * Now check for any error status which may have been recorded in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5621) 	 * journal by a prior ext4_error() or ext4_abort()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5622) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5624) 	j_errno = jbd2_journal_errno(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5625) 	if (j_errno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5626) 		char nbuf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5628) 		errstr = ext4_decode_error(sb, j_errno, nbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5629) 		ext4_warning(sb, "Filesystem error recorded "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5630) 			     "from previous mount: %s", errstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5631) 		ext4_warning(sb, "Marking fs in need of filesystem check.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5633) 		EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5634) 		es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5635) 		ext4_commit_super(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5637) 		jbd2_journal_clear_err(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5638) 		jbd2_journal_update_sb_errno(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5639) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5640) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5643) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5644)  * Force the running and committing transactions to commit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5645)  * and wait on the commit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5646)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5647) int ext4_force_commit(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5649) 	journal_t *journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5651) 	if (sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5652) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5654) 	journal = EXT4_SB(sb)->s_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5655) 	return ext4_journal_force_commit(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5658) static int ext4_sync_fs(struct super_block *sb, int wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5660) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5661) 	tid_t target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5662) 	bool needs_barrier = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5663) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5665) 	if (unlikely(ext4_forced_shutdown(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5666) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5668) 	trace_ext4_sync_fs(sb, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5669) 	flush_workqueue(sbi->rsv_conversion_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5670) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5671) 	 * Writeback quota in non-journalled quota case - journalled quota has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5672) 	 * no dirty dquots
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5673) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5674) 	dquot_writeback_dquots(sb, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5675) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5676) 	 * Data writeback is possible w/o journal transaction, so barrier must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5677) 	 * being sent at the end of the function. But we can skip it if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5678) 	 * transaction_commit will do it for us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5679) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5680) 	if (sbi->s_journal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5681) 		target = jbd2_get_latest_transaction(sbi->s_journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5682) 		if (wait && sbi->s_journal->j_flags & JBD2_BARRIER &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5683) 		    !jbd2_trans_will_send_data_barrier(sbi->s_journal, target))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5684) 			needs_barrier = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5686) 		if (jbd2_journal_start_commit(sbi->s_journal, &target)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5687) 			if (wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5688) 				ret = jbd2_log_wait_commit(sbi->s_journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5689) 							   target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5690) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5691) 	} else if (wait && test_opt(sb, BARRIER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5692) 		needs_barrier = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5693) 	if (needs_barrier) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5694) 		int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5695) 		err = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5696) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5697) 			ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5698) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5700) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5703) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5704)  * LVM calls this function before a (read-only) snapshot is created.  This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5705)  * gives us a chance to flush the journal completely and mark the fs clean.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5706)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5707)  * Note that only this function cannot bring a filesystem to be in a clean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5708)  * state independently. It relies on upper layer to stop all data & metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5709)  * modifications.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5710)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5711) static int ext4_freeze(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5713) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5714) 	journal_t *journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5716) 	if (sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5717) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5719) 	journal = EXT4_SB(sb)->s_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5721) 	if (journal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5722) 		/* Now we set up the journal barrier. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5723) 		jbd2_journal_lock_updates(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5725) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5726) 		 * Don't clear the needs_recovery flag if we failed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5727) 		 * flush the journal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5728) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5729) 		error = jbd2_journal_flush(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5730) 		if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5731) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5733) 		/* Journal blocked and flushed, clear needs_recovery flag. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5734) 		ext4_clear_feature_journal_needs_recovery(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5735) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5737) 	error = ext4_commit_super(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5738) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5739) 	if (journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5740) 		/* we rely on upper layer to stop further updates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5741) 		jbd2_journal_unlock_updates(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5742) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5745) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5746)  * Called by LVM after the snapshot is done.  We need to reset the RECOVER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5747)  * flag here, even though the filesystem is not technically dirty yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5748)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5749) static int ext4_unfreeze(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5751) 	if (sb_rdonly(sb) || ext4_forced_shutdown(EXT4_SB(sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5752) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5754) 	if (EXT4_SB(sb)->s_journal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5755) 		/* Reset the needs_recovery flag before the fs is unlocked. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5756) 		ext4_set_feature_journal_needs_recovery(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5757) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5759) 	ext4_commit_super(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5760) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5763) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5764)  * Structure to save mount options for ext4_remount's benefit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5765)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5766) struct ext4_mount_options {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5767) 	unsigned long s_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5768) 	unsigned long s_mount_opt2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5769) 	kuid_t s_resuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5770) 	kgid_t s_resgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5771) 	unsigned long s_commit_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5772) 	u32 s_min_batch_time, s_max_batch_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5773) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5774) 	int s_jquota_fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5775) 	char *s_qf_names[EXT4_MAXQUOTAS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5776) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5777) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5779) static int ext4_remount(struct super_block *sb, int *flags, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5780) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5781) 	struct ext4_super_block *es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5782) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5783) 	unsigned long old_sb_flags, vfs_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5784) 	struct ext4_mount_options old_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5785) 	int enable_quota = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5786) 	ext4_group_t g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5787) 	unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5788) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5789) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5790) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5791) 	char *to_free[EXT4_MAXQUOTAS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5792) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5793) 	char *orig_data = kstrdup(data, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5795) 	if (data && !orig_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5796) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5798) 	/* Store the original options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5799) 	old_sb_flags = sb->s_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5800) 	old_opts.s_mount_opt = sbi->s_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5801) 	old_opts.s_mount_opt2 = sbi->s_mount_opt2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5802) 	old_opts.s_resuid = sbi->s_resuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5803) 	old_opts.s_resgid = sbi->s_resgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5804) 	old_opts.s_commit_interval = sbi->s_commit_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5805) 	old_opts.s_min_batch_time = sbi->s_min_batch_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5806) 	old_opts.s_max_batch_time = sbi->s_max_batch_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5807) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5808) 	old_opts.s_jquota_fmt = sbi->s_jquota_fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5809) 	for (i = 0; i < EXT4_MAXQUOTAS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5810) 		if (sbi->s_qf_names[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5811) 			char *qf_name = get_qf_name(sb, sbi, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5813) 			old_opts.s_qf_names[i] = kstrdup(qf_name, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5814) 			if (!old_opts.s_qf_names[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5815) 				for (j = 0; j < i; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5816) 					kfree(old_opts.s_qf_names[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5817) 				kfree(orig_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5818) 				return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5819) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5820) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5821) 			old_opts.s_qf_names[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5822) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5823) 	if (sbi->s_journal && sbi->s_journal->j_task->io_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5824) 		journal_ioprio = sbi->s_journal->j_task->io_context->ioprio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5826) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5827) 	 * Some options can be enabled by ext4 and/or by VFS mount flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5828) 	 * either way we need to make sure it matches in both *flags and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5829) 	 * s_flags. Copy those selected flags from *flags to s_flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5830) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5831) 	vfs_flags = SB_LAZYTIME | SB_I_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5832) 	sb->s_flags = (sb->s_flags & ~vfs_flags) | (*flags & vfs_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5834) 	if (!parse_options(data, sb, NULL, &journal_ioprio, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5835) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5836) 		goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5839) 	if ((old_opts.s_mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5840) 	    test_opt(sb, JOURNAL_CHECKSUM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5841) 		ext4_msg(sb, KERN_ERR, "changing journal_checksum "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5842) 			 "during remount not supported; ignoring");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5843) 		sbi->s_mount_opt ^= EXT4_MOUNT_JOURNAL_CHECKSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5844) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5846) 	if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5847) 		if (test_opt2(sb, EXPLICIT_DELALLOC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5848) 			ext4_msg(sb, KERN_ERR, "can't mount with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5849) 				 "both data=journal and delalloc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5850) 			err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5851) 			goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5852) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5853) 		if (test_opt(sb, DIOREAD_NOLOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5854) 			ext4_msg(sb, KERN_ERR, "can't mount with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5855) 				 "both data=journal and dioread_nolock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5856) 			err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5857) 			goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5858) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5859) 	} else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5860) 		if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5861) 			ext4_msg(sb, KERN_ERR, "can't mount with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5862) 				"journal_async_commit in data=ordered mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5863) 			err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5864) 			goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5865) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5866) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5868) 	if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) & EXT4_MOUNT_NO_MBCACHE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5869) 		ext4_msg(sb, KERN_ERR, "can't enable nombcache during remount");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5870) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5871) 		goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5872) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5874) 	if (ext4_test_mount_flag(sb, EXT4_MF_FS_ABORTED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5875) 		ext4_abort(sb, EXT4_ERR_ESHUTDOWN, "Abort forced by user");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5877) 	sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5878) 		(test_opt(sb, POSIX_ACL) ? SB_POSIXACL : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5880) 	es = sbi->s_es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5882) 	if (sbi->s_journal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5883) 		ext4_init_journal_params(sb, sbi->s_journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5884) 		set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5885) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5887) 	if ((bool)(*flags & SB_RDONLY) != sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5888) 		if (ext4_test_mount_flag(sb, EXT4_MF_FS_ABORTED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5889) 			err = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5890) 			goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5891) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5893) 		if (*flags & SB_RDONLY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5894) 			err = sync_filesystem(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5895) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5896) 				goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5897) 			err = dquot_suspend(sb, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5898) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5899) 				goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5901) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5902) 			 * First of all, the unconditional stuff we have to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5903) 			 * to disable replay of the journal when we next remount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5904) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5905) 			sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5907) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5908) 			 * OK, test if we are remounting a valid rw partition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5909) 			 * readonly, and if so set the rdonly flag and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5910) 			 * mark the partition as valid again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5911) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5912) 			if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5913) 			    (sbi->s_mount_state & EXT4_VALID_FS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5914) 				es->s_state = cpu_to_le16(sbi->s_mount_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5916) 			if (sbi->s_journal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5917) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5918) 				 * We let remount-ro finish even if marking fs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5919) 				 * as clean failed...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5920) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5921) 				ext4_mark_recovery_complete(sb, es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5922) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5923) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5924) 			/* Make sure we can mount this feature set readwrite */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5925) 			if (ext4_has_feature_readonly(sb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5926) 			    !ext4_feature_set_ok(sb, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5927) 				err = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5928) 				goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5929) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5930) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5931) 			 * Make sure the group descriptor checksums
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5932) 			 * are sane.  If they aren't, refuse to remount r/w.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5933) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5934) 			for (g = 0; g < sbi->s_groups_count; g++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5935) 				struct ext4_group_desc *gdp =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5936) 					ext4_get_group_desc(sb, g, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5938) 				if (!ext4_group_desc_csum_verify(sb, g, gdp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5939) 					ext4_msg(sb, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5940) 	       "ext4_remount: Checksum for group %u failed (%u!=%u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5941) 		g, le16_to_cpu(ext4_group_desc_csum(sb, g, gdp)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5942) 					       le16_to_cpu(gdp->bg_checksum));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5943) 					err = -EFSBADCRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5944) 					goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5945) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5946) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5948) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5949) 			 * If we have an unprocessed orphan list hanging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5950) 			 * around from a previously readonly bdev mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5951) 			 * require a full umount/remount for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5952) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5953) 			if (es->s_last_orphan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5954) 				ext4_msg(sb, KERN_WARNING, "Couldn't "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5955) 				       "remount RDWR because of unprocessed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5956) 				       "orphan inode list.  Please "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5957) 				       "umount/remount instead");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5958) 				err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5959) 				goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5960) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5962) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5963) 			 * Mounting a RDONLY partition read-write, so reread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5964) 			 * and store the current valid flag.  (It may have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5965) 			 * been changed by e2fsck since we originally mounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5966) 			 * the partition.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5967) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5968) 			if (sbi->s_journal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5969) 				err = ext4_clear_journal_err(sb, es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5970) 				if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5971) 					goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5972) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5973) 			sbi->s_mount_state = le16_to_cpu(es->s_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5975) 			err = ext4_setup_super(sb, es, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5976) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5977) 				goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5979) 			sb->s_flags &= ~SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5980) 			if (ext4_has_feature_mmp(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5981) 				if (ext4_multi_mount_protect(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5982) 						le64_to_cpu(es->s_mmp_block))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5983) 					err = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5984) 					goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5985) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5986) 			enable_quota = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5987) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5988) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5990) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5991) 	 * Reinitialize lazy itable initialization thread based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5992) 	 * current settings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5993) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5994) 	if (sb_rdonly(sb) || !test_opt(sb, INIT_INODE_TABLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5995) 		ext4_unregister_li_request(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5996) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5997) 		ext4_group_t first_not_zeroed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5998) 		first_not_zeroed = ext4_has_uninit_itable(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5999) 		ext4_register_li_request(sb, first_not_zeroed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6000) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6002) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6003) 	 * Handle creation of system zone data early because it can fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6004) 	 * Releasing of existing data is done when we are sure remount will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6005) 	 * succeed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6006) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6007) 	if (test_opt(sb, BLOCK_VALIDITY) && !sbi->s_system_blks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6008) 		err = ext4_setup_system_zone(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6009) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6010) 			goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6011) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6013) 	if (sbi->s_journal == NULL && !(old_sb_flags & SB_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6014) 		err = ext4_commit_super(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6015) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6016) 			goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6017) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6019) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6020) 	/* Release old quota file names */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6021) 	for (i = 0; i < EXT4_MAXQUOTAS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6022) 		kfree(old_opts.s_qf_names[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6023) 	if (enable_quota) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6024) 		if (sb_any_quota_suspended(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6025) 			dquot_resume(sb, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6026) 		else if (ext4_has_feature_quota(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6027) 			err = ext4_enable_quotas(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6028) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6029) 				goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6030) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6031) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6032) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6033) 	if (!test_opt(sb, BLOCK_VALIDITY) && sbi->s_system_blks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6034) 		ext4_release_system_zone(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6036) 	if (!ext4_has_feature_mmp(sb) || sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6037) 		ext4_stop_mmpd(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6039) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6040) 	 * Some options can be enabled by ext4 and/or by VFS mount flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6041) 	 * either way we need to make sure it matches in both *flags and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6042) 	 * s_flags. Copy those selected flags from s_flags to *flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6043) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6044) 	*flags = (*flags & ~vfs_flags) | (sb->s_flags & vfs_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6046) 	ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s", orig_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6047) 	kfree(orig_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6048) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6050) restore_opts:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6051) 	sb->s_flags = old_sb_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6052) 	sbi->s_mount_opt = old_opts.s_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6053) 	sbi->s_mount_opt2 = old_opts.s_mount_opt2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6054) 	sbi->s_resuid = old_opts.s_resuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6055) 	sbi->s_resgid = old_opts.s_resgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6056) 	sbi->s_commit_interval = old_opts.s_commit_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6057) 	sbi->s_min_batch_time = old_opts.s_min_batch_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6058) 	sbi->s_max_batch_time = old_opts.s_max_batch_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6059) 	if (!test_opt(sb, BLOCK_VALIDITY) && sbi->s_system_blks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6060) 		ext4_release_system_zone(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6061) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6062) 	sbi->s_jquota_fmt = old_opts.s_jquota_fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6063) 	for (i = 0; i < EXT4_MAXQUOTAS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6064) 		to_free[i] = get_qf_name(sb, sbi, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6065) 		rcu_assign_pointer(sbi->s_qf_names[i], old_opts.s_qf_names[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6066) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6067) 	synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6068) 	for (i = 0; i < EXT4_MAXQUOTAS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6069) 		kfree(to_free[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6070) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6071) 	if (!ext4_has_feature_mmp(sb) || sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6072) 		ext4_stop_mmpd(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6073) 	kfree(orig_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6074) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6077) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6078) static int ext4_statfs_project(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6079) 			       kprojid_t projid, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6080) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6081) 	struct kqid qid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6082) 	struct dquot *dquot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6083) 	u64 limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6084) 	u64 curblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6086) 	qid = make_kqid_projid(projid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6087) 	dquot = dqget(sb, qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6088) 	if (IS_ERR(dquot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6089) 		return PTR_ERR(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6090) 	spin_lock(&dquot->dq_dqb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6092) 	limit = min_not_zero(dquot->dq_dqb.dqb_bsoftlimit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6093) 			     dquot->dq_dqb.dqb_bhardlimit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6094) 	limit >>= sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6096) 	if (limit && buf->f_blocks > limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6097) 		curblock = (dquot->dq_dqb.dqb_curspace +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6098) 			    dquot->dq_dqb.dqb_rsvspace) >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6099) 		buf->f_blocks = limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6100) 		buf->f_bfree = buf->f_bavail =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6101) 			(buf->f_blocks > curblock) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6102) 			 (buf->f_blocks - curblock) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6105) 	limit = min_not_zero(dquot->dq_dqb.dqb_isoftlimit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6106) 			     dquot->dq_dqb.dqb_ihardlimit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6107) 	if (limit && buf->f_files > limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6108) 		buf->f_files = limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6109) 		buf->f_ffree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6110) 			(buf->f_files > dquot->dq_dqb.dqb_curinodes) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6111) 			 (buf->f_files - dquot->dq_dqb.dqb_curinodes) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6114) 	spin_unlock(&dquot->dq_dqb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6115) 	dqput(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6116) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6118) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6120) static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6122) 	struct super_block *sb = dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6123) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6124) 	struct ext4_super_block *es = sbi->s_es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6125) 	ext4_fsblk_t overhead = 0, resv_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6126) 	u64 fsid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6127) 	s64 bfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6128) 	resv_blocks = EXT4_C2B(sbi, atomic64_read(&sbi->s_resv_clusters));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6130) 	if (!test_opt(sb, MINIX_DF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6131) 		overhead = sbi->s_overhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6133) 	buf->f_type = EXT4_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6134) 	buf->f_bsize = sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6135) 	buf->f_blocks = ext4_blocks_count(es) - EXT4_C2B(sbi, overhead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6136) 	bfree = percpu_counter_sum_positive(&sbi->s_freeclusters_counter) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6137) 		percpu_counter_sum_positive(&sbi->s_dirtyclusters_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6138) 	/* prevent underflow in case that few free space is available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6139) 	buf->f_bfree = EXT4_C2B(sbi, max_t(s64, bfree, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6140) 	buf->f_bavail = buf->f_bfree -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6141) 			(ext4_r_blocks_count(es) + resv_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6142) 	if (buf->f_bfree < (ext4_r_blocks_count(es) + resv_blocks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6143) 		buf->f_bavail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6144) 	buf->f_files = le32_to_cpu(es->s_inodes_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6145) 	buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6146) 	buf->f_namelen = EXT4_NAME_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6147) 	fsid = le64_to_cpup((void *)es->s_uuid) ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6148) 	       le64_to_cpup((void *)es->s_uuid + sizeof(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6149) 	buf->f_fsid = u64_to_fsid(fsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6151) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6152) 	if (ext4_test_inode_flag(dentry->d_inode, EXT4_INODE_PROJINHERIT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6153) 	    sb_has_quota_limits_enabled(sb, PRJQUOTA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6154) 		ext4_statfs_project(sb, EXT4_I(dentry->d_inode)->i_projid, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6155) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6156) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6160) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6162) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6163)  * Helper functions so that transaction is started before we acquire dqio_sem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6164)  * to keep correct lock ordering of transaction > dqio_sem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6165)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6166) static inline struct inode *dquot_to_inode(struct dquot *dquot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6168) 	return sb_dqopt(dquot->dq_sb)->files[dquot->dq_id.type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6171) static int ext4_write_dquot(struct dquot *dquot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6173) 	int ret, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6174) 	handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6175) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6177) 	inode = dquot_to_inode(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6178) 	handle = ext4_journal_start(inode, EXT4_HT_QUOTA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6179) 				    EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6180) 	if (IS_ERR(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6181) 		return PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6182) 	ret = dquot_commit(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6183) 	err = ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6184) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6185) 		ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6186) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6189) static int ext4_acquire_dquot(struct dquot *dquot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6191) 	int ret, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6192) 	handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6194) 	handle = ext4_journal_start(dquot_to_inode(dquot), EXT4_HT_QUOTA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6195) 				    EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6196) 	if (IS_ERR(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6197) 		return PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6198) 	ret = dquot_acquire(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6199) 	err = ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6200) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6201) 		ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6202) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6205) static int ext4_release_dquot(struct dquot *dquot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6207) 	int ret, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6208) 	handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6210) 	handle = ext4_journal_start(dquot_to_inode(dquot), EXT4_HT_QUOTA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6211) 				    EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6212) 	if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6213) 		/* Release dquot anyway to avoid endless cycle in dqput() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6214) 		dquot_release(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6215) 		return PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6216) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6217) 	ret = dquot_release(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6218) 	err = ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6219) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6220) 		ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6221) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6224) static int ext4_mark_dquot_dirty(struct dquot *dquot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6226) 	struct super_block *sb = dquot->dq_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6227) 	struct ext4_sb_info *sbi = EXT4_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6229) 	/* Are we journaling quotas? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6230) 	if (ext4_has_feature_quota(sb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6231) 	    sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6232) 		dquot_mark_dquot_dirty(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6233) 		return ext4_write_dquot(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6234) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6235) 		return dquot_mark_dquot_dirty(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6239) static int ext4_write_info(struct super_block *sb, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6241) 	int ret, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6242) 	handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6244) 	/* Data block + inode block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6245) 	handle = ext4_journal_start(d_inode(sb->s_root), EXT4_HT_QUOTA, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6246) 	if (IS_ERR(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6247) 		return PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6248) 	ret = dquot_commit_info(sb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6249) 	err = ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6250) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6251) 		ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6252) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6255) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6256)  * Turn on quotas during mount time - we need to find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6257)  * the quota file and such...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6258)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6259) static int ext4_quota_on_mount(struct super_block *sb, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6261) 	return dquot_quota_on_mount(sb, get_qf_name(sb, EXT4_SB(sb), type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6262) 					EXT4_SB(sb)->s_jquota_fmt, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6265) static void lockdep_set_quota_inode(struct inode *inode, int subclass)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6267) 	struct ext4_inode_info *ei = EXT4_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6269) 	/* The first argument of lockdep_set_subclass has to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6270) 	 * *exactly* the same as the argument to init_rwsem() --- in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6271) 	 * this case, in init_once() --- or lockdep gets unhappy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6272) 	 * because the name of the lock is set using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6273) 	 * stringification of the argument to init_rwsem().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6274) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6275) 	(void) ei;	/* shut up clang warning if !CONFIG_LOCKDEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6276) 	lockdep_set_subclass(&ei->i_data_sem, subclass);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6279) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6280)  * Standard function to be called on quota_on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6281)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6282) static int ext4_quota_on(struct super_block *sb, int type, int format_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6283) 			 const struct path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6285) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6287) 	if (!test_opt(sb, QUOTA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6288) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6290) 	/* Quotafile not on the same filesystem? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6291) 	if (path->dentry->d_sb != sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6292) 		return -EXDEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6294) 	/* Quota already enabled for this file? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6295) 	if (IS_NOQUOTA(d_inode(path->dentry)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6296) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6298) 	/* Journaling quota? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6299) 	if (EXT4_SB(sb)->s_qf_names[type]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6300) 		/* Quotafile not in fs root? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6301) 		if (path->dentry->d_parent != sb->s_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6302) 			ext4_msg(sb, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6303) 				"Quota file not on filesystem root. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6304) 				"Journaled quota will not work");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6305) 		sb_dqopt(sb)->flags |= DQUOT_NOLIST_DIRTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6306) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6307) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6308) 		 * Clear the flag just in case mount options changed since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6309) 		 * last time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6310) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6311) 		sb_dqopt(sb)->flags &= ~DQUOT_NOLIST_DIRTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6314) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6315) 	 * When we journal data on quota file, we have to flush journal to see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6316) 	 * all updates to the file when we bypass pagecache...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6317) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6318) 	if (EXT4_SB(sb)->s_journal &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6319) 	    ext4_should_journal_data(d_inode(path->dentry))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6320) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6321) 		 * We don't need to lock updates but journal_flush() could
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6322) 		 * otherwise be livelocked...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6323) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6324) 		jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6325) 		err = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6326) 		jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6327) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6328) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6331) 	lockdep_set_quota_inode(path->dentry->d_inode, I_DATA_SEM_QUOTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6332) 	err = dquot_quota_on(sb, type, format_id, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6333) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6334) 		struct inode *inode = d_inode(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6335) 		handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6337) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6338) 		 * Set inode flags to prevent userspace from messing with quota
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6339) 		 * files. If this fails, we return success anyway since quotas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6340) 		 * are already enabled and this is not a hard failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6341) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6342) 		inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6343) 		handle = ext4_journal_start(inode, EXT4_HT_QUOTA, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6344) 		if (IS_ERR(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6345) 			goto unlock_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6346) 		EXT4_I(inode)->i_flags |= EXT4_NOATIME_FL | EXT4_IMMUTABLE_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6347) 		inode_set_flags(inode, S_NOATIME | S_IMMUTABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6348) 				S_NOATIME | S_IMMUTABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6349) 		err = ext4_mark_inode_dirty(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6350) 		ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6351) 	unlock_inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6352) 		inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6353) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6354) 			dquot_quota_off(sb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6356) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6357) 		lockdep_set_quota_inode(path->dentry->d_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6358) 					     I_DATA_SEM_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6359) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6362) static int ext4_quota_enable(struct super_block *sb, int type, int format_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6363) 			     unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6365) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6366) 	struct inode *qf_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6367) 	unsigned long qf_inums[EXT4_MAXQUOTAS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6368) 		le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6369) 		le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6370) 		le32_to_cpu(EXT4_SB(sb)->s_es->s_prj_quota_inum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6371) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6373) 	BUG_ON(!ext4_has_feature_quota(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6375) 	if (!qf_inums[type])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6376) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6378) 	qf_inode = ext4_iget(sb, qf_inums[type], EXT4_IGET_SPECIAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6379) 	if (IS_ERR(qf_inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6380) 		ext4_error(sb, "Bad quota inode # %lu", qf_inums[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6381) 		return PTR_ERR(qf_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6382) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6384) 	/* Don't account quota for quota files to avoid recursion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6385) 	qf_inode->i_flags |= S_NOQUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6386) 	lockdep_set_quota_inode(qf_inode, I_DATA_SEM_QUOTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6387) 	err = dquot_load_quota_inode(qf_inode, type, format_id, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6388) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6389) 		lockdep_set_quota_inode(qf_inode, I_DATA_SEM_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6390) 	iput(qf_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6392) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6395) /* Enable usage tracking for all quota types. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6396) static int ext4_enable_quotas(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6398) 	int type, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6399) 	unsigned long qf_inums[EXT4_MAXQUOTAS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6400) 		le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6401) 		le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6402) 		le32_to_cpu(EXT4_SB(sb)->s_es->s_prj_quota_inum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6403) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6404) 	bool quota_mopt[EXT4_MAXQUOTAS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6405) 		test_opt(sb, USRQUOTA),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6406) 		test_opt(sb, GRPQUOTA),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6407) 		test_opt(sb, PRJQUOTA),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6408) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6410) 	sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NOLIST_DIRTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6411) 	for (type = 0; type < EXT4_MAXQUOTAS; type++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6412) 		if (qf_inums[type]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6413) 			err = ext4_quota_enable(sb, type, QFMT_VFS_V1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6414) 				DQUOT_USAGE_ENABLED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6415) 				(quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6416) 			if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6417) 				ext4_warning(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6418) 					"Failed to enable quota tracking "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6419) 					"(type=%d, err=%d). Please run "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6420) 					"e2fsck to fix.", type, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6421) 				for (type--; type >= 0; type--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6422) 					struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6424) 					inode = sb_dqopt(sb)->files[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6425) 					if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6426) 						inode = igrab(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6427) 					dquot_quota_off(sb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6428) 					if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6429) 						lockdep_set_quota_inode(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6430) 							I_DATA_SEM_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6431) 						iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6432) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6433) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6435) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6436) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6437) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6439) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6442) static int ext4_quota_off(struct super_block *sb, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6444) 	struct inode *inode = sb_dqopt(sb)->files[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6445) 	handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6446) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6448) 	/* Force all delayed allocation blocks to be allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6449) 	 * Caller already holds s_umount sem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6450) 	if (test_opt(sb, DELALLOC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6451) 		sync_filesystem(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6453) 	if (!inode || !igrab(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6454) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6456) 	err = dquot_quota_off(sb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6457) 	if (err || ext4_has_feature_quota(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6458) 		goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6460) 	inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6461) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6462) 	 * Update modification times of quota files when userspace can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6463) 	 * start looking at them. If we fail, we return success anyway since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6464) 	 * this is not a hard failure and quotas are already disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6465) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6466) 	handle = ext4_journal_start(inode, EXT4_HT_QUOTA, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6467) 	if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6468) 		err = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6469) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6470) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6471) 	EXT4_I(inode)->i_flags &= ~(EXT4_NOATIME_FL | EXT4_IMMUTABLE_FL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6472) 	inode_set_flags(inode, 0, S_NOATIME | S_IMMUTABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6473) 	inode->i_mtime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6474) 	err = ext4_mark_inode_dirty(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6475) 	ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6476) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6477) 	inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6478) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6479) 	lockdep_set_quota_inode(inode, I_DATA_SEM_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6480) 	iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6481) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6482) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6483) 	return dquot_quota_off(sb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6486) /* Read data from quotafile - avoid pagecache and such because we cannot afford
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6487)  * acquiring the locks... As quota files are never truncated and quota code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6488)  * itself serializes the operations (and no one else should touch the files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6489)  * we don't have to be afraid of races */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6490) static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6491) 			       size_t len, loff_t off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6493) 	struct inode *inode = sb_dqopt(sb)->files[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6494) 	ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6495) 	int offset = off & (sb->s_blocksize - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6496) 	int tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6497) 	size_t toread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6498) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6499) 	loff_t i_size = i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6501) 	if (off > i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6502) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6503) 	if (off+len > i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6504) 		len = i_size-off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6505) 	toread = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6506) 	while (toread > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6507) 		tocopy = sb->s_blocksize - offset < toread ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6508) 				sb->s_blocksize - offset : toread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6509) 		bh = ext4_bread(NULL, inode, blk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6510) 		if (IS_ERR(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6511) 			return PTR_ERR(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6512) 		if (!bh)	/* A hole? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6513) 			memset(data, 0, tocopy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6514) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6515) 			memcpy(data, bh->b_data+offset, tocopy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6516) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6517) 		offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6518) 		toread -= tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6519) 		data += tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6520) 		blk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6521) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6522) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6525) /* Write to quotafile (we know the transaction is already started and has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6526)  * enough credits) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6527) static ssize_t ext4_quota_write(struct super_block *sb, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6528) 				const char *data, size_t len, loff_t off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6530) 	struct inode *inode = sb_dqopt(sb)->files[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6531) 	ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6532) 	int err = 0, err2 = 0, offset = off & (sb->s_blocksize - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6533) 	int retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6534) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6535) 	handle_t *handle = journal_current_handle();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6537) 	if (!handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6538) 		ext4_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6539) 			" cancelled because transaction is not started",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6540) 			(unsigned long long)off, (unsigned long long)len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6541) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6542) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6543) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6544) 	 * Since we account only one data block in transaction credits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6545) 	 * then it is impossible to cross a block boundary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6546) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6547) 	if (sb->s_blocksize - offset < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6548) 		ext4_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6549) 			" cancelled because not block aligned",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6550) 			(unsigned long long)off, (unsigned long long)len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6551) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6552) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6554) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6555) 		bh = ext4_bread(handle, inode, blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6556) 				EXT4_GET_BLOCKS_CREATE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6557) 				EXT4_GET_BLOCKS_METADATA_NOFAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6558) 	} while (PTR_ERR(bh) == -ENOSPC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6559) 		 ext4_should_retry_alloc(inode->i_sb, &retries));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6560) 	if (IS_ERR(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6561) 		return PTR_ERR(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6562) 	if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6563) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6564) 	BUFFER_TRACE(bh, "get write access");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6565) 	err = ext4_journal_get_write_access(handle, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6566) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6567) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6568) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6569) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6570) 	lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6571) 	memcpy(bh->b_data+offset, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6572) 	flush_dcache_page(bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6573) 	unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6574) 	err = ext4_handle_dirty_metadata(handle, NULL, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6575) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6576) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6577) 	if (inode->i_size < off + len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6578) 		i_size_write(inode, off + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6579) 		EXT4_I(inode)->i_disksize = inode->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6580) 		err2 = ext4_mark_inode_dirty(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6581) 		if (unlikely(err2 && !err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6582) 			err = err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6583) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6584) 	return err ? err : len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6586) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6588) static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6589) 		       const char *dev_name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6591) 	return mount_bdev(fs_type, flags, dev_name, data, ext4_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6594) #if !defined(CONFIG_EXT2_FS) && !defined(CONFIG_EXT2_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6595) static inline void register_as_ext2(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6597) 	int err = register_filesystem(&ext2_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6598) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6599) 		printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6600) 		       "EXT4-fs: Unable to register as ext2 (%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6603) static inline void unregister_as_ext2(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6605) 	unregister_filesystem(&ext2_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6608) static inline int ext2_feature_set_ok(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6610) 	if (ext4_has_unknown_ext2_incompat_features(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6611) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6612) 	if (sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6613) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6614) 	if (ext4_has_unknown_ext2_ro_compat_features(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6615) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6616) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6618) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6619) static inline void register_as_ext2(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6620) static inline void unregister_as_ext2(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6621) static inline int ext2_feature_set_ok(struct super_block *sb) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6622) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6624) static inline void register_as_ext3(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6626) 	int err = register_filesystem(&ext3_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6627) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6628) 		printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6629) 		       "EXT4-fs: Unable to register as ext3 (%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6632) static inline void unregister_as_ext3(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6634) 	unregister_filesystem(&ext3_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6637) static inline int ext3_feature_set_ok(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6639) 	if (ext4_has_unknown_ext3_incompat_features(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6640) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6641) 	if (!ext4_has_feature_journal(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6642) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6643) 	if (sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6644) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6645) 	if (ext4_has_unknown_ext3_ro_compat_features(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6646) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6647) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6650) static struct file_system_type ext4_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6651) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6652) 	.name		= "ext4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6653) 	.mount		= ext4_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6654) 	.kill_sb	= kill_block_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6655) 	.fs_flags	= FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6656) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6657) MODULE_ALIAS_FS("ext4");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6659) /* Shared across all ext4 file systems */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6660) wait_queue_head_t ext4__ioend_wq[EXT4_WQ_HASH_SZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6662) static int __init ext4_init_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6664) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6666) 	ratelimit_state_init(&ext4_mount_msg_ratelimit, 30 * HZ, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6667) 	ext4_li_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6668) 	mutex_init(&ext4_li_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6670) 	/* Build-time check for flags consistency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6671) 	ext4_check_flag_values();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6673) 	for (i = 0; i < EXT4_WQ_HASH_SZ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6674) 		init_waitqueue_head(&ext4__ioend_wq[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6676) 	err = ext4_init_es();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6677) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6678) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6680) 	err = ext4_init_pending();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6681) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6682) 		goto out7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6684) 	err = ext4_init_post_read_processing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6685) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6686) 		goto out6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6688) 	err = ext4_init_pageio();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6689) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6690) 		goto out5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6692) 	err = ext4_init_system_zone();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6693) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6694) 		goto out4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6696) 	err = ext4_init_sysfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6697) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6698) 		goto out3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6700) 	err = ext4_init_mballoc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6701) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6702) 		goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6703) 	err = init_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6704) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6705) 		goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6707) 	err = ext4_fc_init_dentry_cache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6708) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6709) 		goto out05;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6711) 	register_as_ext3();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6712) 	register_as_ext2();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6713) 	err = register_filesystem(&ext4_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6714) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6715) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6717) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6718) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6719) 	unregister_as_ext2();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6720) 	unregister_as_ext3();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6721) 	ext4_fc_destroy_dentry_cache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6722) out05:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6723) 	destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6724) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6725) 	ext4_exit_mballoc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6726) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6727) 	ext4_exit_sysfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6728) out3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6729) 	ext4_exit_system_zone();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6730) out4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6731) 	ext4_exit_pageio();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6732) out5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6733) 	ext4_exit_post_read_processing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6734) out6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6735) 	ext4_exit_pending();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6736) out7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6737) 	ext4_exit_es();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6739) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6742) static void __exit ext4_exit_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6743) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6744) 	ext4_destroy_lazyinit_thread();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6745) 	unregister_as_ext2();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6746) 	unregister_as_ext3();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6747) 	unregister_filesystem(&ext4_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6748) 	ext4_fc_destroy_dentry_cache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6749) 	destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6750) 	ext4_exit_mballoc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6751) 	ext4_exit_sysfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6752) 	ext4_exit_system_zone();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6753) 	ext4_exit_pageio();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6754) 	ext4_exit_post_read_processing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6755) 	ext4_exit_es();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6756) 	ext4_exit_pending();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6759) MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6760) MODULE_DESCRIPTION("Fourth Extended Filesystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6761) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6762) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6763) MODULE_SOFTDEP("pre: crc32c");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6764) module_init(ext4_init_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6765) module_exit(ext4_exit_fs)