From nobody Thu Dec 18 18:03:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C8A5C2BB3F for ; Mon, 20 Nov 2023 04:15:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231676AbjKTEPb (ORCPT ); Sun, 19 Nov 2023 23:15:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbjKTEP1 (ORCPT ); Sun, 19 Nov 2023 23:15:27 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34A5A192 for ; Sun, 19 Nov 2023 20:15:24 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1cc9b626a96so28409665ad.2 for ; Sun, 19 Nov 2023 20:15:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1700453723; x=1701058523; darn=vger.kernel.org; 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=NBYMzx+0ghq9rZyVtiAqDaDvPyfZ7l/tXiv5hFDBJO0=; b=EoV1eH8nMolHwat5vCDJ9l0P1b3M4LhUiKAYjnh0o1A/omwMQFi8hUJVICLiGb1O3D okrCq4TztO3iGFe/FZXhyEPTu97Eh2IYp/mnGQAQoYT9uvIwcY5ADKWpfhNFyt4sRYUt ohZQWBLbh8szGwMUBCdy1tXiUtDOjSpse56YS8plnVG6FZ6T2W1t67o1MUtVDIXxcTN9 aUwnzlOUqPIHXXnlPB09Osb5PNvFneVV66sKJiKT0ZqQ71ldh/bVuJqhn5tCaI9CTazP Eo5xWdOuIRH9r7XJFSX9+TjnJb9WiAuNr0vNeRHOq6Kw8WbCVERQZ3a5v0Sf03l87kis hNgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700453723; x=1701058523; 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=NBYMzx+0ghq9rZyVtiAqDaDvPyfZ7l/tXiv5hFDBJO0=; b=AOVDY6fq5JIhOO4iRdTocruOEIKtYz80GdPfaFoMiiXahiGNTdt51ixBkN35ZXlgGc eVu+ybJC3eYFXKWGi8GQblAQVImqicEpnb23d3Z2VtEC/AOLItAzrHc9CNmADSPIfyPB 9glrQKDYvZkup7kDuYV02L11uGejUBILrBFH2nWEwSQZu/bHuI89Cwwwj5d0alEOKZIE kh2vsO8GsVHwhjx68dvYBN2sVM/KpALfiF1hUuFu5gqFWHAkGZOqawLpLPMaeHM0Dh2h bKPK8dzW5/TEs0Q3wjMeFoiLb6NzNUwClWTuOVUks/IPtSFPXtIcXimqePDm5jWkcZsI l69Q== X-Gm-Message-State: AOJu0YwFl+KGKw+keCT4Bz8uycMTSexamZ+sny4EN+YkpT9SUZ2t+LPb FAXXh/DCD+jE6K/naRAOXaHwB6nCj8u9+vQmAvcPeA== X-Google-Smtp-Source: AGHT+IFzCbeU4CTx9W7O4tgf+D6DkEWwwsoqzZ0Uet0Jse+eegf3YJcfUUdpQFUFODbxgg/IszJdgg== X-Received: by 2002:a17:902:e54e:b0:1cc:636f:f376 with SMTP id n14-20020a170902e54e00b001cc636ff376mr4712244plf.44.1700453723651; Sun, 19 Nov 2023 20:15:23 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id h18-20020a170902f7d200b001cc4e477861sm5065266plw.212.2023.11.19.20.15.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 20:15:23 -0800 (PST) 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 Subject: [PATCH V6 RESEND 1/5] cachefiles: introduce object ondemand state Date: Mon, 20 Nov 2023 12:14:18 +0800 Message-Id: <20231120041422.75170-2-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20231120041422.75170-1-zhujia.zj@bytedance.com> References: <20231120041422.75170-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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: Jingbo Xu Reviewed-by: David Howells --- 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..00beedeaec18 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -44,6 +44,11 @@ struct cachefiles_volume { struct dentry *fanout[256]; /* Fanout subdirs */ }; =20 +enum cachefiles_object_state { + CACHEFILES_ONDEMAND_OBJSTATE_CLOSE, /* Anonymous fd closed by daemon or i= nitial 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 }; =20 @@ -296,6 +302,21 @@ extern void cachefiles_ondemand_clean_object(struct ca= chefiles_object *object); extern int cachefiles_ondemand_read(struct cachefiles_object *object, loff_t pos, size_t len); =20 +#define CACHEFILES_OBJECT_STATE_FUNCS(_state, _STATE) \ +static inline bool \ +cachefiles_ondemand_object_is_##_state(const struct cachefiles_object *obj= ect) \ +{ \ + return object->state =3D=3D CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \ +} \ + \ +static inline void \ +cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ +{ \ + object->state =3D CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \ +} + +CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN); +CACHEFILES_OBJECT_STATE_FUNCS(close, CLOSE); #else static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_ca= che *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 *i= node, =20 xa_lock(&cache->reqs); object->ondemand_id =3D CACHEFILES_ONDEMAND_ID_CLOSED; + cachefiles_ondemand_set_object_close(object); =20 /* * 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); =20 + cachefiles_ondemand_set_object_open(req->object); + out: complete(&req->done); return ret; @@ -363,7 +366,8 @@ static int cachefiles_ondemand_send_req(struct cachefil= es_object *object, /* coupled with the barrier in cachefiles_flush_reqs() */ smp_mb(); =20 - if (opcode !=3D CACHEFILES_OP_OPEN && object->ondemand_id <=3D 0) { + if (opcode !=3D CACHEFILES_OP_OPEN && + !cachefiles_ondemand_object_is_open(object)) { WARN_ON_ONCE(object->ondemand_id =3D=3D 0); xas_unlock(&xas); ret =3D -EIO; @@ -430,18 +434,11 @@ static int cachefiles_ondemand_init_close_req(struct = cachefiles_req *req, void *private) { struct cachefiles_object *object =3D req->object; - int object_id =3D object->ondemand_id; =20 - /* - * 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 <=3D 0) + if (!cachefiles_ondemand_object_is_open(object)) return -ENOENT; =20 - req->msg.object_id =3D object_id; + req->msg.object_id =3D object->ondemand_id; trace_cachefiles_ondemand_close(object, &req->msg); return 0; } @@ -460,7 +457,7 @@ static int cachefiles_ondemand_init_read_req(struct cac= hefiles_req *req, int object_id =3D object->ondemand_id; =20 /* Stop enqueuing requests when daemon has closed anon_fd. */ - if (object_id <=3D 0) { + if (!cachefiles_ondemand_object_is_open(object)) { WARN_ON_ONCE(object_id =3D=3D 0); pr_info_once("READ: anonymous fd closed prematurely.\n"); return -EIO; @@ -485,7 +482,7 @@ int cachefiles_ondemand_init_object(struct cachefiles_o= bject *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; =20 volume_key_size =3D volume->key[0] + 1; --=20 2.20.1 From nobody Thu Dec 18 18:03:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF129C2BB3F for ; Mon, 20 Nov 2023 04:16:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231992AbjKTEQN (ORCPT ); Sun, 19 Nov 2023 23:16:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231970AbjKTEPz (ORCPT ); Sun, 19 Nov 2023 23:15:55 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7AE8DE for ; Sun, 19 Nov 2023 20:15:27 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1cf5901b4c8so8638665ad.1 for ; Sun, 19 Nov 2023 20:15:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1700453727; x=1701058527; darn=vger.kernel.org; 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=bz3jIhYwuRIQTrKQv0iVXi5ds41jIbadiSwFXBU2nXU=; b=L1oS1zYZ05S+pSVELBM3JHToVtQWokzLOlhnwflEvNhFDkKGtz8Dom3fmqGzV1uxJe 5cuIWo70lcaA7TjO8GcZhaCMR2w7v/FzQAr9lvx3tRZISEuy5gzhQxtI4i4D5+a3OSWI 1pph77GjWkmA8Rag+O0/RxbWf6GLpoKiQ/IIvcSUfF3CbSX7OaDmUYj1zMKpmOmONAPy nsQcPVeTkyU06ZgN+OnD87Hhs/ZdFOPnPf0zotWAXlDmWdMykg2FxtWppivTNGY4qNaS GbAfvq/liWfgVvkbAyMk/s1RN2aweakiyLh3U56WE86wbqJQD/S7bvkJqtG72PNnjc5L PftQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700453727; x=1701058527; 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=bz3jIhYwuRIQTrKQv0iVXi5ds41jIbadiSwFXBU2nXU=; b=AlB6p0nuDuCTc14Myk+40eZE/P82jboas2yv/KY9YnjGLKyCKGx+n5onAgpt6uR/La NV1kLU52ATmgz6Y8aW5ZqwlVKekuDOanvB4t7SjMuOzlC0dZwKQTykyKandQPTOkrZcz BmmDHfZ+7WDw1QNlu4xFW1xJDsHtMF5hBLd2T3H2aqdXnNvaVyvdM0pK77oeOXHa25hz RSd7ss2JkXi/ZDns8m0X9j/Z0VmKPD5asfdnUAnNbE1QNBu6ncMp6cX95B1ZwLv95COk 6AiweNczdd+jsCBfLuW4s5P5StSCrogEIET0MIWCNPVx0jar0SZhNoVkOPzeB7q/d6GH V3+A== X-Gm-Message-State: AOJu0Yx+lPb7MyA0im2YTuPkSbmCKRaAFYV9nS7/EIrorwpVka3rlfJ3 Upk9LPPTSJTM5sz+kcKNXSMbCQ== X-Google-Smtp-Source: AGHT+IGz6PiCdVG7TeVF99IUhEgj/RacwYre7R6jqcbwDOVc6nbMTswKqx6m5gY/+n6FnYNy7oIWGg== X-Received: by 2002:a17:902:eecd:b0:1ca:1be4:bda4 with SMTP id h13-20020a170902eecd00b001ca1be4bda4mr6685850plb.4.1700453727298; Sun, 19 Nov 2023 20:15:27 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id h18-20020a170902f7d200b001cc4e477861sm5065266plw.212.2023.11.19.20.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 20:15:27 -0800 (PST) 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 Subject: [PATCH V6 RESEND 2/5] cachefiles: extract ondemand info field from cachefiles_object Date: Mon, 20 Nov 2023 12:14:19 +0800 Message-Id: <20231120041422.75170-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20231120041422.75170-1-zhujia.zj@bytedance.com> References: <20231120041422.75170-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: David Howells --- fs/cachefiles/interface.c | 7 ++++++- fs/cachefiles/internal.h | 26 ++++++++++++++++++++++---- fs/cachefiles/ondemand.c | 34 ++++++++++++++++++++++++++++------ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c index 40052bdb3365..35ba2117a6f6 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; =20 + if (cachefiles_ondemand_init_obj_info(object, volume)) { + kmem_cache_free(cachefiles_object_jar, object); + return NULL; + } + refcount_set(&object->ref, 1); =20 spin_lock_init(&object->lock); @@ -88,7 +93,7 @@ void cachefiles_put_object(struct cachefiles_object *obje= ct, ASSERTCMP(object->file, =3D=3D, NULL); =20 kfree(object->d_name); - + cachefiles_ondemand_deinit_obj_info(object); cache =3D object->volume->cache->cache; fscache_put_cookie(object->cookie, fscache_cookie_put_object); object->cookie =3D NULL; diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 00beedeaec18..b0fe76964bc0 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 */ }; =20 +struct cachefiles_ondemand_info { + int ondemand_id; + enum cachefiles_object_state state; + struct cachefiles_object *object; +}; + /* * Backing file state. */ @@ -66,8 +72,7 @@ struct cachefiles_object { 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; + struct cachefiles_ondemand_info *ondemand; #endif }; =20 @@ -302,17 +307,21 @@ extern void cachefiles_ondemand_clean_object(struct c= achefiles_object *object); extern int cachefiles_ondemand_read(struct cachefiles_object *object, loff_t pos, size_t len); =20 +extern int cachefiles_ondemand_init_obj_info(struct cachefiles_object *obj, + struct cachefiles_volume *volume); +extern void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *= obj); + #define CACHEFILES_OBJECT_STATE_FUNCS(_state, _STATE) \ static inline bool \ cachefiles_ondemand_object_is_##_state(const struct cachefiles_object *obj= ect) \ { \ - return object->state =3D=3D CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \ + return object->ondemand->state =3D=3D CACHEFILES_ONDEMAND_OBJSTATE_##_STA= TE; \ } \ \ static inline void \ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ { \ - object->state =3D CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \ + object->ondemand->state =3D CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \ } =20 CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN); @@ -338,6 +347,15 @@ static inline int cachefiles_ondemand_read(struct cach= efiles_object *object, { return -EOPNOTSUPP; } + +static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_obje= ct *obj, + struct cachefiles_volume *volume) +{ + return 0; +} +static inline void cachefiles_ondemand_deinit_obj_info(struct cachefiles_o= bject *obj) +{ +} #endif =20 /* diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 90456b8a4b3e..deb7e3007aa1 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -9,12 +9,13 @@ static int cachefiles_ondemand_fd_release(struct inode *i= node, { struct cachefiles_object *object =3D file->private_data; struct cachefiles_cache *cache =3D object->volume->cache; - int object_id =3D object->ondemand_id; + struct cachefiles_ondemand_info *info =3D object->ondemand; + int object_id =3D info->ondemand_id; struct cachefiles_req *req; XA_STATE(xas, &cache->reqs, 0); =20 xa_lock(&cache->reqs); - object->ondemand_id =3D CACHEFILES_ONDEMAND_ID_CLOSED; + info->ondemand_id =3D CACHEFILES_ONDEMAND_ID_CLOSED; cachefiles_ondemand_set_object_close(object); =20 /* @@ -222,7 +223,7 @@ static int cachefiles_ondemand_get_fd(struct cachefiles= _req *req) load =3D (void *)req->msg.data; load->fd =3D fd; req->msg.object_id =3D object_id; - object->ondemand_id =3D object_id; + object->ondemand->ondemand_id =3D object_id; =20 cachefiles_get_unbind_pincount(cache); trace_cachefiles_ondemand_open(object, &req->msg, load); @@ -368,7 +369,7 @@ static int cachefiles_ondemand_send_req(struct cachefil= es_object *object, =20 if (opcode !=3D CACHEFILES_OP_OPEN && !cachefiles_ondemand_object_is_open(object)) { - WARN_ON_ONCE(object->ondemand_id =3D=3D 0); + WARN_ON_ONCE(object->ondemand->ondemand_id =3D=3D 0); xas_unlock(&xas); ret =3D -EIO; goto out; @@ -438,7 +439,7 @@ static int cachefiles_ondemand_init_close_req(struct ca= chefiles_req *req, if (!cachefiles_ondemand_object_is_open(object)) return -ENOENT; =20 - req->msg.object_id =3D object->ondemand_id; + req->msg.object_id =3D object->ondemand->ondemand_id; trace_cachefiles_ondemand_close(object, &req->msg); return 0; } @@ -454,7 +455,7 @@ static int cachefiles_ondemand_init_read_req(struct cac= hefiles_req *req, struct cachefiles_object *object =3D req->object; struct cachefiles_read *load =3D (void *)req->msg.data; struct cachefiles_read_ctx *read_ctx =3D private; - int object_id =3D object->ondemand_id; + int object_id =3D object->ondemand->ondemand_id; =20 /* Stop enqueuing requests when daemon has closed anon_fd. */ if (!cachefiles_ondemand_object_is_open(object)) { @@ -500,6 +501,27 @@ void cachefiles_ondemand_clean_object(struct cachefile= s_object *object) cachefiles_ondemand_init_close_req, NULL); } =20 +int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object, + struct cachefiles_volume *volume) +{ + if (!cachefiles_in_ondemand_mode(volume->cache)) + return 0; + + object->ondemand =3D kzalloc(sizeof(struct cachefiles_ondemand_info), + GFP_KERNEL); + if (!object->ondemand) + return -ENOMEM; + + object->ondemand->object =3D object; + return 0; +} + +void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *object) +{ + kfree(object->ondemand); + object->ondemand =3D NULL; +} + int cachefiles_ondemand_read(struct cachefiles_object *object, loff_t pos, size_t len) { --=20 2.20.1 From nobody Thu Dec 18 18:03:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4829C2BB3F for ; Mon, 20 Nov 2023 04:15:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229596AbjKTEPm (ORCPT ); Sun, 19 Nov 2023 23:15:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231836AbjKTEPf (ORCPT ); Sun, 19 Nov 2023 23:15:35 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96094194 for ; Sun, 19 Nov 2023 20:15:31 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1cf6373ce31so1723415ad.0 for ; Sun, 19 Nov 2023 20:15:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1700453731; x=1701058531; darn=vger.kernel.org; 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=aS5flV+CfxePU4FZE8c9ZQB+Fy6Gmv6dv/iJq9bZJTo=; b=hpBQSCEu6DKzxrN2poyR/ek7s6jFa2UwBJG7ekUQi/iHIG/TaGw0qPTzcN3iZf5jPc 6Uurpu/F+lY4SdJ1qtu66s82xWBeX3an1IxbV5CtG9A7rsiRLKgdb5NrpzTsFSZEvA2e k/Lbldo9XAXcsTOVq4ihR/0koh3XcwyW4XBg+nNaihJla0yKfcZtLNd08Kg6sAPytLst u2g5tm4KAhGCwAU0eQZJ8KTJ4/fI/K71ewXD4ZPZD4hJX6fRKmgwkfcdCHOcNiPhPcLu zTnR1Wx8QibA9cAExX9CjqQ74ysBncKF+jjAjHdw2dbSOQZq5x3wFZ9T3fZNOm76MHs0 7OvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700453731; x=1701058531; 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=aS5flV+CfxePU4FZE8c9ZQB+Fy6Gmv6dv/iJq9bZJTo=; b=LgvNHUFiIyCeQws1qQWjZpk/K2EWRHT/hhAqYiGPNTUtUFCv/TKGEG5YIPU9EakwDy 3I3q7gEY1M5dSctFQ56PSbdOsOET9CbjqKbLioqBF2HgPHDuW5ExZvxBYPFFGUFgBDDZ ba77dyGqXPtKt4sfoDpxC+obW5Z7Q8RSOI477JqqE3qiRivFyP1hzpltYYtKJLSoI9WJ JrVf6g4zOrtuXB+hyrOFqHHyKBa/oYF0qfAT92J2FarSMn29p1eounQibKlb46IpeL4t bNHkKEsuq/SX+Otbtt0ZFL+Mr5xNDKUPcrV87UUtt5mmcmf6El5IFdqKpQZe43VLm14c 6bYQ== X-Gm-Message-State: AOJu0YzUIshfIM6dUS4AVCAJvq41iQJCkUt9rafjNsCP/NDLngQlU7C5 quKJptDuqoiORA/xvi4fEXWfhA== X-Google-Smtp-Source: AGHT+IHwWw9of5GVxBHPI7Gz5bET2Khh8mqHNxHnk/cuQWp7L3Pl1nAS6XV+csqH0/RZmAOyby2LSg== X-Received: by 2002:a17:902:fac4:b0:1cc:4b3d:1a8d with SMTP id ld4-20020a170902fac400b001cc4b3d1a8dmr14850687plb.17.1700453731015; Sun, 19 Nov 2023 20:15:31 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id h18-20020a170902f7d200b001cc4e477861sm5065266plw.212.2023.11.19.20.15.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 20:15:30 -0800 (PST) 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 Subject: [PATCH V6 RESEND 3/5] cachefiles: resend an open request if the read request's object is closed Date: Mon, 20 Nov 2023 12:14:20 +0800 Message-Id: <20231120041422.75170-4-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20231120041422.75170-1-zhujia.zj@bytedance.com> References: <20231120041422.75170-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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: Jingbo Xu Reviewed-by: David Howells --- 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 b0fe76964bc0..b9a90f1a0c01 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 i= nitial state */ CACHEFILES_ONDEMAND_OBJSTATE_OPEN, /* Anonymous fd associated with object= is available */ + CACHEFILES_ONDEMAND_OBJSTATE_REOPENING, /* Object that was closed and is = being reopened. */ }; =20 struct cachefiles_ondemand_info { + struct work_struct ondemand_work; int ondemand_id; enum cachefiles_object_state state; struct cachefiles_object *object; @@ -326,6 +328,7 @@ cachefiles_ondemand_set_object_##_state(struct cachefil= es_object *object) \ =20 CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN); CACHEFILES_OBJECT_STATE_FUNCS(close, CLOSE); +CACHEFILES_OBJECT_STATE_FUNCS(reopening, REOPENING); #else static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_ca= che *cache, char __user *_buffer, size_t buflen) diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index deb7e3007aa1..8e130de952f7 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 =3D CACHEFILES_ONDEMAND_ID_CLOSED; cachefiles_ondemand_set_object_close(object); =20 - /* - * 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_rea= d */ + xas_for_each_marked(&xas, req, ULONG_MAX, CACHEFILES_REQ_NEW) { if (req->msg.object_id =3D=3D object_id && - req->msg.opcode =3D=3D CACHEFILES_OP_READ) { - req->error =3D -EIO; + req->msg.opcode =3D=3D 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); =20 cachefiles_ondemand_set_object_open(req->object); + wake_up_all(&cache->daemon_pollwq); =20 out: complete(&req->done); @@ -222,7 +219,6 @@ static int cachefiles_ondemand_get_fd(struct cachefiles= _req *req) =20 load =3D (void *)req->msg.data; load->fd =3D fd; - req->msg.object_id =3D object_id; object->ondemand->ondemand_id =3D object_id; =20 cachefiles_get_unbind_pincount(cache); @@ -238,6 +234,43 @@ static int cachefiles_ondemand_get_fd(struct cachefile= s_req *req) return ret; } =20 +static void ondemand_object_worker(struct work_struct *work) +{ + struct cachefiles_ondemand_info *info =3D + container_of(work, struct cachefiles_ondemand_info, ondemand_work); + + cachefiles_ondemand_init_object(info->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_sta= te *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 !=3D CACHEFILES_OP_READ) + return req; + object =3D req->object; + info =3D object->ondemand; + if (cachefiles_ondemand_object_is_close(object)) { + cachefiles_ondemand_set_object_reopening(object); + queue_work(fscache_wq, &info->ondemand_work); + continue; + } + 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 cachef= iles_cache *cache, int ret =3D 0; XA_STATE(xas, &cache->reqs, cache->req_id_next); =20 + 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 =3D xas_find_marked(&xas, UINT_MAX, CACHEFILES_REQ_NEW); + req =3D cachefiles_ondemand_select_req(&xas, ULONG_MAX); if (!req && cache->req_id_next > 0) { xas_set(&xas, 0); - req =3D xas_find_marked(&xas, cache->req_id_next - 1, CACHEFILES_REQ_NEW= ); + req =3D 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 cachef= iles_cache *cache, xa_unlock(&cache->reqs); =20 id =3D xas.xa_index; - msg->msg_id =3D id; =20 if (msg->opcode =3D=3D CACHEFILES_OP_OPEN) { ret =3D cachefiles_ondemand_get_fd(req); - if (ret) + if (ret) { + cachefiles_ondemand_set_object_close(req->object); goto error; + } } =20 + msg->msg_id =3D id; + msg->object_id =3D req->object->ondemand->ondemand_id; + if (copy_to_user(_buffer, msg, n) !=3D 0) { ret =3D -EFAULT; goto err_put_fd; @@ -317,19 +354,23 @@ static int cachefiles_ondemand_send_req(struct cachef= iles_object *object, void *private) { struct cachefiles_cache *cache =3D object->volume->cache; - struct cachefiles_req *req; + struct cachefiles_req *req =3D NULL; XA_STATE(xas, &cache->reqs, 0); int ret; =20 if (!test_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags)) return 0; =20 - if (test_bit(CACHEFILES_DEAD, &cache->flags)) - return -EIO; + if (test_bit(CACHEFILES_DEAD, &cache->flags)) { + ret =3D -EIO; + goto out; + } =20 req =3D kzalloc(sizeof(*req) + data_len, GFP_KERNEL); - if (!req) - return -ENOMEM; + if (!req) { + ret =3D -ENOMEM; + goto out; + } =20 req->object =3D object; init_completion(&req->done); @@ -367,7 +408,7 @@ static int cachefiles_ondemand_send_req(struct cachefil= es_object *object, /* coupled with the barrier in cachefiles_flush_reqs() */ smp_mb(); =20 - if (opcode !=3D CACHEFILES_OP_OPEN && + if (opcode =3D=3D CACHEFILES_OP_CLOSE && !cachefiles_ondemand_object_is_open(object)) { WARN_ON_ONCE(object->ondemand->ondemand_id =3D=3D 0); xas_unlock(&xas); @@ -392,7 +433,15 @@ static int cachefiles_ondemand_send_req(struct cachefi= les_object *object, wake_up_all(&cache->daemon_pollwq); wait_for_completion(&req->done); ret =3D 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 =3D=3D 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 ca= chefiles_req *req, if (!cachefiles_ondemand_object_is_open(object)) return -ENOENT; =20 - req->msg.object_id =3D object->ondemand->ondemand_id; trace_cachefiles_ondemand_close(object, &req->msg); return 0; } @@ -455,16 +503,7 @@ static int cachefiles_ondemand_init_read_req(struct ca= chefiles_req *req, struct cachefiles_object *object =3D req->object; struct cachefiles_read *load =3D (void *)req->msg.data; struct cachefiles_read_ctx *read_ctx =3D private; - int object_id =3D object->ondemand->ondemand_id; - - /* Stop enqueuing requests when daemon has closed anon_fd. */ - if (!cachefiles_ondemand_object_is_open(object)) { - WARN_ON_ONCE(object_id =3D=3D 0); - pr_info_once("READ: anonymous fd closed prematurely.\n"); - return -EIO; - } =20 - req->msg.object_id =3D object_id; load->off =3D read_ctx->off; load->len =3D 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; =20 object->ondemand->object =3D object; + INIT_WORK(&object->ondemand->ondemand_work, ondemand_object_worker); return 0; } =20 --=20 2.20.1 From nobody Thu Dec 18 18:03:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3ACA9C2BB3F for ; Mon, 20 Nov 2023 04:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232052AbjKTEQT (ORCPT ); Sun, 19 Nov 2023 23:16:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231949AbjKTEQB (ORCPT ); Sun, 19 Nov 2023 23:16:01 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62248D4F for ; Sun, 19 Nov 2023 20:15:35 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6b709048d8eso3421830b3a.2 for ; Sun, 19 Nov 2023 20:15:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1700453735; x=1701058535; darn=vger.kernel.org; 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=I3yQNAV5i9i/OMA9ll/UNVMs7Fn6oZ5qFKK0D5McEKU=; b=d0vGKCk4zGx5Jop+QSR74xHH7BtSZE4ftth39YxjQjjfWGuayxxLq6UGPNKNIBdiL3 GMSRSFvGFpl0PNU/DJi2xAwEa/ViynzkTEky0lpHfIEBeDA4So6liI0SPR68ahTSPPmf ghzbSc0j3L2ctAB282Uuc9MDfvqEfDIVffnesBwajJm5eHgJjXePpZbuH3Z/1MGVVfkd 5UpZI3iOkccLRez16SQKjYsx2LoK2tJQ6C5GQcOEjqu6MVbHuLI6vWl5qAKHlRu2VCQ1 NcNp6f2vM+fziWBp0+hN+Y5KsEw1VGFeg2KRmAXwtpjDjI/EH6oRRqrk2gRPzkAH1Qkz KCNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700453735; x=1701058535; 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=I3yQNAV5i9i/OMA9ll/UNVMs7Fn6oZ5qFKK0D5McEKU=; b=uEThkmMS7toVeQaqlw1wCSVtboVgVpLedvQFKC41wHipTCVFq6lNPlBGpHC0O+s5MS jVPFF3Lihe7+ZOpQEPPgTBaWeRTPJCJbdlTPASqBgr9AepRVTPwq/SZkkq4kK034BqQr 0YtKlHwKgXXsTKCfE5yDB2Kgu0HkRgcOJbaFCpWK6bSfwQK7268kaIBhyClGznbVsnQe 3S05hrIEcihknamljoFfisUJM8PjfaaPcMraVWDnE/eTOAPyDJvvI7hboOe590FF4jBi YotyMGDEa0BaKWvwj02/U7T7BYlj+bYJ+AUP7ePkBIPwAqFdLO2MJjBI3yJAuZqmWznG 3zUA== X-Gm-Message-State: AOJu0YyA0GkyQMQbrzl1YDQ3nizXgF/zUb8pgFOWQRgJWabGcsv8iTZ6 LWVfFoEYmYiIhsoq1wwMgFYZZg== X-Google-Smtp-Source: AGHT+IFkSm1NBdoY7dzAdsWmGn420PY4USgPH4erEC9WZuyziRFrX75OKDKwLGHvlN5iggDKFyl5pw== X-Received: by 2002:a05:6a20:438d:b0:187:b4f2:b025 with SMTP id i13-20020a056a20438d00b00187b4f2b025mr5073423pzl.27.1700453734859; Sun, 19 Nov 2023 20:15:34 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id h18-20020a170902f7d200b001cc4e477861sm5065266plw.212.2023.11.19.20.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 20:15:34 -0800 (PST) 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 RESEND 4/5] cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode Date: Mon, 20 Nov 2023 12:14:21 +0800 Message-Id: <20231120041422.75170-5-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20231120041422.75170-1-zhujia.zj@bytedance.com> References: <20231120041422.75170-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: David Howells --- fs/cachefiles/daemon.c | 14 ++++++++++++-- fs/cachefiles/internal.h | 12 ++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index aa4efcabb5e3..70caa1946207 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -355,14 +355,24 @@ static __poll_t cachefiles_daemon_poll(struct file *f= ile, struct poll_table_struct *poll) { struct cachefiles_cache *cache =3D file->private_data; + XA_STATE(xas, &cache->reqs, 0); + struct cachefiles_req *req; __poll_t mask; =20 poll_wait(file, &cache->daemon_pollwq, poll); mask =3D 0; =20 if (cachefiles_in_ondemand_mode(cache)) { - if (!xa_empty(&cache->reqs)) - mask |=3D EPOLLIN; + if (!xa_empty(&cache->reqs)) { + rcu_read_lock(); + xas_for_each_marked(&xas, req, ULONG_MAX, CACHEFILES_REQ_NEW) { + if (!cachefiles_ondemand_is_reopening_read(req)) { + mask |=3D EPOLLIN; + break; + } + } + rcu_read_unlock(); + } } else { if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags)) mask |=3D EPOLLIN; diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index b9a90f1a0c01..26e5f8f123ef 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -329,6 +329,13 @@ cachefiles_ondemand_set_object_##_state(struct cachefi= les_object *object) \ CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN); CACHEFILES_OBJECT_STATE_FUNCS(close, CLOSE); CACHEFILES_OBJECT_STATE_FUNCS(reopening, REOPENING); + +static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles= _req *req) +{ + return cachefiles_ondemand_object_is_reopening(req->object) && + req->msg.opcode =3D=3D CACHEFILES_OP_READ; +} + #else static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_ca= che *cache, char __user *_buffer, size_t buflen) @@ -359,6 +366,11 @@ static inline int cachefiles_ondemand_init_obj_info(st= ruct cachefiles_object *ob static inline void cachefiles_ondemand_deinit_obj_info(struct cachefiles_o= bject *obj) { } + +static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles= _req *req) +{ + return false; +} #endif =20 /* --=20 2.20.1 From nobody Thu Dec 18 18:03:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BEFCC2BB3F for ; Mon, 20 Nov 2023 04:15:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231962AbjKTEPv (ORCPT ); Sun, 19 Nov 2023 23:15:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231854AbjKTEPn (ORCPT ); Sun, 19 Nov 2023 23:15:43 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DE8FE5 for ; Sun, 19 Nov 2023 20:15:39 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1cc9b626a96so28410595ad.2 for ; Sun, 19 Nov 2023 20:15:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1700453739; x=1701058539; darn=vger.kernel.org; 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=g1pCEGuj3QlPT+22tLUxveNeazv04i3uHRdJIvmcJDY=; b=cRiHIofC6lBoTaNGTTXbgD5XM/5YYq0ngFcBNUcvj2nDMUYqtDxAGlMRyixQ4LCOs+ V8psW/TBZKZsm8963Cp49DrQEcf9eQebkTu6YIPlXMuP3n3nenXtINtdz9bY2EDyzayD 2AZbi/TSiWP0LtSp9ocWpJbfhOvEa1NaQI1wJU1bkFCEwe7fqmgOrbkR8WBGVB3JcZU4 hxGx+LVJypDcjabd+thD8NOFNkvW6sx/p0EZWUCXTz1qis9b6/QNr9nLQhZAiCF/AWAC vtRFPBEnXyCugRrZpsR1jCNGx3xYLErrlRNxdhn2rcy7HDg/ndVQLxMhNfUvs4c/x7fG bBVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700453739; x=1701058539; 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=g1pCEGuj3QlPT+22tLUxveNeazv04i3uHRdJIvmcJDY=; b=rUx+5Khxrhhs97x6PIuOPIpP4jy1PWeREzsmnAVjV4Rp5o++3txkA/DmOmP4tFO6MR Mo4kstdTiMlRmv6mIftNDsEXl7ItDEaPQGiFSzOPAc40ncWrwf8KK7MDwUGhtzUD7Ch0 qNIcQqxPrs4T6GhOo8IUueSCcBxtub3WPz90/VYUeiCT2iZvcQCw1ZCjeoCWo/WFkcbm vUWRuAXOxXFdQQBA5zvue0iFzB48AHx8zU/vNEnqwrzCqXjFfyTDEUkl6zzWrHDaMvQB XErgccyRB+/O3iXw7YEuLf0p6pkEFy0mpE3nGh2JUbvG8bC4auoUv18GRAnel4sRoVMn dGTQ== X-Gm-Message-State: AOJu0YztKMSuGUcvoQqaVp//gULFpv6vgZL9iHiQ4oqek/vObD8FVSgZ IqdarLiSwhtUJB2ct+eI83hQkg== X-Google-Smtp-Source: AGHT+IF1cVI+2neDu9j2yxeuSo0UsEVuHEe5IYfjic0fxvskW7o2Dkv7YVI+VOm6U5rYdsHBVkmZtw== X-Received: by 2002:a17:902:d2d2:b0:1ce:67fa:b398 with SMTP id n18-20020a170902d2d200b001ce67fab398mr4710323plc.16.1700453739021; Sun, 19 Nov 2023 20:15:39 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id h18-20020a170902f7d200b001cc4e477861sm5065266plw.212.2023.11.19.20.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 20:15:38 -0800 (PST) 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 RESEND 5/5] cachefiles: add restore command to recover inflight ondemand read requests Date: Mon, 20 Nov 2023 12:14:22 +0800 Message-Id: <20231120041422.75170-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20231120041422.75170-1-zhujia.zj@bytedance.com> References: <20231120041422.75170-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: David Howells --- 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 70caa1946207..3f24905f4066 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -77,6 +77,7 @@ static const struct cachefiles_daemon_cmd cachefiles_daem= on_cmds[] =3D { { "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 26e5f8f123ef..4a87c9d714a9 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -303,6 +303,9 @@ extern ssize_t cachefiles_ondemand_daemon_read(struct c= achefiles_cache *cache, extern int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args); =20 +extern int cachefiles_ondemand_restore(struct cachefiles_cache *cache, + char *args); + extern int cachefiles_ondemand_init_object(struct cachefiles_object *objec= t); extern void cachefiles_ondemand_clean_object(struct cachefiles_object *obj= ect); =20 diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 8e130de952f7..b8fbbb1961bb 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; } =20 +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; --=20 2.20.1