From: Hsiu-Hsien Lee <swinds24@gmail.com>
To: Theodore Ts'o <tytso@mit.edu>, Andreas Dilger <adilger.kernel@dilger.ca>
Cc: Jan Kara <jack@suse.cz>, Baokun Li <libaokun@linux.alibaba.com>,
Ojaswin Mujoo <ojaswin@linux.ibm.com>,
Ritesh Harjani <ritesh.list@gmail.com>,
Zhang Yi <yi.zhang@huawei.com>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
Hsiu-Hsien Lee <swinds24@gmail.com>
Subject: [PATCH] ext4: use unsigned int for inode numbers in fast commit
Date: Mon, 23 Nov 2026 10:23:09 +0800 [thread overview]
Message-ID: <20261123022309.990044-1-swinds24@gmail.com> (raw)
The fast commit code keeps inode numbers in signed int: fcd_parent and
fcd_ino in struct ext4_fc_dentry_update, the fc_modified_inodes array,
struct dentry_info_args, the inode number in ext4_fc_replay_inode() and
the argument of ext4_fc_record_modified_inode() and
ext4_mark_inode_used(). On a file system with more than 2^31 inodes,
inode numbers of 2^31 and above become negative.
In the commit path, fcd_ino is sign-extended when compared with i_ino,
so the WARN_ON() in ext4_fc_commit_dentry_updates() fires on every
fsync() of a newly created file with such an inode number.
In the replay path, the sign-extended value passed to ext4_iget() is
larger than s_inodes_count, so ext4_iget() reports "iget: illegal
inode #" and the dentry and inode tags of these inodes are not replayed
after a crash.
The on-disk fields are __le32 and converted with cpu_to_le32() and
le32_to_cpu(), so the journal format does not change. Also print these
inode numbers with %u, and print the parent inode number instead of the
child's when the parent directory of a create is not found.
Reproducer:
dd if=/dev/zero of=img bs=1M count=0 seek=9437184 # 9 TiB sparse
mkfs.ext4 -O fast_commit -i 4096 -E lazy_itable_init=1 img
mount -o loop,noinit_itable img /mnt
mkdir /mnt/d1 ... /mnt/d64 # Orlov spreads them over all groups
pick a directory with an inode number >= 2^31, then
dd if=/dev/zero of=/mnt/dN/f bs=4k count=1 conv=fsync
Without this patch every such fsync() triggers the WARN_ON(). With it
there is no warning, and after EXT4_IOC_SHUTDOWN with
EXT4_GOING_FLAGS_NOLOGFLUSH following creates, an unlink, a link and an
append in that directory, all of them are replayed on the next mount and
e2fsck -fn finds no errors.
Fixes: aa75f4d3daae ("ext4: main fast-commit commit path")
Fixes: 8016e29f4362 ("ext4: fast commit recovery path")
Assisted-by: Claude Opus 5.5
Signed-off-by: Hsiu-Hsien Lee <swinds24@gmail.com>
---
Testing: the reproducer and crash test above were run on a 6.6.y
kernel with this patch backported (the same change apart from context).
Without the patch, 10 of 10 fsync() calls in a directory with inode
number 2343567361 triggered the warning; with it, 0 of 10 did in a
directory with inode number 2313158657, while the fast commit stats
showed 26 commits and 0 ineligible. On this tree the
patch is build-tested only (W=1, CONFIG_EXT4_DEBUG, ext4 KUnit tests).
The pending KUnit series for fast_commit.c [1] adds stubs and test
helpers with "int ino" arguments that will need the same type change
if it lands first.
[1] https://lore.kernel.org/linux-ext4/20261119155658.1940864-8-tytso@mit.edu/
fs/ext4/ext4.h | 2 +-
fs/ext4/fast_commit.c | 28 ++++++++++++++++------------
fs/ext4/fast_commit.h | 6 +++---
fs/ext4/ialloc.c | 2 +-
4 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index aa0f23052..75039cf83 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -3067,7 +3067,7 @@ extern int ext4fs_dirhash(const struct inode *dir, const char *name, int len,
struct dx_hash_info *hinfo);
/* ialloc.c */
-extern int ext4_mark_inode_used(struct super_block *sb, int ino);
+extern int ext4_mark_inode_used(struct super_block *sb, unsigned int ino);
extern struct inode *__ext4_new_inode(const struct mnt_idmap *, handle_t *,
struct inode *, umode_t,
const struct qstr *qstr, __u32 goal,
diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index 5f12449b9..4a066e43e 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -1763,7 +1763,8 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid)
/* Helper struct for dentry replay routines */
struct dentry_info_args {
- int parent_ino, dname_len, ino, inode_len;
+ unsigned int parent_ino, ino;
+ int dname_len, inode_len;
char *dname;
};
@@ -1814,14 +1815,14 @@ static int ext4_fc_replay_unlink(struct super_block *sb,
inode = ext4_iget(sb, darg.ino, EXT4_IGET_NORMAL);
if (IS_ERR(inode)) {
- ext4_debug("Inode %d not found", darg.ino);
+ ext4_debug("Inode %u not found", darg.ino);
return 0;
}
old_parent = ext4_iget(sb, darg.parent_ino,
EXT4_IGET_NORMAL);
if (IS_ERR(old_parent)) {
- ext4_debug("Dir with inode %d not found", darg.parent_ino);
+ ext4_debug("Dir with inode %u not found", darg.parent_ino);
iput(inode);
return 0;
}
@@ -1845,7 +1846,7 @@ static int ext4_fc_replay_link_internal(struct super_block *sb,
dir = ext4_iget(sb, darg->parent_ino, EXT4_IGET_NORMAL);
if (IS_ERR(dir)) {
- ext4_debug("Dir with inode %d not found.", darg->parent_ino);
+ ext4_debug("Dir with inode %u not found.", darg->parent_ino);
dir = NULL;
goto out;
}
@@ -1897,7 +1898,8 @@ static int ext4_fc_replay_link(struct super_block *sb,
* Record all the modified inodes during replay. We use this later to setup
* block bitmaps correctly.
*/
-static int ext4_fc_record_modified_inode(struct super_block *sb, int ino)
+static int ext4_fc_record_modified_inode(struct super_block *sb,
+ unsigned int ino)
{
struct ext4_fc_replay_state *state;
int i;
@@ -1907,10 +1909,11 @@ static int ext4_fc_record_modified_inode(struct super_block *sb, int ino)
if (state->fc_modified_inodes[i] == ino)
return 0;
if (state->fc_modified_inodes_used == state->fc_modified_inodes_size) {
- int *fc_modified_inodes;
+ unsigned int *fc_modified_inodes;
fc_modified_inodes = krealloc(state->fc_modified_inodes,
- sizeof(int) * (state->fc_modified_inodes_size +
+ sizeof(*fc_modified_inodes) *
+ (state->fc_modified_inodes_size +
EXT4_FC_REPLAY_REALLOC_INCREMENT),
GFP_KERNEL);
if (!fc_modified_inodes)
@@ -1934,7 +1937,8 @@ static int ext4_fc_replay_inode(struct super_block *sb,
struct ext4_inode *raw_fc_inode;
struct inode *inode = NULL;
struct ext4_iloc iloc;
- int inode_len, ino, ret, tag = tl->fc_tag;
+ int inode_len, ret, tag = tl->fc_tag;
+ unsigned int ino;
struct ext4_extent_header *eh;
size_t off_gen = offsetof(struct ext4_inode, i_generation);
@@ -2058,7 +2062,7 @@ static int ext4_fc_replay_create(struct super_block *sb,
inode = ext4_iget(sb, darg.ino, EXT4_IGET_NORMAL);
if (IS_ERR(inode)) {
- ext4_debug("inode %d not found.", darg.ino);
+ ext4_debug("inode %u not found.", darg.ino);
inode = NULL;
ret = -EINVAL;
goto out;
@@ -2071,7 +2075,7 @@ static int ext4_fc_replay_create(struct super_block *sb,
*/
dir = ext4_iget(sb, darg.parent_ino, EXT4_IGET_NORMAL);
if (IS_ERR(dir)) {
- ext4_debug("Dir %d not found.", darg.ino);
+ ext4_debug("Dir %u not found.", darg.parent_ino);
ret = PTR_ERR(dir);
goto out;
}
@@ -2280,7 +2284,7 @@ ext4_fc_replay_del_range(struct super_block *sb, u8 *val)
inode = ext4_iget(sb, le32_to_cpu(lrange.fc_ino), EXT4_IGET_NORMAL);
if (IS_ERR(inode)) {
- ext4_debug("Inode %d not found", le32_to_cpu(lrange.fc_ino));
+ ext4_debug("Inode %u not found", le32_to_cpu(lrange.fc_ino));
return 0;
}
@@ -2338,7 +2342,7 @@ static int ext4_fc_set_bitmaps_and_counters(struct super_block *sb)
inode = ext4_iget(sb, state->fc_modified_inodes[i],
EXT4_IGET_NORMAL);
if (IS_ERR(inode)) {
- ext4_debug("Inode %d not found.",
+ ext4_debug("Inode %u not found.",
state->fc_modified_inodes[i]);
continue;
}
diff --git a/fs/ext4/fast_commit.h b/fs/ext4/fast_commit.h
index 2f77a37fb..446841c4b 100644
--- a/fs/ext4/fast_commit.h
+++ b/fs/ext4/fast_commit.h
@@ -110,8 +110,8 @@ enum {
*/
struct ext4_fc_dentry_update {
int fcd_op; /* Type of update create / unlink / link */
- int fcd_parent; /* Parent inode number */
- int fcd_ino; /* Inode number */
+ unsigned int fcd_parent; /* Parent inode number */
+ unsigned int fcd_ino; /* Inode number */
struct name_snapshot fcd_name; /* Dirent name */
struct list_head fcd_list;
struct list_head fcd_dilist;
@@ -153,7 +153,7 @@ struct ext4_fc_replay_state {
int fc_crc;
struct ext4_fc_alloc_region *fc_regions;
int fc_regions_size, fc_regions_used, fc_regions_valid;
- int *fc_modified_inodes;
+ unsigned int *fc_modified_inodes;
int fc_modified_inodes_used, fc_modified_inodes_size;
};
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 92e2243b9..4ad7a1809 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -817,7 +817,7 @@ static int find_inode_bit(struct super_block *sb, ext4_group_t group,
return 1;
}
-int ext4_mark_inode_used(struct super_block *sb, int ino)
+int ext4_mark_inode_used(struct super_block *sb, unsigned int ino)
{
unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
struct buffer_head *inode_bitmap_bh = NULL, *group_desc_bh = NULL;
base-commit: 008aad6508e30cd1bb6d2c2cf65221ba1f16a065
--
2.43.0
reply other threads:[~2026-11-23 2:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261123022309.990044-1-swinds24@gmail.com \
--to=swinds24@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
--cc=yi.zhang@huawei.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®