From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: Heming Zhao <heming.zhao@suse.com>,
mark@fasheh.com, jlbec@evilplan.org, hch@lst.de
Cc: ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v10 3/3] ocfs2: switch dio write path from buffer_head to iomap
Date: Tue, 24 Nov 2026 18:56:59 +0800 [thread overview]
Message-ID: <f59ba679-8c22-4ec2-8799-af24d4fd7158@linux.alibaba.com> (raw)
In-Reply-To: <20261124045501.10281-4-heming.zhao@suse.com>
On 11/24/26 12:54 PM, Heming Zhao wrote:
> Converts OCFS2's DIO write path from the legacy buffer_head
> infrastructure to the modern iomap framework.
>
> The buffer_head based ocfs2_dio_wr_get_block() is replaced by
> ocfs2_dio_wr_map_blocks(). Instead of one cluster per call, it now
> hands iomap a mapping of as many clusters as can be described by a
> single struct iomap: up to 16MB, stopped at the first cluster that is
> not of the same kind as the first one (hole, unwritten, written).
>
> Implement ocfs2_dio_end_io() and ocfs2_dio_end_io_write() to handle IO
> completion. They convert UNWRITTEN extents, updates inode size (EOF).
>
> In the buffer_head path, ocfs2_dio_wr_get_block() stores dwc in
> bh->b_private, enabling it to detect the first call for an IO chunk and
> invoke ocfs2_add_inode_to_orphan() to protect the extent allocation.
> However, iomap doesn't provide a similar private field. Therefore, moves
> ocfs2_add_inode_to_orphan() from ocfs2_dio_wr_map_blocks(the buffer_head
> counterpart to ocfs2_dio_wr_get_block()) to ocfs2_file_write_iter().
>
> It is also impossible t pass The dwc to iomap_dio_ops.end_io, the iomap
> ->end_io callback cannot effectively distinguish between I/Os initiated
> by different threads concurrently. For example, when multiple DIO write
> threads operate on the same inode concurrently, the end_io callback
> without the dwc context may incorrectly delete an orphan inode created
> by another thread, leading to a crash. The fix is to move the orphan
> inode deletion from end_io into ocfs2_file_write_iter(). In
> ocfs2_file_write_iter(), inode_lock() serializes the write threads,
> and IOMAP_DIO_FORCE_WAIT ensures that the function only returns after
> the bio completes. This guarantees that i_size has already been
> updated when ocfs2_dio_del_orphan() is called.
>
> iomap calls ->iomap_begin() once per mapping but ->end_io() once per io,
> and the latter only gets the kiocb, so the kiocb is used as the identity
> of the io: ocfs2_file_write_iter() passes it in iomap_iter.private,
> ocfs2_iomap_next() forwards it to ocfs2_dio_wr_map_blocks(), and each
> unwritten record stores it in ue_owner with the cluster range it covers.
>
> Doesn't like ocfs2_dio_wr_get_block(), move the zero operations from
> ocfs2_dio_wr_map_blocks() to ocfs2_file_write_iter(). If do the zeroing
> in ocfs2_dio_wr_map_blocks() would zero blocks that earlier mappings of
> this same dio have already written, as i_size is only updated at dio
> completion. this will makes xfstests generic/538 failure.
>
> Assisted-by: LLM
> Co-developed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> Signed-off-by: Heming Zhao <heming.zhao@suse.com>
> ---
> fs/ocfs2/Kconfig | 1 -
> fs/ocfs2/aops.c | 1600 +++++++++++++++++++++++++++++++----------
> fs/ocfs2/aops.h | 36 +-
> fs/ocfs2/extent_map.c | 34 +-
> fs/ocfs2/extent_map.h | 3 +
> fs/ocfs2/file.c | 282 +++++++-
> fs/ocfs2/inode.h | 9 +
> fs/ocfs2/mmap.c | 2 +-
> fs/ocfs2/super.c | 3 +
> 9 files changed, 1509 insertions(+), 461 deletions(-)
>
...
> + /* The allocation below sleeps on locks. */
> + if (flags & IOMAP_NOWAIT)
> + return -EAGAIN;
>
I've made a mistake in last review thread.
We can't just move this check before fast path, but have to use trylock in
ocfs2_lock_map_blocks().
e.g.
static int ocfs2_lock_map_blocks(struct inode *inode,
struct ocfs2_map_block *map, int flags,
bool nowait)
{
...
if (nowait) {
if (!down_read_trylock(&oi->ip_alloc_sem))
return -EAGAIN;
} else {
down_read(&oi->ip_alloc_sem);
}
...
}
And pass 'flags & IOMAP_NOWAIT' in caller.
Thanks,
Joseph
> - dwc = ocfs2_dio_alloc_write_ctx(bh_result, &first_get_block);
> - if (unlikely(dwc == NULL)) {
> - ret = -ENOMEM;
> - mlog_errno(ret);
> - goto out;
> + /*
> + * This is the fast path for re-write. The range which is in the file
> + * has nothing to allocate nor to convert if it is mapped already. What
> + * changes the file size is done at the end of io, no matter what the
> + * mappings were.
> + */
> + if (lblk < eof_blk) {
> + probe = *map;
> + probe.flags = 0;
> + ret = ocfs2_lock_map_blocks(inode, &probe,
> + OCFS2_GET_BLOCKS_CREATE);
> + if (ret == 0 && (probe.flags & OCFS2_MAP_MAPPED) &&
> + !(probe.flags & OCFS2_MAP_NEW)) {
> + *map = probe;
> + return 0;
> + }
> + ret = 0;
> }
>
...
next prev parent reply other threads:[~2026-11-24 10:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 4:54 [RFC PATCH v10 0/3] migrate ocfs2 DIO " Heming Zhao
2026-11-24 4:54 ` [RFC PATCH v10 1/3] ocfs2: Add new ocfs2_map_blocks() to introduce iomap feature Heming Zhao
2026-11-24 4:54 ` [RFC PATCH v10 2/3] ocfs2: switch DIO read path from buffer_head to iomap Heming Zhao
2026-11-24 9:47 ` Joseph Qi
2026-11-24 4:54 ` [RFC PATCH v10 3/3] ocfs2: switch dio write " Heming Zhao
2026-11-24 10:56 ` Joseph Qi [this message]
2026-11-24 11:04 ` Joseph Qi
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=f59ba679-8c22-4ec2-8799-af24d4fd7158@linux.alibaba.com \
--to=joseph.qi@linux.alibaba.com \
--cc=hch@lst.de \
--cc=heming.zhao@suse.com \
--cc=jlbec@evilplan.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark@fasheh.com \
--cc=ocfs2-devel@lists.linux.dev \
/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®