Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1984550rdb; Sun, 19 Nov 2023 20:16:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2sBI2VyWR9cBd23FY6n3+0FtaHGq9NTcgRKNLOYlFFPm2KJfkN0wRSttTl3gTZiudZ8Di X-Received: by 2002:a17:90b:1bc3:b0:27d:b244:cd28 with SMTP id oa3-20020a17090b1bc300b0027db244cd28mr6551668pjb.42.1700453809234; Sun, 19 Nov 2023 20:16:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700453809; cv=none; d=google.com; s=arc-20160816; b=pO+nxDEPmbdc1L5yUNnDQYexFvrOQwp4ZqwmcGqq84aGrs0mYTEQQPBU/LDEw9aL5U tAkULmnen1NwKVZe+aJzQPL1rCsYMRO7InUANqab59i4cTFkptnvuETJTbzFib9/Uavq gn5m1yPAAL229XPY8fyYj6d43Df9W1jr9y7Ub3a6OjrpvxwUy+fWRbnWfh59UiSS0X4o ftf2XzZD98e2DqU/o/m6M1dtm+moGdSS4DoKy0lRazUjkeVkZ2OfF7bnWo4DnSwNj2JK bTykLeU5aorbn9AzF8OSlg4NcKs59ICQarEALc6GKh6M+FUbDIMtpd2PQSMxh9qQNIQv h77g== 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=bz3jIhYwuRIQTrKQv0iVXi5ds41jIbadiSwFXBU2nXU=; fh=2MjqSmE/Flr/Azt/mtnMNhZyMmjsqHVSxMPyjqy6YHI=; b=jN4+nDg1/8qaBbGpACcdqwB4i656RUKZF3Z20wurOLzNJjgyAdXDf40VzjoscVsB1U RJbhqHxxl6Jcx4jQas2Er+J93baJFZZ84FQ6fO1Gv3eK0ZZ7XQYuIzLs+14DVbmrgHra 9pSZM6O+KNGrPR3FO0ZYbC802062+3CIpGjtucTx0FwtlbM50rvZdBRJLRJM2/kdxdxj BUN7WRQA1D08asSTvosF6JqXmtVDOq37gdosGPe+wqPJwPwHvK3N6IgofuNY+BKtthCu umzqaTERakNnrjkSd7DfEj5L1SX8f8G8WgtN/uFkwx3hY/ohq0xBClK1fsCl1OeLfnH3 yDKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=L1oS1zYZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id mm23-20020a17090b359700b0028524f7bc6fsi1440390pjb.21.2023.11.19.20.16.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 20:16:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=L1oS1zYZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 232898054EF3; Sun, 19 Nov 2023 20:16:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231948AbjKTEQL (ORCPT + 99 others); Sun, 19 Nov 2023 23:16:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231970AbjKTEPz (ORCPT ); Sun, 19 Nov 2023 23:15:55 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7AE8DE for ; Sun, 19 Nov 2023 20:15:27 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1cf5901b4c8so8638665ad.1 for ; Sun, 19 Nov 2023 20:15:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1700453727; x=1701058527; darn=vger.kernel.org; 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=bz3jIhYwuRIQTrKQv0iVXi5ds41jIbadiSwFXBU2nXU=; b=L1oS1zYZ05S+pSVELBM3JHToVtQWokzLOlhnwflEvNhFDkKGtz8Dom3fmqGzV1uxJe 5cuIWo70lcaA7TjO8GcZhaCMR2w7v/FzQAr9lvx3tRZISEuy5gzhQxtI4i4D5+a3OSWI 1pph77GjWkmA8Rag+O0/RxbWf6GLpoKiQ/IIvcSUfF3CbSX7OaDmUYj1zMKpmOmONAPy nsQcPVeTkyU06ZgN+OnD87Hhs/ZdFOPnPf0zotWAXlDmWdMykg2FxtWppivTNGY4qNaS GbAfvq/liWfgVvkbAyMk/s1RN2aweakiyLh3U56WE86wbqJQD/S7bvkJqtG72PNnjc5L PftQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700453727; x=1701058527; 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=bz3jIhYwuRIQTrKQv0iVXi5ds41jIbadiSwFXBU2nXU=; b=AlB6p0nuDuCTc14Myk+40eZE/P82jboas2yv/KY9YnjGLKyCKGx+n5onAgpt6uR/La NV1kLU52ATmgz6Y8aW5ZqwlVKekuDOanvB4t7SjMuOzlC0dZwKQTykyKandQPTOkrZcz BmmDHfZ+7WDw1QNlu4xFW1xJDsHtMF5hBLd2T3H2aqdXnNvaVyvdM0pK77oeOXHa25hz RSd7ss2JkXi/ZDns8m0X9j/Z0VmKPD5asfdnUAnNbE1QNBu6ncMp6cX95B1ZwLv95COk 6AiweNczdd+jsCBfLuW4s5P5StSCrogEIET0MIWCNPVx0jar0SZhNoVkOPzeB7q/d6GH V3+A== X-Gm-Message-State: AOJu0Yx+lPb7MyA0im2YTuPkSbmCKRaAFYV9nS7/EIrorwpVka3rlfJ3 Upk9LPPTSJTM5sz+kcKNXSMbCQ== X-Received: by 2002:a17:902:eecd:b0:1ca:1be4:bda4 with SMTP id h13-20020a170902eecd00b001ca1be4bda4mr6685850plb.4.1700453727298; Sun, 19 Nov 2023 20:15:27 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id h18-20020a170902f7d200b001cc4e477861sm5065266plw.212.2023.11.19.20.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 20:15:27 -0800 (PST) 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 RESEND 2/5] cachefiles: extract ondemand info field from cachefiles_object Date: Mon, 20 Nov 2023 12:14:19 +0800 Message-Id: <20231120041422.75170-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20231120041422.75170-1-zhujia.zj@bytedance.com> References: <20231120041422.75170-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 19 Nov 2023 20:16:46 -0800 (PST) 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 | 7 ++++++- fs/cachefiles/internal.h | 26 ++++++++++++++++++++++---- fs/cachefiles/ondemand.c | 34 ++++++++++++++++++++++++++++------ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c index 40052bdb3365..35ba2117a6f6 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,7 +93,7 @@ void cachefiles_put_object(struct cachefiles_object *object, ASSERTCMP(object->file, ==, NULL); kfree(object->d_name); - + cachefiles_ondemand_deinit_obj_info(object); cache = object->volume->cache->cache; fscache_put_cookie(object->cookie, fscache_cookie_put_object); object->cookie = NULL; diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 00beedeaec18..b0fe76964bc0 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. */ @@ -66,8 +72,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; + struct cachefiles_ondemand_info *ondemand; #endif }; @@ -302,17 +307,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); +extern int cachefiles_ondemand_init_obj_info(struct cachefiles_object *obj, + struct cachefiles_volume *volume); +extern void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *obj); + #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; \ + return object->ondemand->state == CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \ } \ \ static inline void \ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ { \ - object->state = CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \ + object->ondemand->state = CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \ } CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN); @@ -338,6 +347,15 @@ static inline int cachefiles_ondemand_read(struct cachefiles_object *object, { return -EOPNOTSUPP; } + +static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_object *obj, + struct cachefiles_volume *volume) +{ + return 0; +} +static inline void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *obj) +{ +} #endif /* diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 90456b8a4b3e..deb7e3007aa1 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->ondemand; + 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->ondemand->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->ondemand->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->ondemand->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->ondemand->ondemand_id; /* Stop enqueuing requests when daemon has closed anon_fd. */ if (!cachefiles_ondemand_object_is_open(object)) { @@ -500,6 +501,27 @@ 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->ondemand = kzalloc(sizeof(struct cachefiles_ondemand_info), + GFP_KERNEL); + if (!object->ondemand) + return -ENOMEM; + + object->ondemand->object = object; + return 0; +} + +void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *object) +{ + kfree(object->ondemand); + object->ondemand = NULL; +} + int cachefiles_ondemand_read(struct cachefiles_object *object, loff_t pos, size_t len) { -- 2.20.1