Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp503958rwb; Thu, 18 Aug 2022 07:31:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR5s915I5UVt5eycPUn1QLfQdJqLWqJwnt8z0XCIaf8Q/CaavxKZ/xyxomjb41bBFvedeFS8 X-Received: by 2002:a05:6402:5c9:b0:446:fb0:56bb with SMTP id n9-20020a05640205c900b004460fb056bbmr2302077edx.173.1660833065163; Thu, 18 Aug 2022 07:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660833065; cv=none; d=google.com; s=arc-20160816; b=B1YA8PvgOgdK0ktq+jPvPZgiRO2IxeTW3aXL5mOFNWD4Li1poxnf5AYlTqZu1dtTt2 P7cZRkynQlsjIEh1uSFIpBPId66uRpyfWpuTzA5mBt128lrW8ikjVfyhIHA4+7WpEgmz fEF4Xy5S+LraujYLrGno9CmmAC2RYNFtI3fRKSnMQfDNWYe2yng6fO8yQ7692OBWyd2G 4/xtrYLcvRswa7v28KOZ+cnyecfMhbAY0qdydzT5H+QDLJJQgz4mOWAvXm9aqYQVlTCI 0nTO7tnO3bS1Sj3rtuyy1jwVgKK5AMp/I9590TLyFj5bKREXwiQo1CA28qhsSiWzs1D3 MiKQ== 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=AO4PYjCx0vXpaCKfQl5aDcYdKlf6Zm6zj4mxVrexpEo=; b=CXyIWuqqC1VTUWIZF14+NuJnlZwDeZNJUK8ltKpT7V8CVTO8rZNBx7y6oWTRBREfQh R60zFb0kyuCf6tPvjpj8sVavbRsh6Qft+HLOXeUUjQ3xXV5fG6IKo2zsgAcd4hex/ciy aD06U8YajXQT7FoGHTQVxIPJ9GDxmAgQJcKemOB6T471751yNPyU+7F0gsSh50hhdJmO lEQOmHGDi3Zme+4Qh9FWDtx/OigjLpaBhVlhI/4hpX5zualDOxzganjf48WZwEbGyeh/ Qp3eCdRFw4mBQ54aAHhRVyLEov6YqakYtSTqipsq+Eg4QP+XQte5jZSPW6L2EUZ2x6+W fW5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=QyHAjRjj; 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 dm21-20020a170907949500b0073c7f6b6a72si139897ejc.469.2022.08.18.07.30.38; Thu, 18 Aug 2022 07:31:05 -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=QyHAjRjj; 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 S245373AbiHRNxY (ORCPT + 99 others); Thu, 18 Aug 2022 09:53:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245336AbiHRNxG (ORCPT ); Thu, 18 Aug 2022 09:53:06 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F00462A99 for ; Thu, 18 Aug 2022 06:52:48 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id s3-20020a17090a2f0300b001facfc6fdbcso1239642pjd.1 for ; Thu, 18 Aug 2022 06:52:48 -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; bh=AO4PYjCx0vXpaCKfQl5aDcYdKlf6Zm6zj4mxVrexpEo=; b=QyHAjRjjrjiZ9oGIrd+FGPpO7TvOj5bbsDQ3W2m70ZnRfRYHjt8r1XThHlgmtt32Uo rF7GZe9cx1pKlGKPRMLGCqoHQZzS31r0AWKclhM9hIxqCfj+ZB/yM16iq4U7CuSafLwr evPcyB4EqlXbRkQfgeGNfPMlIcxtv0IXxuhCCKjGKsSue42E9LqZDlJcudVDxql8tZYi b0IBNIqrHcZ8olq2KgIKnIr2wy1qAcjunRsZP83Nqh6cAM/D09xR8zvohBpypiR9bk2w SkpTvbWIjgLlD4wG4OTJrWH4kZUG/ddnmpdQgd6TJ+yYoclTy4/NGj8awscyH2NCOKWp /lGA== 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; bh=AO4PYjCx0vXpaCKfQl5aDcYdKlf6Zm6zj4mxVrexpEo=; b=SOpyrJZMRUUpEkHrSAh67YNd01CLb2Rg31R2fvMJl93ouU0q3m8djJs5Cf1RCjIzl9 AIThzfYZVZr+qcJz9M8Q8KvrN3iP+HtgIX/olSHJ8KCcXtu0NTzj9oNcMJ6wpTf+uXuj UGGVuvQkyHiheNt+Djbrfno2saUabp/Xrh5h/CyI4CPatM+9z2g5OiHou7IQkpvKa1GN Z0DjPinDq/rzEuCgenT6TASpAcP0VgjkemDXqYeXmE1JL8PlGuOKlHaOtFgLHqLyxC3G UIHM865N79Gigwzwh0UziMJzh0pDUR+tecVUL5L7T5agGIZLch24hfCdmqVsvapW8jNw UteA== X-Gm-Message-State: ACgBeo1JXxWjpyeTsmMA8aOXi6ayd6DRV/ZrF+k4ENNCYgnWCw+XmxiV Lg+AtDM6wBqUapLrRxdQkBMa7g== X-Received: by 2002:a17:90b:314e:b0:1f3:189c:518f with SMTP id ip14-20020a17090b314e00b001f3189c518fmr3195014pjb.193.1660830767981; Thu, 18 Aug 2022 06:52:47 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([139.177.225.242]) by smtp.gmail.com with ESMTPSA id k17-20020a170902ce1100b0016db0d877e4sm1385697plg.221.2022.08.18.06.52.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 06:52:47 -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: [RFC PATCH 2/5] cachefiles: extract ondemand info field from cachefiles_object Date: Thu, 18 Aug 2022 21:52:01 +0800 Message-Id: <20220818135204.49878-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220818135204.49878-1-zhujia.zj@bytedance.com> References: <20220818135204.49878-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, T_SCC_BODY_TEXT_LINE 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 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 --- fs/cachefiles/interface.c | 6 ++++++ fs/cachefiles/internal.h | 29 +++++++++++++++++++++++++---- fs/cachefiles/ondemand.c | 28 ++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c index a69073a1d3f0..f21f5660ea7f 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(CACHEFILES_ONDEMAND_OBJINFO(object)); 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 6661b3e361da..cdf4ec781933 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -50,6 +50,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. */ @@ -67,8 +73,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; + void *private; #endif }; @@ -302,6 +307,12 @@ 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_ONDEMAND_OBJINFO(object) \ + ((struct cachefiles_ondemand_info *)(object)->private) + #define CACHEFILES_OBJECT_STATE_FUNCS(_state) \ static inline bool \ cachefiles_ondemand_object_is_##_state(const struct cachefiles_object *object) \ @@ -312,7 +323,8 @@ cachefiles_ondemand_object_is_##_state(const struct cachefiles_object *object) \ * a RELEASE barrier. We need to use smp_load_acquire() here * to safely ACQUIRE the memory the other task published. */ \ - return smp_load_acquire(&object->state) == CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ + return smp_load_acquire(&(CACHEFILES_ONDEMAND_OBJINFO(object)->state)) == \ + CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ } \ \ static inline void \ @@ -323,12 +335,15 @@ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ * I.e. here we publish a state with a RELEASE barrier * so that concurrent tasks can ACQUIRE it. */ \ - smp_store_release(&object->state, CACHEFILES_ONDEMAND_OBJSTATE_##_state); \ + smp_store_release(&(CACHEFILES_ONDEMAND_OBJINFO(object)->state), \ + CACHEFILES_ONDEMAND_OBJSTATE_##_state); \ } CACHEFILES_OBJECT_STATE_FUNCS(open); CACHEFILES_OBJECT_STATE_FUNCS(close); #else +#define CACHEFILES_ONDEMAND_OBJINFO(object) NULL + static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, char __user *_buffer, size_t buflen) { @@ -349,6 +364,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 e3155a5f32e4..f51266554e4d 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 = CACHEFILES_ONDEMAND_OBJINFO(object); + 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); /* @@ -218,7 +219,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; + CACHEFILES_ONDEMAND_OBJINFO(object)->ondemand_id = object_id; cachefiles_get_unbind_pincount(cache); trace_cachefiles_ondemand_open(object, &req->msg, load); @@ -358,7 +359,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(CACHEFILES_ONDEMAND_OBJINFO(object)->ondemand_id == 0); xas_unlock(&xas); ret = -EIO; goto out; @@ -434,7 +435,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 = CACHEFILES_ONDEMAND_OBJINFO(object)->ondemand_id; trace_cachefiles_ondemand_close(object, &req->msg); return 0; } @@ -450,7 +451,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 = CACHEFILES_ONDEMAND_OBJINFO(object)->ondemand_id; /* Stop enqueuing requests when daemon has closed anon_fd. */ if (!cachefiles_ondemand_object_is_open(object)) { @@ -496,6 +497,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; + + CACHEFILES_ONDEMAND_OBJINFO(object)->object = object; + return 0; +} + int cachefiles_ondemand_read(struct cachefiles_object *object, loff_t pos, size_t len) { -- 2.20.1