Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp14453rwi; Thu, 13 Oct 2022 20:28:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5vWXhOVsC01niMZBdunNAc1q+GpsiTbqxtTHLc239TzHIX9VhK4P/cCNRTqqvvgYGV71gS X-Received: by 2002:a17:906:c08c:b0:78d:b8ce:c28f with SMTP id f12-20020a170906c08c00b0078db8cec28fmr1952553ejz.437.1665718134230; Thu, 13 Oct 2022 20:28:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665718134; cv=none; d=google.com; s=arc-20160816; b=DRn1t4vTJn4I7kZonNJJ0h9TwWs8Lk6UTf1I1JfDUkD+4iPpSdF3FG2cbjfVDY1o4F mTCs8x4AusLkcfvWGE3iK98Sfrb30X2yiCCgLe+zQK7Sjr3c3obx7u9wbXyztEzvGN5z KCGL0DQ6Bhtgy+pvZ1BvgxZN18bdLQ28o2Nz75a8CmGok716Sw5VF16vF7PbNCDuXdxn DBIEHZYyCYxM1S7zh7h+hqltvWLmr2/p2+NqpgOs4Me3RZlUo3Qdr2LRD4Cx9c9tIK39 H/JNmYl16KAv/FsHaXsTAIis9ab58o8EMCpfulYudwSLVoXGoT1R93LD5dbhIW22aLOr BvoA== 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=RPYvhf6hYj1gmxvw7dTnMnSbUK/V1sm26ubqcw4lSFY=; b=Kgsmvo7qHeJw59Kjpf0OF1IgpdQ5imqslIU+0cObmBDMrB0SKiNjy7FbWE+oMsVhrl D0LDewXRmBubWwkY4NVp9+N+7YTWBkhC/FzxjN6vMMbHvr5dffALM+WEvsQRFNElRkQP mXk1T49DhhIQ+NyGXd0FMJFgwNjZN2qJY/KsJHaLBnL+6v6gefnBgiZ/M2b75CRrHRQK MFdlZ2Eun+EQRQIqreQlZ+RZlw2O+O3lqzJwb3/wjsvqYNFLlOWPDt7NM2B/6qSwtuy+ pE+G/Vi7g5OrbbCasPIc04RvsMjpkjs3r7o0/z+wkUEfnXm5iaaF4SUopBkjlqNm0DPK YnJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=uR1wnjzo; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020a170906724a00b007808f3f4cbcsi1108327ejk.239.2022.10.13.20.28.28; Thu, 13 Oct 2022 20:28:54 -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.20210112.gappssmtp.com header.s=20210112 header.b=uR1wnjzo; 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 S229876AbiJNDJR (ORCPT + 99 others); Thu, 13 Oct 2022 23:09:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbiJNDIj (ORCPT ); Thu, 13 Oct 2022 23:08:39 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8085EEF5A4 for ; Thu, 13 Oct 2022 20:08:34 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id n7so3579596plp.1 for ; Thu, 13 Oct 2022 20:08:33 -0700 (PDT) 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=RPYvhf6hYj1gmxvw7dTnMnSbUK/V1sm26ubqcw4lSFY=; b=uR1wnjzoh66Ntwurmw7mKwF1tShfnXY9UWfot3dsRbBXUbtebLzF0fV/OdZO1YB5Yw PcIMj+Ydd5Hn2ryM/TVGAKfZN0TZjdE6wCe+F3ctIO6FHCtRgJFCsBZIabYASTtj7hln XLsFKwqQlgniZqtFO6A/gIowSCRYZAj2hcvGo8DCes9+7qUqhO1J776gtuITkdeK0N+R UCWdGHLsKwtvYhGN+SfYD2BTsK0or91WpNavAyzl3NsTvh4cFtEMEUkWSbpWAPS3BfS5 gfLNCK1IEWcc2/kryI9FvqKKmhhxnFa5vC2Pe9soKZt87Sg2tIscUDwTaTd9N+OwA2hF baMg== 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=RPYvhf6hYj1gmxvw7dTnMnSbUK/V1sm26ubqcw4lSFY=; b=69tHbWsI3kh0SNef8OaoMwdsQr5ovRVoIpe6tB1n6yt3A7PxqrP84pKib2XhvlpkXv Y9I+bj7M9KzP2Xxc3hGIkQUGg79UZ7q4eXWxLSl0HkLIFLH2MQHOVymKip/BPThvZlN4 0pFOypV36HaoeE96nBPURBLpzuxWYSKP4um1noXX9tO8Cq1rqBRewBj0k39chEV/z1iY T7zV/w4OWbITXgB9z8uj2BLLrYmBIEM5oKoXvM8jw/2cExsZI9F/G6wC1SXXm0qr2xAq k8OYjR+fq8aIqVXw6+GFR7xlclFd5H1JGrjhJbejT35ZFTorbwPHng0MKp2sel/5ZXFM wmZw== X-Gm-Message-State: ACrzQf2+72zDM0we4vPRdKs0Rb9fmAQgCYFIs/M62nDaZ3a/KENXho+h /Ft8nRFTb4wkc5pzTrYWdX88LA== X-Received: by 2002:a17:902:db11:b0:17d:5e67:c51c with SMTP id m17-20020a170902db1100b0017d5e67c51cmr2829795plx.64.1665716912810; Thu, 13 Oct 2022 20:08:32 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([63.216.146.183]) by smtp.gmail.com with ESMTPSA id h4-20020a17090a710400b0020ae09e9724sm425524pjk.53.2022.10.13.20.08.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 20:08:32 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, xiang@kernel.org, jefflexu@linux.alibaba.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, Jia Zhu , Gao Xiang Subject: [PATCH V2 5/5] cachefiles: add restore command to recover inflight ondemand read requests Date: Fri, 14 Oct 2022 11:07:45 +0800 Message-Id: <20221014030745.25748-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20221014030745.25748-1-zhujia.zj@bytedance.com> References: <20221014030745.25748-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=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 --- 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 c74bd1f4ecf5..014369266cb2 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 98d6cf58db11..a3cacba57def 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -302,6 +302,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 c9eea89befec..08677c9d0004 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