* [PATCH] libext2fs: don't truncate the orphan file inode if it is newly allocated
@ 2023-08-25 21:45 Theodore Ts'o
2023-08-31 14:40 ` Eric Whitney
0 siblings, 1 reply; 2+ messages in thread
From: Theodore Ts'o @ 2023-08-25 21:45 UTC (permalink / raw)
To: Ext4 Developers List; +Cc: Eric Whitney, Theodore Ts'o
In ext2fs_create_orphan_file(), don't try truncating inode for the
orphan file if ext2fs_create_orphan_file() allocated the inode. This
avoids problems where the newly allocated inode in the inode table
might contain garbage; if the metadata checksum feature is enabled,
this will generally result in the function failing with a checksum
invalid error, but this can cause mke2fs (which calls
ext2fs_create_orphan_file) to fail.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
lib/ext2fs/orphan.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/lib/ext2fs/orphan.c b/lib/ext2fs/orphan.c
index e25f20ca2..c2f83567f 100644
--- a/lib/ext2fs/orphan.c
+++ b/lib/ext2fs/orphan.c
@@ -127,22 +127,21 @@ errcode_t ext2fs_create_orphan_file(ext2_filsys fs, blk_t num_blocks)
struct mkorphan_info oi;
struct ext4_orphan_block_tail *ob_tail;
- if (!ino) {
+ if (ino) {
+ err = ext2fs_read_inode(fs, ino, &inode);
+ if (err)
+ return err;
+ if (EXT2_I_SIZE(&inode)) {
+ err = ext2fs_truncate_orphan_file(fs);
+ if (err)
+ return err;
+ }
+ } else {
err = ext2fs_new_inode(fs, EXT2_ROOT_INO, LINUX_S_IFREG | 0600,
0, &ino);
if (err)
return err;
ext2fs_inode_alloc_stats2(fs, ino, +1, 0);
- ext2fs_mark_ib_dirty(fs);
- }
-
- err = ext2fs_read_inode(fs, ino, &inode);
- if (err)
- return err;
- if (EXT2_I_SIZE(&inode)) {
- err = ext2fs_truncate_orphan_file(fs);
- if (err)
- return err;
}
memset(&inode, 0, sizeof(struct ext2_inode));
--
2.31.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] libext2fs: don't truncate the orphan file inode if it is newly allocated
2023-08-25 21:45 [PATCH] libext2fs: don't truncate the orphan file inode if it is newly allocated Theodore Ts'o
@ 2023-08-31 14:40 ` Eric Whitney
0 siblings, 0 replies; 2+ messages in thread
From: Eric Whitney @ 2023-08-31 14:40 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: Ext4 Developers List, Eric Whitney
* Theodore Ts'o <tytso@mit.edu>:
> In ext2fs_create_orphan_file(), don't try truncating inode for the
> orphan file if ext2fs_create_orphan_file() allocated the inode. This
> avoids problems where the newly allocated inode in the inode table
> might contain garbage; if the metadata checksum feature is enabled,
> this will generally result in the function failing with a checksum
> invalid error, but this can cause mke2fs (which calls
> ext2fs_create_orphan_file) to fail.
>
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> ---
> lib/ext2fs/orphan.c | 21 ++++++++++-----------
> 1 file changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/lib/ext2fs/orphan.c b/lib/ext2fs/orphan.c
> index e25f20ca2..c2f83567f 100644
> --- a/lib/ext2fs/orphan.c
> +++ b/lib/ext2fs/orphan.c
> @@ -127,22 +127,21 @@ errcode_t ext2fs_create_orphan_file(ext2_filsys fs, blk_t num_blocks)
> struct mkorphan_info oi;
> struct ext4_orphan_block_tail *ob_tail;
>
> - if (!ino) {
> + if (ino) {
> + err = ext2fs_read_inode(fs, ino, &inode);
> + if (err)
> + return err;
> + if (EXT2_I_SIZE(&inode)) {
> + err = ext2fs_truncate_orphan_file(fs);
> + if (err)
> + return err;
> + }
> + } else {
> err = ext2fs_new_inode(fs, EXT2_ROOT_INO, LINUX_S_IFREG | 0600,
> 0, &ino);
> if (err)
> return err;
> ext2fs_inode_alloc_stats2(fs, ino, +1, 0);
> - ext2fs_mark_ib_dirty(fs);
> - }
> -
> - err = ext2fs_read_inode(fs, ino, &inode);
> - if (err)
> - return err;
> - if (EXT2_I_SIZE(&inode)) {
> - err = ext2fs_truncate_orphan_file(fs);
> - if (err)
> - return err;
> }
>
> memset(&inode, 0, sizeof(struct ext2_inode));
> --
> 2.31.0
>
With this patch to mke2fs, I ran ext4/049 on a 6.5 kernel using kvm-xfstests'
4k test scenario. It passed 110/110 trials. Without the patch, it fails
100% of the time. So, it addresses the failures I've been seeing.
Thanks!
Tested-by: Eric Whitney <enwlinux@gmail.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-31 14:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-25 21:45 [PATCH] libext2fs: don't truncate the orphan file inode if it is newly allocated Theodore Ts'o
2023-08-31 14:40 ` Eric Whitney
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).