]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ext4: update the s_overhead_clusters in the backup sb's when resizing
authorTheodore Ts'o <tytso@mit.edu>
Wed, 29 Jun 2022 04:00:26 +0000 (00:00 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 3 Aug 2022 03:52:19 +0000 (23:52 -0400)
When the EXT4_IOC_RESIZE_FS ioctl is complete, update the backup
superblocks.  We don't do this for the old-style resize ioctls since
they are quite ancient, and only used by very old versions of
resize2fs --- and we don't want to update the backup superblocks every
time EXT4_IOC_GROUP_ADD is called, since it might get called a lot.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Link: https://lore.kernel.org/r/20220629040026.112371-2-tytso@mit.edu
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/ext4.h
fs/ext4/ioctl.c
fs/ext4/resize.c
fs/ext4/super.c

index adfc30ee4b7beac49b6a5ce3fd8c4d97b8fc27aa..310e976ef1fdab0b3c211437a28423e9e7862be2 100644 (file)
@@ -3016,7 +3016,7 @@ int ext4_fileattr_set(struct user_namespace *mnt_userns,
                      struct dentry *dentry, struct fileattr *fa);
 int ext4_fileattr_get(struct dentry *dentry, struct fileattr *fa);
 extern void ext4_reset_inode_seed(struct inode *inode);
-int ext4_update_overhead(struct super_block *sb);
+int ext4_update_overhead(struct super_block *sb, bool force);
 
 /* migrate.c */
 extern int ext4_ext_migrate(struct inode *);
@@ -3800,7 +3800,7 @@ static inline void set_bitmap_uptodate(struct buffer_head *bh)
 extern wait_queue_head_t ext4__ioend_wq[EXT4_WQ_HASH_SZ];
 
 extern int ext4_resize_begin(struct super_block *sb);
-extern void ext4_resize_end(struct super_block *sb);
+extern int ext4_resize_end(struct super_block *sb, bool update_backups);
 
 static inline void ext4_set_io_unwritten_flag(struct inode *inode,
                                              struct ext4_io_end *io_end)
index cb01c1da0f9d5136da6a11281fad7587c4d340a7..1702c574407a2769c7a54ea196f4fc8233bd30a9 100644 (file)
@@ -944,7 +944,9 @@ static long ext4_ioctl_group_add(struct file *file,
            test_opt(sb, INIT_INODE_TABLE))
                err = ext4_register_li_request(sb, input->group);
 group_add_out:
-       ext4_resize_end(sb);
+       err2 = ext4_resize_end(sb, false);
+       if (err == 0)
+               err = err2;
        return err;
 }
 
@@ -1223,7 +1225,9 @@ setversion_out:
                        err = err2;
                mnt_drop_write_file(filp);
 group_extend_out:
-               ext4_resize_end(sb);
+               err2 = ext4_resize_end(sb, false);
+               if (err == 0)
+                       err = err2;
                return err;
        }
 
@@ -1371,7 +1375,9 @@ mext_out:
                        err = ext4_register_li_request(sb, o_group);
 
 resizefs_out:
-               ext4_resize_end(sb);
+               err2 = ext4_resize_end(sb, true);
+               if (err == 0)
+                       err = err2;
                return err;
        }
 
@@ -1599,13 +1605,15 @@ static void set_overhead(struct ext4_super_block *es, const void *arg)
        es->s_overhead_clusters = cpu_to_le32(*((unsigned long *) arg));
 }
 
-int ext4_update_overhead(struct super_block *sb)
+int ext4_update_overhead(struct super_block *sb, bool force)
 {
        struct ext4_sb_info *sbi = EXT4_SB(sb);
 
-       if (sb_rdonly(sb) || sbi->s_overhead == 0 ||
-           sbi->s_overhead == le32_to_cpu(sbi->s_es->s_overhead_clusters))
+       if (sb_rdonly(sb))
+               return 0;
+       if (!force &&
+           (sbi->s_overhead == 0 ||
+            sbi->s_overhead == le32_to_cpu(sbi->s_es->s_overhead_clusters)))
                return 0;
-
        return ext4_update_superblocks_fn(sb, set_overhead, &sbi->s_overhead);
 }
index e5c2713aa11ad44e1073266274fe536b99b6df42..e4e89ca82f8cc6b67c0be3ec164a6ab12a2ee048 100644 (file)
@@ -97,10 +97,13 @@ int ext4_resize_begin(struct super_block *sb)
        return ret;
 }
 
-void ext4_resize_end(struct super_block *sb)
+int ext4_resize_end(struct super_block *sb, bool update_backups)
 {
        clear_bit_unlock(EXT4_FLAGS_RESIZING, &EXT4_SB(sb)->s_ext4_flags);
        smp_mb__after_atomic();
+       if (update_backups)
+               return ext4_update_overhead(sb, true);
+       return 0;
 }
 
 static ext4_group_t ext4_meta_bg_first_group(struct super_block *sb,
index 845f2f8aee5f9bba35e2f28fb457a4e98f03fa04..6a8a752d812b25da709400d93f085982c9d9385f 100644 (file)
@@ -5523,7 +5523,7 @@ static int ext4_fill_super(struct super_block *sb, struct fs_context *fc)
                         "Quota mode: %s.", descr, ext4_quota_mode(sb));
 
        /* Update the s_overhead_clusters if necessary */
-       ext4_update_overhead(sb);
+       ext4_update_overhead(sb, false);
        return 0;
 
 free_sbi: