From patchwork Mon Nov 20 04:14:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 166937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1972344vqn; Sun, 19 Nov 2023 20:16:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/0c7D4ghjjCXI11cjTCXl26K3NlrwCXhq03JnINfe7smU70jXNNrzBlx35CDZKfcyPasG X-Received: by 2002:a05:6a21:7889:b0:187:6880:b02a with SMTP id bf9-20020a056a21788900b001876880b02amr5205977pzc.3.1700453785052; Sun, 19 Nov 2023 20:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700453785; cv=none; d=google.com; s=arc-20160816; b=k++9q39dTDWnWS1PkZ0MMPUeXj7KXU+rj6b2z5sW9YKMMWCirdOpAwtxrOjejGU/mB 6lbgkk2K53rRFpsFwOxd3JPDjh9CidOW+rgUhxwEHljYeinGN2d4kgWMBkcKA7fvf4W2 B4iMEwZZ89DwXnqrwhUQgUDbdSkmn+LLSemLZyd0EeCCVSjGT3nigX2g5V1QDR3NJ3f2 zn69Olz7hAclUIPU7Dz6EzU2vbJ9cfSNISuno6U3doHTL2pfRGY86U2yABuHOd/jOc+Y 2UGx7CAQJLQjpKhqc4AeDXm3+zQfoVjzcTGGl8v2RPo/3BQPc4Jw/XvrK1cL41l7lfZ+ h6xQ== 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:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id lk3-20020a17090b33c300b0027b0aac2191si7355364pjb.15.2023.11.19.20.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 20:16:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; 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:3 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 lipwig.vger.email (Postfix) with ESMTP id DF73D80A4A13; Sun, 19 Nov 2023 20:16:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231926AbjKTEPs (ORCPT + 27 others); Sun, 19 Nov 2023 23:15:48 -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 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Sun, 19 Nov 2023 20:16:20 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783055027933101995 X-GMAIL-MSGID: 1783055027933101995 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;