Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1984674rdb; Sun, 19 Nov 2023 20:17:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQnTsTCAx3SAHIdNaIo987rm6V1C5wbnmxhjzt0t4A6IqLsxOEZ7xEpej4g2UWT8o9A3MT X-Received: by 2002:a9d:63cb:0:b0:6d6:33c7:802a with SMTP id e11-20020a9d63cb000000b006d633c7802amr7166400otl.2.1700453836806; Sun, 19 Nov 2023 20:17:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700453836; cv=none; d=google.com; s=arc-20160816; b=ApVwLkTuL7utQBXxju0W5ZihcWBpjbb6tT2K4uxbugZTG9WxS0+aJ3nzM2MbDFpn7X HS+JWmCDBocZUTRxubLwBYSopWFcboZupv94UPmjHJ5z9bmvau9739fycRLkC+z/lHqg VsRoiZ/ctDG5YaiuNSPne3SK2kr4hU0e4fEzyZBRINrmzZURQmRTzA0xmgXyKh9Y4u4g ATcEqMSEYWGqsP3XcD9/TuJU4ChPmzft7Spa/65NotcCQyMm50+kG1zSYuMWqTUluJCL C1uTB5laJEPkFk4w5GPGGhKsjOE96iWGxQahYGBrNszYM0/mUG6fMc/UiYqzWE+6zWZr x1GA== 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=g1pCEGuj3QlPT+22tLUxveNeazv04i3uHRdJIvmcJDY=; fh=gTY9Ttsg2h15YfzLiYhbw6/47QPOSTuIOvkuo3BASSw=; b=H0zW93mC7rX1pZTflgWruwUWm9dHnH603wsYKEgtOkWaH4XnvHYS6wRfNEoiGo8D4D oO3YQXWL/whSaqZU5brIMsZIXVUV4Ig9HNC/fkNCSwYzxDKOmqCDIbxcWwMKn5Dtp9mE VFfdhmYnNNuR1qO05xCIvMvkMj8niMsDEU6OgWKUho/MzPSCpEMYfz7Bzgk6UJcafX4m KLCk80vvMoeEfNAGKBVCKwowyOR+eru3gUT5PFsi0jH2zVNIS1dWcNNyWZVEKFWa+YqZ lZXxFtzSzduA+/+OIWGExyWDx2DJtxtJfax9A+HjnAhKC+WB8GjvQkxhfCGl9RAEINzc 3SYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=cRiHIofC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d16-20020a634f10000000b005c1cd418245si7192391pgb.737.2023.11.19.20.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 20:17:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=cRiHIofC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 1667780755DB; Sun, 19 Nov 2023 20:15:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231790AbjKTEPr (ORCPT + 99 others); Sun, 19 Nov 2023 23:15:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231854AbjKTEPn (ORCPT ); Sun, 19 Nov 2023 23:15:43 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DE8FE5 for ; Sun, 19 Nov 2023 20:15:39 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1cc9b626a96so28410595ad.2 for ; Sun, 19 Nov 2023 20:15:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1700453739; x=1701058539; darn=vger.kernel.org; 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=g1pCEGuj3QlPT+22tLUxveNeazv04i3uHRdJIvmcJDY=; b=cRiHIofC6lBoTaNGTTXbgD5XM/5YYq0ngFcBNUcvj2nDMUYqtDxAGlMRyixQ4LCOs+ V8psW/TBZKZsm8963Cp49DrQEcf9eQebkTu6YIPlXMuP3n3nenXtINtdz9bY2EDyzayD 2AZbi/TSiWP0LtSp9ocWpJbfhOvEa1NaQI1wJU1bkFCEwe7fqmgOrbkR8WBGVB3JcZU4 hxGx+LVJypDcjabd+thD8NOFNkvW6sx/p0EZWUCXTz1qis9b6/QNr9nLQhZAiCF/AWAC vtRFPBEnXyCugRrZpsR1jCNGx3xYLErrlRNxdhn2rcy7HDg/ndVQLxMhNfUvs4c/x7fG bBVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700453739; x=1701058539; 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=g1pCEGuj3QlPT+22tLUxveNeazv04i3uHRdJIvmcJDY=; b=rUx+5Khxrhhs97x6PIuOPIpP4jy1PWeREzsmnAVjV4Rp5o++3txkA/DmOmP4tFO6MR Mo4kstdTiMlRmv6mIftNDsEXl7ItDEaPQGiFSzOPAc40ncWrwf8KK7MDwUGhtzUD7Ch0 qNIcQqxPrs4T6GhOo8IUueSCcBxtub3WPz90/VYUeiCT2iZvcQCw1ZCjeoCWo/WFkcbm vUWRuAXOxXFdQQBA5zvue0iFzB48AHx8zU/vNEnqwrzCqXjFfyTDEUkl6zzWrHDaMvQB XErgccyRB+/O3iXw7YEuLf0p6pkEFy0mpE3nGh2JUbvG8bC4auoUv18GRAnel4sRoVMn dGTQ== X-Gm-Message-State: AOJu0YztKMSuGUcvoQqaVp//gULFpv6vgZL9iHiQ4oqek/vObD8FVSgZ IqdarLiSwhtUJB2ct+eI83hQkg== X-Received: by 2002:a17:902:d2d2:b0:1ce:67fa:b398 with SMTP id n18-20020a170902d2d200b001ce67fab398mr4710323plc.16.1700453739021; Sun, 19 Nov 2023 20:15:39 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id h18-20020a170902f7d200b001cc4e477861sm5065266plw.212.2023.11.19.20.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 20:15:38 -0800 (PST) From: Jia Zhu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, jefflexu@linux.alibaba.com, hsiangkao@linux.alibaba.com, Jia Zhu , Xin Yin Subject: [PATCH V6 RESEND 5/5] cachefiles: add restore command to recover inflight ondemand read requests Date: Mon, 20 Nov 2023 12:14:22 +0800 Message-Id: <20231120041422.75170-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20231120041422.75170-1-zhujia.zj@bytedance.com> References: <20231120041422.75170-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 19 Nov 2023 20:15:57 -0800 (PST) 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 Reviewed-by: Jingbo Xu --- 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 70caa1946207..3f24905f4066 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 26e5f8f123ef..4a87c9d714a9 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -303,6 +303,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 8e130de952f7..b8fbbb1961bb 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