!230 [sync] PR-228: e2fsck: update quota accounting after directory optimization

From: @openeuler-sync-bot 
Reviewed-by: @swf504 
Signed-off-by: @swf504
This commit is contained in:
openeuler-ci-bot 2024-06-22 06:44:37 +00:00 committed by Gitee
commit a7a590f8a2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 94 additions and 1 deletions

View File

@ -0,0 +1,88 @@
From eb782652045e67a5379dd319613b0d3d924901dd Mon Sep 17 00:00:00 2001
From: "Luis Henriques (SUSE)" <luis.henriques@linux.dev>
Date: Fri, 5 Apr 2024 15:24:02 +0100
Subject: [PATCH] e2fsck: update quota accounting after directory optimization
In "Pass 3A: Optimizing directories", a directory may have it's size reduced.
If that happens and quota is enabled in the filesystem, the quota information
will be incorrect because it doesn't take the rehash into account. This issue
was detected by running fstest ext4/014.
This patch simply updates the quota data accordingly, after the directory is
written and it's size has been updated.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=218626
Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Link: https://lore.kernel.org/r/20240405142405.12312-2-luis.henriques@linux.dev
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
e2fsck/rehash.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c
index c1da7d5..04d543b 100644
--- a/e2fsck/rehash.c
+++ b/e2fsck/rehash.c
@@ -987,14 +987,18 @@ errcode_t e2fsck_rehash_dir(e2fsck_t ctx, ext2_ino_t ino,
{
ext2_filsys fs = ctx->fs;
errcode_t retval;
- struct ext2_inode inode;
+ struct ext2_inode_large inode;
char *dir_buf = 0;
struct fill_dir_struct fd = { NULL, NULL, 0, 0, 0, NULL,
0, 0, 0, 0, 0, 0 };
struct out_dir outdir = { 0, 0, 0, 0 };
- struct name_cmp_ctx name_cmp_ctx = {0, NULL};
+ struct name_cmp_ctx name_cmp_ctx = {0, NULL};
+ __u64 osize;
- e2fsck_read_inode(ctx, ino, &inode, "rehash_dir");
+ e2fsck_read_inode_full(ctx, ino, EXT2_INODE(&inode),
+ sizeof(inode), "rehash_dir");
+
+ osize = EXT2_I_SIZE(&inode);
if (ext2fs_has_feature_inline_data(fs->super) &&
(inode.i_flags & EXT4_INLINE_DATA_FL))
@@ -1013,7 +1017,7 @@ errcode_t e2fsck_rehash_dir(e2fsck_t ctx, ext2_ino_t ino,
fd.ino = ino;
fd.ctx = ctx;
fd.buf = dir_buf;
- fd.inode = &inode;
+ fd.inode = EXT2_INODE(&inode);
fd.dir = ino;
if (!ext2fs_has_feature_dir_index(fs->super) ||
(inode.i_size / fs->blocksize) < 2)
@@ -1092,14 +1096,25 @@ resort:
goto errout;
}
- retval = write_directory(ctx, fs, &outdir, ino, &inode, fd.compress);
+ retval = write_directory(ctx, fs, &outdir, ino, EXT2_INODE(&inode),
+ fd.compress);
if (retval)
goto errout;
+ if ((osize > EXT2_I_SIZE(&inode)) &&
+ (ino != quota_type2inum(PRJQUOTA, fs->super)) &&
+ (ino != fs->super->s_orphan_file_inum) &&
+ (ino == EXT2_ROOT_INO || ino >= EXT2_FIRST_INODE(ctx->fs->super)) &&
+ !(inode.i_flags & EXT4_EA_INODE_FL)) {
+ quota_data_sub(ctx->qctx, &inode,
+ ino, osize - EXT2_I_SIZE(&inode));
+ }
+
if (ctx->options & E2F_OPT_CONVERT_BMAP)
retval = e2fsck_rebuild_extents_later(ctx, ino);
else
- retval = e2fsck_check_rebuild_extents(ctx, ino, &inode, pctx);
+ retval = e2fsck_check_rebuild_extents(ctx, ino,
+ EXT2_INODE(&inode), pctx);
errout:
ext2fs_free_mem(&dir_buf);
ext2fs_free_mem(&fd.harray);
--
2.43.0

View File

@ -1,6 +1,6 @@
Name: e2fsprogs
Version: 1.47.0
Release: 4
Release: 5
Summary: Second extended file system management tools
License: GPLv2+ and LGPLv2 and MIT
URL: http://e2fsprogs.sourceforge.net/
@ -20,6 +20,7 @@ Patch10: 0010-tune2fs-fuse2fs-debugfs-save-error-information-durin.patch
Patch11: 0011-mke2fs.conf-remove-metadata_csum_seed-and-orphan_fil.patch
Patch12: 0012-debugfs-fix-infinite-loop-while-dumping-the-journal.patch
Patch13: 0013-e4crypt-fix-spurious-Success-error-message.patch
Patch14: 0014-e2fsck-update-quota-accounting-after-directory-optim.patch
BuildRequires: gcc pkgconfig texinfo
BuildRequires: fuse-devel libblkid-devel libuuid-devel
@ -160,6 +161,10 @@ exit 0
%{_mandir}/man8/*
%changelog
* Wed Jun 12 2024 liuh <liuhuan01@kylinos.cn> - 1.47.0-5
- sync patch from community
fix e2fsck: update quota accounting after directory optimization
* Wed Jun 5 2024 liuh <liuhuan01@kylinos.cn> - 1.47.0-4
- sync patch from community