From patchwork Fri Oct 14 03:07:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 2472 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp590282wrs; Thu, 13 Oct 2022 20:10:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM46gEddRX/y76N4kJ+W/mqvNfI+nkCdzo0WbD3g0kFGd3z6JKdFuamAgVK+y3cjjCCloDDl X-Received: by 2002:a17:902:f689:b0:179:fdac:c4e2 with SMTP id l9-20020a170902f68900b00179fdacc4e2mr2964735plg.119.1665717045354; Thu, 13 Oct 2022 20:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665717045; cv=none; d=google.com; s=arc-20160816; b=rjD59s0u7Qz+Pz4FiFGKQBRH8b90Aoo5NihHkVTA1jL3EuHVGQFLYs62gggT+PM42J Cf1TIwy7iiJv7J1cdMIszL0jqM3B5SD3PStpEeCqHWmO3gzWU1rth3mqo08Uk3F5FEDY ofeUvJ9cPCN/b9ODcytNDmUHNGpRGFLFPtJxJwqeBvY4JfrjH5ZY+QS2kENUg85irfDg RV95SZ6c6GT5PkWt/k257Rd3IF89r/6ESLHVT51SNnXe4UYRK2p3iswWuTqmRYo4Zkcb QpZ+fJrIkCyrkUnhTVz+skUJ44jb8nHGzQ/u3g69iF7pUW5mEbZOUn/bM3lFHMr+lkS1 9aiw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z5-20020aa785c5000000b0054307ac90f1si1117220pfn.319.2022.10.13.20.10.31; Thu, 13 Oct 2022 20:10:45 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746630916923214049?= X-GMAIL-MSGID: =?utf-8?q?1746630916923214049?= 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 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;