Whamcloud - gitweb
libext2fs: don't needlessly byte swap the group descriptors in ext2fs_flush
authorTheodore Ts'o <tytso@mit.edu>
Fri, 17 Jan 2020 00:17:26 +0000 (19:17 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 17 Jan 2020 00:49:06 +0000 (19:49 -0500)
If the EXT2_FLAG_SUPER_ONLY is set, there's no reason to allocate the
shadow block group descriptors and byte swap the group descriptors.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/closefs.c

index 6814cdc..69cbdd8 100644 (file)
@@ -333,18 +333,22 @@ errcode_t ext2fs_flush2(ext2_filsys fs, int flags)
        retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &super_shadow);
        if (retval)
                goto errout;
-       retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize,
-                                 &group_shadow);
-       if (retval)
-               goto errout;
        memcpy(super_shadow, fs->super, sizeof(struct ext2_super_block));
-       memcpy(group_shadow, fs->group_desc, (size_t) fs->blocksize *
-              fs->desc_blocks);
-
        ext2fs_swap_super(super_shadow);
-       for (j = 0; j < fs->group_desc_count; j++) {
-               gdp = ext2fs_group_desc(fs, group_shadow, j);
-               ext2fs_swap_group_desc2(fs, gdp);
+
+       if (((fs->flags & EXT2_FLAG_SUPER_ONLY) == 0) &&
+           !ext2fs_has_feature_journal_dev(fs->super)) {
+               retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize,
+                                         &group_shadow);
+               if (retval)
+                       goto errout;
+               memcpy(group_shadow, fs->group_desc, (size_t) fs->blocksize *
+                      fs->desc_blocks);
+
+               for (j = 0; j < fs->group_desc_count; j++) {
+                       gdp = ext2fs_group_desc(fs, group_shadow, j);
+                       ext2fs_swap_group_desc2(fs, gdp);
+               }
        }
 #else
        super_shadow = fs->super;