Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp267421rwi; Fri, 14 Oct 2022 01:27:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7y0fIe672OXLTw19GuMwSXY9jZQIMl6M1hBOAESCKEPlkkmNwVFWmgr+Ze5UCQtXJASc+S X-Received: by 2002:a17:906:8a64:b0:78d:b00d:fe with SMTP id hy4-20020a1709068a6400b0078db00d00femr2831570ejc.32.1665736057750; Fri, 14 Oct 2022 01:27:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665736057; cv=none; d=google.com; s=arc-20160816; b=QXer3/qovN04NKDvZgzsyy01XfgRZv7gkgqY6z2nP1+OshISnUbNDivikrYdU6oibc EvKk6TDaS3MzJy4/jT/OUKcpuBWuHx6AxcDZP8Kv5Sf1U7YCkBwIfVxtlzutp7950wy4 iZyDShWHaVYIORRBOLCNaOAQpLIbvkgHNK5rPWzCQ2PkLnHCioInuPOOLGAWaqNnKgNl I15W9szBOh7XzhRkHPNrNsWZ+UWLI0CAK/kNSoXrfnRzXhb7icDq1iDSKSnPSOsm+Jl5 vIfB+UMPboFlTMKtfL+qklcW04zf2fOJeJzgSUhGYbciJso6wlETmhlTxpKgHYYuBgx3 P7rQ== 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=MsHt2Vlq5/8KPYKyRiTtMnPNfh9OvSknQSy607VoKmnF6yvln5rDePtDN/ML/mC+wi 1Wn88q0CNB8Ly9751R76J4FqbxIioi935FglzadsQ6uXkF5JaFrG3eVpvJofE1G6bqvm I9LyCJxYok+1q3wL3Zh9vMl3fI1uCelZAwbwCmz4wmOFN7P/706kPnA97vXvA+DGZL4E ppJwFhZHXb2y4/OpavaxA+5AN3od42bUcck8sjQ9EJD/8dtkU9dY9ijVipcjGUTylOHh HZ4h1331yrBj4FQ+J8IkaQITJOozASPkgoAz1n1F1A87OZLI5fJKbUNGchtvesRJQABw J0Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=s6mTcuzx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd10-20020a170907968a00b0078d8c03a5a6si2143439ejc.759.2022.10.14.01.26.51; Fri, 14 Oct 2022 01:27:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=s6mTcuzx; 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 S230061AbiJNIGn (ORCPT + 99 others); Fri, 14 Oct 2022 04:06:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbiJNIGi (ORCPT ); Fri, 14 Oct 2022 04:06:38 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDA4423BFD for ; Fri, 14 Oct 2022 01:06:37 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id q1so3662689pgl.11 for ; Fri, 14 Oct 2022 01:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fNcrPzu+uKXnduESO+DuwK3jbFzibhJrS7INeKZTCZc=; b=s6mTcuzxdQgjMZE+5rWYB3WrBeBE0mZ0uh+9CoMVdSZf/Rer1uclsQsj1VpvUf88H2 I3CVtWquR0qeE0e0qpqx7LHQWmP911nP/15f3lsxYpurPX3vWxmZcm1k33VDR6u08183 nt1pDo5AACmby1uPOceFFJqqIBHeYzlibk57ZQbRC4++rn++5jkOK9Q/L/jSgBf0OVij NE9tAeBAsBxcGfjY8HF0lht0puF1ZPdyAKg7/fFSB4lfyBCV/QFinmAZBFpyNO3S8XOv WezHwXuVe259W19+ecN3fU3vSg6g7v1yGhHLecR+0KSONAMdSDeohqpnvcxtzhFVwP0C eHxw== 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=Ls4wx+0iKUEsFbvymyzFTQR5Bn734dwadqIeI8XXS5BYVSHRt+7mWSvOyOx7b6xV0B xPkWoOS8kSYdXYMiPT0K27/e1d9/Q4xHVt1avdedR2t7C32Ee++1dz/YNWYnwUyOLaUW rk4Umym+i6c1ZycTCuELFJ4SAq1wPnniNEXc4xTiXufjgIX0nbPwjuzkE/YwHVZRuK9L tgfc172NEHnGR3sjsSdoHDL3fwDkjVks+8PPhIEh6oQmrNI60pgPTN4UnznzPIcA7XYO H9Bv6q98I5FghA6sINfoeu6+QQ6WZCUfl9fv/Swmp18wMHYIEg1d+7UQHbiZg+0UITXH HtDA== X-Gm-Message-State: ACrzQf0vmTarNG5z2bGI83iFPLt4JTvSa8neJAmJr4FV5Vq8Rzd5joTY tf/w1J5FeF9n/aur/wd1gxblpA== X-Received: by 2002:a63:f07:0:b0:440:5c6e:5833 with SMTP id e7-20020a630f07000000b004405c6e5833mr3564382pgl.375.1665734797311; Fri, 14 Oct 2022 01:06:37 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([63.216.146.188]) by smtp.gmail.com with ESMTPSA id ik20-20020a170902ab1400b001730a1af0fbsm1119196plb.23.2022.10.14.01.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 01:06:37 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, xiang@kernel.org, jefflexu@linux.alibaba.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, Jia Zhu Subject: [PATCH V3 1/5] cachefiles: introduce object ondemand state Date: Fri, 14 Oct 2022 16:05:55 +0800 Message-Id: <20221014080559.42108-2-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20221014080559.42108-1-zhujia.zj@bytedance.com> References: <20221014080559.42108-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Previously, @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; -- 2.20.1