Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2329429rwl; Fri, 6 Jan 2023 05:07:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXtf+QjRJ4M1KngpTuDXS74czvWPu2w+hyQ344UFqbg8mreB3CS/xpGFulsKNTqrzx6LHxra X-Received: by 2002:a17:907:7e84:b0:7a4:bbce:ddae with SMTP id qb4-20020a1709077e8400b007a4bbceddaemr63250610ejc.59.1673010475126; Fri, 06 Jan 2023 05:07:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673010475; cv=none; d=google.com; s=arc-20160816; b=AG0v/QOoxJ8fWeUoIdKx/ISmUG4nJcky5Y50EKcZgkKrrnB9i33XqS2pE00cExw66Y xF3cxiRzZKsnQdw/jtxnYidgJqdI6hFo1bl7UUs2jRVJdcOTFezQqwWATtpeXezjHMx3 ftWB8NtMjC2A2BlLNT+RN5yG/GvMWNjnOBWBwq5Uw+13d/M1BvL+zZ+NQMvC4zu1lO8u t5BgD5nlh/7ev+i0Tab92aTEuFJUl1L861l9uxvTkGklRU0fxoCiSDIVGnstuPHi8taW RKjdrsa2ZTeECXxV8NBPM1hWTpIX2p1zzFmKcVW+GraBQhUI5AnxvfTPmUPxZGzJiN8F rs2g== 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=kxWiVkdTqcbUSfP2ja6n7cFVaew1Ywg9ZocDw/v2Ipg=; b=rs25HxrMOFVA8jeNbGX6vp7YiKE7P/Si4gpXrJDm0JKxYX11zlv6As7cWpdgbjaHh+ G7tykynQ+xsr+cXo9lWCy9XFJ4/ninKdaoffY51mNqKE/PEP5GTltQX0V108v1reubfy kbD1a92PMxxCYcWYSbMd71MtP0urGK3opfzIIqAKkCLBet10i1TUvCwuEPPBY6wdBGI6 sZOiPt3jkANAtd99JdZzM1uiYXaxJ/dLCR9ue/iNCfF5AMHscoSnagIiNKOlecrHvBCA f1BAF2SqZvd0KVAdlGo0MtW+DkFx4r6oHQB6JrO6BwLq/rOs9sDEdJ3ritS+gq7ybMaU g4UA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt12-20020a170907728c00b007c110cdf37bsi1389378ejc.529.2023.01.06.05.07.39; Fri, 06 Jan 2023 05:07:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233945AbjAFMxx (ORCPT + 56 others); Fri, 6 Jan 2023 07:53:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231666AbjAFMxj (ORCPT ); Fri, 6 Jan 2023 07:53:39 -0500 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99F03745B7; Fri, 6 Jan 2023 04:53:37 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VZ-Kul8_1673009613; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VZ-Kul8_1673009613) by smtp.aliyun-inc.com; Fri, 06 Jan 2023 20:53:34 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 3/6] erofs: alloc anonymous file for blob in share domain mode Date: Fri, 6 Jan 2023 20:53:27 +0800 Message-Id: <20230106125330.55529-4-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230106125330.55529-1-jefflexu@linux.alibaba.com> References: <20230106125330.55529-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham 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 In prep for the following support for page cache sharing based mmap, allocate an anonymous file for each blob, so that we can link associated vma to blobs later. Since page cache sharing will be enabled only for share domain mode, prepare anonymous file only in share domain mode. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 24 +++++++++++++++++++++++- fs/erofs/internal.h | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 4d7785a70926..ea276884f043 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -4,6 +4,8 @@ * Copyright (C) 2022, Bytedance Inc. All rights reserved. */ #include +#include +#include #include "internal.h" static DEFINE_MUTEX(erofs_domain_list_lock); @@ -316,6 +318,8 @@ const struct address_space_operations erofs_fscache_access_aops = { .readahead = erofs_fscache_readahead, }; +static const struct file_operations erofs_fscache_meta_fops = {}; + static void erofs_fscache_domain_put(struct erofs_domain *domain) { mutex_lock(&erofs_domain_list_lock); @@ -428,6 +432,7 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, struct fscache_cookie *cookie; struct super_block *psb = sb; struct inode *inode; + struct file *file; int ret; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); @@ -457,10 +462,24 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); inode->i_private = ctx; + if (EROFS_SB(sb)->domain_id) { + ihold(inode); + file = alloc_file_pseudo(inode, erofs_pseudo_mnt, "[erofs]", + O_RDONLY, &erofs_fscache_meta_fops); + if (IS_ERR(file)) { + ret = PTR_ERR(file); + iput(inode); + goto err_inode; + } + ctx->file = file; + } + ctx->cookie = cookie; ctx->inode = inode; return ctx; +err_inode: + iput(inode); err_cookie: fscache_unuse_cookie(cookie, NULL, NULL); fscache_relinquish_cookie(cookie, false); @@ -473,6 +492,8 @@ static void erofs_fscache_relinquish_cookie(struct erofs_fscache *ctx) { fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); + if (ctx->file) + fput(ctx->file); iput(ctx->inode); kfree(ctx->name); kfree(ctx); @@ -565,7 +586,8 @@ void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) mutex_lock(&erofs_domain_cookies_lock); /* drop the ref for the sentinel in pseudo mount */ iput(ctx->inode); - drop = atomic_read(&ctx->inode->i_count) == 1; + /* one initial ref, and one ref for anonymous file */ + drop = atomic_read(&ctx->inode->i_count) == 2; if (drop) erofs_fscache_relinquish_cookie(ctx); mutex_unlock(&erofs_domain_cookies_lock); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index b3d04bc2d279..24d471fe2fa4 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -109,6 +109,7 @@ struct erofs_domain { struct erofs_fscache { struct fscache_cookie *cookie; struct inode *inode; /* anonymous indoe for the blob */ + struct file *file; /* anonymous file */ struct erofs_domain *domain; char *name; }; -- 2.19.1.6.gb485710b