From patchwork Wed Jan 11 05:25:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 41757 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3142890wrt; Tue, 10 Jan 2023 21:42:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXsZAW9IjEiFhSJua/NdFv0yK301SIX48U5FQJ0Td5olfZnYSA7A0WH6KxnXO0fRlI0c0dEk X-Received: by 2002:a17:906:524b:b0:7c1:5b5e:4d78 with SMTP id y11-20020a170906524b00b007c15b5e4d78mr63220381ejm.51.1673415747323; Tue, 10 Jan 2023 21:42:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673415747; cv=none; d=google.com; s=arc-20160816; b=o2GxBDUKT/jJDpp7OyEcQVdOm9PURllc4+P7VfWew/lILPZ68jU36hnkPSO0zoAisz r86Hx1j15sndg0DwAkmjw/yJBWM6UVjqE72BNkHGd4WSco4F704mORZaDhhbQ9aXaBU4 YEEST+t5M8+dFqBnJ8hihUU91jPpTgw3A4aLIDWXpxVY/lZGgD2vHBnEFNNyTpKoQu+k mqTiI/4opdP5wUeh4v/NuS8yhlSXNA97edWKv1c5E3AUZ/z8KPRHDEmQWST0GONqbe9C gJWc/vBr4dgzoN8hCqgHSO80nmaJY0VOna307UOdL1Ai/E5K1d0f2y3aXqcxB1lvf5OA HNbQ== 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=fNcrPzu+uKXnduESO+DuwK3jbFzibhJrS7INeKZTCZc=; b=Fi/4ulTbidCzdAQxFXHRD3BNtUG3ym/8gUjr9dj7fuXDNfPOrmyYLQC9M5O1lbMpTP bJ1QmflcdyA4f1ssl+O4b0VbJR+Ltu1McbZ7Jp94xa9b5mr6kQ99rPJ6ddLR5BInP+6t +wmg8dGo6xAyyh5aV1qH+XHMCwRBMEGEVzsM2WI/1uEV9EtZfSLAqxwH102odr324nPA ycBekW30Ck7/MKuv3TTIDXNmd61caNEtHVDhKs+xhW3ijuHD17Vo1xK8kETtHWPOXm36 aM8X8Kj8VweLTj4bZ3yi3poRO0eXOftCaaHSWtB4d30nkL1xB6bWKIenW/21xsmL8FRc 4GGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=LZxfjTdR; 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 hd34-20020a17090796a200b007d82520dec8si5147669ejc.263.2023.01.10.21.42.01; Tue, 10 Jan 2023 21:42:27 -0800 (PST) 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=LZxfjTdR; 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 S236201AbjAKFhe (ORCPT + 99 others); Wed, 11 Jan 2023 00:37:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235981AbjAKFgu (ORCPT ); Wed, 11 Jan 2023 00:36:50 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52B4A13CE7 for ; Tue, 10 Jan 2023 21:25:30 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id o1-20020a17090a678100b00219cf69e5f0so18837291pjj.2 for ; Tue, 10 Jan 2023 21:25:30 -0800 (PST) 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=fNcrPzu+uKXnduESO+DuwK3jbFzibhJrS7INeKZTCZc=; b=LZxfjTdR1pPmJdsipvdkRpy4mZJ6EeNJCFfEuDJU1+rxJsrZhiLO9qy9sutwriedMA W5e6Va8R3Hz4XGEjCuXcPeI3LHEgP8UjOO4kVj+2TRS+eP+6O+VzB76zb+HRWY1yjlHn e6Tde7QbSEIQGr47mJPO/paMMXCT09X0zvBVsiY3HRzvyj3TnqFTVte/MzQ7g5dda9I6 fndk2z9Ybwpt0JPz8PHBULIMLm4nzBmaoyRaxyJdf4zp/P+pV6mJ8Wi4NDSwpNHphV6D SGFPtqS+WGpnDEJKrvgOUkryBlDkTknk7oK74iacVQX3uw+FZVLcWPm4tdWQ1XvoSUGg GxJA== 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=fNcrPzu+uKXnduESO+DuwK3jbFzibhJrS7INeKZTCZc=; b=R/iAKY1Iss6YBt4+TMGHGapIwZD+4pVxiD7SW7gu8pW+cvv4O9E0jaGZNsU4Ixq4Di IITBrcH31QGdnF24E3wYdWGY5TJhBUHYzC//tWAUmSklxF1TE2UikfM7v0eQM7pPnfq8 +2PNb64grJW57SwNSY9u5KkJTQs6sxTiVd48Ss7Hf5/pMhAtCTcjzwIvXx7phrHoKuQI QnHBBSHW583Ow3VLi5NTIV/2IKPdr0rIFAG8vjV5yHBZSxr/Pe2Bd77c5XZiLgzMhEwg FlF5Ybi9thti9Fr/RVCWHRX9mTWJHMlAJCV2c7feP8Xs4YTuKOif6Z7WkOthkF3Eg9Rz +B3w== X-Gm-Message-State: AFqh2kqRiuidXTgSNlBWNsV/tB8hi0Hm1kcTH7l/KnwbBdBm80GQf46f ND1FWfUKMfjAx8/xvzvIdXLjNw== X-Received: by 2002:a17:903:1d0:b0:192:4f32:3ba7 with SMTP id e16-20020a17090301d000b001924f323ba7mr89259102plh.18.1673414729822; Tue, 10 Jan 2023 21:25:29 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.10]) by smtp.gmail.com with ESMTPSA id l10-20020a170903244a00b0019334350ce6sm4934520pls.244.2023.01.10.21.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 21:25:29 -0800 (PST) From: Jia Zhu To: dhowells@redhat.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jia Zhu , Xin Yin , Jingbo Xu Subject: [PATCH V4 1/5] cachefiles: introduce object ondemand state Date: Wed, 11 Jan 2023 13:25:11 +0800 Message-Id: <20230111052515.53941-2-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230111052515.53941-1-zhujia.zj@bytedance.com> References: <20230111052515.53941-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?1754703590446343651?= X-GMAIL-MSGID: =?utf-8?q?1754703590446343651?= Previously, @ondemand_id field was used not only to identify ondemand state of the object, but also to represent the index of the xarray. This commit introduces @state field to decouple the role of @ondemand_id and adds helpers to access it. Signed-off-by: Jia Zhu Reviewed-by: Xin Yin Reviewed-by: Jingbo Xu --- fs/cachefiles/internal.h | 21 +++++++++++++++++++++ fs/cachefiles/ondemand.c | 21 +++++++++------------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 2ad58c465208..b9c76a935ecd 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -44,6 +44,11 @@ struct cachefiles_volume { struct dentry *fanout[256]; /* Fanout subdirs */ }; +enum cachefiles_object_state { + CACHEFILES_ONDEMAND_OBJSTATE_close, /* Anonymous fd closed by daemon or initial state */ + CACHEFILES_ONDEMAND_OBJSTATE_open, /* Anonymous fd associated with object is available */ +}; + /* * Backing file state. */ @@ -62,6 +67,7 @@ struct cachefiles_object { #define CACHEFILES_OBJECT_USING_TMPFILE 0 /* Have an unlinked tmpfile */ #ifdef CONFIG_CACHEFILES_ONDEMAND int ondemand_id; + enum cachefiles_object_state state; #endif }; @@ -296,6 +302,21 @@ extern void cachefiles_ondemand_clean_object(struct cachefiles_object *object); extern int cachefiles_ondemand_read(struct cachefiles_object *object, loff_t pos, size_t len); +#define CACHEFILES_OBJECT_STATE_FUNCS(_state) \ +static inline bool \ +cachefiles_ondemand_object_is_##_state(const struct cachefiles_object *object) \ +{ \ + return object->state == CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ +} \ + \ +static inline void \ +cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ +{ \ + object->state = CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ +} + +CACHEFILES_OBJECT_STATE_FUNCS(open); +CACHEFILES_OBJECT_STATE_FUNCS(close); #else static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, char __user *_buffer, size_t buflen) diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 0254ed39f68c..90456b8a4b3e 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -15,6 +15,7 @@ static int cachefiles_ondemand_fd_release(struct inode *inode, xa_lock(&cache->reqs); object->ondemand_id = CACHEFILES_ONDEMAND_ID_CLOSED; + cachefiles_ondemand_set_object_close(object); /* * Flush all pending READ requests since their completion depends on @@ -176,6 +177,8 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args) set_bit(FSCACHE_COOKIE_NO_DATA_TO_READ, &cookie->flags); trace_cachefiles_ondemand_copen(req->object, id, size); + cachefiles_ondemand_set_object_open(req->object); + out: complete(&req->done); return ret; @@ -363,7 +366,8 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object, /* coupled with the barrier in cachefiles_flush_reqs() */ smp_mb(); - if (opcode != CACHEFILES_OP_OPEN && object->ondemand_id <= 0) { + if (opcode != CACHEFILES_OP_OPEN && + !cachefiles_ondemand_object_is_open(object)) { WARN_ON_ONCE(object->ondemand_id == 0); xas_unlock(&xas); ret = -EIO; @@ -430,18 +434,11 @@ static int cachefiles_ondemand_init_close_req(struct cachefiles_req *req, void *private) { struct cachefiles_object *object = req->object; - int object_id = object->ondemand_id; - /* - * It's possible that object id is still 0 if the cookie looking up - * phase failed before OPEN request has ever been sent. Also avoid - * sending CLOSE request for CACHEFILES_ONDEMAND_ID_CLOSED, which means - * anon_fd has already been closed. - */ - if (object_id <= 0) + if (!cachefiles_ondemand_object_is_open(object)) return -ENOENT; - req->msg.object_id = object_id; + req->msg.object_id = object->ondemand_id; trace_cachefiles_ondemand_close(object, &req->msg); return 0; } @@ -460,7 +457,7 @@ static int cachefiles_ondemand_init_read_req(struct cachefiles_req *req, int object_id = object->ondemand_id; /* Stop enqueuing requests when daemon has closed anon_fd. */ - if (object_id <= 0) { + if (!cachefiles_ondemand_object_is_open(object)) { WARN_ON_ONCE(object_id == 0); pr_info_once("READ: anonymous fd closed prematurely.\n"); return -EIO; @@ -485,7 +482,7 @@ int cachefiles_ondemand_init_object(struct cachefiles_object *object) * creating a new tmpfile as the cache file. Reuse the previously * allocated object ID if any. */ - if (object->ondemand_id > 0) + if (cachefiles_ondemand_object_is_open(object)) return 0; volume_key_size = volume->key[0] + 1; From patchwork Wed Jan 11 05:25:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 41758 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3142957wrt; Tue, 10 Jan 2023 21:42:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXsAXCB4CF/7DIQ6Yemg2CgNmUhk5YEKn+h9WORFogfgZ671gE4hUeS/pimXbGDTF1tIH7Hz X-Received: by 2002:a05:6402:22ad:b0:488:6003:24b6 with SMTP id cx13-20020a05640222ad00b00488600324b6mr31486303edb.40.1673415758453; Tue, 10 Jan 2023 21:42:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673415758; cv=none; d=google.com; s=arc-20160816; b=BQ+sIFqizwoqiySCYDPMIvYiSUDA3wjuiNC0ce+sQaRHSchuz7C8OKOmTZULqP7gEs brk+pXziNNJG9wMnL6js/n+8nKRbygHry/Q8zxYk5z2+rLjW+gEmyvanBytEInNqlj1a hu+cRJfFMbIrT9Yse3OE4U2+IfanatwqXmfWEzE9CA3ZKr5v6dgRyI6wR6Q/qQN2gJuP BE9q24XSUOY50xEdTU3TwQqvs9ZY3CxnG8HPtfG66LeukvJUrkJVP8X2ZT1mDbygGLfc KS8PcrS3mKhPb1z/ohBv7Y5lSxXnHfzJTvMZv9HRlI8fS/y/LKNaaOxAE8gupMUPTHki X47A== 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=BUNmB6S9jkYzZMjtNGXZtdFizVu+vOEWVlJtmuAd/sM=; b=Y78r7L32iAPWQ5r1WPnNnq+hoiHzyI0UIxWSdxdrZCQqdTNJgFAWqNgxbfVKI6CBid hX5bxZsqXAhAwUNexEzSSv6YWB1BQHIQlZaccpk9e6noiRxhDzMkfgb2ebRLXfSiBEry EDbi0RWo3+iImjiS3K1U19UG9nyf6AwNAAdodpzZu4NtdyRA5WxnvLCqSAahK8gwBj/Z vlsP6rvHyA11cmc5Lm8WPNrJH9sf4ZSCVu7mb66y/QrPPuch5+aqovQwn4rjIW2Mj5BN igAxKOgiFj6Dq2iA4GF4wlCjrYpc49xcI0/kP84nj9WYJyETEGiQvPiRPQKaNa1ATdOI ORAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=L+d64pR+; 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 y22-20020a056402359600b00461dc830100si16314478edc.452.2023.01.10.21.42.11; Tue, 10 Jan 2023 21:42:38 -0800 (PST) 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=L+d64pR+; 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 S236041AbjAKFhw (ORCPT + 99 others); Wed, 11 Jan 2023 00:37:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235913AbjAKFgv (ORCPT ); Wed, 11 Jan 2023 00:36:51 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A619F3C727 for ; Tue, 10 Jan 2023 21:25:33 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id d3so15610578plr.10 for ; Tue, 10 Jan 2023 21:25:33 -0800 (PST) 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=BUNmB6S9jkYzZMjtNGXZtdFizVu+vOEWVlJtmuAd/sM=; b=L+d64pR+VebvUUUjaiccGVxSldyfm09MSkGMj332GTcZUFoR6eZLdEUtDH829a2993 6Uhr9TkD6wWdjiHnlHHQaOwHMPZiyUiax+N2LN8M38QGaXN/ydu7ebZuOzSQhoX8ejYs Sn4VQWsI+te85j9k/jOD8MnzWiF3LOp9+edZXKDV4VvVWxPrgogO/cM8B3xv+3WSIExj 8esc0+I6W2RN9y5jaMobJehHZxlQ4n5bWVonUhk8D5UadhDbOLtH8qmWgJrZd0fjkH0h nwGYo1tExfYMKl+dPV3Y+ZluctX+zABCgCZqQM5L65npM0Q30HeiUn8T0rZlZSkwIOSJ 2q0A== 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=BUNmB6S9jkYzZMjtNGXZtdFizVu+vOEWVlJtmuAd/sM=; b=L4ZAMvEJksICjmYxTD3NLhEP7kbnx7fMts6PCeygHmNfacKOSPiRUyJOFnUwCpCfLo Fs9Ce6rF1f70+gCBgbhdd84REBm5FRGuvanBMwvPuzGFEMrGi5oE5VUYt0hzpRPWBori ZltQR4fgBYQyfT99zutQO9mUeZ469RNcxfDIXKSv5k2UXvdPdyOHWWNQdjAm5n/zzmkJ H0yUcoQGF28tcinRTrOT5Wj0K0UqCdmm7BL/JrYmwhWTvA0YpXEL9GijJ5DsSFI8fPfK J16sTDZUYW7Ae7gOs/uCsXA+E9+trBiUmvhX/fAbfehIAC5l/Qa9Lvtq/iFhYKGe2rkI VHSA== X-Gm-Message-State: AFqh2kqCDzqE9mW++fHapCxnZITP2hJi9izK+VDUf+ORiSBubvxGaWx1 ih2y20Az3noQkEC9pLgNojRuTg== X-Received: by 2002:a17:902:ed89:b0:192:816c:8c31 with SMTP id e9-20020a170902ed8900b00192816c8c31mr49172243plj.35.1673414733204; Tue, 10 Jan 2023 21:25:33 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.10]) by smtp.gmail.com with ESMTPSA id l10-20020a170903244a00b0019334350ce6sm4934520pls.244.2023.01.10.21.25.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 21:25:32 -0800 (PST) From: Jia Zhu To: dhowells@redhat.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jia Zhu , Jingbo Xu Subject: [PATCH V4 2/5] cachefiles: extract ondemand info field from cachefiles_object Date: Wed, 11 Jan 2023 13:25:12 +0800 Message-Id: <20230111052515.53941-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230111052515.53941-1-zhujia.zj@bytedance.com> References: <20230111052515.53941-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=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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754703602346430219?= X-GMAIL-MSGID: =?utf-8?q?1754703602346430219?= We'll introduce a @work_struct field for @object in subsequent patches, it will enlarge the size of @object. As the result of that, this commit extracts ondemand info field from @object. Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/cachefiles/interface.c | 6 ++++++ fs/cachefiles/internal.h | 24 ++++++++++++++++++------ fs/cachefiles/ondemand.c | 28 ++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c index a69073a1d3f0..690e3e1ee661 100644 --- a/fs/cachefiles/interface.c +++ b/fs/cachefiles/interface.c @@ -31,6 +31,11 @@ struct cachefiles_object *cachefiles_alloc_object(struct fscache_cookie *cookie) if (!object) return NULL; + if (cachefiles_ondemand_init_obj_info(object, volume)) { + kmem_cache_free(cachefiles_object_jar, object); + return NULL; + } + refcount_set(&object->ref, 1); spin_lock_init(&object->lock); @@ -88,6 +93,7 @@ void cachefiles_put_object(struct cachefiles_object *object, ASSERTCMP(object->file, ==, NULL); kfree(object->d_name); + kfree(object->private); cache = object->volume->cache->cache; fscache_put_cookie(object->cookie, fscache_cookie_put_object); diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index b9c76a935ecd..beaf3a8785ce 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -49,6 +49,12 @@ enum cachefiles_object_state { CACHEFILES_ONDEMAND_OBJSTATE_open, /* Anonymous fd associated with object is available */ }; +struct cachefiles_ondemand_info { + int ondemand_id; + enum cachefiles_object_state state; + struct cachefiles_object *object; +}; + /* * Backing file state. */ @@ -65,10 +71,7 @@ struct cachefiles_object { enum cachefiles_content content_info:8; /* Info about content presence */ unsigned long flags; #define CACHEFILES_OBJECT_USING_TMPFILE 0 /* Have an unlinked tmpfile */ -#ifdef CONFIG_CACHEFILES_ONDEMAND - int ondemand_id; - enum cachefiles_object_state state; -#endif + struct cachefiles_ondemand_info *private; }; #define CACHEFILES_ONDEMAND_ID_CLOSED -1 @@ -302,17 +305,20 @@ extern void cachefiles_ondemand_clean_object(struct cachefiles_object *object); extern int cachefiles_ondemand_read(struct cachefiles_object *object, loff_t pos, size_t len); +extern int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object, + struct cachefiles_volume *volume); + #define CACHEFILES_OBJECT_STATE_FUNCS(_state) \ static inline bool \ cachefiles_ondemand_object_is_##_state(const struct cachefiles_object *object) \ { \ - return object->state == CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ + return object->private->state == CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ } \ \ static inline void \ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ { \ - object->state = CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ + object->private->state = CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ } CACHEFILES_OBJECT_STATE_FUNCS(open); @@ -338,6 +344,12 @@ static inline int cachefiles_ondemand_read(struct cachefiles_object *object, { return -EOPNOTSUPP; } + +static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object, + struct cachefiles_volume *volume) +{ + return 0; +} #endif /* diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 90456b8a4b3e..6e47667c6690 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -9,12 +9,13 @@ static int cachefiles_ondemand_fd_release(struct inode *inode, { struct cachefiles_object *object = file->private_data; struct cachefiles_cache *cache = object->volume->cache; - int object_id = object->ondemand_id; + struct cachefiles_ondemand_info *info = object->private; + int object_id = info->ondemand_id; struct cachefiles_req *req; XA_STATE(xas, &cache->reqs, 0); xa_lock(&cache->reqs); - object->ondemand_id = CACHEFILES_ONDEMAND_ID_CLOSED; + info->ondemand_id = CACHEFILES_ONDEMAND_ID_CLOSED; cachefiles_ondemand_set_object_close(object); /* @@ -222,7 +223,7 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req) load = (void *)req->msg.data; load->fd = fd; req->msg.object_id = object_id; - object->ondemand_id = object_id; + object->private->ondemand_id = object_id; cachefiles_get_unbind_pincount(cache); trace_cachefiles_ondemand_open(object, &req->msg, load); @@ -368,7 +369,7 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object, if (opcode != CACHEFILES_OP_OPEN && !cachefiles_ondemand_object_is_open(object)) { - WARN_ON_ONCE(object->ondemand_id == 0); + WARN_ON_ONCE(object->private->ondemand_id == 0); xas_unlock(&xas); ret = -EIO; goto out; @@ -438,7 +439,7 @@ static int cachefiles_ondemand_init_close_req(struct cachefiles_req *req, if (!cachefiles_ondemand_object_is_open(object)) return -ENOENT; - req->msg.object_id = object->ondemand_id; + req->msg.object_id = object->private->ondemand_id; trace_cachefiles_ondemand_close(object, &req->msg); return 0; } @@ -454,7 +455,7 @@ static int cachefiles_ondemand_init_read_req(struct cachefiles_req *req, struct cachefiles_object *object = req->object; struct cachefiles_read *load = (void *)req->msg.data; struct cachefiles_read_ctx *read_ctx = private; - int object_id = object->ondemand_id; + int object_id = object->private->ondemand_id; /* Stop enqueuing requests when daemon has closed anon_fd. */ if (!cachefiles_ondemand_object_is_open(object)) { @@ -500,6 +501,21 @@ void cachefiles_ondemand_clean_object(struct cachefiles_object *object) cachefiles_ondemand_init_close_req, NULL); } +int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object, + struct cachefiles_volume *volume) +{ + if (!cachefiles_in_ondemand_mode(volume->cache)) + return 0; + + object->private = kzalloc(sizeof(struct cachefiles_ondemand_info), + GFP_KERNEL); + if (!object->private) + return -ENOMEM; + + object->private->object = object; + return 0; +} + int cachefiles_ondemand_read(struct cachefiles_object *object, loff_t pos, size_t len) { From patchwork Wed Jan 11 05:25:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 41759 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3143021wrt; Tue, 10 Jan 2023 21:42:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXtUuQjd2ezp7hiUHDE7nTOFfT+H+LQG7PphK6Mcy79bQb4iBxvKL0CvNQ3Ces+KymkpOlbJ X-Received: by 2002:a17:907:93d5:b0:83c:cca7:64a7 with SMTP id cp21-20020a17090793d500b0083ccca764a7mr55058760ejc.73.1673415774786; Tue, 10 Jan 2023 21:42:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673415774; cv=none; d=google.com; s=arc-20160816; b=irrmKQpqAfvUetF4iosrJsWGfcwadiBamVgDSlYbSyCncA3uWClvVMGcBUJex5qqF/ Eo4yoVqe1w+WYBn1lZUxQetRU1265NyHfpZZOEMpzeUWD87SnATF/o0DgvVeOEpAjSbk crlQErmUFKRG/GE2cu1eSxqLFRZVIOmVXwRSL/YTeA6WLLzpzn7lmeCG2PghWVMcSXZZ Mh2vQt233Y0gfgX5zZLrK1iYU+l9n4XTT+FviENT57GrsJkkrGOAAjmPLjgXdp35h/q9 8OCJPTx2K8tKM/yB6EsvA5JN3pDt6ii+JSbBJhfX8/qWM0kHKZ9M3i4dcwDuzOjWtJMf 7AWg== 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=NxesNgIdPvkYanE3SX5ef2YSm8oaM0kD5UaXuDy462Q=; b=BWA4kiyUtRNpvR5QuRjuJp/enUN5m4g+4QI1A2pfgisrntwB2b1PBopnto3tk7qJ+8 o87/2l4mIOiwvK9XQuOC5P68DL413t7fvSkE4D8OZUKsEyQgA34e/peWmq26ak0GpmZN sjaVxpP0+WEwbYy1OrFsK/0DkGcx1uKARDLqW5WFn0Y+17PW3/kOHYzXxfb7cfBlE8p9 lzW0ARMLXrnfHh0tmy4lJ6yrnYM/MQKxv8QgftRau4/x67JN3MRgX67vd7T7+cNT2oTl Ce7lknFJUc+6rhgl1iSnciFxWfS/LUwPH0suqITNAuF8YrMSCpbTZXmCIhADfkMYuC7h JUMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=fqJll3HK; 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 hr39-20020a1709073fa700b007c4f6c371a8si16179722ejc.519.2023.01.10.21.42.31; Tue, 10 Jan 2023 21:42:54 -0800 (PST) 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=fqJll3HK; 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 S229699AbjAKFiA (ORCPT + 99 others); Wed, 11 Jan 2023 00:38:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236011AbjAKFgy (ORCPT ); Wed, 11 Jan 2023 00:36:54 -0500 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 EA1193C71B for ; Tue, 10 Jan 2023 21:25:36 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id y1so15646050plb.2 for ; Tue, 10 Jan 2023 21:25:36 -0800 (PST) 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=NxesNgIdPvkYanE3SX5ef2YSm8oaM0kD5UaXuDy462Q=; b=fqJll3HKWCB0vcfigp+GvhTJhMi+uNsm9YG48MhUt7KsGHGEJDNZThgCC4hHQFqGv2 XLwUbdDIT7GkhFKeIWTpYzGTlnucAOktdeAXaPlHSGL8/ML7jzHdapRiUHkJXShEt3/0 vSXA9FpyKo6qCidgFBgbvWVRpbwVCHM1ARIwoLx0HuqfjxlMuym4uITQPAlB0w9I5ttF rqCR0InKrWv0mzVfnJix1uqLWnBZJ09frNm4Un7nyfPXHSYIyjjxvCfo40LP7Eg1dyQU GmlSz1rJ+vs3JKPLOUiUnTQcrQSNWUlmUQOw04qgCWgVjYwWXSflAgHqwe9czFA+v/zO B6Vw== 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=NxesNgIdPvkYanE3SX5ef2YSm8oaM0kD5UaXuDy462Q=; b=v/dUtkQXlfVOUeXoGVlCGgl8eFcywNS+dwq6mOSJ64c+Nfosx9QBxhmHRGJa6fQfQa 2rRLeQZADlnXVSgT8yaqK47YRnsHWeSls26yubuI+n2KrM/DWMVvQlUcsVK/d/coGeSL yjQNsJ0I+f5WnYAcYjrtEcMOBobSt8sucM6fIleRY1zNuQL+G8TDYN2lTtCiZD64I3c9 QHandVef7khvgQIZpWkNDHtQPIYzRf5fkmq9cKx43AFYCO5buWxkPvkoy9X9t6VxSvLU 2FRDnXWo7j9wXBUaoBMnRa5a/DjL2s1/SMS7DPnMEjnckj2YJbPc/ItfPj53G7+pUJax YcfA== X-Gm-Message-State: AFqh2krkL9mm/YMyW9TAFjEN9AuNsiIL+oQ1HUKibEJo5KAKzMiv/IbB NRcNB91GJ6o2kFrR+qau7eAXFQ== X-Received: by 2002:a17:902:aa82:b0:193:2f1a:65b1 with SMTP id d2-20020a170902aa8200b001932f1a65b1mr1257700plr.59.1673414736334; Tue, 10 Jan 2023 21:25:36 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.10]) by smtp.gmail.com with ESMTPSA id l10-20020a170903244a00b0019334350ce6sm4934520pls.244.2023.01.10.21.25.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 21:25:36 -0800 (PST) From: Jia Zhu To: dhowells@redhat.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jia Zhu , Xin Yin , Jingbo Xu Subject: [PATCH V4 3/5] cachefiles: resend an open request if the read request's object is closed Date: Wed, 11 Jan 2023 13:25:13 +0800 Message-Id: <20230111052515.53941-4-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230111052515.53941-1-zhujia.zj@bytedance.com> References: <20230111052515.53941-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?1754703619897755667?= X-GMAIL-MSGID: =?utf-8?q?1754703619897755667?= When an anonymous fd is closed by user daemon, if there is a new read request for this file comes up, the anonymous fd should be re-opened to handle that read request rather than fail it directly. 1. Introduce reopening state for objects that are closed but have inflight/subsequent read requests. 2. No longer flush READ requests but only CLOSE requests when anonymous fd is closed. 3. Enqueue the reopen work to workqueue, thus user daemon could get rid of daemon_read context and handle that request smoothly. Otherwise, the user daemon will send a reopen request and wait for itself to process the request. Signed-off-by: Jia Zhu Reviewed-by: Xin Yin Reviewed-by: Jingbo Xu --- fs/cachefiles/internal.h | 3 ++ fs/cachefiles/ondemand.c | 98 ++++++++++++++++++++++++++++------------ 2 files changed, 72 insertions(+), 29 deletions(-) diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index beaf3a8785ce..2ed836d4169e 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -47,9 +47,11 @@ struct cachefiles_volume { enum cachefiles_object_state { CACHEFILES_ONDEMAND_OBJSTATE_close, /* Anonymous fd closed by daemon or initial state */ CACHEFILES_ONDEMAND_OBJSTATE_open, /* Anonymous fd associated with object is available */ + CACHEFILES_ONDEMAND_OBJSTATE_reopening, /* Object that was closed and is being reopened. */ }; struct cachefiles_ondemand_info { + struct work_struct work; int ondemand_id; enum cachefiles_object_state state; struct cachefiles_object *object; @@ -323,6 +325,7 @@ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ CACHEFILES_OBJECT_STATE_FUNCS(open); CACHEFILES_OBJECT_STATE_FUNCS(close); +CACHEFILES_OBJECT_STATE_FUNCS(reopening); #else static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, char __user *_buffer, size_t buflen) diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 6e47667c6690..8e7f8c152a5b 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -18,14 +18,10 @@ static int cachefiles_ondemand_fd_release(struct inode *inode, info->ondemand_id = CACHEFILES_ONDEMAND_ID_CLOSED; cachefiles_ondemand_set_object_close(object); - /* - * Flush all pending READ requests since their completion depends on - * anon_fd. - */ - xas_for_each(&xas, req, ULONG_MAX) { + /* Only flush CACHEFILES_REQ_NEW marked req to avoid race with daemon_read */ + xas_for_each_marked(&xas, req, ULONG_MAX, CACHEFILES_REQ_NEW) { if (req->msg.object_id == object_id && - req->msg.opcode == CACHEFILES_OP_READ) { - req->error = -EIO; + req->msg.opcode == CACHEFILES_OP_CLOSE) { complete(&req->done); xas_store(&xas, NULL); } @@ -179,6 +175,7 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args) trace_cachefiles_ondemand_copen(req->object, id, size); cachefiles_ondemand_set_object_open(req->object); + wake_up_all(&cache->daemon_pollwq); out: complete(&req->done); @@ -222,7 +219,6 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req) load = (void *)req->msg.data; load->fd = fd; - req->msg.object_id = object_id; object->private->ondemand_id = object_id; cachefiles_get_unbind_pincount(cache); @@ -238,6 +234,43 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req) return ret; } +static void ondemand_object_worker(struct work_struct *work) +{ + struct cachefiles_object *object = + ((struct cachefiles_ondemand_info *)work)->object; + + cachefiles_ondemand_init_object(object); +} + +/* + * If there are any inflight or subsequent READ requests on the + * closed object, reopen it. + * Skip read requests whose related object is reopening. + */ +static struct cachefiles_req *cachefiles_ondemand_select_req(struct xa_state *xas, + unsigned long xa_max) +{ + struct cachefiles_req *req; + struct cachefiles_object *object; + struct cachefiles_ondemand_info *info; + + xas_for_each_marked(xas, req, xa_max, CACHEFILES_REQ_NEW) { + if (req->msg.opcode != CACHEFILES_OP_READ) + return req; + object = req->object; + info = object->private; + if (cachefiles_ondemand_object_is_close(object)) { + cachefiles_ondemand_set_object_reopening(object); + queue_work(fscache_wq, &info->work); + continue; + } else if (cachefiles_ondemand_object_is_reopening(object)) { + continue; + } + return req; + } + return NULL; +} + ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, char __user *_buffer, size_t buflen) { @@ -248,16 +281,16 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, int ret = 0; XA_STATE(xas, &cache->reqs, cache->req_id_next); + xa_lock(&cache->reqs); /* * Cyclically search for a request that has not ever been processed, * to prevent requests from being processed repeatedly, and make * request distribution fair. */ - xa_lock(&cache->reqs); - req = xas_find_marked(&xas, UINT_MAX, CACHEFILES_REQ_NEW); + req = cachefiles_ondemand_select_req(&xas, ULONG_MAX); if (!req && cache->req_id_next > 0) { xas_set(&xas, 0); - req = xas_find_marked(&xas, cache->req_id_next - 1, CACHEFILES_REQ_NEW); + req = cachefiles_ondemand_select_req(&xas, cache->req_id_next - 1); } if (!req) { xa_unlock(&cache->reqs); @@ -277,14 +310,18 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, xa_unlock(&cache->reqs); id = xas.xa_index; - msg->msg_id = id; if (msg->opcode == CACHEFILES_OP_OPEN) { ret = cachefiles_ondemand_get_fd(req); - if (ret) + if (ret) { + cachefiles_ondemand_set_object_close(req->object); goto error; + } } + msg->msg_id = id; + msg->object_id = req->object->private->ondemand_id; + if (copy_to_user(_buffer, msg, n) != 0) { ret = -EFAULT; goto err_put_fd; @@ -317,19 +354,23 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object, void *private) { struct cachefiles_cache *cache = object->volume->cache; - struct cachefiles_req *req; + struct cachefiles_req *req = NULL; XA_STATE(xas, &cache->reqs, 0); int ret; if (!test_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags)) return 0; - if (test_bit(CACHEFILES_DEAD, &cache->flags)) - return -EIO; + if (test_bit(CACHEFILES_DEAD, &cache->flags)) { + ret = -EIO; + goto out; + } req = kzalloc(sizeof(*req) + data_len, GFP_KERNEL); - if (!req) - return -ENOMEM; + if (!req) { + ret = -ENOMEM; + goto out; + } req->object = object; init_completion(&req->done); @@ -367,7 +408,7 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object, /* coupled with the barrier in cachefiles_flush_reqs() */ smp_mb(); - if (opcode != CACHEFILES_OP_OPEN && + if (opcode == CACHEFILES_OP_CLOSE && !cachefiles_ondemand_object_is_open(object)) { WARN_ON_ONCE(object->private->ondemand_id == 0); xas_unlock(&xas); @@ -392,7 +433,15 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object, wake_up_all(&cache->daemon_pollwq); wait_for_completion(&req->done); ret = req->error; + kfree(req); + return ret; out: + /* Reset the object to close state in error handling path. + * If error occurs after creating the anonymous fd, + * cachefiles_ondemand_fd_release() will set object to close. + */ + if (opcode == CACHEFILES_OP_OPEN) + cachefiles_ondemand_set_object_close(object); kfree(req); return ret; } @@ -439,7 +488,6 @@ static int cachefiles_ondemand_init_close_req(struct cachefiles_req *req, if (!cachefiles_ondemand_object_is_open(object)) return -ENOENT; - req->msg.object_id = object->private->ondemand_id; trace_cachefiles_ondemand_close(object, &req->msg); return 0; } @@ -455,16 +503,7 @@ static int cachefiles_ondemand_init_read_req(struct cachefiles_req *req, struct cachefiles_object *object = req->object; struct cachefiles_read *load = (void *)req->msg.data; struct cachefiles_read_ctx *read_ctx = private; - int object_id = object->private->ondemand_id; - - /* Stop enqueuing requests when daemon has closed anon_fd. */ - if (!cachefiles_ondemand_object_is_open(object)) { - WARN_ON_ONCE(object_id == 0); - pr_info_once("READ: anonymous fd closed prematurely.\n"); - return -EIO; - } - req->msg.object_id = object_id; load->off = read_ctx->off; load->len = read_ctx->len; trace_cachefiles_ondemand_read(object, &req->msg, load); @@ -513,6 +552,7 @@ int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object, return -ENOMEM; object->private->object = object; + INIT_WORK(&object->private->work, ondemand_object_worker); return 0; } From patchwork Wed Jan 11 05:25:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 41756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3142822wrt; Tue, 10 Jan 2023 21:42:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXv3GJ+Zij1oCt2x6W4FvqoUO/jra0sqUPGIH1H4xLBi3xgBelBGzpWFORD7aoEYjUEspghm X-Received: by 2002:aa7:d689:0:b0:46c:3f90:f5d9 with SMTP id d9-20020aa7d689000000b0046c3f90f5d9mr60506860edr.5.1673415737405; Tue, 10 Jan 2023 21:42:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673415737; cv=none; d=google.com; s=arc-20160816; b=dIOG6FtZgvafuykghKOTWL23G555d1sGXGrWvs8YNhwSiwDdSITuy7uRAJZIjvIRWX Q0evNTmA12IXxGap7wvUUQ8klsBvE1ise/Z3O3swM3LydVdBUudHLvTghApsJWHBfgP1 W6sBtFMlzk8Pt4w/s6fUn578AuHl92215UYb+Id/VIGH1V+3O1UGNKmsY4hmbrgLKhZC WR2No6Lh81c1bk0kiYq0YFer787oD0AAX1HlN6XhCKzdGgctVPZCIug35NCX3W06AZoD fLcHmIph6zk89WG3Z6gxEbuTO701tCxox+TWMnBvZP+kBnBa1DEHIwjors3QpIli90Sv 9X9g== 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=pDYD8kdF4QcIxV+XVTzksOOF3bsvD3XSTsyoZ+oU6es=; b=PyvfF63yCQxU9aevZhZjetD8KHqtKFNhsk+ZEkLo67fRwPMsFna+5eWrtjFJjXg4LR +SR2jBOma0OmxpZm9q0ofnUeDIblYTZ1heCBdK56vJKuFVvyu2SuR5mGkYD/8tNcyMCC cBTCC4W0BZKb8kyIBoEXgDVrocx3aTZy8wNwZQC4sgrvjTCBM0Aiag1B+eUECaox04aB x0fs2c2f8NI1wSVbBrkwswL0cMNS2ZMahxQh3Brb41JW6pLFyF2G3gUIaCb5O+SeJPYD 5iL+65yZg8SblptRuwNnrAdtQGKiTtMYDEsW8sUzn6Jy9Y/AvI6OA+0ldALkAQf7qmZZ pr2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=OmLcznBU; 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 b11-20020a056402084b00b0046721c5b7e0si16342812edz.511.2023.01.10.21.41.50; Tue, 10 Jan 2023 21:42:17 -0800 (PST) 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=OmLcznBU; 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 S230314AbjAKFhK (ORCPT + 99 others); Wed, 11 Jan 2023 00:37:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbjAKFgf (ORCPT ); Wed, 11 Jan 2023 00:36:35 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 082A53C722 for ; Tue, 10 Jan 2023 21:25:40 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id n12so14733132pjp.1 for ; Tue, 10 Jan 2023 21:25:40 -0800 (PST) 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=pDYD8kdF4QcIxV+XVTzksOOF3bsvD3XSTsyoZ+oU6es=; b=OmLcznBUhwb6V7Iv7/A44e+lcoabUFSifrsud2HZbjVV7xNimVZi/xOnDXpfOVYkOV 0pgBY+uBOAHtdIjKnohFMo4hqlkBl9ZHyeqyzBaySzyKorNmjJiUSWtNAu1MnThr9bZ0 03dCX3pZ6EOLf0aI13y7Ym+iM2d6scbetEoZSNrRqLYPoVSFETLAuGx1cNfb9JjnrSTc mT157ARyhoes8Nqvpe4yrO/lbpCdnXgoypUyCK5igRGq+PUyXMi/WFxz99+plbto03cw sJIne/4ds8ktscqloKaTaaJHVs23pSHwZOS/mCkjRrjfeSok1V4aNUnBCpmKLtHysNCz qxbQ== 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=pDYD8kdF4QcIxV+XVTzksOOF3bsvD3XSTsyoZ+oU6es=; b=Zy6aaJnJjUuJ7XbdeIknIobbkEg34wMIuPhkZNCeZc3WJS/KS53ofaJlpC3b5aog/I tzS+KbARl+D9FjhXlTv6QeFwu0iTtA9djaruvqso/JnIao2AlkowuECYSECxEPr2elbF lGZMfn/jCxkuRPIf6ofnGOsS2yIUOGR5t9wQAyIrr40BlqjjqD0gEjmCbnFdvHTFTo/x ZPBvIscdffgujBmyU88etqSqmu6m6eKicBHgTx/dRZ5WH4vpHICg8wwHLBoNtuUI0nEI 9ubryGXaT4/fXE6Zw7CC71JCZKkR8B4c7gQUF4yYpykAvW2+gKfX1nRqwqWY3jGh+DOu /X6w== X-Gm-Message-State: AFqh2kqQOSdm/K+15suI2Vkys6g78lbqOqazaHGyZR5joqkoTDY37+DS lMpDHIxFNoNWZKWCOy3xV1ZXaWrs21ygj0mD X-Received: by 2002:a17:902:968d:b0:192:8d74:99e0 with SMTP id n13-20020a170902968d00b001928d7499e0mr46324926plp.4.1673414739479; Tue, 10 Jan 2023 21:25:39 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.10]) by smtp.gmail.com with ESMTPSA id l10-20020a170903244a00b0019334350ce6sm4934520pls.244.2023.01.10.21.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 21:25:39 -0800 (PST) From: Jia Zhu To: dhowells@redhat.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jia Zhu , Xin Yin , Jingbo Xu Subject: [PATCH V4 4/5] cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode Date: Wed, 11 Jan 2023 13:25:14 +0800 Message-Id: <20230111052515.53941-5-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230111052515.53941-1-zhujia.zj@bytedance.com> References: <20230111052515.53941-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=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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754703580699123730?= X-GMAIL-MSGID: =?utf-8?q?1754703580699123730?= Don't trigger EPOLLIN when there are only reopening read requests in xarray. Suggested-by: Xin Yin Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/cachefiles/daemon.c | 15 +++++++++++++-- fs/cachefiles/internal.h | 12 ++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index aa4efcabb5e3..b8d8f280fb7a 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -355,14 +355,25 @@ static __poll_t cachefiles_daemon_poll(struct file *file, struct poll_table_struct *poll) { struct cachefiles_cache *cache = file->private_data; + struct xarray *xa = &cache->reqs; + struct cachefiles_req *req; + unsigned long index; __poll_t mask; poll_wait(file, &cache->daemon_pollwq, poll); mask = 0; if (cachefiles_in_ondemand_mode(cache)) { - if (!xa_empty(&cache->reqs)) - mask |= EPOLLIN; + if (!xa_empty(xa)) { + xa_lock(xa); + xa_for_each_marked(xa, index, req, CACHEFILES_REQ_NEW) { + if (!cachefiles_ondemand_is_reopening_read(req)) { + mask |= EPOLLIN; + break; + } + } + xa_unlock(xa); + } } else { if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags)) mask |= EPOLLIN; diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 2ed836d4169e..3d94990a8b38 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -326,6 +326,13 @@ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ CACHEFILES_OBJECT_STATE_FUNCS(open); CACHEFILES_OBJECT_STATE_FUNCS(close); CACHEFILES_OBJECT_STATE_FUNCS(reopening); + +static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req) +{ + return cachefiles_ondemand_object_is_reopening(req->object) && + req->msg.opcode == CACHEFILES_OP_READ; +} + #else static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, char __user *_buffer, size_t buflen) @@ -353,6 +360,11 @@ static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_object *ob { return 0; } + +static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req) +{ + return false; +} #endif /* From patchwork Wed Jan 11 05:25:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 41760 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3143715wrt; Tue, 10 Jan 2023 21:45:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXuG765teknmxdi/Ks+wIB7NpiPiqZdojsAazasNj7LVhxsM4ukJM/Dr/BhptmMvUqDJsA8A X-Received: by 2002:a17:906:eda7:b0:7c4:f402:9769 with SMTP id sa7-20020a170906eda700b007c4f4029769mr77684194ejb.76.1673415930802; Tue, 10 Jan 2023 21:45:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673415930; cv=none; d=google.com; s=arc-20160816; b=v/i18FzBNcdZh7RhUTDWXq9mtjzr05jcJVr/V4wwnovlgoCzQjZPXjenr88eXa034A D97wmwINOsZn4jkx74m/Vsnoro1YfBsWYnkohMAVj/0T0AWsJ8rfr81AZmNenKupPpLq HRcxQozQepHqGu+0IPuTNxROfZN12ENMAjsKLYCwBohi8lo6k4KAMJaaMu1GltvepOfg jrmp/fTU8prv2+AJYI55vpmlhT8QBcoiXSBhS5c237SM28p1xnT/5Xjem3Xq4NeW93hs +YDBEB7ggcK/Wy2w/S576gkfjv8sjriBxpVycZ6vPO55fKQOaQSe7mAM2my4dVErycGP f03w== 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=zIpHcwHuLOh4SwnFnBbeF8LhMIZd7B1uohTZsNHDUqE=; b=YwSsE0hLWWj+0LuYHP5exvudwqGHj1rThzzKt2RkDksGSkjkkOuD71eU31hM5g9t8U 3Po05vs+P6D807YzQ4WBYj31e/k1b6o3aElUdanthEeUH3y4k6opbCUKhdZNZtVFKxFs BKYCDrVseCb5IMzLiwBdLRvX6GzdxtM94G7RSnSq12GCwfBfwjYlOVj/XRC2Nu2yX9pb cg+tNd2POM57j4DYA5jKYXZtdronmwFHRKcBT1J5paK7kpoNh0nStkFbv9iOSX+avcKx asEtjKRfubMpRa0As80ifH69CTIzCFm3P5rhRqJAV3iieh80lsHmszesbtJR4/H5ymMf L1WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=lSpQZ5Nl; 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 s19-20020a170906455300b007b5ce4a436csi10217543ejq.227.2023.01.10.21.45.07; Tue, 10 Jan 2023 21:45:30 -0800 (PST) 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=lSpQZ5Nl; 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 S236508AbjAKFiH (ORCPT + 99 others); Wed, 11 Jan 2023 00:38:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236012AbjAKFgy (ORCPT ); Wed, 11 Jan 2023 00:36:54 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D0FE11157 for ; Tue, 10 Jan 2023 21:25:47 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id o7-20020a17090a0a0700b00226c9b82c3aso15911996pjo.3 for ; Tue, 10 Jan 2023 21:25:47 -0800 (PST) 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=zIpHcwHuLOh4SwnFnBbeF8LhMIZd7B1uohTZsNHDUqE=; b=lSpQZ5Nl1oGZSNpIMCryP8PrFoR67A6GlkkwW9vZo8CD5btOX8PPc93muHthaWNoKy D7CXmW0L+PtqlbTMaYsKksxeEXV2J8Jtlorc6bsUuGpLizxf7K7risMkBcP7+WH8b4d9 cmYK91t3GBHw7IxZT/XQM/4Bv0vbcGPGoMvsNB167guolV2JvVEHqur5YyX67Zk2uC+5 9iNih8DPSpq0lJeRqR3bo99I4HxVwMdBli9ioY5G6clMrBrOWbm53/xq9j/SZtwlfpgh SLY8jNvHJbxEAnHLYa/sF6JQItsls4Pvnu846zRgjyotBkLOpjMHwXFe+ZI6VsWsBBNZ bOCg== 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=zIpHcwHuLOh4SwnFnBbeF8LhMIZd7B1uohTZsNHDUqE=; b=46txjF7TMjFXesbagIAKLWcgLyiUdShRiubb0D/c8+BckpkldV7LLtqgCMYAcH8KHD LpiH1U2HOi3j9AoxiZjG6usQHGgmoGgWPyqT9YUoaLmTJ7xopbwz8EsLQa4vAKXVZ9qG 2xAR66AL64CgMMJHi/LkjW5fzgN7oeN/o2Pp+k7I/Vr+JMWiiXbJkT4wVYbwxJ2rFu3U uHPoUnl+BwamTf5PBn3TRIm+YJdwnYlBsmZveJYE+WDIUqYZgsL2VKZWEiDsJxCgI1lr tWFjniIRQPjbtZvGinr/TprnUD7kn7J3sXQeB7OrupQs/4tPNU/vCW9yPf2os9ShKI2t R71g== X-Gm-Message-State: AFqh2krOh42yRvUoH7OZf88ESKIafqpYcPa9/LO9qo2GRhekqr09uOOp ddVIGP5VKZ/EtHDwfQa7L1Cz9Q== X-Received: by 2002:a17:902:9a0b:b0:189:d3dc:a9c4 with SMTP id v11-20020a1709029a0b00b00189d3dca9c4mr65777152plp.36.1673414746818; Tue, 10 Jan 2023 21:25:46 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.10]) by smtp.gmail.com with ESMTPSA id l10-20020a170903244a00b0019334350ce6sm4934520pls.244.2023.01.10.21.25.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 21:25:46 -0800 (PST) From: Jia Zhu To: dhowells@redhat.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jia Zhu , Gao Xiang , Xin Yin , Jingbo Xu Subject: [PATCH V4 5/5] cachefiles: add restore command to recover inflight ondemand read requests Date: Wed, 11 Jan 2023 13:25:15 +0800 Message-Id: <20230111052515.53941-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230111052515.53941-1-zhujia.zj@bytedance.com> References: <20230111052515.53941-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=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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754703783098344923?= X-GMAIL-MSGID: =?utf-8?q?1754703783098344923?= 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 b8d8f280fb7a..5d9ec62cdd5e 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 8e7f8c152a5b..711b47448c85 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;