Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1531485rwb; Fri, 12 Aug 2022 02:31:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR4lyf0+f/paYfp1hWcjQgB/GNgvAfbGd0zyqq7Zafztsbe4A6KJ6hgGEhwfT+9B7AGZyLNE X-Received: by 2002:a63:3c52:0:b0:421:5af6:9902 with SMTP id i18-20020a633c52000000b004215af69902mr2360850pgn.548.1660296659777; Fri, 12 Aug 2022 02:30:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660296659; cv=none; d=google.com; s=arc-20160816; b=zk45mEjbaJnw5eNDlDXOuJSINfj6ZypQUUq7517CA8Y8yFSHb/Mooh2CrgOQta6dcU GO+k0W6vLNQgCHkxqjZkzP8Vz8yfUoT63qSo36mPsu2ZZDRvqu/PNWd0KMwczHY3z+QU rnTI5iszJpAioUKd7F3Bhh1xDZj7oU6CLjmDDfmBLwsJQ9n6kNt6PLfnuQtJv+krLvuZ rLiSNhPANDCB3G95XymhSlk9WwDd2JrORJkjYW8oChfN++0FB/s7YnhtBD+wzQflDgYS BFYW96Fx+2dSvgVxvuokkpsOgIdo6kRqF+dGtN+4gRhnB+5TJNKeJ72g1LhOZQYE7zyc vqxA== 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 :message-id:date:subject:cc:to:from; bh=6rIixgmmvYu/6xb/VWRS1iw5aBcHIG7Selyu1KCrWBY=; b=UYs9e/l0fvOc7yiuF5cMDjSEHKISGX0DOmeuKcbaOtoWw+TRqLQjId0meHpJjmOHu5 5zkcRHPznqvT5A5zN+PMCB1GCKyG2WiKHXtus6CKVc+cb0JsrCnS6HaXZL2nXjM4IHFT JXDAgwYytqMsSPa8dBQ16X2TbeINKNHZCOkG9SPMh6sE8P5/MwuuW1lIUUFXHewFCccW fGkCSK61DIKV3qjoqwhkzPAsu3ckEhnUH9bLfG1LzoDCfPXmA2gd+xJlhYurzLcwOiib CjkzgFDtLJlPShhZJobalZeBVCXpsGzLTjudipPKKeOduBgvVVmCk7aei0RT0ysJ1XPh 3uFw== 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 z2-20020a056a00240200b0052b8a92ed84si1837464pfh.172.2022.08.12.02.30.46; Fri, 12 Aug 2022 02:30:59 -0700 (PDT) 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 S237803AbiHLJKP (ORCPT + 99 others); Fri, 12 Aug 2022 05:10:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231586AbiHLJKO (ORCPT ); Fri, 12 Aug 2022 05:10:14 -0400 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A4AE2611E; Fri, 12 Aug 2022 02:10:10 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R881e4;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=5;SR=0;TI=SMTPD_---0VM17qn1_1660295406; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VM17qn1_1660295406) by smtp.aliyun-inc.com; Fri, 12 Aug 2022 17:10:07 +0800 From: Jingbo Xu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jingbo Xu Subject: [PATCH] cachefiles: support multiple daemons Date: Fri, 12 Aug 2022 17:10:05 +0800 Message-Id: <20220812091005.65540-1-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 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,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,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 Currently CacheFiles can work in either the original mode caching for network filesystems, or on-demand mode for container scenarios. Due to the limit of singleton daemon, these two modes can not co-exist. The current implementation can already work well in multiple daemon mode. This patch only removes the explicit limitation, and thus enabling the multiple daemon mdoe. Signed-off-by: Jingbo Xu --- PS: Currently all filessytems using fscache (including network filesystems and erofs) call fscache_acquire_volume() with @cache_name is NULL, and thus they will be bound to the first registered cache. In this case, if the first registered cache is in the original mode, mounting erofs will fail since the boudn cache is not in on-demand mode. This can be fixed by specifying the name of the cache to be bound when calling fscache_acquire_volume(). Or adds a flag field to fscache_acquire_volume(), specifying if the caller wants to bind a cache in on-demand mode or not. --- fs/cachefiles/daemon.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index aa4efcabb5e3..a4f70516d250 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -44,8 +44,6 @@ static int cachefiles_daemon_tag(struct cachefiles_cache *, char *); static int cachefiles_daemon_bind(struct cachefiles_cache *, char *); static void cachefiles_daemon_unbind(struct cachefiles_cache *); -static unsigned long cachefiles_open; - const struct file_operations cachefiles_daemon_fops = { .owner = THIS_MODULE, .open = cachefiles_daemon_open, @@ -95,16 +93,10 @@ static int cachefiles_daemon_open(struct inode *inode, struct file *file) if (!capable(CAP_SYS_ADMIN)) return -EPERM; - /* the cachefiles device may only be open once at a time */ - if (xchg(&cachefiles_open, 1) == 1) - return -EBUSY; - /* allocate a cache record */ cache = kzalloc(sizeof(struct cachefiles_cache), GFP_KERNEL); - if (!cache) { - cachefiles_open = 0; + if (!cache) return -ENOMEM; - } mutex_init(&cache->daemon_mutex); init_waitqueue_head(&cache->daemon_pollwq); @@ -169,7 +161,6 @@ void cachefiles_put_unbind_pincount(struct cachefiles_cache *cache) { if (refcount_dec_and_test(&cache->unbind_pincount)) { cachefiles_daemon_unbind(cache); - cachefiles_open = 0; kfree(cache); } } -- 2.24.4