Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp846993rwe; Fri, 14 Apr 2023 10:25:09 -0700 (PDT) X-Google-Smtp-Source: AKy350Y1ambGsRe9vxoTbAjECzimYBxc6002RQYsLmV919Wx/JGqCCjNC4Vj0V0a+XdYMMng+YmJ X-Received: by 2002:a17:902:6944:b0:19e:e001:6a75 with SMTP id k4-20020a170902694400b0019ee0016a75mr3644516plt.6.1681493109036; Fri, 14 Apr 2023 10:25:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681493109; cv=none; d=google.com; s=arc-20160816; b=WpqXI2hLNwRYELE6fi643tWxjATWvQANyk/jTOsmEmRpaMvp8ZjxKkx6OUThpplU00 YhVXKQMX5V8/BS0iUsR2MO45PAHxNnzJmmo9jJUy3kGoJ20/Y/6U4MMQYUuaORM0/n9K XmF0GdA4A/cpUleRiG0HByq31cYINrnM9mmBjBKpivgnO9wG/wmr0O8gmEgSsK+5FSKV yvXxWsj6MALLXR4AIU4S0maMmP3Uw7c/ch8HIdHSgBD2mGlXA0Yl99lbfympPlPaMKsO FEQPd08HfY5HDJY00EJM83lhCVwLnywuSCgehv2uVac83DtV5sSuUNYNa7yoSb7eDnW+ G9/w== 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=iyRNuAUEDwU7cFP/FwiLl7ToUiN3TCE52oxG0Yaf7cc=; b=iHnlRfQ11A0T1qQ+WeGIi9uEwxCa9o9DTCxHuc9T2C6sHQ0zeLIxBMbx3TgBoTi4Xx NXman7MCRauwG3//m9FLT6LchVdWT3xmA3jHCMaqPMXmQVBmhSxYZf4cTu7AVPu9tv1e G/ZcVGbQpRpBpJuXW0EFGCQ1T9jJozYkGGPjrv+JrNdd7c4AqFAUBgztTYefrT2JycVS FO8uLPpfe+fRUzmlgwMCIPt7CVwK77Rz2AEeH0Bke0oNjH+OjnYH4IDFYxTSFiWtOC4y E03JK19ScrSouoJBO604APW+YW9guz0ziTrXUOTlwATrBMlUO0KDzoTJiqM3gNv60Dc6 ne4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=AIipzAJf; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g23-20020a1709029f9700b001a511921c06si4898182plq.358.2023.04.14.10.24.53; Fri, 14 Apr 2023 10:25:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=AIipzAJf; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229703AbjDNRX1 (ORCPT + 99 others); Fri, 14 Apr 2023 13:23:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjDNRXY (ORCPT ); Fri, 14 Apr 2023 13:23:24 -0400 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 C98016A5E for ; Fri, 14 Apr 2023 10:23:22 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id hg14-20020a17090b300e00b002471efa7a8fso5678574pjb.0 for ; Fri, 14 Apr 2023 10:23:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681493002; x=1684085002; 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=iyRNuAUEDwU7cFP/FwiLl7ToUiN3TCE52oxG0Yaf7cc=; b=AIipzAJf7XKNk+M8FHlQLcwlGgE+JSGaHPiF8CepatLjwqRTV/bqqk9I2Rf7HKREqD BZdO597TmZQf6gGGYTKbQ+mXvRDF4+eTRvAFDcKXYxHtQfZYjLN43SLF9a0/+AhUmcvZ WmZnJZWycAHdLpCdjfFiwErskCDLNcnM4O2/elLIgoVJGUhTs7ACP1egFxOoSpWk9xqg OXG7bwxJ+uSAxNzqD1iky0G/xG8WMqCtt4DXd9TgnKh7T7494+xRGRexcHBri6llRm6t N8wlisxjx3mV+7T/q+tnGQWC3h4pv8fQW+Sl1V/QVBg0YofvhGII9lA5uu/brRKxQF+N hWYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681493002; x=1684085002; 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=iyRNuAUEDwU7cFP/FwiLl7ToUiN3TCE52oxG0Yaf7cc=; b=HWf7w4hrO/teD8OA33KCMiECDgNjxDRSgx8JrR1cHMHpW4StD2wQ4ToM8KkNcBY+Bu nJX3qXfj6YZ3EM6+kUBm284YHlH3CvSppkVT+N2/nq4Srnk4hC04pHVkUoeRj1IlIRqM L4RktjnK9UjNpXv1yrql59L4ku4gGf9/kc8r0q/1zUQjkVjKM69m8x8vZEHe6zlDpMpU 4YXp/VVpVqV1kein+q/yay3LbbMaxXOH1LoXAfPqJ1gL4kffAxUIYNLtJ8ga9Q06mTqM JhG2tVRT7Rfyyg+pdOScYMkglzZg6viWqmUA4vJ4+X+w8wwFLNCQJEuPBD7O4xky4JgS 3KwA== X-Gm-Message-State: AAQBX9ejA9Ix4/epjnkxDtgfqH0wnCikRDjPiKbADnkvI0iLWoWuvUUS Ag0RWxNKZp36cwX2JjlXBAOtYQ== X-Received: by 2002:a17:903:200b:b0:1a5:2640:10fe with SMTP id s11-20020a170903200b00b001a5264010femr2818290pla.67.1681493002303; Fri, 14 Apr 2023 10:23:22 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id q12-20020a631f4c000000b0051b8172fa68sm370315pgm.38.2023.04.14.10.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 10:23:21 -0700 (PDT) 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 1/5] cachefiles: introduce object ondemand state Date: Sat, 15 Apr 2023 01:22:35 +0800 Message-Id: <20230414172239.33743-2-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230414172239.33743-1-zhujia.zj@bytedance.com> References: <20230414172239.33743-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Previously, @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 --- 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 2ad58c4652084..00beedeaec183 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, _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, OPEN); +CACHEFILES_OBJECT_STATE_FUNCS(close, 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 0254ed39f68ce..90456b8a4b3e0 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; -- 2.20.1