Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2258392rwi; Tue, 11 Oct 2022 06:49:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4I70lKmu23r+dAUdicF2IdkUI14wgzLCnKCjCl+PTz291VJ/WdT1ZRT/O/VYGUL/2dO3IV X-Received: by 2002:a17:906:15ca:b0:78d:b7b3:2afa with SMTP id l10-20020a17090615ca00b0078db7b32afamr8056957ejd.69.1665496179137; Tue, 11 Oct 2022 06:49:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665496179; cv=none; d=google.com; s=arc-20160816; b=Brm5HPLoWwQPGtlpked7P+ez+vmWPGY07dBx1Pqq8P5Ud8VftqVXqwaaB36cy9a9nU 0nT/qKXeFvsVED82kMbmIQ32D7/3t7D0qGcUiHaPT3MGoo3SLyp0Kh90bGW2FzUdu2jq 1zTVC9NioIR3WTuZish5+RmwneOXc7gZWKDpnFeQaFMHPFbnAH3wW7z4G03cjoCpKQeS QRaEIPzFoZP2LE67kC0JgXnKxjzl9IdNMUtlRuiQLkNKJqc/wiP/acCXG5WV4ofMfc5q 3pMkdelxzjxemGdPA+S5S5mH0QDYF0gIOeNo2iYGsvPBlEJ2BG3O07PblY/PL4TvjrnC EJlQ== 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 :dkim-signature; bh=Kf3ZhctXueFJ0kbJ2xpRhM9KgFk3kGNXq2GUSVGfPOQ=; b=OPj+rwA/OSobNT9/FyLxIb151RJNiHGPxE52TQQmL9N5Rjp/dpFdlePxl3xsOH7Ob1 35p0oMYuYiT4th3LSYrR19YdbXLHg08xWaeoEEGVn6XTBO0gOYBOlCzo4lWndYC9vh06 czmMcI8M7mcVFK/+d+UAU2Xrtf5PUo6Ffle820QEtk7U48W45FokeU8Wxdg9bIu5ThiA Qi4SddjSiZEtcgFCAnKFtAEoBelAeSSBT9u7+DCHTU+loKMJ8rAoLkh5vqxrdGLtjCLS i2WnHdqMNiWU80iCbjtqYRAsqg4SjB3mwZKD7udlzP3Qsq3v0J5g2dEqdsCYl/uvmOU5 c8lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=QUnuJb+6; 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=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w18-20020aa7cb52000000b004593faf4fccsi12046837edt.110.2022.10.11.06.49.09; Tue, 11 Oct 2022 06:49:39 -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; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=QUnuJb+6; 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=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230174AbiJKNSZ (ORCPT + 99 others); Tue, 11 Oct 2022 09:18:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbiJKNR1 (ORCPT ); Tue, 11 Oct 2022 09:17:27 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7FE515FC2 for ; Tue, 11 Oct 2022 06:16:34 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id h13so12042592pfr.7 for ; Tue, 11 Oct 2022 06:16:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Kf3ZhctXueFJ0kbJ2xpRhM9KgFk3kGNXq2GUSVGfPOQ=; b=QUnuJb+6K78QvzX+CdefQECwtLKILI2InWFSw4OzOu7QHNDVoLPmNqV5UvdKmhyA3N KgzM7ww0PT7BkpNoOqo4MHkGexzbg3CK36roe4uoSD9jf26rKZMgpbGHi3D5lBCICVUa TyvYGVzJ0S2jFoSNd8eZpaD2WzpZiysKrBycBrHsaku1p37fHRu0BMk7MbT2AU+0Qybg egPZv1YRQtXiMlilzSUZlmYMqO2aTY774H89QOao2P8uyAsM5twteFQ8af0GeLWb6u3w fYtMjA1cBKSwTDj8DczZffZWgbFXKdahvzKi3fcIjFDujBaA9wqWREOC8QQnajIR9EVB Ao/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Kf3ZhctXueFJ0kbJ2xpRhM9KgFk3kGNXq2GUSVGfPOQ=; b=BfcCfo3JL1uckKUdrQVBMaJhsH6GZVZi0Q0KDuchluPJMCdeSGnwH4Snr/DcTUIOc3 h+GajYIp8lXw29a3WtQLxFKNfOIFeNdoqwgg1Q4cD6X9BmXCYhpy3pAROO3JCIQKCqkB 6URm7uz2l+fqRojSB6VVK/IATOblYBiZgjxUHQsGfe/kliXBNFqKU15dBLuZ1Xhr7RHR BIjM7O0Ojud9wk5G8RvZqRc/GtAos8x7gMpjNpilLFbZJL6MqpHvEt+WDjNKlbBQNyLG LNB6pCA1gHXM3FK77PWtm/msQC54koENNObSfuhJaxdwHaBIlHMU7VZw6lbh3T/2UhBa BGdQ== X-Gm-Message-State: ACrzQf3wKz2lzPdg8cRlSmIAVyNI10Vb3Xe4JVfbIJhZD+HybRz/2yha ibEQe/EtqdPYM7GICG94JoEg2A== X-Received: by 2002:a63:2c4c:0:b0:434:e001:89fd with SMTP id s73-20020a632c4c000000b00434e00189fdmr21065376pgs.444.1665494183614; Tue, 11 Oct 2022 06:16:23 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([63.216.146.190]) by smtp.gmail.com with ESMTPSA id d14-20020a170902654e00b00181f8523f60sm4773415pln.225.2022.10.11.06.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 06:16:23 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, xiang@kernel.org, jefflexu@linux.alibaba.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, Jia Zhu , Gao Xiang Subject: [PATCH 5/5] cachefiles: add restore command to recover inflight ondemand read requests Date: Tue, 11 Oct 2022 21:15:52 +0800 Message-Id: <20221011131552.23833-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20221011131552.23833-1-zhujia.zj@bytedance.com> References: <20221011131552.23833-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Previously, in ondemand read scenario, if the anonymous fd was closed by user daemon, inflight and subsequent read requests would return EIO. As long as the device connection is not released, user daemon can hold and restore inflight requests by setting the request flag to CACHEFILES_REQ_NEW. Suggested-by: Gao Xiang Signed-off-by: Jia Zhu Signed-off-by: Xin Yin --- fs/cachefiles/daemon.c | 1 + fs/cachefiles/internal.h | 3 +++ fs/cachefiles/ondemand.c | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index c74bd1f4ecf5..014369266cb2 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -77,6 +77,7 @@ static const struct cachefiles_daemon_cmd cachefiles_daemon_cmds[] = { { "tag", cachefiles_daemon_tag }, #ifdef CONFIG_CACHEFILES_ONDEMAND { "copen", cachefiles_ondemand_copen }, + { "restore", cachefiles_ondemand_restore }, #endif { "", NULL } }; diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 4655b8a14a60..756812fd8f68 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -302,6 +302,9 @@ extern ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, extern int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args); +extern int cachefiles_ondemand_restore(struct cachefiles_cache *cache, + char *args); + extern int cachefiles_ondemand_init_object(struct cachefiles_object *object); extern void cachefiles_ondemand_clean_object(struct cachefiles_object *object); diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 69bf5446cc9c..bf3005dce00f 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -182,6 +182,29 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args) return ret; } +int cachefiles_ondemand_restore(struct cachefiles_cache *cache, char *args) +{ + struct cachefiles_req *req; + + XA_STATE(xas, &cache->reqs, 0); + + if (!test_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags)) + return -EOPNOTSUPP; + + /* + * Reset the requests to CACHEFILES_REQ_NEW state, so that the + * requests have been processed halfway before the crash of the + * user daemon could be reprocessed after the recovery. + */ + xas_lock(&xas); + xas_for_each(&xas, req, ULONG_MAX) + xas_set_mark(&xas, CACHEFILES_REQ_NEW); + xas_unlock(&xas); + + wake_up_all(&cache->daemon_pollwq); + return 0; +} + static int cachefiles_ondemand_get_fd(struct cachefiles_req *req) { struct cachefiles_object *object; -- 2.20.1