From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796491194; b=gTAurfVfC/nSoWV62DS422A8x0cfEJGl26KaJOdx1+0aVzkxLyjRF+/Z9BtBqARL2w/0 ma6ajKskUkKfpstAdq4jtxyf0YaZ92Su1iS4B2gPMmMbOY7oqbjMGPJeS3xOCeuZ0hv8a B1/ZIkOK/66IvlI/RTjhgQvIrYJ1xOV+cnoYJl6bqVHRiSs/em9tXS86QSFYUMa1X09Jf PkonuflDvAkqvs9n+vuT594deWliAPO1OnqWIFiRmyMm1YpngjIkQcjZxiX3EZsbAgQFo 2jiWyNMhrR5MNL7XOnrL6ouwGdtoxcTW6iZ0ed7W7QqRWyuSn40sHv5XcNaDQbbLs6w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796491194; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=/hJ6JelWx00M/gMYmfnAbSfMwau07d1EQy5xA3h9Q44=; b=EcTsBWXQ3KVzAeAruFzxp8rCne/JOYwwXV0qLqWKgM7MMXUxWIRYj7FIjt9nzG9V1ggM E/xUITgv4z9EdkJQ6ruzHKgopWBq+8fPWCYyKgE6upluAAb0bf7Tt77/jhJYzCy42A2AQ QVVsA5Hd2+zPZs+VmuUaUr06/y/eHqY55oAPrK/0qzcHmUKH61nzSnvtcWKaBw7tDAdAD IwqlyHYpO3va2D1y80SCVn97CelENhApURQRv3/dwstecnap2FUwnSMtEV1ZDjfLqFHb1 43buuAsro2uNPQazwVrBponvp+ABs65SOxGvbH4vg+tUhwDPS+hpu8yoKKybjk7IRCg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=Zpp8EFjv; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BAC3606A330 for ; Sat, 5 Dec 2026 17:19:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=Zpp8EFjv Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2922F1F0092B; Sat, 5 Dec 2026 17:19:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796491194; bh=/hJ6JelWx00M/gMYmfnAbSfMwau07d1EQy5xA3h9Q44=; h=Date:To:From:In-Reply-To:References:Subject; b=Zpp8EFjvVfqe1e5MTvA1/O+q0fe+9O9Lx1qXY9NIlUNYgbPNMVdHb3RJKU41lJn7Z Ggsh9NOB5zKA68eWRZ1ZSPokHSI0cE5RQ45RhYPTAli2A0VkVJ4WCqT38oEeYWUnBj H73jn8v1DkJ1s8QtLWLkbtPzE+FSRs8ZHnp34JpE= Date: Sat, 05 Dec 2026 09:19:53 -0800 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 From: Andrew Morton In-Reply-To: <20261205143959.704982-2-joseph.qi@linux.alibaba.com> References: <20261205143959.704982-2-joseph.qi@linux.alibaba.com> Subject: + ocfs2-add-new-ocfs2_map_blocks-to-introduce-iomap-feature.patch added to mm-nonmm-unstable branch Message-Id: <20261205171954.2922F1F0092B@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: ocfs2: Add new ocfs2_map_blocks() to introduce iomap feature has been added to the -mm mm-nonmm-unstable branch. Its filename is ocfs2-add-new-ocfs2_map_blocks-to-introduce-iomap-feature.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/ocfs2-add-new-ocfs2_map_blocks-to-introduce-iomap-feature.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 Subject: ocfs2: Add new ocfs2_map_blocks() to introduce iomap feature Date: Sat, 05 Dec 2026 22:39:50 +0800 Patch series "migrate ocfs2 DIO from buffer_head to iomap", v18. This patch set migrates ocfs2 Direct I/O (DIO) from the legacy buffer_head path to iomap, so ocfs2 stops being a user of __blockdev_direct_IO() and LEGACY_DIRECT_IO can be dropped. Reads are served by ocfs2_iomap_begin() over ocfs2_map_blocks(). Writes get a mapping of as many clusters as one struct iomap can describe, allocate their whole contiguous range with a single ocfs2_add_inode_data() call, and convert the unwritten extents at completion. The kiocb is the identity of the I/O across ->iomap_begin() and ->end_io(), so the unwritten records and the append-DIO orphan entry belong to a specific write instead of to a buffer_head. The overall design is as in v17: patch 6/10 reworks the write context, the folio preparation and the unwritten extent tracking for multi-cluster mappings. Unwritten extents become a range with an owner instead of one entry per cluster carrying a physical address; the physical cluster is looked up at conversion time with ocfs2_get_clusters_uncached(). The buffer_head path is ported onto this and still maps one cluster per call, so behaviour is unchanged. patch 7/10 switches the write path to iomap. ocfs2_dio_wr_map_blocks() replaces ocfs2_dio_wr_get_block() and hands out a mapping of as many clusters as one struct iomap can describe, up to 16MB, stopped at the first cluster of a different kind. Completion converts the recorded ranges and updates i_size. The orphan add and remove and the EOF gap zeroing move to ocfs2_file_write_iter(), where inode_lock() serializes the writers and IOMAP_DIO_FORCE_WAIT makes an extending write complete before the function returns. The kiocb passed in iomap_iter.private is the identity of the I/O, so the unwritten records belong to a specific write. ocfs2 no longer needs LEGACY_DIRECT_IO. The mapping waits for unwritten records belonging to another dio before it takes the re-write fast path, and the unwritten check distinguishes its own records from a foreign one. Those two arrive together: a completion that fails part way has already converted clusters and dropped the locks but still owns the records and is about to write the zeroed head/tail buffers over them, so the fast path must not hand them out first. Every path that falls back to generic_perform_write() upgrades the rw lock to EX, including the -ENOTBLK / zero-length bounce inside the direct branch. Under coherency=buffered a PR lock lets another node write the same range directly while this node does a read-modify-write in the page cache. The upgrade releases PR and takes EX as two requests, because a single upgrade can deadlock in the cluster lock manager when two nodes upgrade at once; the inode is re-prepared after the drop. patch 8/10 keeps sub-page O_DIRECT overwrites of already-written blocks direct. v12.1 demoted every non-page-aligned write when i_blocksize(inode) < PAGE_SIZE, which on 16K and 64K page kernels is every ocfs2 volume, so all sub-page overwrites took an exclusive rw lock and failed IOCB_NOWAIT. Probe the partial blocks at both ends with a no-create lookup and demote only for a hole, an unwritten extent, or an extending write. The probe runs after generic_write_checks() has resolved O_APPEND and clamped the length and ocfs2_prepare_inode_for_write() has refreshed the inode. patch 9/10 writes the zeroed head/tail buffers out at mapping time. They can be wholly beyond i_size until completion, and __block_write_full_folio() clears their dirty bit without submitting them, so the zeroes never reach the disk and the converted cluster exposes stale blocks. Submit every buffer first and wait in a second pass, so a cluster spanning many folios does not cost one round trip per folio. patch 10/10 makes buffered writes wait for in-flight direct writes before deferring zeroing and unwritten conversion to them. A dio that fails or ends short leaves the cluster unwritten while the buffered data sits in a dirty folio, and it reads back as zeroes once that folio is evicted. Known limitations left open deliberately: - ocfs2_page_mkwrite() still defers zeroing and unwritten conversion to an in-flight dio without waiting for it. A plain wait cannot be added there: it holds the inode cluster lock and ip_alloc_sem that ocfs2_dio_end_io_write() needs to convert, so waiting would deadlock against any in-flight dio's completion, and it holds no i_rwsem, so the unwritten set can grow while waiting. It is also reachable through get_user_pages() from bio_iov_iter_get_pages() when a direct read's destination buffer is an mmap of the same file. - a failed extending dio still leaves its orphan entry (OCFS2_DIO_ORPHANED_FL) and the clusters it allocated beyond i_size for recovery. The in-memory ownership marker is given up, so the next extending write recovers the entry through ocfs2_add_inode_to_orphan(), which truncates to i_size. An unlink before that still strands the inode, since ocfs2_delete_inode() refuses to wipe an inode with the flag set, until an unclean recovery. - a direct write into a large hole on fragmented free space still allocates a per-cluster descriptor array for the whole requested span before trimming it to a single extent, and re-scans the remaining clusters on each shortened mapping (up to 16MB, 4096 clusters with 4K clusters). This is a performance limitation, not a correctness one; see the TODO in ocfs2_alloc_write_ctxt(). ========== # test report Single node, o2cb cluster stack, on next-20261202, re-run on the v18 tip (7742103a974f). The v18 changes are validation-ordering, errno and minor cleanups; all results are identical to v17. ## ocfs2 testsuite single_run-WIP.sh -d /dev/vdb (40G), mkfs -b 4k -C 16k -N 4 --fs-features=usrquota,grpquota. 79 PASSED, 3 FAILED, total runtime 5936 seconds. Two failures are buildkernel data=writeback and data=ordered, both failing in 0-1 seconds on a missing buildkernel log file, unrelated to the filesystem, as in the pre-series baseline. The third, xattr_test, fails identically on the base kernel with this series removed (flistxattr ERANGE in the -b 512 -C 4096 case), so it is not introduced by this series. ## xfstests ./check -E ocfs2.exclude <90 generic DIO tests> mkfs -b 4k -C 16k -N 4 --fs-features=usrquota,grpquota 52 pass, 10 fail, 28 not run, about 3160 seconds. Per-test verdicts identical to the pre-conversion baseline. Failures: generic/091 generic/094 generic/219 generic/263 generic/326 generic/328 generic/521 generic/587 generic/617 generic/733 - all pre-existing. Also run on a 1M cluster volume, so clustersize > PAGE_SIZE and the head/tail folio paths actually execute: sub-cluster O_DIRECT zeroing reads back from disk correctly, and four concurrent O_DIRECT writers over a shared region complete without corruption. A sub-page test on a 1K block volume confirms written-block sub-page O_DIRECT overwrites stay direct and a demoted IOCB_NOWAIT write returns -EAGAIN without touching mtime. No WARNING, BUG or hung task in any run. One lockdep report is seen during generic/113, a mmap_lock -> ocfs2 inode cluster lock chain via ocfs2_mmap_prepare()/ocfs2_fiemap(); it does not fail the test and is in code this series does not change. Nico Schmidt also ran v14 on a two-node dm-multipath iSCSI SAN (mixed old and new DIO kernels): single-node fio/qemu-io O_DIRECT, two-node concurrent writes with crc32c cross-verification, and a SysRq-b crash/recovery test all passed with no data errors. ============= patchset history v1 patch set: https://lore.kernel.org/ocfs2-devel/20260724052559.15409-1-heming.zhao@suse.com/ v2 patch set: https://lore.kernel.org/ocfs2-devel/20260727061802.18485-1-heming.zhao@suse.com/ v3 patch set: https://lore.kernel.org/ocfs2-devel/20261018143319.22329-1-heming.zhao@suse.com/ v4 patch set: https://lore.kernel.org/ocfs2-devel/20261103135605.22943-1-heming.zhao@suse.com/ v5 patch set: https://lore.kernel.org/ocfs2-devel/20261105071930.16399-1-heming.zhao@suse.com/ v6 patch set: https://lore.kernel.org/ocfs2-devel/20261115154013.9379-1-heming.zhao@suse.com/ v7 patch set: https://lore.kernel.org/ocfs2-devel/20261118002050.9019-1-heming.zhao@suse.com/ v8 patch set: https://lore.kernel.org/ocfs2-devel/20261119064029.11910-1-heming.zhao@suse.com/ v9 patch set: https://lore.kernel.org/ocfs2-devel/20261120060014.12087-1-heming.zhao@suse.com/ v10 patch set: https://lore.kernel.org/ocfs2-devel/20261124045501.10281-1-heming.zhao@suse.com/ v11 patch set: https://lore.kernel.org/ocfs2-devel/20261124152623.7838-1-heming.zhao@suse.com/ v12 patch set: https://lore.kernel.org/ocfs2-devel/20261125154626.22335-1-heming.zhao@suse.com/ v12.1 patch set: https://lore.kernel.org/ocfs2-devel/20261127033313.9169-1-heming.zhao@suse.com/ v13 patch set: https://lore.kernel.org/ocfs2-devel/20261130100203.383093-1-joseph.qi@linux.alibaba.com/ v14 patch set: https://lore.kernel.org/ocfs2-devel/20261201100724.2909559-1-joseph.qi@linux.alibaba.com/ v15 patch set: https://lore.kernel.org/ocfs2-devel/20261202143507.1754776-1-joseph.qi@linux.alibaba.com/ v16 patch set: https://lore.kernel.org/ocfs2-devel/20261203124037.4112319-1-joseph.qi@linux.alibaba.com/ v17 patch set: https://lore.kernel.org/ocfs2-devel/20261205081923.4097763-1-joseph.qi@linux.alibaba.com/ This patch (of 10): As part of migrating OCFS2 DIO read/write code paths towards the modern and performant iomap framework, here introduces ocfs2_map_blocks() to replace the legacy, high-overhead buffer_head based block mapping routines. In addition, OCFS2_MAP_* flags are defined to bridge OCFS2 internal block mapping flags with the iomap API requirements. Subsequent iomap integration patches will build on this core block mapping routine. The implementation draws inspiration from ext4_map_blocks(). Link: https://lore.kernel.org/20261205143959.704982-1-joseph.qi@linux.alibaba.com Link: https://patch.msgid.link/20261205143959.704982-2-joseph.qi@linux.alibaba.com Signed-off-by: Heming Zhao Signed-off-by: Joseph Qi Signed-off-by: Andrew Morton Reviewed-by: Christoph Hellwig Reviewed-by: Joseph Qi Cc: Mark Fasheh Cc: Joel Becker fs/ocfs2/aops.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/aops.h | 2 + fs/ocfs2/ocfs2.h | 25 +++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) --- a/fs/ocfs2/aops.c~ocfs2-add-new-ocfs2_map_blocks-to-introduce-iomap-feature +++ a/fs/ocfs2/aops.c @@ -126,6 +126,77 @@ static int ocfs2_lock_get_block(struct i return ret; } +/* ocfs2 never allocates in this function */ +int ocfs2_map_blocks(struct inode *inode, struct ocfs2_map_block *map, + int flags) +{ + int err = 0; + unsigned int ext_flags; + u64 max_blocks = map->len; + u64 p_blkno, count, past_eof; + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); + int create = flags & OCFS2_GET_BLOCKS_CREATE; + + if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SYSTEM_FILE) + mlog(ML_NOTICE, "map_block on system inode 0x%p (%llu)\n", + inode, inode->i_ino); + + err = ocfs2_extent_map_get_blocks(inode, map->lblk, &p_blkno, &count, + &ext_flags); + if (err) { + mlog(ML_ERROR, "get_blocks() failed, inode: 0x%p, " + "block: %llu\n", inode, map->lblk); + goto bail; + } + + if (max_blocks < count) + count = max_blocks; + + map->pblk = p_blkno; + map->len = count; + + /* + * A truncate raced us and removed the cluster on a sparse file + * system. Bail with the flags clear: the read caller reports + * IOMAP_HOLE, while the create caller (the direct-write re-write + * probe) instead allocates the cluster, so a write is never handed + * IOMAP_HOLE, which iomap_dio_iter() rejects. + */ + if (create && map->pblk == 0 && ocfs2_sparse_alloc(osb)) + goto bail; + + if (p_blkno) { + if (ext_flags & OCFS2_EXT_UNWRITTEN) + map->flags |= OCFS2_MAP_UNWRITTEN; + else + map->flags |= OCFS2_MAP_MAPPED; + } + + if (!ocfs2_sparse_alloc(osb)) { + if (map->pblk == 0) { + err = -EIO; + mlog(ML_ERROR, + "iblock = %llu p_blkno = %llu blkno=(%llu)\n", + (unsigned long long)map->lblk, + (unsigned long long)map->pblk, + (unsigned long long)OCFS2_I(inode)->ip_blkno); + mlog(ML_ERROR, "Size %llu, clusters %u\n", + (unsigned long long)i_size_read(inode), + OCFS2_I(inode)->ip_clusters); + dump_stack(); + goto bail; + } + } + + past_eof = ocfs2_blocks_for_bytes(inode->i_sb, i_size_read(inode)); + + if (create && (map->lblk >= past_eof)) + map->flags |= OCFS2_MAP_NEW; + +bail: + return err; +} + int ocfs2_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create) { --- a/fs/ocfs2/aops.h~ocfs2-add-new-ocfs2_map_blocks-to-introduce-iomap-feature +++ a/fs/ocfs2/aops.h @@ -42,6 +42,8 @@ int ocfs2_size_fits_inline_data(struct b int ocfs2_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create); +int ocfs2_map_blocks(struct inode *inode, struct ocfs2_map_block *map, + int flags); /* all ocfs2_dio_end_io()'s fault */ #define ocfs2_iocb_is_rw_locked(iocb) \ test_bit(0, (unsigned long *)&iocb->private) --- a/fs/ocfs2/ocfs2.h~ocfs2-add-new-ocfs2_map_blocks-to-introduce-iomap-feature +++ a/fs/ocfs2/ocfs2.h @@ -515,7 +515,30 @@ struct ocfs2_super struct ocfs2_filecheck_sysfs_entry osb_fc_ent; }; -#define OCFS2_SB(sb) ((struct ocfs2_super *)(sb)->s_fs_info) +/* + * Logical to physical block mapping, used by ocfs2_map_blocks() + * + * This structure is used to pass requests into ocfs2_map_blocks() + * as well as to store the information returned by ocfs2_map_blocks(). + * It takes less room on the stack than a struct buffer_head. + */ +#define OCFS2_MAP_NEW BIT(BH_New) +#define OCFS2_MAP_MAPPED BIT(BH_Mapped) +#define OCFS2_MAP_UNWRITTEN BIT(BH_Unwritten) +#define OCFS2_MAP_FLAGS (OCFS2_MAP_NEW | OCFS2_MAP_MAPPED |\ + OCFS2_MAP_UNWRITTEN) + +struct ocfs2_map_block { + u64 pblk; /* physical block# */ + u64 lblk; /* logical block# */ + u64 len; /* number of block */ + unsigned int flags; +}; + +/* Flags used by ocfs2_map_blocks() */ +#define OCFS2_GET_BLOCKS_CREATE (0x0001) + +#define OCFS2_SB(sb) ((struct ocfs2_super *)(sb)->s_fs_info) /* Useful typedef for passing around journal access functions */ typedef int (*ocfs2_journal_access_func)(handle_t *handle, _ 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