From patchwork Fri Oct 14 03:07:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 2470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp590117wrs; Thu, 13 Oct 2022 20:10:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4QyhEgCrOznd1WDlJfDBDpPPVBLoM4SyLmn2aNEszja4c9uBxibB118DFMK1iPu98VZrxM X-Received: by 2002:a17:903:32c4:b0:17f:be8e:5987 with SMTP id i4-20020a17090332c400b0017fbe8e5987mr3049141plr.119.1665717011312; Thu, 13 Oct 2022 20:10:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665717011; cv=none; d=google.com; s=arc-20160816; b=sS4Yg7YKG2s9KCgORFT0ZXz3qv3jlPCtieqJitN3DgmUuBMc0uP16twOQc8SOtpeHN shnHiVbaZYOcsKAioYx+4KeP/y/1F8ffFU1pkgDS9+YRQMj1DF2nKcPFZbrHNDW0ZUM+ vB77z34fiOh3lZ2agGTIadT4LXgv63CDT/lw7Qqr7IOHWzlfGiS/uafCOPhrSvnIzgUn 56CknUK5/vRB3DhJExq7uCBGuadseawzkSXHtiaGfrzg+ZaYTFlQA4Fqu0he9qZI1E0m EkzHTuLcqOx6UkhdD8l1ZsL/zw3HJA177w0/WAOHvOaVQjTLbaBIwe6I3I8KjGjf9Bw6 x1YQ== 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=aSVa2F/ebCCk4BjmPs6WDOXWP+s2jItqlfRtZrqeNzw=; b=F0cS3a5+Qic5xCFoxYBFP3QcjmSjQhALByBHWiVqwETn0FS8iLA3nhfOo06xaEBot2 2Yoo3a1bLLeVM1IA3U0TyhVY8XaE/6X4OJEIFvTD/LZdIwG+uyV7qF9Sbzt2zlPMufkC CCICGoXKXoBL5imDwDw0ReWQA4ff5CulbeRghdmYtShYlEjl/rw7Q595pHhDr2n6/5Ro QEmqaLfLZe+Ul8WRuEiIfxqK4+1KTDhBmEA7SeJqIybAt7nICDfoFhj0pM9csnqhsRIL knVZTnz99J6X+Y3yqoavkSYTp3ZahL1ygoKT7/B/vlAMMvFDdfb/g9IwMXo+/m5qzElJ Dxog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=YWIx2Ki8; 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 u30-20020a056a00099e00b00562a956d979si1221901pfg.67.2022.10.13.20.09.58; Thu, 13 Oct 2022 20:10:11 -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=YWIx2Ki8; 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 S229784AbiJNDIp (ORCPT + 99 others); Thu, 13 Oct 2022 23:08:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229593AbiJNDIc (ORCPT ); Thu, 13 Oct 2022 23:08:32 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 787F819C06B for ; Thu, 13 Oct 2022 20:08:22 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id h10so3575626plb.2 for ; Thu, 13 Oct 2022 20:08:22 -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=aSVa2F/ebCCk4BjmPs6WDOXWP+s2jItqlfRtZrqeNzw=; b=YWIx2Ki8eHWnee4J69UfYiBa8EluGMcAzDUQNhmDxOIQ5fkf5wXK4AW5I7O64Do3GG DaRjzl/mqfqcLxdUb5EExyBNOzFZ8Mtq5aggwXnXV2rzhGIF86UVsGGx5PC3CY9qgoKM 8TkuGm/BuGIxdxLdvvVYDdQ14etBGQNZlMSiabAWh9qb1gnXAQn4uZocGqMSnywXvcWH 6Ui71cBGZRx9kCUO8hQUZ9nYSv4sI7kLwS+51gwua1l35TKXh/ulpp93T3FZDQtJCsN7 9w9yuoEAdSqVUwrmHoT18/xy0bMCZv4oGZvy9zzhf2JfBCihWuidGheB4eWD9aGdVZG0 2NJg== 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=aSVa2F/ebCCk4BjmPs6WDOXWP+s2jItqlfRtZrqeNzw=; b=RXQGIcm7rPEipIwcyPKugF80ViuEOgjae5/ZB25auYq6Zwa2kGKu/DMJa0/GwWQrIJ 2y+j3PvvmlLXr7WAsLPMhUC7yrbl8TsHt7wbHlgPuT8UpND5oRYzi26a83j9+WoMcFIM HmPlIgCFmiwSqETFUgDw9D3gymFDo1ayNdV2xpTdmcEv5KevfgPS5hOoxoaabbK9d5J8 XN2RtMBWuQoEe8OUZkXluea1S9wM6x2uPCWvbmS7cih6RB9SUT4+oWCHoajb+Kh3NgwE rCTNqFUeAOaVzGTq6YOSfDhcMTyGTiJAduQcCPbNUZNl2FSoFQdOWymenmX9ggSpn2wZ Jc/A== X-Gm-Message-State: ACrzQf0/BF5nv8j8rMFxYvu4mrozygNQklrNAeASCP51TdXoICkc94E5 Gohzbi6wuQI9URLY9UJXiM+yiw== X-Received: by 2002:a17:902:e750:b0:17f:71fa:d695 with SMTP id p16-20020a170902e75000b0017f71fad695mr3155945plf.105.1665716889703; Thu, 13 Oct 2022 20:08:09 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([63.216.146.183]) by smtp.gmail.com with ESMTPSA id h4-20020a17090a710400b0020ae09e9724sm425524pjk.53.2022.10.13.20.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 20:08:09 -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 V2 2/5] cachefiles: extract ondemand info field from cachefiles_object Date: Fri, 14 Oct 2022 11:07:42 +0800 Message-Id: <20221014030745.25748-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20221014030745.25748-1-zhujia.zj@bytedance.com> References: <20221014030745.25748-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=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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746630880693751518?= X-GMAIL-MSGID: =?utf-8?q?1746630880693751518?= 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 39895bbd149a..be1e7fbdb444 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. */ @@ -66,10 +72,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 @@ -303,17 +306,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); @@ -339,6 +345,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) {