From patchwork Wed Jan 11 05:25:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 41758 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3142957wrt; Tue, 10 Jan 2023 21:42:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXsAXCB4CF/7DIQ6Yemg2CgNmUhk5YEKn+h9WORFogfgZ671gE4hUeS/pimXbGDTF1tIH7Hz X-Received: by 2002:a05:6402:22ad:b0:488:6003:24b6 with SMTP id cx13-20020a05640222ad00b00488600324b6mr31486303edb.40.1673415758453; Tue, 10 Jan 2023 21:42:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673415758; cv=none; d=google.com; s=arc-20160816; b=BQ+sIFqizwoqiySCYDPMIvYiSUDA3wjuiNC0ce+sQaRHSchuz7C8OKOmTZULqP7gEs brk+pXziNNJG9wMnL6js/n+8nKRbygHry/Q8zxYk5z2+rLjW+gEmyvanBytEInNqlj1a hu+cRJfFMbIrT9Yse3OE4U2+IfanatwqXmfWEzE9CA3ZKr5v6dgRyI6wR6Q/qQN2gJuP BE9q24XSUOY50xEdTU3TwQqvs9ZY3CxnG8HPtfG66LeukvJUrkJVP8X2ZT1mDbygGLfc KS8PcrS3mKhPb1z/ohBv7Y5lSxXnHfzJTvMZv9HRlI8fS/y/LKNaaOxAE8gupMUPTHki X47A== 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=BUNmB6S9jkYzZMjtNGXZtdFizVu+vOEWVlJtmuAd/sM=; b=Y78r7L32iAPWQ5r1WPnNnq+hoiHzyI0UIxWSdxdrZCQqdTNJgFAWqNgxbfVKI6CBid hX5bxZsqXAhAwUNexEzSSv6YWB1BQHIQlZaccpk9e6noiRxhDzMkfgb2ebRLXfSiBEry EDbi0RWo3+iImjiS3K1U19UG9nyf6AwNAAdodpzZu4NtdyRA5WxnvLCqSAahK8gwBj/Z vlsP6rvHyA11cmc5Lm8WPNrJH9sf4ZSCVu7mb66y/QrPPuch5+aqovQwn4rjIW2Mj5BN igAxKOgiFj6Dq2iA4GF4wlCjrYpc49xcI0/kP84nj9WYJyETEGiQvPiRPQKaNa1ATdOI ORAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=L+d64pR+; 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 y22-20020a056402359600b00461dc830100si16314478edc.452.2023.01.10.21.42.11; Tue, 10 Jan 2023 21:42:38 -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=L+d64pR+; 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 S236041AbjAKFhw (ORCPT + 99 others); Wed, 11 Jan 2023 00:37:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235913AbjAKFgv (ORCPT ); Wed, 11 Jan 2023 00:36:51 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A619F3C727 for ; Tue, 10 Jan 2023 21:25:33 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id d3so15610578plr.10 for ; Tue, 10 Jan 2023 21:25:33 -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=BUNmB6S9jkYzZMjtNGXZtdFizVu+vOEWVlJtmuAd/sM=; b=L+d64pR+VebvUUUjaiccGVxSldyfm09MSkGMj332GTcZUFoR6eZLdEUtDH829a2993 6Uhr9TkD6wWdjiHnlHHQaOwHMPZiyUiax+N2LN8M38QGaXN/ydu7ebZuOzSQhoX8ejYs Sn4VQWsI+te85j9k/jOD8MnzWiF3LOp9+edZXKDV4VvVWxPrgogO/cM8B3xv+3WSIExj 8esc0+I6W2RN9y5jaMobJehHZxlQ4n5bWVonUhk8D5UadhDbOLtH8qmWgJrZd0fjkH0h nwGYo1tExfYMKl+dPV3Y+ZluctX+zABCgCZqQM5L65npM0Q30HeiUn8T0rZlZSkwIOSJ 2q0A== 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=BUNmB6S9jkYzZMjtNGXZtdFizVu+vOEWVlJtmuAd/sM=; b=L4ZAMvEJksICjmYxTD3NLhEP7kbnx7fMts6PCeygHmNfacKOSPiRUyJOFnUwCpCfLo Fs9Ce6rF1f70+gCBgbhdd84REBm5FRGuvanBMwvPuzGFEMrGi5oE5VUYt0hzpRPWBori ZltQR4fgBYQyfT99zutQO9mUeZ469RNcxfDIXKSv5k2UXvdPdyOHWWNQdjAm5n/zzmkJ H0yUcoQGF28tcinRTrOT5Wj0K0UqCdmm7BL/JrYmwhWTvA0YpXEL9GijJ5DsSFI8fPfK J16sTDZUYW7Ae7gOs/uCsXA+E9+trBiUmvhX/fAbfehIAC5l/Qa9Lvtq/iFhYKGe2rkI VHSA== X-Gm-Message-State: AFqh2kqCDzqE9mW++fHapCxnZITP2hJi9izK+VDUf+ORiSBubvxGaWx1 ih2y20Az3noQkEC9pLgNojRuTg== X-Received: by 2002:a17:902:ed89:b0:192:816c:8c31 with SMTP id e9-20020a170902ed8900b00192816c8c31mr49172243plj.35.1673414733204; Tue, 10 Jan 2023 21:25:33 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 21:25:32 -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 , Jingbo Xu Subject: [PATCH V4 2/5] cachefiles: extract ondemand info field from cachefiles_object Date: Wed, 11 Jan 2023 13:25:12 +0800 Message-Id: <20230111052515.53941-3-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=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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754703602346430219?= X-GMAIL-MSGID: =?utf-8?q?1754703602346430219?= 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 --- fs/cachefiles/interface.c | 6 ++++++ fs/cachefiles/internal.h | 24 ++++++++++++++++++------ fs/cachefiles/ondemand.c | 28 ++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c index a69073a1d3f0..690e3e1ee661 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(object->private); 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 b9c76a935ecd..beaf3a8785ce 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 */ }; +struct cachefiles_ondemand_info { + int ondemand_id; + enum cachefiles_object_state state; + struct cachefiles_object *object; +}; + /* * Backing file state. */ @@ -65,10 +71,7 @@ struct cachefiles_object { enum cachefiles_content content_info:8; /* Info about content presence */ 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; -#endif + struct cachefiles_ondemand_info *private; }; #define CACHEFILES_ONDEMAND_ID_CLOSED -1 @@ -302,17 +305,20 @@ 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_OBJECT_STATE_FUNCS(_state) \ static inline bool \ cachefiles_ondemand_object_is_##_state(const struct cachefiles_object *object) \ { \ - return object->state == CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ + return object->private->state == CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ } \ \ static inline void \ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ { \ - object->state = CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ + object->private->state = CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ } CACHEFILES_OBJECT_STATE_FUNCS(open); @@ -338,6 +344,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 90456b8a4b3e..6e47667c6690 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 = object->private; + 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); /* @@ -222,7 +223,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; + object->private->ondemand_id = object_id; cachefiles_get_unbind_pincount(cache); trace_cachefiles_ondemand_open(object, &req->msg, load); @@ -368,7 +369,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(object->private->ondemand_id == 0); xas_unlock(&xas); ret = -EIO; goto out; @@ -438,7 +439,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 = object->private->ondemand_id; trace_cachefiles_ondemand_close(object, &req->msg); return 0; } @@ -454,7 +455,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 = object->private->ondemand_id; /* Stop enqueuing requests when daemon has closed anon_fd. */ if (!cachefiles_ondemand_object_is_open(object)) { @@ -500,6 +501,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; + + object->private->object = object; + return 0; +} + int cachefiles_ondemand_read(struct cachefiles_object *object, loff_t pos, size_t len) {