From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.100 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796481607; b=0PWryJrdvbP2BVZsHMNpbUGvZhvjVKUoFaqBDVXfAsTsEUAPJkUZFp1UuPAlQCMd4IcH C9NhZ9rb9+H4DIUudlf4Y4Sww5snRqzHIgYp49l5h0I2GOVbmNXeTMopECxqvS6QqeGoc StvORHb22E9s2GbjeUDfqU0NVbelNV/EZNkcjSL/jQefViNeotFvS2hqBSr5XeK+yIAP/ Q1S8bjMuJhUxBPi0hZqnmg9N3gtxRn068bF3MHdTrifhJgH1L6RPUjSpbTuZtvUo+B8cv oJwavyO0IC/Z0cF25IefgzJeFh95zCm4Tso0ZSeTVMVMDWJrb+nw6JezkkhJYpUWZRQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796481607; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=kOiHAKcFgT6ZzQ7YSZTEkvTArmAzbKPFoj6FiRpzFu4=; b=jOoGCmWz7paCStfBC/QkrEqlqCrf2RZwl52OdgqhgSy+o8/JvfCmK7Wls0m+LQ2J+zSx +RrIlVsCDpVbSEPp5P3GZUmn4FRf3HYyZcfRUXxTljcRZDxqPq8jA2nH0IT5NSY9fIt6L hQzAzc2xefe1TK4f9hTY0ZBELRFabA2GRYs13/xdxXyNpCKCIoEKO7GZZs41nSdvq+tNO tAZUS4G2pvG+YJFWE5GUZRCyWsl1Bb1CNLccPU3XuiG4eiCA2qY7rcsOdloJkg25vG5Ez gvPeOFnmZbToOdRZyhGUosu9huLhH+aq3146WoukLR2M182lw3JNXmX8a9/iequBoJw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=IVK+5mt6; arc=none smtp.remote-ip=115.124.30.100 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 049EA606A330 for ; Sat, 5 Dec 2026 14:40:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 049EA606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=IVK+5mt6 DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796481602; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=kOiHAKcFgT6ZzQ7YSZTEkvTArmAzbKPFoj6FiRpzFu4=; b=IVK+5mt6/SylMfj/vNRTfyOJT0NIv/F4V6kf/gGgbTxM+J3YL8NVSoOx8350rT+VgeUl3LkBEXK7epJicgTlD2iwSOjLF+9Igbneaygn27dmoEEHmxpEAmPyQ8yFzJHhnXjuZe1e0VPRyvVHZnoriHBugSO36NgwKqQDlhxni3g= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037026112;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0XGJscI4_1796481601; Received: from localhost(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0XGJscI4_1796481601 cluster:ay36) by smtp.aliyun-inc.com; Sat, 05 Dec 2026 22:40:01 +0800 From: Joseph Qi To: Andrew Morton , Heming Zhao , hch@lst.de Cc: Mark Fasheh , Joel Becker , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, Joseph Qi Subject: [PATCH v18 00/10] migrate ocfs2 DIO from buffer_head to iomap Date: Sat, 5 Dec 2026 22:39:49 +0800 Message-Id: <20261205143959.704982-1-joseph.qi@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. It is based on commit 799dd9365531 (next-20261202). v18 changelog: Fixes from review of v17: patch 5/10: ocfs2_make_clusters_writable() advances i_datasync_tid only for file-data CoW, not xattr CoW, so a later fdatasync does not force an unnecessary journal commit. patch 6/10: reset the 'added' cluster count on the -ENOSPC retry so a failed retry does not record a stale i_blocks/fsync update. patch 7/10: validate the direct write (device alignment, IOCB_NOWAIT extending, source prefault) before kiocb_modified(), so a rejected write no longer dirties the inode or strips capabilities; the device-alignment check is done once, early, instead of being duplicated across the path. patch 8/10: ocfs2_dio_subpage_needs_buffered() returns the lookup error instead of masking it as a buffered demotion (-EAGAIN under NOWAIT), and the dead IOCB_NOWAIT branch in the buffered fallback is removed. patch 9/10: the commit message names bh_submit() rather than submit_bh(). patch 1/10 - 4/10, 10/10: no functional change. The v17 fixes are retained. 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/ Heming Zhao (7): ocfs2: Add new ocfs2_map_blocks() to introduce iomap feature ocfs2: switch DIO read path from buffer_head to iomap ocfs2: add ocfs2_get_clusters_uncached() ocfs2: refactor ocfs2_lock_allocators() and add a dio variant ocfs2: record the fsync transaction when CoW makes clusters writable ocfs2: rework the direct write context for multi-cluster mappings ocfs2: switch dio write path from buffer_head to iomap Joseph Qi (3): ocfs2: keep sub-page overwrites of written blocks on direct I/O ocfs2: write the dio zeroed head/tail buffers out before completion ocfs2: make buffered writes wait for in-flight direct writes fs/ocfs2/Kconfig | 2 +- fs/ocfs2/aops.c | 2420 +++++++++++++++++++++++++++++++++------ fs/ocfs2/aops.h | 45 +- fs/ocfs2/extent_map.c | 34 +- fs/ocfs2/extent_map.h | 3 + fs/ocfs2/file.c | 403 ++++++- fs/ocfs2/inode.h | 8 + fs/ocfs2/mmap.c | 3 +- fs/ocfs2/ocfs2.h | 25 +- fs/ocfs2/refcounttree.c | 2 + fs/ocfs2/suballoc.c | 50 +- fs/ocfs2/suballoc.h | 5 + fs/ocfs2/super.c | 3 + 13 files changed, 2543 insertions(+), 460 deletions(-) -- 2.39.3