linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH e2fsprogs v2 0/4] quota-related e2fsck fixes and tests
@ 2024-04-04 11:10 Luis Henriques (SUSE)
  2024-04-04 11:10 ` [PATCH v2 1/4] e2fsck: update quota accounting after directory optimization Luis Henriques (SUSE)
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Luis Henriques (SUSE) @ 2024-04-04 11:10 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger; +Cc: linux-ext4, Luis Henriques (SUSE)

Hi!

I'm (re)sending two fixes to e2fsck that are related with quota handling.
The fixes are the first two patches, the other two are test cases for these
fixes.

As I mentioned in v1, the issues were found using fstests ext4/014 and
ext4/019.  And the only thing in this series that changed from v1 was the
first test ("tests: new test to check quota after directory optimization"),
which is now using a much simplified version of the testcase.

Note that, since the first two patches didn't change, they have already a

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

which I'm not including in the patches themselves.  Should I?  Or is that
better left for the maintainer (eventually) applying them?

Cheers,
-- 
Luis

Luis Henriques (SUSE) (4):
  e2fsck: update quota accounting after directory optimization
  e2fsck: update quota when deallocating a bad inode
  tests: new test to check quota after directory optimization
  tests: new test to check quota after a bad inode deallocation

 e2fsck/pass2.c                          |  33 +++++++++++++++++-------
 e2fsck/rehash.c                         |  27 ++++++++++++++-----
 tests/f_quota_deallocate_inode/expect.1 |  18 +++++++++++++
 tests/f_quota_deallocate_inode/expect.2 |   7 +++++
 tests/f_quota_deallocate_inode/image.gz | Bin 0 -> 11594 bytes
 tests/f_quota_deallocate_inode/name     |   1 +
 tests/f_quota_shrinkdir/expect.1        |  18 +++++++++++++
 tests/f_quota_shrinkdir/expect.2        |   7 +++++
 tests/f_quota_shrinkdir/image.gz        | Bin 0 -> 10761 bytes
 tests/f_quota_shrinkdir/name            |   1 +
 10 files changed, 96 insertions(+), 16 deletions(-)
 create mode 100644 tests/f_quota_deallocate_inode/expect.1
 create mode 100644 tests/f_quota_deallocate_inode/expect.2
 create mode 100644 tests/f_quota_deallocate_inode/image.gz
 create mode 100644 tests/f_quota_deallocate_inode/name
 create mode 100644 tests/f_quota_shrinkdir/expect.1
 create mode 100644 tests/f_quota_shrinkdir/expect.2
 create mode 100644 tests/f_quota_shrinkdir/image.gz
 create mode 100644 tests/f_quota_shrinkdir/name


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/4] e2fsck: update quota accounting after directory optimization
  2024-04-04 11:10 [PATCH e2fsprogs v2 0/4] quota-related e2fsck fixes and tests Luis Henriques (SUSE)
@ 2024-04-04 11:10 ` Luis Henriques (SUSE)
  2024-04-04 11:10 ` [PATCH v2 2/4] e2fsck: update quota when deallocating a bad inode Luis Henriques (SUSE)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Luis Henriques (SUSE) @ 2024-04-04 11:10 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger; +Cc: linux-ext4, Luis Henriques (SUSE)

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>
---
 e2fsck/rehash.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c
index c1da7d52724e..4847d172e5fe 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);

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/4] e2fsck: update quota when deallocating a bad inode
  2024-04-04 11:10 [PATCH e2fsprogs v2 0/4] quota-related e2fsck fixes and tests Luis Henriques (SUSE)
  2024-04-04 11:10 ` [PATCH v2 1/4] e2fsck: update quota accounting after directory optimization Luis Henriques (SUSE)
@ 2024-04-04 11:10 ` Luis Henriques (SUSE)
  2024-04-04 17:25   ` Andreas Dilger
  2024-04-04 11:10 ` [PATCH v2 3/4] tests: new test to check quota after directory optimization Luis Henriques (SUSE)
  2024-04-04 11:10 ` [PATCH v2 4/4] tests: new test to check quota after a bad inode deallocation Luis Henriques (SUSE)
  3 siblings, 1 reply; 8+ messages in thread
From: Luis Henriques (SUSE) @ 2024-04-04 11:10 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger; +Cc: linux-ext4, Luis Henriques (SUSE)

If a bad inode is found it will be deallocated.  However, if the filesystem has
quota enabled, the quota information isn't being updated accordingly.  This
issue was detected by running fstest ext4/019.

This patch fixes the issue by decreasing the inode count from the
quota and, if blocks are also being released, also subtract them as well.

Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
---
 e2fsck/pass2.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
