From: "Theodore Y. Ts'o" <tytso@mit.edu>
To: Jan Kara <jack@suse.cz>
Cc: linux-ext4@vger.kernel.org
Subject: Re: [PATCH 3/7] ext2fs: Update allocation info earlier in ext2fs_mkdir() and ext2fs_symlink()
Date: Sun, 15 Mar 2020 12:15:09 -0400 [thread overview]
Message-ID: <20200315161509.GQ225435@mit.edu> (raw)
In-Reply-To: <20200308022024.GG99899@mit.edu>
Ah, I see now why this patch is needed. If we don't update the block
allocation bitmap to indicate block has been taken, and there is a
need to allocate an htree index block, we will end up allocating the
same block twice.
Thanks, I've applied this patch with the following added.
- Ted
diff --git a/lib/ext2fs/mkdir.c b/lib/ext2fs/mkdir.c
index 947003eb..437c8ffc 100644
--- a/lib/ext2fs/mkdir.c
+++ b/lib/ext2fs/mkdir.c
@@ -43,6 +43,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
blk64_t blk;
char *block = 0;
int inline_data = 0;
+ int drop_refcount = 0;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
@@ -149,6 +150,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
if (!inline_data)
ext2fs_block_alloc_stats2(fs, blk, +1);
ext2fs_inode_alloc_stats2(fs, ino, +1, 1);
+ drop_refcount = 1;
/*
* Link the directory into the filesystem hierarchy
@@ -181,10 +183,16 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
if (retval)
goto cleanup;
}
+ drop_refcount = 0;
cleanup:
if (block)
ext2fs_free_mem(&block);
+ if (drop_refcount) {
+ if (!inline_data)
+ ext2fs_block_alloc_stats2(fs, blk, -1);
+ ext2fs_inode_alloc_stats2(fs, ino, -1, 1);
+ }
return retval;
}
diff --git a/lib/ext2fs/symlink.c b/lib/ext2fs/symlink.c
index 3e07a539..a66fb7ec 100644
--- a/lib/ext2fs/symlink.c
+++ b/lib/ext2fs/symlink.c
@@ -54,6 +54,7 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
int fastlink, inlinelink;
unsigned int target_len;
char *block_buf = 0;
+ int drop_refcount = 0;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
@@ -168,6 +169,7 @@ need_block:
if (!fastlink && !inlinelink)
ext2fs_block_alloc_stats2(fs, blk, +1);
ext2fs_inode_alloc_stats2(fs, ino, +1, 0);
+ drop_refcount = 1;
/*
* Link the symlink into the filesystem hierarchy
@@ -185,10 +187,16 @@ need_block:
if (retval)
goto cleanup;
}
+ drop_refcount = 0;
cleanup:
if (block_buf)
ext2fs_free_mem(&block_buf);
+ if (drop_refcount) {
+ if (!fastlink && !inlinelink)
+ ext2fs_block_alloc_stats2(fs, blk, -1);
+ ext2fs_inode_alloc_stats2(fs, ino, -1, 0);
+ }
return retval;
}
next prev parent reply other threads:[~2020-03-15 16:15 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-13 10:15 [PATCH 0/7 v2] e2fsprogs: Better handling of indexed directories Jan Kara
2020-02-13 10:15 ` [PATCH 1/7] e2fsck: Clarify overflow link count error message Jan Kara
2020-02-14 19:27 ` Andreas Dilger
2020-03-07 18:52 ` Theodore Y. Ts'o
2020-02-13 10:15 ` [PATCH 2/7] e2fsck: Fix indexed dir rehash failure with metadata_csum enabled Jan Kara
2020-02-14 19:28 ` Andreas Dilger
2020-03-07 23:17 ` Theodore Y. Ts'o
2020-03-16 9:30 ` Jan Kara
2020-02-13 10:15 ` [PATCH 3/7] ext2fs: Update allocation info earlier in ext2fs_mkdir() and ext2fs_symlink() Jan Kara
2020-02-14 19:37 ` Andreas Dilger
2020-03-08 0:02 ` Theodore Y. Ts'o
2020-03-08 2:20 ` Theodore Y. Ts'o
2020-03-15 16:15 ` Theodore Y. Ts'o [this message]
2020-03-16 9:32 ` Jan Kara
2020-02-13 10:15 ` [PATCH 4/7] ext2fs: Implement dir entry creation in htree directories Jan Kara
2020-03-15 16:43 ` Theodore Y. Ts'o
2020-02-13 10:16 ` [PATCH 5/7] tests: Modify f_large_dir test to excercise indexed dir handling Jan Kara
2020-02-18 20:29 ` Andreas Dilger
2020-03-15 16:43 ` Theodore Y. Ts'o
2020-02-13 10:16 ` [PATCH 6/7] tests: Add test to excercise indexed directories with metadata_csum Jan Kara
2020-02-18 20:34 ` Andreas Dilger
2020-02-13 10:16 ` [PATCH 7/7] tune2fs: Update dir checksums when clearing dir_index feature Jan Kara
2020-02-18 20:50 ` Andreas Dilger
2020-02-19 10:23 ` Jan Kara
2020-03-15 17:15 ` Theodore Y. Ts'o
2020-03-16 0:11 ` Andreas Dilger
2020-03-16 9:27 ` Jan Kara
2020-03-26 14:27 ` Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200315161509.GQ225435@mit.edu \
--to=tytso@mit.edu \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.