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;