Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2190894pxb; Fri, 25 Mar 2022 12:43:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynqzXUxcfhLl/KluZxkBHLEYLQBSyPUrW/ZPBh8UL5A8vadP/W7UkZvWpmoS1gB0LlP/kl X-Received: by 2002:a17:902:f687:b0:154:64be:3518 with SMTP id l7-20020a170902f68700b0015464be3518mr13640363plg.4.1648237408133; Fri, 25 Mar 2022 12:43:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648237408; cv=none; d=google.com; s=arc-20160816; b=aNnpSbRTTIhi5SF8YKwzTn05UPl41Hh9iVN3kjR+9KWBryeIf5USEl84SRiLGuhBye B++EsS0jcB9XAM3Lv+LLmXA2W/k91Xvl02fPr7VGmCJJUpdTZq49g1u1+wcDioGOmM90 xELzSiF2FmPV9suztyrn2RTDDLmjv4abZR8E2UMVGf8NxRgeAu6Ee8tzhOvfNL9yOjB+ vcR7wGsqQcJ3wZ+vV31Z5A1iZJ82Wu7SzzGHmKQBV8xyIVYx8gtUuvnqBM6IuGtP7Ff0 YgedXKa2ag/qqEaITHmOeSp5gvwGAM/YPbKH0g2Zlr1lScOic54cILNd15CPOWkZacdT ggng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=TQsZW8tTItT/sAaEUxY07SDiFRZXJPPgfLEBCt3+zag=; b=GeYkrERoHDWptv8TinQuw3r83bhkz+lGfSA5QLaFlmo1s2arOtf2MtZyjeXvJkjshs 7CsUkEpdo/d2uF9d6tkRywqwnr2lVJxMk5t91kGrwDuE4ifUf64KH/ax5dcMvEn+d9Tk 0lcyWxAGjcwl+sTi9NelY1nT4/Y/iCxcEOuB+95ThykyFRr1+iaknfthgJJzVxt6Z433 l5aDuG9B96gfYL22bva9e6jA/l0oFxQo+l0OuA6metZ1lBnX7pUAqw8d8M7gZ6bnTGQO sHBcGVpwGteKNkkb02Y9IdGHVkFruVYCJy5iWIlXD7vCUsIdlx58Bo+fsaxSWFZ023O8 LHRg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n14-20020a170902f60e00b00153b2d16490si3234433plg.152.2022.03.25.12.43.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 12:43:28 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F13A829E4ED; Fri, 25 Mar 2022 11:34:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359050AbiCYMZO (ORCPT + 99 others); Fri, 25 Mar 2022 08:25:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359089AbiCYMYt (ORCPT ); Fri, 25 Mar 2022 08:24:49 -0400 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 223A3D64F1; Fri, 25 Mar 2022 05:22:57 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R271e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04357;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=18;SR=0;TI=SMTPD_---0V89qR1S_1648210970; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V89qR1S_1648210970) by smtp.aliyun-inc.com(127.0.0.1); Fri, 25 Mar 2022 20:22:51 +0800 From: Jeffle Xu To: dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: torvalds@linux-foundation.org, gregkh@linuxfoundation.org, willy@infradead.org, linux-fsdevel@vger.kernel.org, joseph.qi@linux.alibaba.com, bo.liu@linux.alibaba.com, tao.peng@linux.alibaba.com, gerry@linux.alibaba.com, eguan@linux.alibaba.com, linux-kernel@vger.kernel.org, luodaowen.backend@bytedance.com, tianzichen@kuaishou.com, fannaihao@baidu.com Subject: [PATCH v6 17/22] erofs: implement fscache-based data read for non-inline layout Date: Fri, 25 Mar 2022 20:22:18 +0800 Message-Id: <20220325122223.102958-18-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220325122223.102958-1-jefflexu@linux.alibaba.com> References: <20220325122223.102958-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implements the data plane of reading data from bootstrap blob file over fscache for non-inline layout. Be noted that compressed layout is not supported yet. Signed-off-by: Jeffle Xu --- fs/erofs/fscache.c | 83 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/inode.c | 8 ++++- fs/erofs/internal.h | 5 +++ 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 91377939b4f7..4a9a4e60c15d 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -60,10 +60,93 @@ static int erofs_fscache_readpage_blob(struct file *data, struct page *page) return ret; } +static inline int erofs_fscache_get_map(struct erofs_map_blocks *map, + struct super_block *sb) +{ + struct erofs_sb_info *sbi = EROFS_SB(sb); + + map->m_fscache = sbi->bootstrap; + return 0; +} + +static int erofs_fscache_readpage_noinline(struct folio *folio, + struct erofs_map_blocks *map) +{ + struct fscache_cookie *cookie = map->m_fscache->cookie; + /* + * 1) For FLAT_PLAIN layout, the output map.m_la shall be equal to o_la, + * and the output map.m_pa is exactly the physical address of o_la. + * 2) For CHUNK_BASED layout, the output map.m_la is rounded down to the + * nearest chunk boundary, and the output map.m_pa is actually the + * physical address of this chunk boundary. So we need to recalculate + * the actual physical address of o_la. + */ + loff_t start = map->m_pa + (map->o_la - map->m_la); + + return erofs_fscache_read_folio(cookie, folio, start); +} + +static int erofs_fscache_do_readpage(struct folio *folio) +{ + struct inode *inode = folio_file_mapping(folio)->host; + struct erofs_inode *vi = EROFS_I(inode); + struct super_block *sb = inode->i_sb; + struct erofs_map_blocks map; + int ret; + + if (erofs_inode_is_data_compressed(vi->datalayout)) { + erofs_info(sb, "compressed layout not supported yet"); + return -EOPNOTSUPP; + } + + DBG_BUGON(folio_size(folio) != EROFS_BLKSIZ); + + map.m_la = map.o_la = folio_pos(folio); + + ret = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); + if (ret) + return ret; + + if (!(map.m_flags & EROFS_MAP_MAPPED)) { + folio_zero_range(folio, 0, folio_size(folio)); + return 0; + } + + ret = erofs_fscache_get_map(&map, sb); + if (ret) + return ret; + + switch (vi->datalayout) { + case EROFS_INODE_FLAT_PLAIN: + case EROFS_INODE_CHUNK_BASED: + return erofs_fscache_readpage_noinline(folio, &map); + default: + DBG_BUGON(1); + return -EOPNOTSUPP; + } +} + +static int erofs_fscache_readpage(struct file *file, struct page *page) +{ + struct folio *folio = page_folio(page); + int ret; + + ret = erofs_fscache_do_readpage(folio); + if (!ret) + folio_mark_uptodate(folio); + + folio_unlock(folio); + return ret; +} + static const struct address_space_operations erofs_fscache_blob_aops = { .readpage = erofs_fscache_readpage_blob, }; +const struct address_space_operations erofs_fscache_access_aops = { + .readpage = erofs_fscache_readpage, +}; + /* * erofs_fscache_get_folio - find and read page cache of blob file * @ctx: the context of the blob file diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index ff62f84f47d3..744faf3ef9f4 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -296,7 +296,13 @@ static int erofs_fill_inode(struct inode *inode, int isdir) err = z_erofs_fill_inode(inode); goto out_unlock; } - inode->i_mapping->a_ops = &erofs_raw_access_aops; + +#ifdef CONFIG_EROFS_FS_ONDEMAND + if (erofs_is_nodev_mode(inode->i_sb)) + inode->i_mapping->a_ops = &erofs_fscache_access_aops; +#endif + if (!erofs_is_nodev_mode(inode->i_sb)) + inode->i_mapping->a_ops = &erofs_raw_access_aops; out_unlock: erofs_put_metabuf(&buf); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index fa89a1e3012f..6537ededed51 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -442,6 +442,9 @@ struct erofs_map_blocks { unsigned short m_deviceid; char m_algorithmformat; unsigned int m_flags; + + struct erofs_fscache *m_fscache; + erofs_off_t o_la; }; /* Flags used by erofs_map_blocks_flatmode() */ @@ -634,6 +637,8 @@ struct erofs_fscache *erofs_fscache_get(struct super_block *sb, char *path, void erofs_fscache_put(struct erofs_fscache *ctx); struct folio *erofs_fscache_get_folio(struct erofs_fscache *ctx, pgoff_t index); + +extern const struct address_space_operations erofs_fscache_access_aops; #else static inline int erofs_init_fscache(void) { return 0; } static inline void erofs_exit_fscache(void) {} -- 2.27.0