From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796392442; b=IybIUtS8XShirJQKCLnp7kYPQ14n3RHcWUZ4dNhHOyqjEUVeNCW7yJh1HYAmHpkjrkr+ VrR8SgJzWs3ekX4gS84NhfuCPB5i8gojus8ABpjmuo9LEtGDjesvEwRSUhAJLSm6sYe+u gEc+UCuIe7VE5tl7NDhFjsuIoX7Z4PYZ01glncJlroms0FKzoQTbFUEZRTIuDIim2gIwj 0amlo5jG0vYSt+RTUZ6EXRREqXh+gsEHm0QuHARx/sm93wd3Tyt6xbNRFRupqvrFZINK8 k3OnAsXSlXxIx2WhGuIysapA3asOVQkYlEppBfm2zbCYWxSvxhVuhtN5Pxje9iwPFgA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796392442; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=BghEw3BxIva7NcQxDSY7a81tCgFL20buPVS02AseiBo=; b=aAjIoc4iZUebELnn6NLbYDeS/WK9Zap5rGx1QCDNueFXyH4I73meMNye/7LanGsQA27w j9iJ9VY/FvxRTExKHFA7TRm/Q60y92ZEsHDy9x0H6DNSCr2tfU2kw5vEwWRskmwS1TGr5 P5x4brqzA+oqEqzm6Hx01J2FaL32oFH64Wh2sL1Q/tnqRAF4LlMQMKAKkHVwmNhRaokkA LP/i24PkwLJHZ4rBk7fUo0psXn5IY/AXfX6jw8Hbvvb/uv50v6mQrXvYgxxBdSBojyk9A k3NROdGYEAzro6fdfdQiQWu+Zo7XdsBzl8cATDo6NjqrobhlmQftYre8ukmJJLOZP3Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=BiHZV75A; arc=none smtp.remote-ip=209.85.128.54 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4269606A680 for ; Fri, 4 Dec 2026 13:54:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C4269606A680 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=BiHZV75A Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4bb67b3a18aso491035e9.3 for ; Fri, 04 Dec 2026 05:54:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1796392440; x=1796997240; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=BghEw3BxIva7NcQxDSY7a81tCgFL20buPVS02AseiBo=; b=BiHZV75AHu5lVa/mzLhtJcNvDkBsBtfAZgusdchD2bLZH/hZbImsNI1yGdZ1CPMQZe FnO1PQXNhMKbVPqgj7Wf2C9guSnCqlCARYVPki/NXR4wsM4zNcTiu8SJassFrbjGrsNV TcnKONMVzdXsjf2Ua9+WJQfe6+lZbIcCbajVsG8M5jToKCzVhYlgQeTiHMI9QyLfmtGw emNrJhOhvf0Wvj4Gz22MBA5fn+UxR0lB/Y+kib8WnvTri/FWo3KzEftqlzJbZlSVtM6P 6OvgbR4HFmbqJBafCgFaB/uRxYlbsCN0cj4Gx5QBIuS047jjUTDguN7ztnLAGOrcYd0h rI5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796392440; x=1796997240; h=content-transfer-encoding:content-type:in-reply-to:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BghEw3BxIva7NcQxDSY7a81tCgFL20buPVS02AseiBo=; b=nSADxS4jfQMI3y6Syif/hIVx8czqldooylj7XRb2enAf2czkNgrVejBylJw1jGGv38 cpcC9L1GUeuhlB0bZf0ffC7SD9elDxbXaB7HyGroEI4IXDeQ6Hq88i7b9ZgN+xjwEQYL D/BWBDPZOUTQKN0onM7pwOSehKYOUYb7weQDIlcSQUEMIsLL+IHvHk0hSIH3Hs0jg0Oj udc2cdygQaedh99HCgKNh72O1FuF+NpAGtsqAj+olXbEMdoKOtuT/1Fp8scKHGR2qwxs APxKcDHRD//IlmcZIMVPW1NIpnSdLobUTwvpjVyGPl2qzgN2PcffyU2C8VZ7UOIF7jIU 5gtg== X-Forwarded-Encrypted: i=1; AL+hErHVv0gh4Kt0nOgkXApCznAolfZWUQ4/PhMLihq7aP1bUIz3A6a9Z4E+poUm9AK5qNMDtv4d4VxfI+cf9v4=@vger.kernel.org X-Gm-Message-State: APuU4Z9AFdDXw5rr42PoMh8zhM1zjHRBE7ybkGkUuIrJzEAOFXe7r0f5 qC6rqpahjwkOQU08OGRozKyI/4UE7wg5EF1eyqjfHb86NiS+JnA0hAUCkY38bH3cqRk= X-Gm-Gg: AZFdTZeuRMRIKfKo0am7e2cSRYCsj3rADEBIH+vDMkZd1PYL+cT68Oz5ctdPo8Zi1xx tXcDYyhb7kS/+etJEIuWAK2u2FneIimFH4KE7LZiMmWX3mCUkSy3pbMAPGSeNCl/An7fzXkwkTS q0S4BSjHSNJIaCeg7CijzycM3UtX101wkP9/2dkRx9WVs9LTrRnHSMV/tXT7FclIdfawaa/+YYR hoN99xd+9JHmJusMs9+BuAipG5OpGTfGsXpmbKW1swfRJkcLJ6CXJGczZ+1hceT+kdZY9ycB95U wbX4AwaZHabMypN/CqJkd/pl7F+3VFRedFIFve2rs+nDYSp499mseuMj2drDkCXKRk2j3o7kxfv hZ7tVhwRZHf6YHeQKWvahtMO2nZ0SyEuD/6aNnKtXtEhvUwN7i1RdE/Nw6WdlZmEXa1Fc+SWAGO 6lar0XlVw5HNFYIZ8UHObUF034UPjzhU1YC/Cy7u/bn6ZIuq6b+8i94Z0OeHfKtHsRol4PhR1aN dFGWdrttWG6t0GWjodyzeiMGDlIhE51ii8JsCKZgneIBoprsHdrx4HKowsG3ANTi0ReHZn0/GiQ Qy53WUbDeQ+rM7st8CraHTUY1UtEQw22lQ== X-Received: by 2002:a05:600c:621b:b0:4bb:b631:92e3 with SMTP id 5b1f17b1804b1-4bbeb850ed3mr38718965e9.2.1796392440151; Fri, 04 Dec 2026 05:54:00 -0800 (PST) Received: from [10.202.112.30] ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1b7941c5dsm12392785ad.54.2026.12.04.05.53.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 05:53:59 -0800 (PST) Message-ID: Date: Fri, 4 Dec 2026 21:53:54 +0800 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v16 01/10] ocfs2: Add new ocfs2_map_blocks() to introduce iomap feature To: Joseph Qi , Andrew Morton , hch@lst.de Cc: Mark Fasheh , Joel Becker , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org References: <20261203124037.4112319-1-joseph.qi@linux.alibaba.com> <20261203124037.4112319-2-joseph.qi@linux.alibaba.com> From: Heming Zhao Content-Language: en-US In-Reply-To: <20261203124037.4112319-2-joseph.qi@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/3/26 20:40, Joseph Qi wrote: > 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 | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ > fs/ocfs2/aops.h | 2 ++ > fs/ocfs2/ocfs2.h | 25 ++++++++++++++++- > 3 files changed, 96 insertions(+), 1 deletion(-) > > diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c > index 4acdbb70882cd..64fcf6eb3d89b 100644 > --- a/fs/ocfs2/aops.c > +++ b/fs/ocfs2/aops.c > @@ -126,6 +126,76 @@ 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; > + > + /* > + * If we see this on a sparse file system, then a truncate has > + * raced us and removed the cluster. We treat this as a hole > + * and skip setting the iomap flags. The caller will set > + * iomap->type to IOMAP_HOLE. > + */ > + 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) > + sashiko didn't send review result to list/me, so I past them here: ``` Do OCFS2_MAP_NEW, OCFS2_MAP_MAPPED, and OCFS2_MAP_UNWRITTEN need to be tied to BH_* bit positions? In ext4, EXT4_MAP_* mirrors BH_* because ext4_update_bh_state() copies map.m_flags directly into bh->b_state using EXT4_MAP_FLAGS. Here, map->flags is never copied to or from bh->b_state, and OCFS2_MAP_FLAGS has no users anywhere in the series. Similarly, ocfs2_map_blocks() duplicates the bulk of ocfs2_get_block() right above it without refactoring ocfs2_get_block() to share the common mapping logic. Either share the mapping core between ocfs2_get_block() and ocfs2_map_blocks(), or define OCFS2_MAP_* with standalone bit positions and drop OCFS2_MAP_FLAGS. ``` I suggest keeping the current define style. Migrating direct IO to iomap is the first step, and we should plan to migrate buffered IO later. These BH_* defines may be useful at that time. If all the IO paths have been switched to iomap and the BH_* are no longer used, it won't be late to remove them. Thanks, Heming > +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,