Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp847853rwe; Fri, 14 Apr 2023 10:26:00 -0700 (PDT) X-Google-Smtp-Source: AKy350YXwrSi17PZY5kVmRxzyn5QQMZaunfjolmkMh8F0sw59aclR0stZpw5+W/LfdT0Hj0VBUoo X-Received: by 2002:a17:903:11d0:b0:1a6:9671:253e with SMTP id q16-20020a17090311d000b001a69671253emr4519608plh.47.1681493160398; Fri, 14 Apr 2023 10:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681493160; cv=none; d=google.com; s=arc-20160816; b=f1+1SbYtxMSCMGqQwT1vX3RNZ1U0BGK5d0KpYyvmI0VmOGHV+Dha8tCddCS4U12PiT lwVqyucngtUM8hJp48G6izJvp6Ud/AMzS2d1NYX7xFYhC7+mwkTEUlgI7WqMGa9ClOlp aM4bOzox5h2uqVfcOL6cS5Jkg9Vm/iW4MMtZLN5+fWe6JEAIlpzHBlvTPPriKijqh6Ur VWGaEwWM3QffDZo9z5sOv+g8GhiiAY2EJftDYu0apT0uNM3Dm9ZQY9umMK+V+Jo3+O2S PpGYx9aiiVgXzHAD3OmiVxNlraQHKRvf3OnODv0r9LjhtLof1oVrFHGm7nWUgsTOVK7V 57Mg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x3-20020a170902fe8300b0019f27fd7cb1si4722481plm.150.2023.04.14.10.25.45; Fri, 14 Apr 2023 10:26:00 -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 S230355AbjDNRY1 (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 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_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 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; -- 2.20.1