Message ID | 20231221085826.1768395-1-yukuai1@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-8045-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp280536dyi; Thu, 21 Dec 2023 01:06:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9qn8p8bjmpCMTRRICpKu1csdmyIhvsE6QKky6kX9THyPJOYZDXhmdSFpxWf/zIMHp5nSl X-Received: by 2002:a17:903:40ce:b0:1d3:ee28:a762 with SMTP id t14-20020a17090340ce00b001d3ee28a762mr1737344pld.104.1703149599711; Thu, 21 Dec 2023 01:06:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703149599; cv=none; d=google.com; s=arc-20160816; b=ymD2Gf+z/Ye7EccGjzI9VhjwSL2wnltkmYJpWiy3pG8ZeBJXxwWLsBhU6OhkD8KfnK gO0d5vTBvTjbW6T/6FMzUw+ngipVlxCJ8Jel/HaGTJB1qPwv0oZsSptl77HAaNHCuxpS WGup4u8wFelJCRTn10gIk3wsr/Cs4yMoCFAyjS8pTPMpXSQkr1oDrWZZ5YyBJeoGYlib 8dotN4dJ4+TCS8rzx8knrcfxxXcBUiXOCQSrroEHsZ7trZGZ0G+76uCDIM0Wo4Zve+wz BhJXGkRFFy/n7t6zLgjW4hxwCsuXu0qtpWGcZCL79WfDdzoqYey/dIX6n9eGlAuQmG9n bmcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=jgu3KMjXFsgMJ0qiJPYReVuVFLGz/OPlcCuNB2zzsLc=; fh=ra0zcfFNH7JWn2tyKhchpyMoSpFA+1HuRrgbaLqrjLs=; b=yEhU1bE/yqiYBo1Hgu09ptmV7FcX1ax4a6QSqLN2qni17a6OflGxl6RWx3XW02mIn0 vVJlyPfgllPWtAPB4vu89OEEgXFc7Ur0+nkArq7R6HnKCt/wnIyWPDVP2W3t3F21/Q0H DtFRfDgWRz7VjB9PeoutgStB1kX+quqbDry97OlMU/9AD/IAx7ZIMhdv7h/dG+B2A6Vn K8PIl7zC7zNzZeKHvnQEXb0tueZdwPhxDPded18mIsHOngh8fM+KJgozmt7RHtjHjtkI qHKprHtrVQVKEtWZKKeSvPatdP6r7vJ/Ab4X0dcFng9IUsluC46MnxKCeljp9VEl/gJ3 cT6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8045-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8045-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b18-20020a170902d31200b001c62cfff799si1209695plc.176.2023.12.21.01.06.39 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:06:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8045-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8045-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8045-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A274C286EEC for <ouuuleilei@gmail.com>; Thu, 21 Dec 2023 09:06:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA8CE38F9B; Thu, 21 Dec 2023 09:00:32 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A744C208AE; Thu, 21 Dec 2023 09:00:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Swksc71JYz4f3lVY; Thu, 21 Dec 2023 17:00:20 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 2D0F41A01CA; Thu, 21 Dec 2023 17:00:26 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBHlQun_oNlCxfvEA--.34192S4; Thu, 21 Dec 2023 17:00:25 +0800 (CST) From: Yu Kuai <yukuai1@huaweicloud.com> To: axboe@kernel.dk, roger.pau@citrix.com, colyli@suse.de, kent.overstreet@gmail.com, joern@lazybastard.org, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, sth@linux.ibm.com, hoeppner@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, jejb@linux.ibm.com, martin.petersen@oracle.com, clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, viro@zeniv.linux.org.uk, brauner@kernel.org, nico@fluxnic.net, xiang@kernel.org, chao@kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.com, konishi.ryusuke@gmail.com, willy@infradead.org, akpm@linux-foundation.org, hare@suse.de, p.raghav@samsung.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-bcache@vger.kernel.org, linux-mtd@lists.infradead.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org, linux-nilfs@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH RFC v3 for-6.8/block 11/17] erofs: use bdev api Date: Thu, 21 Dec 2023 16:58:26 +0800 Message-Id: <20231221085826.1768395-1-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231221085712.1766333-1-yukuai1@huaweicloud.com> References: <20231221085712.1766333-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cCh0CgBHlQun_oNlCxfvEA--.34192S4 X-Coremail-Antispam: 1UD129KBjvJXoW7ZFWUAF1xtr4rGr45Ww17Jrb_yoW8KF1kpr W3Cr1rGrWrXrs09wn2gr1UZF13ta97Gw48CayxJw1Fv3yUtryagFyvywnrGr48Kr4kKrs2 qF1Ivry8uw1UJrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUv014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F4 0E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Wrv_Gr1U MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I 0E14v26F4UJVW0owCI42IY6xAIw20EY4v20xvaj40_Gr0_Zr1lIxAIcVC2z280aVAFwI0_ Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVWxJr0_GcJvcSsGvfC2KfnxnUUI43ZEXa7VU1 VOJ5UUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785881794331247620 X-GMAIL-MSGID: 1785881794331247620 |
Series |
None
|
|
Commit Message
Yu Kuai
Dec. 21, 2023, 8:58 a.m. UTC
From: Yu Kuai <yukuai3@huawei.com> Avoid to access bd_inode directly, prepare to remove bd_inode from block_device. Signed-off-by: Yu Kuai <yukuai3@huawei.com> --- fs/erofs/data.c | 18 ++++++++++++------ fs/erofs/internal.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-)
Comments
On Thu 21-12-23 16:58:26, Yu Kuai wrote: > From: Yu Kuai <yukuai3@huawei.com> > > Avoid to access bd_inode directly, prepare to remove bd_inode from > block_device. > > Signed-off-by: Yu Kuai <yukuai3@huawei.com> I'm not erofs maintainer but IMO this is quite ugly and grows erofs_buf unnecessarily. I'd rather store 'sb' pointer in erofs_buf and then do the right thing in erofs_bread() which is the only place that seems to care about the erofs_is_fscache_mode() distinction... Also blkszbits is then trivially sb->s_blocksize_bits so it would all seem much more straightforward. Honza > --- > fs/erofs/data.c | 18 ++++++++++++------ > fs/erofs/internal.h | 2 ++ > 2 files changed, 14 insertions(+), 6 deletions(-) > > diff --git a/fs/erofs/data.c b/fs/erofs/data.c > index c98aeda8abb2..bbe2fe199bf3 100644 > --- a/fs/erofs/data.c > +++ b/fs/erofs/data.c > @@ -32,8 +32,8 @@ void erofs_put_metabuf(struct erofs_buf *buf) > void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, > enum erofs_kmap_type type) > { > - struct inode *inode = buf->inode; > - erofs_off_t offset = (erofs_off_t)blkaddr << inode->i_blkbits; > + u8 blkszbits = buf->inode ? buf->inode->i_blkbits : buf->blkszbits; > + erofs_off_t offset = (erofs_off_t)blkaddr << blkszbits; > pgoff_t index = offset >> PAGE_SHIFT; > struct page *page = buf->page; > struct folio *folio; > @@ -43,7 +43,9 @@ void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, > erofs_put_metabuf(buf); > > nofs_flag = memalloc_nofs_save(); > - folio = read_cache_folio(inode->i_mapping, index, NULL, NULL); > + folio = buf->inode ? > + read_mapping_folio(buf->inode->i_mapping, index, NULL) : > + bdev_read_folio(buf->bdev, offset); > memalloc_nofs_restore(nofs_flag); > if (IS_ERR(folio)) > return folio; > @@ -67,10 +69,14 @@ void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, > > void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb) > { > - if (erofs_is_fscache_mode(sb)) > + if (erofs_is_fscache_mode(sb)) { > buf->inode = EROFS_SB(sb)->s_fscache->inode; > - else > - buf->inode = sb->s_bdev->bd_inode; > + buf->bdev = NULL; > + } else { > + buf->inode = NULL; > + buf->bdev = sb->s_bdev; > + buf->blkszbits = EROFS_SB(sb)->blkszbits; > + } > } > > void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, > diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h > index b0409badb017..c9206351b485 100644 > --- a/fs/erofs/internal.h > +++ b/fs/erofs/internal.h > @@ -224,8 +224,10 @@ enum erofs_kmap_type { > > struct erofs_buf { > struct inode *inode; > + struct block_device *bdev; > struct page *page; > void *base; > + u8 blkszbits; > enum erofs_kmap_type kmap_type; > }; > #define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL }) > -- > 2.39.2 >
Hi, Jan! 在 2024/01/04 20:02, Jan Kara 写道: > On Thu 21-12-23 16:58:26, Yu Kuai wrote: >> From: Yu Kuai <yukuai3@huawei.com> >> >> Avoid to access bd_inode directly, prepare to remove bd_inode from >> block_device. >> >> Signed-off-by: Yu Kuai <yukuai3@huawei.com> > > I'm not erofs maintainer but IMO this is quite ugly and grows erofs_buf > unnecessarily. I'd rather store 'sb' pointer in erofs_buf and then do the > right thing in erofs_bread() which is the only place that seems to care > about the erofs_is_fscache_mode() distinction... Also blkszbits is then > trivially sb->s_blocksize_bits so it would all seem much more > straightforward. Thanks for your suggestion, I'll follow this unless Gao Xiang has other suggestions. Kuai > > Honza > >> --- >> fs/erofs/data.c | 18 ++++++++++++------ >> fs/erofs/internal.h | 2 ++ >> 2 files changed, 14 insertions(+), 6 deletions(-) >> >> diff --git a/fs/erofs/data.c b/fs/erofs/data.c >> index c98aeda8abb2..bbe2fe199bf3 100644 >> --- a/fs/erofs/data.c >> +++ b/fs/erofs/data.c >> @@ -32,8 +32,8 @@ void erofs_put_metabuf(struct erofs_buf *buf) >> void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, >> enum erofs_kmap_type type) >> { >> - struct inode *inode = buf->inode; >> - erofs_off_t offset = (erofs_off_t)blkaddr << inode->i_blkbits; >> + u8 blkszbits = buf->inode ? buf->inode->i_blkbits : buf->blkszbits; >> + erofs_off_t offset = (erofs_off_t)blkaddr << blkszbits; >> pgoff_t index = offset >> PAGE_SHIFT; >> struct page *page = buf->page; >> struct folio *folio; >> @@ -43,7 +43,9 @@ void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, >> erofs_put_metabuf(buf); >> >> nofs_flag = memalloc_nofs_save(); >> - folio = read_cache_folio(inode->i_mapping, index, NULL, NULL); >> + folio = buf->inode ? >> + read_mapping_folio(buf->inode->i_mapping, index, NULL) : >> + bdev_read_folio(buf->bdev, offset); >> memalloc_nofs_restore(nofs_flag); >> if (IS_ERR(folio)) >> return folio; >> @@ -67,10 +69,14 @@ void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, >> >> void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb) >> { >> - if (erofs_is_fscache_mode(sb)) >> + if (erofs_is_fscache_mode(sb)) { >> buf->inode = EROFS_SB(sb)->s_fscache->inode; >> - else >> - buf->inode = sb->s_bdev->bd_inode; >> + buf->bdev = NULL; >> + } else { >> + buf->inode = NULL; >> + buf->bdev = sb->s_bdev; >> + buf->blkszbits = EROFS_SB(sb)->blkszbits; >> + } >> } >> >> void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, >> diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h >> index b0409badb017..c9206351b485 100644 >> --- a/fs/erofs/internal.h >> +++ b/fs/erofs/internal.h >> @@ -224,8 +224,10 @@ enum erofs_kmap_type { >> >> struct erofs_buf { >> struct inode *inode; >> + struct block_device *bdev; >> struct page *page; >> void *base; >> + u8 blkszbits; >> enum erofs_kmap_type kmap_type; >> }; >> #define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL }) >> -- >> 2.39.2 >>
On 2024/1/4 20:32, Yu Kuai wrote: > Hi, Jan! > > 在 2024/01/04 20:02, Jan Kara 写道: >> On Thu 21-12-23 16:58:26, Yu Kuai wrote: >>> From: Yu Kuai <yukuai3@huawei.com> >>> >>> Avoid to access bd_inode directly, prepare to remove bd_inode from >>> block_device. >>> >>> Signed-off-by: Yu Kuai <yukuai3@huawei.com> >> >> I'm not erofs maintainer but IMO this is quite ugly and grows erofs_buf >> unnecessarily. I'd rather store 'sb' pointer in erofs_buf and then do the >> right thing in erofs_bread() which is the only place that seems to care >> about the erofs_is_fscache_mode() distinction... Also blkszbits is then >> trivially sb->s_blocksize_bits so it would all seem much more >> straightforward. > > Thanks for your suggestion, I'll follow this unless Gao Xiang has other > suggestions. Yes, that would be better, I'm fine with that. Yet in the future we may support a seperate large dirblocksize more than block size, but we could revisit later. Thanks, Gao Xiang > > Kuai >> >> Honza >>
diff --git a/fs/erofs/data.c b/fs/erofs/data.c index c98aeda8abb2..bbe2fe199bf3 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -32,8 +32,8 @@ void erofs_put_metabuf(struct erofs_buf *buf) void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, enum erofs_kmap_type type) { - struct inode *inode = buf->inode; - erofs_off_t offset = (erofs_off_t)blkaddr << inode->i_blkbits; + u8 blkszbits = buf->inode ? buf->inode->i_blkbits : buf->blkszbits; + erofs_off_t offset = (erofs_off_t)blkaddr << blkszbits; pgoff_t index = offset >> PAGE_SHIFT; struct page *page = buf->page; struct folio *folio; @@ -43,7 +43,9 @@ void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, erofs_put_metabuf(buf); nofs_flag = memalloc_nofs_save(); - folio = read_cache_folio(inode->i_mapping, index, NULL, NULL); + folio = buf->inode ? + read_mapping_folio(buf->inode->i_mapping, index, NULL) : + bdev_read_folio(buf->bdev, offset); memalloc_nofs_restore(nofs_flag); if (IS_ERR(folio)) return folio; @@ -67,10 +69,14 @@ void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb) { - if (erofs_is_fscache_mode(sb)) + if (erofs_is_fscache_mode(sb)) { buf->inode = EROFS_SB(sb)->s_fscache->inode; - else - buf->inode = sb->s_bdev->bd_inode; + buf->bdev = NULL; + } else { + buf->inode = NULL; + buf->bdev = sb->s_bdev; + buf->blkszbits = EROFS_SB(sb)->blkszbits; + } } void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index b0409badb017..c9206351b485 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -224,8 +224,10 @@ enum erofs_kmap_type { struct erofs_buf { struct inode *inode; + struct block_device *bdev; struct page *page; void *base; + u8 blkszbits; enum erofs_kmap_type kmap_type; }; #define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL })