Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5687741pxb; Thu, 20 Jan 2022 02:29:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1SOXW4fWO8ox9TNkquLKH5mO1ZMAiEZN8fZ8DhTlZHMynZbWMNEFtY04FRm6lmZUXHSW0 X-Received: by 2002:a17:90b:4f49:: with SMTP id pj9mr9975631pjb.187.1642674590887; Thu, 20 Jan 2022 02:29:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642674590; cv=none; d=google.com; s=arc-20160816; b=ShlDCyGN14vGqe5xUhuY5obo+zRn/yvnk/XYa/CjUvZM83r5Y1Uf+PFvrPyIZ5N8Sa tvFgWk/z79IByVtZqMozx8omqeP9I+MdlBkFoii9h7kBA85Wa730duJPgUzW7bJb5FtU GStaLDRt05bUky1Tp8vqWc3YwkNgVNGLT8T+U57SNUU/FCMqNA0qpceqkKClDNPQmsld lHdYDzZ3mSzQnax0Y+iuhb65wOm+nR2s1b6JwyiIidL5Yrs/yCdpboGxtqhWZ+8KfSds jLQEs2hVQQd+PHvF3yIR8KqAhydciZ0iDcH+AYaDIL4iH0YXwyR9bnp957fbUgHmfya5 FjLg== 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=xfW9oZE35e+xdYiLk2DTwzVTLz8EqtH33GCFlgrYaLA=; b=MfciodmRJQ+gST3RUzRgW0Iivd86H/h5FM8oNDxmh7iWytne3bogXpHFrkNcazNMO+ /FwuPJuJgPOO7HZz2tmdE8jR/sfMOGbh+yyM6yKkEomtqzWixdXZJY6bpQ7jwzD4OUB6 DIfa44JrFMs1JuplyO7MhPMwSySTRVbrA9o9c4p9BBVc7e1+J5KQq8bdwE/Cg4pNngg/ 38uJfdNaQudsLgh8QeR9BJC2nZz9SALwFW0DfnM4e/Oe8zd2IvRPafK+8MzjZ3zXIIUd ccyInGob85rvMRY7sBCs5yq7RiHtwa5dtIxyx9a70dd2vH1dTyeyiHT/JeXdD+RYK3d8 7o2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d3si2961919plg.418.2022.01.20.02.29.38; Thu, 20 Jan 2022 02:29:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242870AbiARNNP (ORCPT + 99 others); Tue, 18 Jan 2022 08:13:15 -0500 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:33659 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242296AbiARNMg (ORCPT ); Tue, 18 Jan 2022 08:12:36 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0V2C1oyZ_1642511553; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V2C1oyZ_1642511553) by smtp.aliyun-inc.com(127.0.0.1); Tue, 18 Jan 2022 21:12:33 +0800 From: Jeffle Xu To: dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: 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 Subject: [PATCH v2 14/20] erofs: implement fscache-based metadata read Date: Tue, 18 Jan 2022 21:12:10 +0800 Message-Id: <20220118131216.85338-15-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220118131216.85338-1-jefflexu@linux.alibaba.com> References: <20220118131216.85338-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch implements the data plane of reading metadata from bootstrap blob file over fscache. Be noted that currently it only supports the scenario where the backing file has no hole. Once it hits a hole of the backing file, erofs will fail the IO with -EOPNOTSUPP for now. The following patch will fix this issue, i.e. implementing the demand reading mode. Signed-off-by: Jeffle Xu --- fs/erofs/data.c | 11 +++++++++-- fs/erofs/fscache.c | 33 +++++++++++++++++++++++++++++++++ fs/erofs/internal.h | 3 +++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index f3aa133866e5..51ccbc02dd73 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -31,15 +31,22 @@ void erofs_put_metabuf(struct erofs_buf *buf) void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, erofs_blk_t blkaddr, enum erofs_kmap_type type) { - struct address_space *const mapping = sb->s_bdev->bd_inode->i_mapping; + struct address_space *mapping; + struct erofs_sb_info *sbi = EROFS_SB(sb); erofs_off_t offset = blknr_to_addr(blkaddr); pgoff_t index = offset >> PAGE_SHIFT; struct page *page = buf->page; if (!page || page->index != index) { erofs_put_metabuf(buf); - page = read_cache_page_gfp(mapping, index, + if (erofs_bdev_mode(sb)) { + mapping = sb->s_bdev->bd_inode->i_mapping; + page = read_cache_page_gfp(mapping, index, mapping_gfp_constraint(mapping, ~__GFP_FS)); + } else { + page = erofs_fscache_read_cache_page(sbi->bootstrap, + index); + } if (IS_ERR(page)) return page; /* should already be PageUptodate, no need to lock page */ diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 74683df6144d..5a25ae523e5e 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -6,9 +6,42 @@ static struct fscache_volume *volume; +static int erofs_blob_begin_cache_operation(struct netfs_read_request *rreq) +{ + return fscache_begin_read_operation(&rreq->cache_resources, + rreq->netfs_priv); +} + +/* .cleanup() is needed if rreq->netfs_priv is non-NULL */ +static void erofs_noop_cleanup(struct address_space *mapping, void *netfs_priv) +{ +} + +static const struct netfs_read_request_ops erofs_blob_req_ops = { + .begin_cache_operation = erofs_blob_begin_cache_operation, + .cleanup = erofs_noop_cleanup, +}; + +static int erofs_fscache_blob_readpage(struct file *data, struct page *page) +{ + struct folio *folio = page_folio(page); + struct erofs_fscache_context *ctx = + (struct erofs_fscache_context *)data; + + return netfs_readpage(NULL, folio, &erofs_blob_req_ops, ctx->cookie); +} + static const struct address_space_operations erofs_fscache_blob_aops = { + .readpage = erofs_fscache_blob_readpage, }; +struct page *erofs_fscache_read_cache_page(struct erofs_fscache_context *ctx, + pgoff_t index) +{ + DBG_BUGON(!ctx->inode); + return read_mapping_page(ctx->inode->i_mapping, index, ctx); +} + static int erofs_fscache_init_cookie(struct erofs_fscache_context *ctx, char *path) { diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 277dcd5888ea..fca706cfaf72 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -633,6 +633,9 @@ struct erofs_fscache_context *erofs_fscache_get_ctx(struct super_block *sb, char *path, bool need_inode); void erofs_fscache_put_ctx(struct erofs_fscache_context *ctx); +struct page *erofs_fscache_read_cache_page(struct erofs_fscache_context *ctx, + pgoff_t index); + #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ #endif /* __EROFS_INTERNAL_H */ -- 2.27.0