From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Davy Felipe <davyfelipe34@gmail.com>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Yangtao Li <frank.li@vivo.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] hfs: handle extent B-tree write errors
Date: Wed, 23 Sep 2026 12:37:19 -0700 [thread overview]
Message-ID: <c569d5f8ee542e5c86a7e4dee23df99f4ec0becd.camel@dubeyko.com> (raw)
In-Reply-To: <20260922234039.1307375-1-davyfelipe34@gmail.com>
On Tue, 2026-09-22 at 20:40 -0300, Davy Felipe wrote:
> __hfs_ext_write_extent() does not report all failures while updating
> the extents B-tree.
>
> When inserting a new extent record, the return value of
> hfs_brec_insert() is ignored and HFS_FLG_EXT_DIRTY and
> HFS_FLG_EXT_NEW
> are cleared even if the insertion fails.
>
> When updating an existing extent record, hfs_bnode_write() returns
> void, so its caller cannot detect a rejected write. Validate the
> extent
> record size and node range before calling hfs_bnode_write().
>
> Propagate errors returned by hfs_brec_insert() and return -EIO for an
> invalid existing extent record. Only clear the extent dirty flags
> after
> a successful operation.
>
> Fault injection confirmed both failure paths. Insertion errors are
> propagated to the caller, and invalid existing-record writes are
> rejected before hfs_bnode_write() without clearing the dirty state.
>
> Signed-off-by: Davy Felipe <davyfelipe34@gmail.com>
>
> Changes in v2:
> - Validate the existing extent record size and node range before
> calling hfs_bnode_write(), following review feedback.
> - Return -EIO without clearing HFS_FLG_EXT_DIRTY when validation
> fails.
> - Fault-injection tested the existing-record failure path. Before the
> change, hfs_bnode_write() rejected an invalid offset internally but
> __hfs_ext_write_extent() continued and cleared the dirty flag. With
> v2, the invalid write is rejected before hfs_bnode_write().
>
> ---
> fs/hfs/extent.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/fs/hfs/extent.c b/fs/hfs/extent.c
> index f066a99a863b..13426503fbb3 100644
> --- a/fs/hfs/extent.c
> +++ b/fs/hfs/extent.c
> @@ -121,12 +121,21 @@ static int __hfs_ext_write_extent(struct inode
> *inode, struct hfs_find_data *fd)
> res = hfs_bmap_reserve(fd->tree, fd->tree->depth +
> 1);
> if (res)
> return res;
> - hfs_brec_insert(fd, HFS_I(inode)->cached_extents,
> sizeof(hfs_extent_rec));
> + res = hfs_brec_insert(fd, HFS_I(inode)-
> >cached_extents,
> + sizeof(hfs_extent_rec));
> + if (res)
> + return res;
> HFS_I(inode)->flags &=
> ~(HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW);
> } else {
> if (res)
> return res;
> - hfs_bnode_write(fd->bnode, HFS_I(inode)-
> >cached_extents, fd->entryoffset, fd->entrylength);
> + if (fd->entrylength != sizeof(hfs_extent_rec) ||
> + fd->entryoffset < 0 ||
> + (u64)fd->entryoffset + fd->entrylength >
> + fd->tree->node_size)
I think it will be better to introduce a small check function that can
be reused then. And code will be cleaner here. What do you think?
> + return -EIO;
> + hfs_bnode_write(fd->bnode, HFS_I(inode)-
> >cached_extents,
> + fd->entryoffset, fd->entrylength);
I see that you are trying not to go into huge modification. But,
frankly speaking, I believe we need the refactoring of
hfs_bnode_write() calling. This function should return error code and
we need to process this error code in other methods. Maybe, future
refactoring work for you? ;)
Thanks,
Slava.
> HFS_I(inode)->flags &= ~HFS_FLG_EXT_DIRTY;
> }
> return 0;
next prev parent reply other threads:[~2026-09-23 19:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 16:02 [PATCH] hfs: propagate extent B-tree insertion errors Davy Felipe
2026-09-21 21:19 ` Viacheslav Dubeyko
2026-09-23 23:08 ` [PATCH v3] hfs: handle extent B-tree write errors Davy Felipe
2026-09-22 23:40 ` [PATCH v2] " Davy Felipe
2026-09-23 19:37 ` Viacheslav Dubeyko [this message]
2026-09-23 22:14 ` Davy Felipe
2026-09-24 0:16 ` [PATCH v4] " Davy Felipe
2026-09-24 19:23 ` Viacheslav Dubeyko
2026-09-24 20:53 ` Davy Felipe
2026-09-24 23:10 ` [PATCH v5] " Davy Felipe
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=c569d5f8ee542e5c86a7e4dee23df99f4ec0becd.camel@dubeyko.com \
--to=slava@dubeyko.com \
--cc=davyfelipe34@gmail.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@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 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®