From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,mark@fasheh.com,joseph.qi@linux.alibaba.com,
jlbec@evilplan.org,hch@lst.de,heming.zhao@suse.com,akpm@linux-foundation.org
Subject: + ocfs2-switch-dio-read-path-from-buffer_head-to-iomap.patch added to mm-nonmm-unstable branch
Date: Sat, 05 Dec 2026 09:19:57 -0800 [thread overview]
Message-ID: <20261205171957.AC9A21F00A10@smtp.kernel.org> (raw)
In-Reply-To: <20261205143959.704982-3-joseph.qi@linux.alibaba.com>
The patch titled
Subject: ocfs2: switch DIO read path from buffer_head to iomap
has been added to the -mm mm-nonmm-unstable branch. Its filename is
ocfs2-switch-dio-read-path-from-buffer_head-to-iomap.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/ocfs2-switch-dio-read-path-from-buffer_head-to-iomap.patch
This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Heming Zhao <heming.zhao@suse.com>
Subject: ocfs2: switch DIO read path from buffer_head to iomap
Date: Sat, 05 Dec 2026 22:39:51 +0800
Migrates the DIO read path from the legacy buffer_head infrastructure
to the modern and more efficient iomap framework.
Under the current code, ocfs2 holds a cluster lock during DIO via
ocfs2_iocb_set_rw_locked(), and releases the cluster lock in
ocfs2_dio_end_io() via ocfs2_iocb_clear_rw_locked(). The lock level is
stashed in iocb->private.
However, iomap DIO owns that field (it stores a bio there for polled I/O
and unconditionally clears it before calling ->end_io). Any side-channel
state packed into iocb->private is corrupted, which trips the end_io
lock-state check.
Instead, encode the unlock level by passing distinct iomap_dio_ops methods
e.g.: ocfs2_iomap_dio_ops_r_pr ocfs2_iomap_dio_ops_w_pr for PRMODE or
ocfs2_iomap_dio_ops_w_ex for EXMODE. Also note that the ops_w_{pr|ex} are
defined in a later patch.
Additionally, the *_iter() functions use the split __iomap_dio_rw() +
iomap_dio_complete() API so they can determine unambiguously, from the
return value, whether the completion handler already dropped the lock
(real I/O, sync or -EIOCBQUEUED) or whether the caller must drop it
(no I/O issued, or buffered fallback).
The new function ocfs2_iomap_begin() performs a similar role to
ocfs2_get_block(). While ocfs2_get_block() retrieves only one block per
call, ocfs2_iomap_begin() can handle multiple blocks at once.
Link: https://patch.msgid.link/20261205143959.704982-3-joseph.qi@linux.alibaba.com
Signed-off-by: Heming Zhao <heming.zhao@suse.com>
Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Co-developed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
fs/ocfs2/Kconfig | 1
fs/ocfs2/aops.c | 118 +++++++++++++++++++++++++++++++++++++++++++--
fs/ocfs2/aops.h | 5 +
fs/ocfs2/file.c | 67 ++++++++++++++++++++++---
4 files changed, 179 insertions(+), 12 deletions(-)
--- a/fs/ocfs2/aops.c~ocfs2-switch-dio-read-path-from-buffer_head-to-iomap
+++ a/fs/ocfs2/aops.c
@@ -4,6 +4,7 @@
*/
#include <linux/fs.h>
+#include <linux/iomap.h>
#include <linux/slab.h>
#include <linux/highmem.h>
#include <linux/pagemap.h>
@@ -126,6 +127,19 @@ static int ocfs2_lock_get_block(struct i
return ret;
}
+static int ocfs2_lock_map_blocks(struct inode *inode,
+ struct ocfs2_map_block *map, int flags)
+{
+ int ret = 0;
+ struct ocfs2_inode_info *oi = OCFS2_I(inode);
+
+ down_read(&oi->ip_alloc_sem);
+ ret = ocfs2_map_blocks(inode, map, flags);
+ up_read(&oi->ip_alloc_sem);
+
+ return ret;
+}
+
/* ocfs2 never allocates in this function */
int ocfs2_map_blocks(struct inode *inode, struct ocfs2_map_block *map,
int flags)
@@ -172,8 +186,11 @@ int ocfs2_map_blocks(struct inode *inode
map->flags |= OCFS2_MAP_MAPPED;
}
+ past_eof = ocfs2_blocks_for_bytes(inode->i_sb, i_size_read(inode));
+
if (!ocfs2_sparse_alloc(osb)) {
- if (map->pblk == 0) {
+ /* detected a hole (unallocated extent) in a file */
+ if (map->pblk == 0 && map->lblk < past_eof) {
err = -EIO;
mlog(ML_ERROR,
"iblock = %llu p_blkno = %llu blkno=(%llu)\n",
@@ -188,8 +205,6 @@ int ocfs2_map_blocks(struct inode *inode
}
}
- past_eof = ocfs2_blocks_for_bytes(inode->i_sb, i_size_read(inode));
-
if (create && (map->lblk >= past_eof))
map->flags |= OCFS2_MAP_NEW;
@@ -2533,6 +2548,103 @@ static ssize_t ocfs2_direct_IO(struct ki
ocfs2_dio_end_io, 0);
}
+static int ocfs2_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
+ unsigned int flags, struct iomap *iomap, struct iomap *srcmap)
+{
+ int ret;
+ struct ocfs2_map_block map;
+ u8 blkbits = inode->i_blkbits;
+ u64 max_lblk = (inode->i_sb->s_maxbytes - 1) >> blkbits;
+
+ if ((offset >> blkbits) > max_lblk) {
+ if (flags & IOMAP_WRITE)
+ return -EINVAL;
+ /*
+ * A read past the last possible block: report a hole so iomap
+ * reverts the iterator and returns a short read up to i_size,
+ * rather than failing a read that straddles s_maxbytes with
+ * -EINVAL as __blockdev_direct_IO() used to short-read it.
+ */
+ iomap->bdev = inode->i_sb->s_bdev;
+ iomap->offset = offset;
+ iomap->length = length;
+ iomap->type = IOMAP_HOLE;
+ iomap->addr = IOMAP_NULL_ADDR;
+ return 0;
+ }
+
+ /*
+ * Calculate the first and last logical blocks respectively.
+ */
+ map.lblk = offset >> blkbits;
+ map.len = min_t(loff_t, (offset + length - 1) >> blkbits,
+ max_lblk) - map.lblk + 1;
+ map.flags = 0;
+
+ if (flags & IOMAP_WRITE) {
+ return -EOPNOTSUPP;
+ }
+
+ ret = ocfs2_lock_map_blocks(inode, &map, 0);
+ if (ret < 0)
+ return ret;
+
+ iomap->bdev = inode->i_sb->s_bdev;
+ iomap->offset = (u64)map.lblk << blkbits;
+ iomap->length = (u64)map.len << blkbits;
+
+ if (map.pblk == 0) {
+ iomap->type = IOMAP_HOLE;
+ iomap->addr = IOMAP_NULL_ADDR;
+ } else {
+ if (map.flags & OCFS2_MAP_UNWRITTEN) {
+ iomap->type = IOMAP_UNWRITTEN;
+ } else if (map.flags & OCFS2_MAP_MAPPED) {
+ iomap->type = IOMAP_MAPPED;
+ } else {
+ WARN_ON_ONCE(1);
+ return -EIO;
+ }
+ iomap->addr = (sector_t)map.pblk << blkbits;
+ }
+
+ if (map.flags & OCFS2_MAP_NEW)
+ iomap->flags |= IOMAP_F_NEW;
+
+ return 0;
+}
+
+int ocfs2_iomap_next(const struct iomap_iter *iter, struct iomap *iomap,
+ struct iomap *srcmap)
+{
+ int ret;
+
+ if (iomap->length) {
+ ret = iomap_iter_continue(iter, iomap, srcmap, 0);
+ if (ret <= 0)
+ return ret;
+ }
+
+ ret = ocfs2_iomap_begin(iter->inode, iter->pos, iter->len, iter->flags,
+ iomap, srcmap);
+ return ret < 0 ? ret : 1;
+}
+
+static int ocfs2_dio_end_io_r_pr(struct kiocb *iocb, ssize_t size,
+ int error, unsigned int flags)
+{
+ struct inode *inode = file_inode(iocb->ki_filp);
+
+ /* Read errors go to userspace, not the log, as in ext4 and xfs. */
+ ocfs2_rw_unlock(inode, 0);
+
+ return error;
+}
+
+const struct iomap_dio_ops ocfs2_iomap_dio_ops_r_pr = {
+ .end_io = ocfs2_dio_end_io_r_pr,
+};
+
const struct address_space_operations ocfs2_aops = {
.dirty_folio = block_dirty_folio,
.read_folio = ocfs2_read_folio,
--- a/fs/ocfs2/aops.h~ocfs2-switch-dio-read-path-from-buffer_head-to-iomap
+++ a/fs/ocfs2/aops.h
@@ -7,6 +7,11 @@
#define OCFS2_AOPS_H
#include <linux/fs.h>
+#include <linux/iomap.h>
+
+extern const struct iomap_dio_ops ocfs2_iomap_dio_ops_r_pr;
+int ocfs2_iomap_next(const struct iomap_iter *iter, struct iomap *iomap,
+ struct iomap *srcmap);
int ocfs2_map_folio_blocks(struct folio *folio, u64 *p_blkno,
struct inode *inode, unsigned int from,
--- a/fs/ocfs2/file.c~ocfs2-switch-dio-read-path-from-buffer_head-to-iomap
+++ a/fs/ocfs2/file.c
@@ -9,6 +9,7 @@
#include <linux/capability.h>
#include <linux/fs.h>
+#include <linux/iomap.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/highmem.h>
@@ -2399,6 +2400,26 @@ out:
return ret;
}
+static bool ocfs2_should_use_dio(struct kiocb *iocb, struct iov_iter *iter,
+ struct inode *inode)
+{
+ struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+
+ /*
+ * Fallback to buffered I/O if we see an inode without
+ * extents.
+ */
+ if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)
+ return false;
+
+ /* Fallback to buffered I/O if we do not support append dio. */
+ if (iocb->ki_pos + iter->count > i_size_read(inode) &&
+ !ocfs2_supports_append_dio(osb))
+ return false;
+
+ return true;
+}
+
static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
struct iov_iter *from)
{
@@ -2588,7 +2609,8 @@ static ssize_t ocfs2_file_read_iter(stru
if (!direct_io && nowait)
return -EOPNOTSUPP;
- ocfs2_iocb_init_rw_locked(iocb);
+ if (!iov_iter_count(to))
+ return 0; /* skip atime */
/*
* buffered reads protect themselves in ->read_folio(). O_DIRECT reads
@@ -2606,8 +2628,6 @@ static ssize_t ocfs2_file_read_iter(stru
goto bail;
}
rw_level = 0;
- /* communicate with ocfs2_dio_end_io */
- ocfs2_iocb_set_rw_locked(iocb, rw_level);
}
/*
@@ -2628,17 +2648,46 @@ static ssize_t ocfs2_file_read_iter(stru
}
ocfs2_inode_unlock(inode, lock_level);
- ret = generic_file_read_iter(iocb, to);
+ if (direct_io && ocfs2_should_use_dio(iocb, to, inode)) {
+ /*
+ * Use the split iomap DIO API so we can tell who owns the
+ * rw_lock on return; reads always hold it at PR level, dropped
+ * by ocfs2_iomap_dio_ops_r_pr(). Call it directly rather than
+ * through generic_file_read_iter(): iomap advances iocb->ki_pos
+ * itself, so the generic helper would advance ki_pos twice.
+ */
+ struct iomap_dio *dio;
+
+ dio = __iomap_dio_rw(iocb, to, ocfs2_iomap_next,
+ &ocfs2_iomap_dio_ops_r_pr, 0, NULL, 0);
+ if (dio == NULL) {
+ /* No I/O issued; rw_lock still held. */
+ ret = 0;
+ } else if (IS_ERR(dio)) {
+ ret = PTR_ERR(dio);
+ if (ret == -EIOCBQUEUED)
+ rw_level = -1;
+ } else {
+ ret = iomap_dio_complete(dio);
+ rw_level = -1;
+ }
+ /*
+ * iomap does not update atime, and calling __iomap_dio_rw()
+ * directly bypasses generic_file_read_iter(), which would have
+ * done it for DIO. Use the struct file: the kiocb may already
+ * be freed after an async submission (-EIOCBQUEUED).
+ */
+ file_accessed(filp);
+ /* never fall back to buffered read */
+ } else {
+ iocb->ki_flags &= ~IOCB_DIRECT;
+ ret = generic_file_read_iter(iocb, to);
+ }
trace_generic_file_read_iter_ret(ret);
/* buffered aio wouldn't have proper lock coverage today */
BUG_ON(ret == -EIOCBQUEUED && !direct_io);
- /* see ocfs2_file_write_iter */
- if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) {
- rw_level = -1;
- }
-
bail:
if (rw_level != -1)
ocfs2_rw_unlock(inode, rw_level);
--- a/fs/ocfs2/Kconfig~ocfs2-switch-dio-read-path-from-buffer_head-to-iomap
+++ a/fs/ocfs2/Kconfig
@@ -7,6 +7,7 @@ config OCFS2_FS
select CRC32
select QUOTA
select QUOTA_TREE
+ select FS_IOMAP
select FS_POSIX_ACL
select LEGACY_DIRECT_IO
help
_
Patches currently in -mm which might be from heming.zhao@suse.com are
ocfs2-add-new-ocfs2_map_blocks-to-introduce-iomap-feature.patch
ocfs2-switch-dio-read-path-from-buffer_head-to-iomap.patch
ocfs2-add-ocfs2_get_clusters_uncached.patch
ocfs2-refactor-ocfs2_lock_allocators-and-add-a-dio-variant.patch
ocfs2-record-the-fsync-transaction-when-cow-makes-clusters-writable.patch
ocfs2-rework-the-direct-write-context-for-multi-cluster-mappings.patch
ocfs2-switch-dio-write-path-from-buffer_head-to-iomap.patch
next prev parent reply other threads:[~2026-12-05 17:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 14:39 [PATCH v18 00/10] migrate ocfs2 DIO from buffer_head to iomap Joseph Qi
2026-12-05 14:39 ` [PATCH v18 01/10] ocfs2: Add new ocfs2_map_blocks() to introduce iomap feature Joseph Qi
2026-12-05 17:19 ` + ocfs2-add-new-ocfs2_map_blocks-to-introduce-iomap-feature.patch added to mm-nonmm-unstable branch Andrew Morton
2026-12-05 14:39 ` [PATCH v18 02/10] ocfs2: switch DIO read path from buffer_head to iomap Joseph Qi
2026-12-05 17:19 ` Andrew Morton [this message]
2026-12-05 14:39 ` [PATCH v18 03/10] ocfs2: add ocfs2_get_clusters_uncached() Joseph Qi
2026-12-05 17:20 ` + ocfs2-add-ocfs2_get_clusters_uncached.patch added to mm-nonmm-unstable branch Andrew Morton
2026-12-05 14:39 ` [PATCH v18 04/10] ocfs2: refactor ocfs2_lock_allocators() and add a dio variant Joseph Qi
2026-12-05 17:20 ` + ocfs2-refactor-ocfs2_lock_allocators-and-add-a-dio-variant.patch added to mm-nonmm-unstable branch Andrew Morton
2026-12-05 14:39 ` [PATCH v18 05/10] ocfs2: record the fsync transaction when CoW makes clusters writable Joseph Qi
2026-12-05 17:20 ` + ocfs2-record-the-fsync-transaction-when-cow-makes-clusters-writable.patch added to mm-nonmm-unstable branch Andrew Morton
2026-12-05 14:39 ` [PATCH v18 06/10] ocfs2: rework the direct write context for multi-cluster mappings Joseph Qi
2026-12-05 17:20 ` + ocfs2-rework-the-direct-write-context-for-multi-cluster-mappings.patch added to mm-nonmm-unstable branch Andrew Morton
2026-12-05 14:39 ` [PATCH v18 07/10] ocfs2: switch dio write path from buffer_head to iomap Joseph Qi
2026-12-05 17:20 ` + ocfs2-switch-dio-write-path-from-buffer_head-to-iomap.patch added to mm-nonmm-unstable branch Andrew Morton
2026-12-05 14:39 ` [PATCH v18 08/10] ocfs2: keep sub-page overwrites of written blocks on direct I/O Joseph Qi
2026-12-05 17:20 ` + ocfs2-keep-sub-page-overwrites-of-written-blocks-on-direct-i-o.patch added to mm-nonmm-unstable branch Andrew Morton
2026-12-05 14:39 ` [PATCH v18 09/10] ocfs2: write the dio zeroed head/tail buffers out before completion Joseph Qi
2026-12-05 17:20 ` + ocfs2-write-the-dio-zeroed-head-tail-buffers-out-before-completion.patch added to mm-nonmm-unstable branch Andrew Morton
2026-12-05 14:39 ` [PATCH v18 10/10] ocfs2: make buffered writes wait for in-flight direct writes Joseph Qi
2026-12-05 17:20 ` + ocfs2-make-buffered-writes-wait-for-in-flight-direct-writes.patch added to mm-nonmm-unstable branch Andrew Morton
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=20261205171957.AC9A21F00A10@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=hch@lst.de \
--cc=heming.zhao@suse.com \
--cc=jlbec@evilplan.org \
--cc=joseph.qi@linux.alibaba.com \
--cc=mark@fasheh.com \
--cc=mm-commits@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.