From patchwork Wed Jan 11 05:25:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 41760 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3143715wrt; Tue, 10 Jan 2023 21:45:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXuG765teknmxdi/Ks+wIB7NpiPiqZdojsAazasNj7LVhxsM4ukJM/Dr/BhptmMvUqDJsA8A X-Received: by 2002:a17:906:eda7:b0:7c4:f402:9769 with SMTP id sa7-20020a170906eda700b007c4f4029769mr77684194ejb.76.1673415930802; Tue, 10 Jan 2023 21:45:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673415930; cv=none; d=google.com; s=arc-20160816; b=v/i18FzBNcdZh7RhUTDWXq9mtjzr05jcJVr/V4wwnovlgoCzQjZPXjenr88eXa034A D97wmwINOsZn4jkx74m/Vsnoro1YfBsWYnkohMAVj/0T0AWsJ8rfr81AZmNenKupPpLq HRcxQozQepHqGu+0IPuTNxROfZN12ENMAjsKLYCwBohi8lo6k4KAMJaaMu1GltvepOfg jrmp/fTU8prv2+AJYI55vpmlhT8QBcoiXSBhS5c237SM28p1xnT/5Xjem3Xq4NeW93hs +YDBEB7ggcK/Wy2w/S576gkfjv8sjriBxpVycZ6vPO55fKQOaQSe7mAM2my4dVErycGP f03w== 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=zIpHcwHuLOh4SwnFnBbeF8LhMIZd7B1uohTZsNHDUqE=; b=YwSsE0hLWWj+0LuYHP5exvudwqGHj1rThzzKt2RkDksGSkjkkOuD71eU31hM5g9t8U 3Po05vs+P6D807YzQ4WBYj31e/k1b6o3aElUdanthEeUH3y4k6opbCUKhdZNZtVFKxFs BKYCDrVseCb5IMzLiwBdLRvX6GzdxtM94G7RSnSq12GCwfBfwjYlOVj/XRC2Nu2yX9pb cg+tNd2POM57j4DYA5jKYXZtdronmwFHRKcBT1J5paK7kpoNh0nStkFbv9iOSX+avcKx asEtjKRfubMpRa0As80ifH69CTIzCFm3P5rhRqJAV3iieh80lsHmszesbtJR4/H5ymMf L1WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=lSpQZ5Nl; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s19-20020a170906455300b007b5ce4a436csi10217543ejq.227.2023.01.10.21.45.07; Tue, 10 Jan 2023 21:45:30 -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; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=lSpQZ5Nl; 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 S236508AbjAKFiH (ORCPT + 99 others); Wed, 11 Jan 2023 00:38:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236012AbjAKFgy (ORCPT ); Wed, 11 Jan 2023 00:36:54 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D0FE11157 for ; Tue, 10 Jan 2023 21:25:47 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id o7-20020a17090a0a0700b00226c9b82c3aso15911996pjo.3 for ; Tue, 10 Jan 2023 21:25:47 -0800 (PST) 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=zIpHcwHuLOh4SwnFnBbeF8LhMIZd7B1uohTZsNHDUqE=; b=lSpQZ5Nl1oGZSNpIMCryP8PrFoR67A6GlkkwW9vZo8CD5btOX8PPc93muHthaWNoKy D7CXmW0L+PtqlbTMaYsKksxeEXV2J8Jtlorc6bsUuGpLizxf7K7risMkBcP7+WH8b4d9 cmYK91t3GBHw7IxZT/XQM/4Bv0vbcGPGoMvsNB167guolV2JvVEHqur5YyX67Zk2uC+5 9iNih8DPSpq0lJeRqR3bo99I4HxVwMdBli9ioY5G6clMrBrOWbm53/xq9j/SZtwlfpgh SLY8jNvHJbxEAnHLYa/sF6JQItsls4Pvnu846zRgjyotBkLOpjMHwXFe+ZI6VsWsBBNZ bOCg== 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=zIpHcwHuLOh4SwnFnBbeF8LhMIZd7B1uohTZsNHDUqE=; b=46txjF7TMjFXesbagIAKLWcgLyiUdShRiubb0D/c8+BckpkldV7LLtqgCMYAcH8KHD LpiH1U2HOi3j9AoxiZjG6usQHGgmoGgWPyqT9YUoaLmTJ7xopbwz8EsLQa4vAKXVZ9qG 2xAR66AL64CgMMJHi/LkjW5fzgN7oeN/o2Pp+k7I/Vr+JMWiiXbJkT4wVYbwxJ2rFu3U uHPoUnl+BwamTf5PBn3TRIm+YJdwnYlBsmZveJYE+WDIUqYZgsL2VKZWEiDsJxCgI1lr tWFjniIRQPjbtZvGinr/TprnUD7kn7J3sXQeB7OrupQs/4tPNU/vCW9yPf2os9ShKI2t R71g== X-Gm-Message-State: AFqh2krOh42yRvUoH7OZf88ESKIafqpYcPa9/LO9qo2GRhekqr09uOOp ddVIGP5VKZ/EtHDwfQa7L1Cz9Q== X-Received: by 2002:a17:902:9a0b:b0:189:d3dc:a9c4 with SMTP id v11-20020a1709029a0b00b00189d3dca9c4mr65777152plp.36.1673414746818; Tue, 10 Jan 2023 21:25:46 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.10]) by smtp.gmail.com with ESMTPSA id l10-20020a170903244a00b0019334350ce6sm4934520pls.244.2023.01.10.21.25.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 21:25:46 -0800 (PST) From: Jia Zhu To: dhowells@redhat.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jia Zhu , Gao Xiang , Xin Yin , Jingbo Xu Subject: [PATCH V4 5/5] cachefiles: add restore command to recover inflight ondemand read requests Date: Wed, 11 Jan 2023 13:25:15 +0800 Message-Id: <20230111052515.53941-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230111052515.53941-1-zhujia.zj@bytedance.com> References: <20230111052515.53941-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754703783098344923?= X-GMAIL-MSGID: =?utf-8?q?1754703783098344923?= 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 b8d8f280fb7a..5d9ec62cdd5e 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 3d94990a8b38..e1f8bd47a315 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -301,6 +301,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 8e7f8c152a5b..711b47448c85 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;