Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp266352rwi; Fri, 14 Oct 2022 01:26:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4tNsBwwrivrliRJZIBeoXHO+6fhVQAdwQN262mru3wkS+2w7Di8wKAJG4FlJXlWWONYhjP X-Received: by 2002:a17:906:4783:b0:780:5be5:c81b with SMTP id cw3-20020a170906478300b007805be5c81bmr2794199ejc.76.1665735984198; Fri, 14 Oct 2022 01:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665735984; cv=none; d=google.com; s=arc-20160816; b=DHqneLcoD8YQE83AlfJ0xsR3sfqlZnpCZ+pAsxBtJOCpkHR6xG8ZV0UpvqZegph1iQ hPvYbfXkidCc4rEGINI8L7TvjCje1kd4/30djK8469y3iztU2bhlyTEHZejMQFC5vvzi 0BoRF5z9QXdd0MwJgH2DaW3FkPJi/1PjVtTfPVtZuO7Iro/DhqS50e3nYV9UTgh50ud9 ABZJmn7oohW2+mMXM1LkF9VySEzI0xnYa1ZApyc8cp+EvFTA9bW9NE2LTfQlAwWpjmJL YCgAcM7IyqI2vOecH2DjKxtQk2l1u0J3OkFYMMR2GswcaU2NMac3c69aHE0tF/KJn9+J fuIQ== 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=mJhr9GEso5XW6jomGaYhGKFuz4nHt5uQZJthz4evrwY=; b=y4rovHjYTYbZmFMduQcL7d79lblUNLHrz6Y0uS3S69iVq2uRVsKuVzbbpx0s1C7p9P GlVs+/88qiL+Yl4tdxSGcwMMGa13BehCqJp6T1QkmqSowzbE2AmsJ1cTngqTMpxzLJ+C hGHigaitWR8uQ4PrKHsmwQbrMHaOsWlCmjGH/b4CiM41vc/s+4B3mYzoisCI0rPxP6W9 mUL3FP1jGorWDybFCZZAQA4QXjklnDYycT0Ov/BP1DMi1wl+k7eb7YPfAwM2LNhg6MQO cHt+wzLxe6yzPUQdZL6XSPm/rISDodL9iTZyTEs8X3uz2R78rtkZjjCZHld8IfZzOPAF 4QSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=qVTtmipa; 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 hd10-20020a170907968a00b0078d8c03a5a6si2143439ejc.759.2022.10.14.01.25.58; Fri, 14 Oct 2022 01:26:24 -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=qVTtmipa; 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 S230058AbiJNIHZ (ORCPT + 99 others); Fri, 14 Oct 2022 04:07:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230113AbiJNIHH (ORCPT ); Fri, 14 Oct 2022 04:07:07 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E6931BE1FE for ; Fri, 14 Oct 2022 01:06:53 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id m6so4273064pfb.0 for ; Fri, 14 Oct 2022 01:06:52 -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=mJhr9GEso5XW6jomGaYhGKFuz4nHt5uQZJthz4evrwY=; b=qVTtmipam3rM6KfQlKjS9oB81qvNT4EbK05pZ/u8KhqTeMxi1fgQuugD0vIdferh4A YbPU1ZdtYPR/ZPK5WVwhOLx0PTxgdovGreGSp3BwRvbk/eVN1SZMEkZTSXOGevy3iugB AogReglRz/ngZipTLIK2lRwUlzQ7E6noznmewO+dUqWDsZMVyqKhugFDig/QBvybFt8t Vsx7w7v2uUUB5MSDzYmRU6/oD4TB2PLfO4YaDpnr5j9n7LFnLE8L91zITpD9smh490eb 0/OSLFJHUGkje4f/2tYzx91hXBA5zHhogkFUEypk+BKxWcCeQ66erKddmZAiYYVM9FTE hyHQ== 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=mJhr9GEso5XW6jomGaYhGKFuz4nHt5uQZJthz4evrwY=; b=va9eDGHIkjBjM3EqwwyQdW8Y3KyBsQhi4FAVhZvBADGq8/ij0ri6VQ5ELIoC4CBeim rrNl9uJIUG/ErT25p450TSlVStnzNOfxJkV8sAPo2gFMGNyJ7BiRMZXWlYW6d7u4lC29 t7FRqaYO8S8ly4Rz/pztTPPgD8+BrVD6Oztbk5p4Tvtz4BLdhh42UgWwGoaYq4TUbOJq +X3HCWbei/TCqWJK8SlXIvOzAsBR8keuHiCXbnUvBHYRmQq61KhvKXPyVSSV2z2R9o6U 67mWADUBnUhlQU7anfafECpJaBDULB4VUQp0nL+s6OVjUEfyic74EX5WtJ4wVv/c/6z7 sOGw== X-Gm-Message-State: ACrzQf3U8SYEQi/5ey/b9iD2ppyZvFIktauuMXyFi2DTVnWZfVSfJX+I cnQs11WjOEYF2QlGWk2Ji4JkMg== X-Received: by 2002:a05:6a00:1a0e:b0:547:1cf9:40e8 with SMTP id g14-20020a056a001a0e00b005471cf940e8mr3894976pfv.82.1665734811751; Fri, 14 Oct 2022 01:06:51 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([63.216.146.188]) by smtp.gmail.com with ESMTPSA id ik20-20020a170902ab1400b001730a1af0fbsm1119196plb.23.2022.10.14.01.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 01:06:51 -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 V3 5/5] cachefiles: add restore command to recover inflight ondemand read requests Date: Fri, 14 Oct 2022 16:05:59 +0800 Message-Id: <20221014080559.42108-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20221014080559.42108-1-zhujia.zj@bytedance.com> References: <20221014080559.42108-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=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 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 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 d8dce55d907c..c773ea940cc1 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