From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.119 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796458778; b=fQYjcizabRseKPJYLW144vuXxEoivdQhN2Zqn2oqaDvEKvgq+DbfRQxPJyO0d47Z8gUX Wn1PGdMJXix8+Gmk9OYBSvG+hjEzGX8Ifp3hWtocFCk5QMPr42wHpVw+uEtRHI8/NThap XzCCQCH/9flNqSX8j+WLlB1H4uc2VGUzVSgQxRRPSYgHddvvK3ZgKYnQgFcoxpUFc66Dj qL7CLAaT4mT512Gu3oHEUR3KwNSAfUlfyuYtAIdCwcxuamOtOfNVlpSyAdDoCoqfMGU5b k/T2GIMF62D1jhVOQG65z2ivEKY+SCVm60TyUGxzxYCacs3TWp5UZh9MUPwAIUoUX8A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796458778; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=hNGf0p8te5nrf4sbalK2aAQv9PuZ7NLZXf7GkDEm57M=; b=ecc49fljROdI6m1XAzNniLfZxFYBXKNGx/d0VdNWTXlQw70xTWWdKnC+PxeiPcp3lpdy MUB8tz7PkjWneVK4DExVn8Vk+2URAnZh9mBP2cbMMf2WQ5+JyJIpkdCALJksud7feZlzg wjEfWo8YekLyb0Ktig+k97TLfcpFMwW6f/7+6tEK69hmlpLIEcEKRqEr4P5MA7sfValmm hGQDQouoeygMc4UIt3U5BkGPELYVdULGyp3GtBvuyuS44yiGJwPS/g+JLQTr9XM/m9vYi bZ/VwJevMeql0TifS55k8XpN5OEIo/RSnw84YP0VnFYRZhOsnUUKGFnQJzcNcTGAEsg== 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=Uu1QBeWZ; arc=none smtp.remote-ip=115.124.30.119 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (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 B4212606A68B for ; Sat, 5 Dec 2026 08:19:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B4212606A68B 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=Uu1QBeWZ DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796458766; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=hNGf0p8te5nrf4sbalK2aAQv9PuZ7NLZXf7GkDEm57M=; b=Uu1QBeWZ7Ur0bAuphmX19UJZD0sUJ+DJgciq4g0gfwg7oLsLKOjlZ0h1PVomPmIu03UaTfjC5DEmpybPB8/2tdvcbT/aUOTncLsNWfnt7rWlHZMl+V0MGDk/YSI6mtcaGK25R+JcMgPJv0ZnjG8knQY5GmvbVFG0X81kEbJoqMU= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033040069076;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0XGJGPZx_1796458765; Received: from localhost(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0XGJGPZx_1796458765 cluster:ay36) by smtp.aliyun-inc.com; Sat, 05 Dec 2026 16:19:26 +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 v17 01/10] ocfs2: Add new ocfs2_map_blocks() to introduce iomap feature Date: Sat, 5 Dec 2026 16:19:14 +0800 Message-Id: <20261205081923.4097763-2-joseph.qi@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20261205081923.4097763-1-joseph.qi@linux.alibaba.com> References: <20261205081923.4097763-1-joseph.qi@linux.alibaba.com> 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 From: Heming Zhao 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(). Signed-off-by: Heming Zhao Reviewed-by: Christoph Hellwig Reviewed-by: Joseph Qi --- fs/ocfs2/aops.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/aops.h | 2 ++ fs/ocfs2/ocfs2.h | 25 ++++++++++++++++- 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 4acdbb70882cd..5ae8cff9a56e8 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -126,6 +126,77 @@ static int ocfs2_lock_get_block(struct inode *inode, sector_t iblock, 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) { diff --git a/fs/ocfs2/aops.h b/fs/ocfs2/aops.h index 114efc9111e43..8dd6edd7c1a13 100644 --- a/fs/ocfs2/aops.h +++ b/fs/ocfs2/aops.h @@ -42,6 +42,8 @@ int ocfs2_size_fits_inline_data(struct buffer_head *di_bh, u64 new_size); 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) diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h index 8bee145e48887..0c2674615c3d6 100644 --- a/fs/ocfs2/ocfs2.h +++ b/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, -- 2.39.3