index b91628567a7f..e16b488af643 100644
--- a/e2fsck/pass2.c
+++ b/e2fsck/pass2.c
@@ -1859,12 +1859,13 @@ static int deallocate_inode_block(ext2_filsys fs,
 static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
 {
 	ext2_filsys fs = ctx->fs;
-	struct ext2_inode	inode;
+	struct ext2_inode_large	inode;
 	struct problem_context	pctx;
 	__u32			count;
 	struct del_block	del_block;
 
-	e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
+	e2fsck_read_inode_full(ctx, ino, EXT2_INODE(&inode),
+			       sizeof(inode), "deallocate_inode");
 	clear_problem_context(&pctx);
 	pctx.ino = ino;
 
@@ -1874,29 +1875,29 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
 	e2fsck_read_bitmaps(ctx);
 	ext2fs_inode_alloc_stats2(fs, ino, -1, LINUX_S_ISDIR(inode.i_mode));
 
-	if (ext2fs_file_acl_block(fs, &inode) &&
+	if (ext2fs_file_acl_block(fs, EXT2_INODE(&inode)) &&
 	    ext2fs_has_feature_xattr(fs->super)) {
 		pctx.errcode = ext2fs_adjust_ea_refcount3(fs,
-				ext2fs_file_acl_block(fs, &inode),
+				ext2fs_file_acl_block(fs, EXT2_INODE(&inode)),
 				block_buf, -1, &count, ino);
 		if (pctx.errcode == EXT2_ET_BAD_EA_BLOCK_NUM) {
 			pctx.errcode = 0;
 			count = 1;
 		}
 		if (pctx.errcode) {
-			pctx.blk = ext2fs_file_acl_block(fs, &inode);
+			pctx.blk = ext2fs_file_acl_block(fs, EXT2_INODE(&inode));
 			fix_problem(ctx, PR_2_ADJ_EA_REFCOUNT, &pctx);
 			ctx->flags |= E2F_FLAG_ABORT;
 			return;
 		}
 		if (count == 0) {
 			ext2fs_block_alloc_stats2(fs,
-				  ext2fs_file_acl_block(fs, &inode), -1);
+				  ext2fs_file_acl_block(fs, EXT2_INODE(&inode)), -1);
 		}
-		ext2fs_file_acl_block_set(fs, &inode, 0);
+		ext2fs_file_acl_block_set(fs, EXT2_INODE(&inode), 0);
 	}
 
-	if (!ext2fs_inode_has_valid_blocks2(fs, &inode))
+	if (!ext2fs_inode_has_valid_blocks2(fs, EXT2_INODE(&inode)))
 		goto clear_inode;
 
 	/* Inline data inodes don't have blocks to iterate */
@@ -1921,10 +1922,22 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
 		ctx->flags |= E2F_FLAG_ABORT;
 		return;
 	}
+
+	if ((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)) {
+		if (del_block.num > 0)
+			quota_data_sub(ctx->qctx, &inode, ino,
+				       del_block.num * EXT2_CLUSTER_SIZE(fs->super));
+		quota_data_inodes(ctx->qctx, (struct ext2_inode_large *)&inode,
+				  ino, -1);
+	}
+
 clear_inode:
 	/* Inode may have changed by block_iterate, so reread it */
-	e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
-	e2fsck_clear_inode(ctx, ino, &inode, 0, "deallocate_inode");
+	e2fsck_read_inode(ctx, ino, EXT2_INODE(&inode), "deallocate_inode");
+	e2fsck_clear_inode(ctx, ino, EXT2_INODE(&inode), 0, "deallocate_inode");
 }
 
 /*

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/4] tests: new test to check quota after directory optimization
  2024-04-04 11:10 [PATCH e2fsprogs v2 0/4] quota-related e2fsck fixes and tests Luis Henriques (SUSE)
  2024-04-04 11:10 ` [PATCH v2 1/4] e2fsck: update quota accounting after directory optimization Luis Henriques (SUSE)
  2024-04-04 11:10 ` [PATCH v2 2/4] e2fsck: update quota when deallocating a bad inode Luis Henriques (SUSE)
@ 2024-04-04 11:10 ` Luis Henriques (SUSE)
  2024-04-04 11:10 ` [PATCH v2 4/4] tests: new test to check quota after a bad inode deallocation Luis Henriques (SUSE)
  3 siblings, 0 replies; 8+ messages in thread
From: Luis Henriques (SUSE) @ 2024-04-04 11:10 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger; +Cc: linux-ext4, Luis Henriques (SUSE)

This new test validates e2fsck by verifying that quota data is updated after a
directory optimization is performed.  This issue was initially found by fstest
ext4/014, and this test was based on it.  It includes a filesystem image where
the lost+found directory is unlinked after a new link to it is created:

  # debugfs -w -R "ln lost+found foo" f_testnew/image
  # debugfs -w -R "unlink lost+found" f_testnew/image

Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
---
 tests/f_quota_shrinkdir/expect.1 |  18 ++++++++++++++++++
 tests/f_quota_shrinkdir/expect.2 |   7 +++++++
 tests/f_quota_shrinkdir/image.gz | Bin 0 -> 10761 bytes
 tests/f_quota_shrinkdir/name     |   1 +
 4 files changed, 26 insertions(+)
 create mode 100644 tests/f_quota_shrinkdir/expect.1
 create mode 100644 tests/f_quota_shrinkdir/expect.2
 create mode 100644 tests/f_quota_shrinkdir/image.gz
 create mode 100644 tests/f_quota_shrinkdir/name

diff --git a/tests/f_quota_shrinkdir/expect.1 b/tests/f_quota_shrinkdir/expect.1
new file mode 100644
index 000000000000..e4fc48ea6f90
--- /dev/null
+++ b/tests/f_quota_shrinkdir/expect.1
@@ -0,0 +1,18 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+/lost+found not found.  Create? yes
+
+Pass 3A: Optimizing directories
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+[QUOTA WARNING] Usage inconsistent for ID 0:actual (3072, 3) != expected (13312, 2)
+Update quota info for quota type 0? yes
+
+[QUOTA WARNING] Usage inconsistent for ID 0:actual (3072, 3) != expected (13312, 2)
+Update quota info for quota type 1? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 12/256 files (16.7% non-contiguous), 1145/8192 blocks
+Exit status is 1
diff --git a/tests/f_quota_shrinkdir/expect.2 b/tests/f_quota_shrinkdir/expect.2
new file mode 100644
index 000000000000..fcb2cb81441e
--- /dev/null
+++ b/tests/f_quota_shrinkdir/expect.2
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 12/256 files (16.7% non-contiguous), 1145/8192 blocks
+Exit status is 0
diff --git a/tests/f_quota_shrinkdir/image.gz b/tests/f_quota_shrinkdir/image.gz
new file mode 100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/tests/f_quota_shrinkdir/name b/tests/f_quota_shrinkdir/name
new file mode 100644
index 000000000000..8772ae5c814b
--- /dev/null
+++ b/tests/f_quota_shrinkdir/name
@@ -0,0 +1 @@
+update quota on directory optimization

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 4/4] tests: new test to check quota after a bad inode deallocation
  2024-04-04 11:10 [PATCH e2fsprogs v2 0/4] quota-related e2fsck fixes and tests Luis Henriques (SUSE)
                   ` (2 preceding siblings ...)
  2024-04-04 11:10 ` [PATCH v2 3/4] tests: new test to check quota after directory optimization Luis Henriques (SUSE)
@ 2024-04-04 11:10 ` Luis Henriques (SUSE)
  2024-04-04 17:27   ` Andreas Dilger
  3 siblings, 1 reply; 8+ messages in thread
From: Luis Henriques (SUSE) @ 2024-04-04 11:10 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger; +Cc: linux-ext4, Luis Henriques (SUSE)

This new test validates e2fsck by verifying that quota is updated after a bad
inode is deallocated.  It mimics fstest ext4/019 by including a filesystem image
where a symbolic link was created to an existing file, using a long symlink
name.  This symbolic link was then wiped with:

  # debugfs -w -R 'zap -f /testlink 0' f_testnew/image

Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
---
 tests/f_quota_deallocate_inode/expect.1 |  18 ++++++++++++++++++
 tests/f_quota_deallocate_inode/expect.2 |   7 +++++++
 tests/f_quota_deallocate_inode/image.gz | Bin 0 -> 11594 bytes
 tests/f_quota_deallocate_inode/name     |   1 +
 4 files changed, 26 insertions(+)
 create mode 100644 tests/f_quota_deallocate_inode/expect.1
 create mode 100644 tests/f_quota_deallocate_inode/expect.2
 create mode 100644 tests/f_quota_deallocate_inode/image.gz
 create mode 100644 tests/f_quota_deallocate_inode/name

diff --git a/tests/f_quota_deallocate_inode/expect.1 b/tests/f_quota_deallocate_inode/expect.1
new file mode 100644
index 000000000000..2b2f128dbb57
--- /dev/null
+++ b/tests/f_quota_deallocate_inode/expect.1
@@ -0,0 +1,18 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Symlink /testlink (inode #14) is invalid.
+Clear? yes
+
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+[QUOTA WARNING] Usage inconsistent for ID 0:actual (15360, 4) != expected (16384, 5)
+Update quota info for quota type 0? yes
+
+[QUOTA WARNING] Usage inconsistent for ID 0:actual (15360, 4) != expected (16384, 5)
+Update quota info for quota type 1? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 13/256 files (15.4% non-contiguous), 1157/8192 blocks
+Exit status is 1
diff --git a/tests/f_quota_deallocate_inode/expect.2 b/tests/f_quota_deallocate_inode/expect.2
new file mode 100644
index 000000000000..802317949959
--- /dev/null
+++ b/tests/f_quota_deallocate_inode/expect.2
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 13/256 files (15.4% non-contiguous), 1157/8192 blocks
+Exit status is 0
diff --git a/tests/f_quota_deallocate_inode/image.gz b/tests/f_quota_deallocate_inode/image.gz
new file mode 100644
index 0000000000000000000000000000000000000000..798a72c3a0da0323fc55c5e034f778e967394c81
GIT binary patch
literal 11594
zcmeI%eNYqUx&UyiRgMQsPLKCM5rNy&@i@JTaO(gyn54Bwu%aS@KoXLGC`cj%3rjQ*
zg2hU`eAU`Q6+=`M67t1|OCTYMNYyF=B1u;HiWUXBD+!3pM<Bb`+nL^fZpZWAnK|C<
zpU=B9@B9At*>|63*0<;ne|Yru^5mt<QqvMs4lQ{;=yG8#(4PN9*SUP@$xXViE`Pne
zK0NZ1cQ*uWjI00T&$OjGws9}5lt>bmzrFo={>8rrML%Ee8uX`}&l>)HyIhiM`?l!8
zzr9U)`^DDT9B%VE?Pm3~_)+VS*Q)$^^N!t~t4cW<+s=aa??*fw9p6o9CU1POevfa^
zM=hi06`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(+uE
zk{3^rip@Rn&-UYv%bTPuvkHdLO3k%AdWGp3u$@6Q$Yk&=T4+ylNU?aKREDTfwLOOs
zRj{(4{mswlD3^!;?5%(J+~4FIg0sg@wm+^XwlU+wjAwvo-4!OyUsjDgL;s6^$UEw`
z`G4ywChN9o3fQK*v`2mxE<tOEt;6xPMmnrOoB27q>S3y_E(*Cu)D1IIjOWlQK3Ave
zuA7A(p(pGK0tq?ZSDFb|qYd_BBDz=-VXlSy&~x@90wtNnlK7jCqgU-;2(IdBW6*CE
zm28v5^>y_WTBNy>M>W*3ATIpCp2mo&fc^p;awwH`7RVPaLu>7sj;l(g!EAwT!0vZ$
zttdFNMzJz5W;N#ot^RMOZD5AqzO$TOn%rHrj(vw#SFY5Wez%E0Y1L*q2wQ<Nn$}81
zj5>H25No&!I%2W|291z((I<{j=klroz65@n7UyNUh1T<rrR}RUC!=5U52i88>ipnd
z^auVClG2A2A@M^_qgVJ}kgitI=%zmS7qpn4oW|&>OMx=sR&X~-RmJj`c$k|(#%@Jw
zpzi;4jr_>pTF+9?o;Nu;e|K;BA^LT(A+wjy)MN(5kN2N)f6tJ9`Q|cS>gtV4f8dr-
z-wv=emJx~v`;Q)o>U6WpL;YTb6}m4+@BqUXi@u|*QoLialT3a*N4Y0lix<vAPdQ$m
z3|{WWAGW^d%}{SH%C>*I@@!~wL}g%(y>xR8b>Hu<!x{W12wZpTOTPCIxXaX9$w}~y
z@)iGtIh|8D1)Ks-0jGddz$xGqa0)mDoB~b(r+`zyDc}@v3OEIv0!{&^fK%XKNMKSp
k(f<Db{OruXh^uso|3WKwF7^L|z}z2?A5?k2O3x+#4eAK~X#fBK

literal 0
HcmV?d00001

diff --git a/tests/f_quota_deallocate_inode/name b/tests/f_quota_deallocate_inode/name
new file mode 100644
index 000000000000..396887c16f84
--- /dev/null
+++ b/tests/f_quota_deallocate_inode/name
@@ -0,0 +1 @@
+update quota when deallocating bad inode

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/4] e2fsck: update quota when deallocating a bad inode
  2024-04-04 11:10 ` [PATCH v2 2/4] e2fsck: update quota when deallocating a bad inode Luis Henriques (SUSE)
@ 2024-04-04 17:25   ` Andreas Dilger
  2024-04-04 20:23     ` Luis Henriques
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Dilger @ 2024-04-04 17:25 UTC (permalink / raw)
  To: Luis Henriques (SUSE); +Cc: Theodore Ts'o, linux-ext4

[-- Attachment #1: Type: text/plain, Size: 3949 bytes --]

On Apr 4, 2024, at 5:10 AM, Luis Henriques (SUSE) <luis.henriques@linux.dev> wrote:
> 
> If a bad inode is found it will be deallocated.  However, if the filesystem has
> quota enabled, the quota information isn't being updated accordingly.  This
> issue was detected by running fstest ext4/019.
> 
> This patch fixes the issue by decreasing the inode count from the
> quota and, if blocks are also being released, also subtract them as well.
> 
> Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
> ---
> e2fsck/pass2.c | 33 +++++++++++++++++++++++----------
> 1 file changed, 23 insertions(+), 10 deletions(-)
> 
> diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
> index b91628567a7f..e16b488af643 100644
> --- a/e2fsck/pass2.c
> +++ b/e2fsck/pass2.c
> @@ -1859,12 +1859,13 @@ static int deallocate_inode_block(ext2_filsys fs,

I'd hoped you might include a better comment for this function, but the code
itself looks OK.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
> {
> 	ext2_filsys fs = ctx->fs;
> -	struct ext2_inode	inode;
> +	struct ext2_inode_large	inode;
> 	struct problem_context	pctx;
> 	__u32			count;
> 	struct del_block	del_block;
> 
> -	e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
> +	e2fsck_read_inode_full(ctx, ino, EXT2_INODE(&inode),
> +			       sizeof(inode), "deallocate_inode");
> 	clear_problem_context(&pctx);
> 	pctx.ino = ino;
> 
> @@ -1874,29 +1875,29 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
> 	e2fsck_read_bitmaps(ctx);
> 	ext2fs_inode_alloc_stats2(fs, ino, -1, LINUX_S_ISDIR(inode.i_mode));
> 
> -	if (ext2fs_file_acl_block(fs, &inode) &&
> +	if (ext2fs_file_acl_block(fs, EXT2_INODE(&inode)) &&
> 	    ext2fs_has_feature_xattr(fs->super)) {
> 		pctx.errcode = ext2fs_adjust_ea_refcount3(fs,
> -				ext2fs_file_acl_block(fs, &inode),
> +				ext2fs_file_acl_block(fs, EXT2_INODE(&inode)),
> 				block_buf, -1, &count, ino);
> 		if (pctx.errcode == EXT2_ET_BAD_EA_BLOCK_NUM) {
> 			pctx.errcode = 0;
> 			count = 1;
> 		}
> 		if (pctx.errcode) {
> -			pctx.blk = ext2fs_file_acl_block(fs, &inode);
> +			pctx.blk = ext2fs_file_acl_block(fs, EXT2_INODE(&inode));
> 			fix_problem(ctx, PR_2_ADJ_EA_REFCOUNT, &pctx);
> 			ctx->flags |= E2F_FLAG_ABORT;
> 			return;
> 		}
> 		if (count == 0) {
> 			ext2fs_block_alloc_stats2(fs,
> -				  ext2fs_file_acl_block(fs, &inode), -1);
> +				  ext2fs_file_acl_block(fs, EXT2_INODE(&inode)), -1);
> 		}
> -		ext2fs_file_acl_block_set(fs, &inode, 0);
> +		ext2fs_file_acl_block_set(fs, EXT2_INODE(&inode), 0);
> 	}
> 
> -	if (!ext2fs_inode_has_valid_blocks2(fs, &inode))
> +	if (!ext2fs_inode_has_valid_blocks2(fs, EXT2_INODE(&inode)))
> 		goto clear_inode;
> 
> 	/* Inline data inodes don't have blocks to iterate */
> @@ -1921,10 +1922,22 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
> 		ctx->flags |= E2F_FLAG_ABORT;
> 		return;
> 	}
> +
> +	if ((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)) {
> +		if (del_block.num > 0)
> +			quota_data_sub(ctx->qctx, &inode, ino,
> +				       del_block.num * EXT2_CLUSTER_SIZE(fs->super));
> +		quota_data_inodes(ctx->qctx, (struct ext2_inode_large *)&inode,
> +				  ino, -1);
> +	}
> +
> clear_inode:
> 	/* Inode may have changed by block_iterate, so reread it */
> -	e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
> -	e2fsck_clear_inode(ctx, ino, &inode, 0, "deallocate_inode");
> +	e2fsck_read_inode(ctx, ino, EXT2_INODE(&inode), "deallocate_inode");
> +	e2fsck_clear_inode(ctx, ino, EXT2_INODE(&inode), 0, "deallocate_inode");
> }
> 
> /*


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 4/4] tests: new test to check quota after a bad inode deallocation
  2024-04-04 11:10 ` [PATCH v2 4/4] tests: new test to check quota after a bad inode deallocation Luis Henriques (SUSE)
@ 2024-04-04 17:27   ` Andreas Dilger
  0 siblings, 0 replies; 8+ messages in thread
From: Andreas Dilger @ 2024-04-04 17:27 UTC (permalink / raw)
  To: Luis Henriques (SUSE); +Cc: Theodore Ts'o, linux-ext4

[-- Attachment #1: Type: text/plain, Size: 7906 bytes --]

On Apr 4, 2024, at 5:10 AM, Luis Henriques (SUSE) <luis.henriques@linux.dev> wrote:
> 
> This new test validates e2fsck by verifying that quota is updated after a bad
> inode is deallocated.  It mimics fstest ext4/019 by including a filesystem image
> where a symbolic link was created to an existing file, using a long symlink
> name.  This symbolic link was then wiped with:
> 
>  # debugfs -w -R 'zap -f /testlink 0' f_testnew/image
> 
> Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>

After your explanation in the previous version of this patch, I now understand
that this is fixing e2fsck so that it only reports the quota inconsistency in
the first e2fsck run, and not the second e2fsck run (as it had previously).

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> tests/f_quota_deallocate_inode/expect.1 |  18 ++++++++++++++++++
> tests/f_quota_deallocate_inode/expect.2 |   7 +++++++
> tests/f_quota_deallocate_inode/image.gz | Bin 0 -> 11594 bytes
> tests/f_quota_deallocate_inode/name     |   1 +
> 4 files changed, 26 insertions(+)
> create mode 100644 tests/f_quota_deallocate_inode/expect.1
> create mode 100644 tests/f_quota_deallocate_inode/expect.2
> create mode 100644 tests/f_quota_deallocate_inode/image.gz
> create mode 100644 tests/f_quota_deallocate_inode/name
> 
> diff --git a/tests/f_quota_deallocate_inode/expect.1 b/tests/f_quota_deallocate_inode/expect.1
> new file mode 100644
> index 000000000000..2b2f128dbb57
> --- /dev/null
> +++ b/tests/f_quota_deallocate_inode/expect.1
> @@ -0,0 +1,18 @@
> +Pass 1: Checking inodes, blocks, and sizes
> +Pass 2: Checking directory structure
> +Symlink /testlink (inode #14) is invalid.
> +Clear? yes
> +
> +Pass 3: Checking directory connectivity
> +Pass 4: Checking reference counts
> +Pass 5: Checking group summary information
> +[QUOTA WARNING] Usage inconsistent for ID 0:actual (15360, 4) != expected (16384, 5)
> +Update quota info for quota type 0? yes
> +
> +[QUOTA WARNING] Usage inconsistent for ID 0:actual (15360, 4) != expected (16384, 5)
> +Update quota info for quota type 1? yes
> +
> +
> +test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
> +test_filesys: 13/256 files (15.4% non-contiguous), 1157/8192 blocks
> +Exit status is 1
> diff --git a/tests/f_quota_deallocate_inode/expect.2 b/tests/f_quota_deallocate_inode/expect.2
> new file mode 100644
> index 000000000000..802317949959
> --- /dev/null
> +++ b/tests/f_quota_deallocate_inode/expect.2
> @@ -0,0 +1,7 @@
> +Pass 1: Checking inodes, blocks, and sizes
> +Pass 2: Checking directory structure
> +Pass 3: Checking directory connectivity
> +Pass 4: Checking reference counts
> +Pass 5: Checking group summary information
> +test_filesys: 13/256 files (15.4% non-contiguous), 1157/8192 blocks
> +Exit status is 0
> diff --git a/tests/f_quota_deallocate_inode/image.gz b/tests/f_quota_deallocate_inode/image.gz
> new file mode 100644
> index 0000000000000000000000000000000000000000..798a72c3a0da0323fc55c5e034f778e967394c81
> GIT binary patch
> literal 11594
> zcmeI%eNYqUx&UyiRgMQsPLKCM5rNy&@i@JTaO(gyn54Bwu%aS@KoXLGC`cj%3rjQ*
> zg2hU`eAU`Q6+=`M67t1|OCTYMNYyF=B1u;HiWUXBD+!3pM<Bb`+nL^fZpZWAnK|C<
> zpU=B9@B9At*>|63*0<;ne|Yru^5mt<QqvMs4lQ{;=yG8#(4PN9*SUP@$xXViE`Pne
> zK0NZ1cQ*uWjI00T&$OjGws9}5lt>bmzrFo={>8rrML%Ee8uX`}&l>)HyIhiM`?l!8
> zzr9U)`^DDT9B%VE?Pm3~_)+VS*Q)$^^N!t~t4cW<+s=aa??*fw9p6o9CU1POevfa^
> zM=hi06`Q<TXR<xAFb!_H|JRX}p!APutBE?Jrw3Os_l&O0`{~@6H}6N!s8ZdNjyUej
> zy&-dDYv=QUpv|(O@oztewg~QC=u5T=Zj8EA9W%S9i1~xR6qUSe`CAz)_(IuGWp~|^
> zf``>Javj^&Upu34uyNu=H+g|lU0?oQys&q7E7rKEE_>OXx~;@y{7=~fQSTZsSrM3<
> zr^-4+iJ<IQ^7?C(0u8or#C*xvyOeD$;Ani)9T6vY36?Xe81q=W<*2=FwDzsZ2VM4{
> zARgwwmTL`6D(IaWSXCQ^i><<)qRj$Fbz#@SmO-Uge!)WXVnW7~l2PHofL2?0u_awq
> z-iv{}iKqp0UJ@>vHz-|g7pH}vO!Iem$GMm;5a%`p;P=Kt@;k<Gds0%c4<5Fna`+a$
> zuwDK0JWlb%X`Ng)=27*sXJCTa#Lk|G%yGN@W50GrD&QFUg&)TlPXPCS@)ly}45E-h
> zoQl`X;Gu<;H-$gMbZlr=d9!c#OS6@pflb*`21h+m@6hVR`1A~(-sbSt4P%x|>O{Js
> zYvyd;lx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itI=%zmS7qpn4oW|&>OMx=sR&X~-RmJj`c$k|(#%@Jw
> zpzi;4jr_>pTF+9?o;Nu;e|K;BA^LT(A+wjy)MN(5kN2N)f6tJ9`Q|cS>gtV4f8dr-
> z-wv=emJx~v`;Q)o>U6WpL;YTb6}m4+@BqUXi@u|*QoLialT3a*N4Y0lix<vAPdQ$m
> z3|{WWAGW^d%}{SH%C>*I@@!~wL}g%(y>xR8b>Hu<!x{W12wZpTOTPCIxXaX9$w}~y
> z@)iGtIh|8D1)Ks-0jGddz$xGqa0)mDoB~b(r+`zyDc}@v3OEIv0!{&^fK%XKNMKSp
> k(f<Db{OruXh^uso|3WKwF7^L|z}z2?A5?k2O3x+#4eAK~X#fBK
> 
> literal 0
> HcmV?d00001
> 
> diff --git a/tests/f_quota_deallocate_inode/name b/tests/f_quota_deallocate_inode/name
> new file mode 100644
> index 000000000000..396887c16f84
> --- /dev/null
> +++ b/tests/f_quota_deallocate_inode/name
> @@ -0,0 +1 @@
> +update quota when deallocating bad inode


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/4] e2fsck: update quota when deallocating a bad inode
  2024-04-04 17:25   ` Andreas Dilger
@ 2024-04-04 20:23     ` Luis Henriques
  0 siblings, 0 replies; 8+ messages in thread
From: Luis Henriques @ 2024-04-04 20:23 UTC (permalink / raw)
  To: Andreas Dilger; +Cc: Theodore Ts'o, linux-ext4

On Thu, Apr 04 2024, Andreas Dilger wrote:

> On Apr 4, 2024, at 5:10 AM, Luis Henriques (SUSE) <luis.henriques@linux.dev> wrote:
>> 
>> If a bad inode is found it will be deallocated.  However, if the filesystem has
>> quota enabled, the quota information isn't being updated accordingly.  This
>> issue was detected by running fstest ext4/019.
>> 
>> This patch fixes the issue by decreasing the inode count from the
>> quota and, if blocks are also being released, also subtract them as well.
>> 
>> Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
>> ---
>> e2fsck/pass2.c | 33 +++++++++++++++++++++++----------
>> 1 file changed, 23 insertions(+), 10 deletions(-)
>> 
>> diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
>> index b91628567a7f..e16b488af643 100644
>> --- a/e2fsck/pass2.c
>> +++ b/e2fsck/pass2.c
>> @@ -1859,12 +1859,13 @@ static int deallocate_inode_block(ext2_filsys fs,
>
> I'd hoped you might include a better comment for this function, but the code
> itself looks OK.

Ouch!  I totally forgot about that, sorry.  I'll send out v3 tomorrow.
And thanks for you reviews and suggestions.

Cheers,
-- 
Luis

> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
>
>> static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
>> {
>> 	ext2_filsys fs = ctx->fs;
>> -	struct ext2_inode	inode;
>> +	struct ext2_inode_large	inode;
>> 	struct problem_context	pctx;
>> 	__u32			count;
>> 	struct del_block	del_block;
>> 
>> -	e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
>> +	e2fsck_read_inode_full(ctx, ino, EXT2_INODE(&inode),
>> +			       sizeof(inode), "deallocate_inode");
>> 	clear_problem_context(&pctx);
>> 	pctx.ino = ino;
>> 
>> @@ -1874,29 +1875,29 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
>> 	e2fsck_read_bitmaps(ctx);
>> 	ext2fs_inode_alloc_stats2(fs, ino, -1, LINUX_S_ISDIR(inode.i_mode));
>> 
>> -	if (ext2fs_file_acl_block(fs, &inode) &&
>> +	if (ext2fs_file_acl_block(fs, EXT2_INODE(&inode)) &&
>> 	    ext2fs_has_feature_xattr(fs->super)) {
>> 		pctx.errcode = ext2fs_adjust_ea_refcount3(fs,
>> -				ext2fs_file_acl_block(fs, &inode),
>> +				ext2fs_file_acl_block(fs, EXT2_INODE(&inode)),
>> 				block_buf, -1, &count, ino);
>> 		if (pctx.errcode == EXT2_ET_BAD_EA_BLOCK_NUM) {
>> 			pctx.errcode = 0;
>> 			count = 1;
>> 		}
>> 		if (pctx.errcode) {
>> -			pctx.blk = ext2fs_file_acl_block(fs, &inode);
>> +			pctx.blk = ext2fs_file_acl_block(fs, EXT2_INODE(&inode));
>> 			fix_problem(ctx, PR_2_ADJ_EA_REFCOUNT, &pctx);
>> 			ctx->flags |= E2F_FLAG_ABORT;
>> 			return;
>> 		}
>> 		if (count == 0) {
>> 			ext2fs_block_alloc_stats2(fs,
>> -				  ext2fs_file_acl_block(fs, &inode), -1);
>> +				  ext2fs_file_acl_block(fs, EXT2_INODE(&inode)), -1);
>> 		}
>> -		ext2fs_file_acl_block_set(fs, &inode, 0);
>> +		ext2fs_file_acl_block_set(fs, EXT2_INODE(&inode), 0);
>> 	}
>> 
>> -	if (!ext2fs_inode_has_valid_blocks2(fs, &inode))
>> +	if (!ext2fs_inode_has_valid_blocks2(fs, EXT2_INODE(&inode)))
>> 		goto clear_inode;
>> 
>> 	/* Inline data inodes don't have blocks to iterate */
>> @@ -1921,10 +1922,22 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
>> 		ctx->flags |= E2F_FLAG_ABORT;
>> 		return;
>> 	}
>> +
>> +	if ((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)) {
>> +		if (del_block.num > 0)
>> +			quota_data_sub(ctx->qctx, &inode, ino,
>> +				       del_block.num * EXT2_CLUSTER_SIZE(fs->super));
>> +		quota_data_inodes(ctx->qctx, (struct ext2_inode_large *)&inode,
>> +				  ino, -1);
>> +	}
>> +
>> clear_inode:
>> 	/* Inode may have changed by block_iterate, so reread it */
>> -	e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
>> -	e2fsck_clear_inode(ctx, ino, &inode, 0, "deallocate_inode");
>> +	e2fsck_read_inode(ctx, ino, EXT2_INODE(&inode), "deallocate_inode");
>> +	e2fsck_clear_inode(ctx, ino, EXT2_INODE(&inode), 0, "deallocate_inode");
>> }
>> 
>> /*
>
>
> Cheers, Andreas

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-04-04 20:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-04 11:10 [PATCH e2fsprogs v2 0/4] quota-related e2fsck fixes and tests Luis Henriques (SUSE)
2024-04-04 11:10 ` [PATCH v2 1/4] e2fsck: update quota accounting after directory optimization Luis Henriques (SUSE)
2024-04-04 11:10 ` [PATCH v2 2/4] e2fsck: update quota when deallocating a bad inode Luis Henriques (SUSE)
2024-04-04 17:25   ` Andreas Dilger
2024-04-04 20:23     ` Luis Henriques
2024-04-04 11:10 ` [PATCH v2 3/4] tests: new test to check quota after directory optimization Luis Henriques (SUSE)
2024-04-04 11:10 ` [PATCH v2 4/4] tests: new test to check quota after a bad inode deallocation Luis Henriques (SUSE)
2024-04-04 17:27   ` Andreas Dilger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).