From patchwork Fri Apr 14 17:22:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 83540 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp546134vqo; Fri, 14 Apr 2023 10:30:13 -0700 (PDT) X-Google-Smtp-Source: AKy350aTR/ZJel1IZ7MrKpRTlDu7kn6ARpgAOuWIdL3hC4fub1/gFv5YCKJoYMe6H43pgz6zgxD5 X-Received: by 2002:a17:902:f7d3:b0:1a6:6fe3:df91 with SMTP id h19-20020a170902f7d300b001a66fe3df91mr3376978plw.50.1681493413200; Fri, 14 Apr 2023 10:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681493413; cv=none; d=google.com; s=arc-20160816; b=apJ+kvof2Gy765744esfU0h8ndvcT9pPpgSVObx2Yi0t7X0VwQ8+Q0lPzroMozrLIS qiGw9TPEx39IjJDST4hBs0sH8aOX1q96iTboGEMt43SuzVH+lXWWPlpf0JZF2II3lglb n5Etlxf0njO4gtfb7W7WK0zuTWIQxJaGTiht+h9JOXXSscLnd64g7Iu38tGqUJnh5m1x GQAxojn+7zh9N27snfw2Al9+4GBJGQn6IJvjhWoKNW0g2hgNzNK/Kw3tI2aEwn4mG4dC kdbfaM4r4zAC7RMmYa49uGTgbX3+WTkOX2bveNFRlxHT2GvZ8UKHpdkSeff0ivKvPmcg 3ezw== 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=qgUvM997QJXfBj7OoFl5jxJ2P02ysazlJ3MfSoqKoTg=; b=0YuBYtqSeFdqy1C6GjnfS2yAzYrnx2LYoK51eZX7Usr0aPTSpU5i5VWEZT8cLZoJyn Wm1iXpdWWG39xjxJUNa9tMdvx+/meHFOJCnPM8XfEQ2CH8xk0+oNwmIcs5E0xh7sSb1a F1u6wY2Igcy7xWpDcvTbiIhzOGo88vhp+T5dbCv/enVaOyEFTtkOiZjW3ey+KRpSb5T2 YSlUOtH4bS33NVUa+J17+pwmbpPqWuPLE5/euBdhwkgbXCRUxGmh7oKGSFnCSu2Nnlq1 2Jx6y3PaqmUJRmuHoaqs1mcc35Zm+/daEYsIQAA6f9S23qXQH1vDnLhM+Zo8vUgQivNO 9rCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=T3zZn09j; 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=pass (p=QUARANTINE sp=QUARANTINE 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 r19-20020a170902be1300b001a1e308a820si4779462pls.624.2023.04.14.10.29.59; Fri, 14 Apr 2023 10:30:13 -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 header.s=google header.b=T3zZn09j; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230430AbjDNRY1 (ORCPT + 99 others); Fri, 14 Apr 2023 13:24:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbjDNRYI (ORCPT ); Fri, 14 Apr 2023 13:24:08 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BF5183D2 for ; Fri, 14 Apr 2023 10:23:37 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id o2so18964415plg.4 for ; Fri, 14 Apr 2023 10:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681493017; x=1684085017; 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=qgUvM997QJXfBj7OoFl5jxJ2P02ysazlJ3MfSoqKoTg=; b=T3zZn09jU30v3X8gm7zDVFka4YxfNrNYqbfTW7odCAvrYSgeHu3+TWK/Uex+lInrl0 ZR1SLxQQ2glTEULCFiZ8A/qnkb3MFe92XInJENc/PcgdijaRXP2jIN6X1kDLUnP++6IQ QxplK7Pa9BQFppNM64xGUztMw2VnSlZCV2zATAGfF/9q2HqmOLCVZbagxFdEGTigAVE7 RRP7UH3QmA5SfzjT8wMk+gaqYPYHMimKUVP4jk4csTXP/FrA5rfpwAOvMO2aZza7K1yL I+DdpAxZdgWcfk37FG8L7ECQ6ETodw8zhueKCA6Z7daSTQ1CBJEUdu45EQFDRCXK1SVa kMig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681493017; x=1684085017; 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=qgUvM997QJXfBj7OoFl5jxJ2P02ysazlJ3MfSoqKoTg=; b=i+Tt5l1SFhYqzoe4mnSLr4llv5hYaWBAv3SxCjBpzWDP+EG73i44JLPCQWoL/KGfer nWU8WDz3UfqnHbs0x+a4eyVlcRxmh42sBLY2bEuGmmsbjkj7hrhC+gz0gAjcrIroMCdD OHZW7XuU/KoFm1tFBfHGPKjI2BlSCCknvt0kY7o0118320mexBrW3u3mFR9VOubYSiSw KGpfg9xh3yXq2tE6Bpkl32CeZYc5XNrCKkOr7HqdAq3bMuOs6OiM9SqwvQedXY1Jm2Zc voTQ4TElAXS3UjnsUOEcX4KtiPgISmZMz/vbNIMfW64nJ6YOdA3lTl5Z+5lJsDRF1ieo EBcA== X-Gm-Message-State: AAQBX9ff7DO+ub3FGwfQG9/gKhUvOWg+ebqnXhLMVAqlSd0jkfCLbvdH pPD8CVOlcvwSOY9qqtWHszKzIQ== X-Received: by 2002:a05:6a20:8f2a:b0:ee:b24e:a40b with SMTP id b42-20020a056a208f2a00b000eeb24ea40bmr335653pzk.53.1681493017046; Fri, 14 Apr 2023 10:23:37 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id q12-20020a631f4c000000b0051b8172fa68sm370315pgm.38.2023.04.14.10.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 10:23:36 -0700 (PDT) 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 5/5] cachefiles: add restore command to recover inflight ondemand read requests Date: Sat, 15 Apr 2023 01:22:39 +0800 Message-Id: <20230414172239.33743-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230414172239.33743-1-zhujia.zj@bytedance.com> References: <20230414172239.33743-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 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_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 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?1763173637316339072?= X-GMAIL-MSGID: =?utf-8?q?1763173637316339072?= 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 70caa1946207d..3f24905f40661 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 26e5f8f123ef1..4a87c9d714a94 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 8e130de952f7d..b8fbbb1961bbc 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;