From patchwork Wed Mar 29 14:01:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 76595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp448764vqo; Wed, 29 Mar 2023 07:18:38 -0700 (PDT) X-Google-Smtp-Source: AKy350aCXwFfIq4avkUq4qOwuqyfVpVfhY5kY6ZbLhjqtJSWaehoFBiHm9Gx3iSq7ezOCyYMNYNP X-Received: by 2002:a17:907:3fa3:b0:93d:425a:b935 with SMTP id hr35-20020a1709073fa300b0093d425ab935mr23990994ejc.25.1680099517961; Wed, 29 Mar 2023 07:18:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680099517; cv=none; d=google.com; s=arc-20160816; b=lVQTsV7E/eKirlHywCI/w8fK8cNT3wrvj9UbnBxLvS92XlFEK4XG+UnIvcC2Fz2yK+ AlnpN5gmaJe8JTWX16H6gUUEQjUlTXscCsROoNyFcc8KJ/4znJxrKqyx8td0W/HplSbg GhptsNMM+dqZeVVUniUvuVK5Sgubtp7wYzUNSUivJK8QdoMTrWwBCJ+zVbAciOFwS3cy N2Ju6/aYmZvM6ZelcdzGjYbFbbmI9oA20PyDUzWr2/qFKiEzSa14LjvY4MAAQzbIYdZ0 xvzzE9NX3TtJ5YeMCvjjiQt+n5j4yErawirAfGQP3v8f5ch8p7O2jyB4ia66/cA386se Fg1A== 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=iyRNuAUEDwU7cFP/FwiLl7ToUiN3TCE52oxG0Yaf7cc=; b=urM7LKjaeiI9BwsdAmV/c0WCYFl6Qu64j3+YyyN/tbjLL+TFzzNWipN0EGkrLf8IzG V7A2tWOXHAiqi3RJ+NKibjyPSfKLw0G6s/p1DEzV3LlGcHM2n0KQXrZJr9NVbu2w74nc +xPV1MTQa23Hu5XvvehEEP9aiLYBaE4VUJv0vduT0dkLop4rqHiuf0UITYjTS8p5ZbEa hUo+iG7HGxx5vzkdFuxSMNQQIiBD54E6hc+eKXaF4zq22kLXOmt1uSDFm8VDrrpM+IL+ 93FQyekA/UDjmjfZWXhu20ElnbRV1OCyGCLnr7nqXc+DJJrJ1Kl5drCsQnV+gVX+Rp9S 0h1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=iQ4wh80K; 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=pass (p=QUARANTINE sp=QUARANTINE 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 un2-20020a170907cb8200b0093defbd628fsi13537221ejc.1046.2023.03.29.07.18.14; Wed, 29 Mar 2023 07:18: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 header.s=google header.b=iQ4wh80K; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230390AbjC2ODP (ORCPT + 99 others); Wed, 29 Mar 2023 10:03:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230121AbjC2ODJ (ORCPT ); Wed, 29 Mar 2023 10:03:09 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BA20469C for ; Wed, 29 Mar 2023 07:02:17 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id b7so239799pfv.2 for ; Wed, 29 Mar 2023 07:02:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1680098536; 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=iyRNuAUEDwU7cFP/FwiLl7ToUiN3TCE52oxG0Yaf7cc=; b=iQ4wh80Kq03ysjTxXIDtcgtYgWFf6onO3QJVR/Nz97PoDHP60/cNowM16zO+Dqsw+9 pNmJwbEaF/x0ErB8rjPHZTcgPOf9AKZQ0k8yRx5q71DyNpzpYXDyERVEHz2raK6RmGnf Zp3xhYFnWawNieU/+GcGMMBAIAEP+/Rx5XMwnHE8JMxdZq91ivCusm9hYMc+qQKPYyLk mAQi/PcSWscDwgpGp61vKmgEfO702Xp8XOm2D2v0w9wHWXVAzRlf+aWEcDe0D9KmRXpw GM8XTzTGXfugqVUWjbMWKLhTN8xyIDwb2ZZQCG3KsTvVIrCIpWlpxNdtuCS8lq/S0ObG qZRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680098536; 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=iyRNuAUEDwU7cFP/FwiLl7ToUiN3TCE52oxG0Yaf7cc=; b=0v1LNq4ncsld/flUJ9lsXb/TTpl7NvUL7nCMv6eXSP2fi0XCqD+I6UPDOt2P54Wokc 8qRPEt6vP4DURusV6tJXpNae7QkD38UBd6g8fBiMy/aDMDOiXpw2OfPd1i/7jDbEyjXk CrUIDaNHTGhGmX9qRiMEUrtMp1FaKNGgGwujB/Xl2uM6K3ByfMfrlmqvdpF00EabFLma hvdE01qGt0N4WHGqut/bhMIwLSWa0zg3W+kj7CrQcvZmlcCcuXdU0oNunNPFUJMqK+Du F49E6wPWw7vaULR/LJoNsDmEdyOSwokfbSdY4zPjd0/fjfotR865dD+rVyVr24e/ajW4 lONQ== X-Gm-Message-State: AO0yUKUTfbmlLy4zWJ0Tdw8eE3sln6zCeJ6KZVBMM3KBRjBa3B0lO/iu QV7frxyQ6I2R/DW3apoVrl4j/Q== X-Received: by 2002:aa7:95a4:0:b0:626:dc8:b004 with SMTP id a4-20020aa795a4000000b006260dc8b004mr19577552pfk.26.1680098536504; Wed, 29 Mar 2023 07:02:16 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.213.176.14]) by smtp.gmail.com with ESMTPSA id y17-20020aa78051000000b006288ca3cadfsm5399468pfm.35.2023.03.29.07.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:02:16 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, jefflexu@linux.alibaba.com, hsiangkao@linux.alibaba.com, yinxin.x@bytedance.com, Jia Zhu Subject: [PATCH V5 1/5] cachefiles: introduce object ondemand state Date: Wed, 29 Mar 2023 22:01:51 +0800 Message-Id: <20230329140155.53272-2-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230329140155.53272-1-zhujia.zj@bytedance.com> References: <20230329140155.53272-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,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?1761712031965710009?= X-GMAIL-MSGID: =?utf-8?q?1761712031965710009?= 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 --- 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 2ad58c4652084..00beedeaec183 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, _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, OPEN); +CACHEFILES_OBJECT_STATE_FUNCS(close, 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 0254ed39f68ce..90456b8a4b3e0 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; From patchwork Wed Mar 29 14:01:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 76600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp449287vqo; Wed, 29 Mar 2023 07:19:19 -0700 (PDT) X-Google-Smtp-Source: AKy350akzOib29d53gzSqtkRcJf/VmX2Pkxa3OXjmDIyg2TW787mUGqzXgrW+j991/Wc6qO+EQNQ X-Received: by 2002:a62:7988:0:b0:625:e8ec:4f5b with SMTP id u130-20020a627988000000b00625e8ec4f5bmr19037935pfc.6.1680099559188; Wed, 29 Mar 2023 07:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680099559; cv=none; d=google.com; s=arc-20160816; b=fl4+U5x1667LhjSQrxfecwbE0soT0PAEi3BxUlO6g5Slp8A3pF9HIh8/sZYZYgEG6+ 4VtIZHl9FDiy946Z/4x+kTHN9r4n8Wv8a1ybRbSCNvOhUmoaKtVYYkxVaCnyKUU9JkdD MnF6vButJ6RlnE5u3gz1ec0TdFmb1uVEmeQ7lzdgWiQhnkdxAYkPkTi3QH2PbIkYpU4q 4piXEdGORqf6TrtLDnKXpisBOxheqZOuDluPn/triGDVtZZJZ86Y0Gcb9u7Xn+dMGIdX RwykmyYz3YSOcimdRb4aY9q3OMxAIvyiUZ7S20F9wTTsZfKjebSFMeydbH16fi9DwLAt ccqw== 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=ipz6nTPRZ3Cs9OsNmMIh4U9rG9HmGZtivZr/8M/3lr4=; b=dHeiTUqoe2XHZ1YYOoOOcuax45V99efJ7IPJYw1E+V3xk4weY7QJWsQs4jfqPY6RzX 7LdH4MlaFHJXYipvbGuURpeplwJTR4xbbIghQj00GgcEUjYsQ3PxJ2oiNxim9VtU17Cg 9SMqv49PrShUOhkBgmcR+fYEo8OcX077A5WcCz8+ygH/jQwgpVZ29AxjJZRKSPqXuOXk Q7uk/cBX8rDYjJZmuQLuSJBGfJTbgrlqWhEmSExG1Weah6atxObKnZQD/uMkdzdb3+VN 7f2dKIC5rnqrYG6gSkvv0GmuGCl05WMhEdF3utGxplRzveTHA7GLFfzN6J1M07y+U+z7 YZFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=KK5RXIWB; 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=pass (p=QUARANTINE sp=QUARANTINE 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 d15-20020a056a0010cf00b006221fa0b8d1si31684822pfu.71.2023.03.29.07.19.06; Wed, 29 Mar 2023 07:19:19 -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 header.s=google header.b=KK5RXIWB; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229903AbjC2ODL (ORCPT + 99 others); Wed, 29 Mar 2023 10:03:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229654AbjC2ODI (ORCPT ); Wed, 29 Mar 2023 10:03:08 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C93340C1 for ; Wed, 29 Mar 2023 07:02:20 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id y19so9335056pgk.5 for ; Wed, 29 Mar 2023 07:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1680098539; 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=ipz6nTPRZ3Cs9OsNmMIh4U9rG9HmGZtivZr/8M/3lr4=; b=KK5RXIWBzOFHUKrSn9Akg3XNn5mIB+AFnUVMOtoHbzi8h4bmZvhzB913MMW3xR9qNL nal5MnGN92l38eEs5rCDhiH7Ywb1lLxV4DFyySym7Wq03Fo8mTU4Xp6ag/7iavAT92dt PPrFCxA9eFgti0a/wnvShWjT1/3w+iWmUEkKMH9NxRonwHIx3XZfBGdu5N7guQd7TCUS DPvBI0IZ7dxsQ25o+miaDO1KiICiwk2BTXqlWjo7JyZ2PSfGPyk/dInT7ChXKLs+UAm2 PELYGkA3fmB2nrkTSTCPU9Jz0T1z/aKZdNZlX3U6dODgbSmPkdc/Vs+Oo3n4dgDJJ3+F bz0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680098539; 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=ipz6nTPRZ3Cs9OsNmMIh4U9rG9HmGZtivZr/8M/3lr4=; b=PPdB+rBdY721brjpKx0ds4B2x6R9E7MegqA0OjYWHjvOMZVinkmfWjVJxqp72fvA0P D/cyAE2kW9CebfccwX+iBasWgr1t6LubzR324enJ3SGQc2gbi4Uc83DaCz+W24A8LHjq 4OEjcm1bINdnVVNEI7iqXrGBD96G+GqSVcM8abPXfKtQ9x1uf5/8n1IWaC/kB48Suu+I 3vGR9pbz5oJm8n8jWuJNIQJYM8NiLq9vwNf+qj913k70ntRjiDO3qcFt3M77XyueSfdS YY6kwrJKd5yR6Xjooyy6hA0uP5uxO5UJo9qCqXre8qBzUzn+7d1+q5S/VO5fIb5bU1xy q2Rg== X-Gm-Message-State: AAQBX9fXcWrdJvi2qlJDerLlvlFYBE8+XKeQCYXwEPQ/Gzh76JhruDPL V1iFSMQIxMQ/dtNJKl0bkXlz3w== X-Received: by 2002:a62:1bc4:0:b0:61d:e10f:4e70 with SMTP id b187-20020a621bc4000000b0061de10f4e70mr17953451pfb.0.1680098539612; Wed, 29 Mar 2023 07:02:19 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.213.176.14]) by smtp.gmail.com with ESMTPSA id y17-20020aa78051000000b006288ca3cadfsm5399468pfm.35.2023.03.29.07.02.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:02:19 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, jefflexu@linux.alibaba.com, hsiangkao@linux.alibaba.com, yinxin.x@bytedance.com, Jia Zhu Subject: [PATCH V5 2/5] cachefiles: extract ondemand info field from cachefiles_object Date: Wed, 29 Mar 2023 22:01:52 +0800 Message-Id: <20230329140155.53272-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230329140155.53272-1-zhujia.zj@bytedance.com> References: <20230329140155.53272-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,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?1761712075475889255?= X-GMAIL-MSGID: =?utf-8?q?1761712075475889255?= 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 | 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 40052bdb33655..35ba2117a6f65 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 00beedeaec183..b0fe76964bc0d 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 90456b8a4b3e0..deb7e3007aa1d 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) { From patchwork Wed Mar 29 14:01:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 76596 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp448830vqo; Wed, 29 Mar 2023 07:18:43 -0700 (PDT) X-Google-Smtp-Source: AK7set+68eBT8ieEeCb2YE8LXnzEvl1BF9PEaAAFE8rm6p7qvTLNeyXT1c6CngrT3xZae92fPsZB X-Received: by 2002:a05:6a20:6d84:b0:bf:8a97:6e48 with SMTP id gl4-20020a056a206d8400b000bf8a976e48mr17020340pzb.37.1680099523645; Wed, 29 Mar 2023 07:18:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680099523; cv=none; d=google.com; s=arc-20160816; b=VeFRYpBjPWbweb0yJEw6cN9oF8NhPigCOwtgzM6GNx2wpP1TIxx6/iefGCWxTek0OK cNTuQFP0uno1qdF1dxHCJVgR6BSyMR7gPvTUkGGbY/EzUZdbq/6GpWCsZaaQG5HTYVzl V7CkF/snlyT/V0/+uXVJQ/NkIzTxsizGeys+YPtkxCHZL3cIiW+sXlyUuSRFQbNVHFZt FtM34ey1udMK972n3MxsxlB1XIDG5u7tA/6JnVXNUaPSQsgoYmrjCOVXQKo/5dhJZg5R 8MiIuM0veowGfs4pRfiG5rDDlFx6UHXTrMqujVu5MKRxuNF3G3an8sw4EdnnIxhbJf2e 1utQ== 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=ySOXSnP6FL6oSMQRzhqbuOuGsOFMLOtSkAgA+zIYAhs=; b=DdB0jr1e5JfjprTI7MMsdwRT0jOvU+/KNAZMrmb8V8yQ+w6GPMhoENGK9OjWxY7Mwj EoTIXxW2OMn2TDxM4v41BLIdnCC6dXLrQ4MlTbnY6g++q06X88JKyqh+8IKk6EQl+3er /TQNCtlDqNityH497cPkR2BWHpZVqUtq4WrS2TNpvKJMS3NYjBV6upio/hbNxylptKRh srvu8BsCaGpbgy37df1qDm/eoydLVFcwza47t0E0jw4/OCZZsd7E+Z0s8tfcaOSu8MV3 7CgN6hF5ynBt8NdrZoVrD50eQgycp3LMqpRSHlZjFkoEmSofWjFEK2Es1fyGRa8FGMRv JK+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=lBBT46Ei; 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=pass (p=QUARANTINE sp=QUARANTINE 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 t3-20020a635343000000b00513233eb86asi12040766pgl.593.2023.03.29.07.18.30; Wed, 29 Mar 2023 07:18:43 -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 header.s=google header.b=lBBT46Ei; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbjC2ODN (ORCPT + 99 others); Wed, 29 Mar 2023 10:03:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230288AbjC2ODJ (ORCPT ); Wed, 29 Mar 2023 10:03:09 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A59C49EE for ; Wed, 29 Mar 2023 07:02:23 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id h14so9321396pgj.7 for ; Wed, 29 Mar 2023 07:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1680098543; 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=ySOXSnP6FL6oSMQRzhqbuOuGsOFMLOtSkAgA+zIYAhs=; b=lBBT46EiZ6nhEUijL9RTLbkzz/aFlI5Nsz967BOEHG641BjvZbUcOSi+UM5IWQoK2R UmYb//Y+6iZJ9wmV3VZL35pWHc8242KHyK8mLRoCUTCaEQPYdH9X47Ck+hmsMxvKrQs2 Otsf4FBxUM7TRWPzhZkTuhp9j/nyBRCwo0+Rns3IUjHLwSi0mcjba3Geqjg0VRotUdu9 bR6bOSUjQSBaibj3YC0pzGWuV0uSC76QbD8DuaxIcDQHAzayvuOLNV0zM6Qt03Jdj9lQ IWkCL7lAfC1YxO1Te6ZoYBdLa+Y/dnu34nmGQEVZcoEv1yFRySagmuElwm2n5Vwd37xy U8HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680098543; 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=ySOXSnP6FL6oSMQRzhqbuOuGsOFMLOtSkAgA+zIYAhs=; b=DhAgAK8x0X3fjrBy1tL419ahuAL3QdlNSpRW4V0GNDVia88PM1hb53BYGLwRjNXwg9 5fbrucSGtTZi0r2Wq68n5Wx8mqwIlQz4mu2KRERNMZ6CJy39jae/W6jsTTpwNnrkFr9M w3x70cmk4CvG+8pCrcQ4rpSjQ5oUuQR51OlvGvEO8ARQoHML6ew7nkc3ieg1rvvlhjvy bGMmJamte5fGw7u1weT122WQf/e1+Ceg8/Uf7MfcoPvw0fCbjSV1qtCUjqu3HPvX17Gd Lxj2gEAukt+Te6faa/QdQxKVb9oh4xiM8f8quaCs6Ngy10RtvFcfamIy2/toPDN5Nv5i kgdg== X-Gm-Message-State: AAQBX9eX4A1g+EKGsdv64dZCvu62Cdu0r0Nde6bAop+Nu0EO1V61pZCu AbpgpgNRgiuQAEUpgmOB2aSgEQ== X-Received: by 2002:aa7:8e8e:0:b0:625:7300:5550 with SMTP id a14-20020aa78e8e000000b0062573005550mr19748934pfr.31.1680098542784; Wed, 29 Mar 2023 07:02:22 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.213.176.14]) by smtp.gmail.com with ESMTPSA id y17-20020aa78051000000b006288ca3cadfsm5399468pfm.35.2023.03.29.07.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:02:22 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, jefflexu@linux.alibaba.com, hsiangkao@linux.alibaba.com, yinxin.x@bytedance.com, Jia Zhu Subject: [PATCH V5 3/5] cachefiles: resend an open request if the read request's object is closed Date: Wed, 29 Mar 2023 22:01:53 +0800 Message-Id: <20230329140155.53272-4-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230329140155.53272-1-zhujia.zj@bytedance.com> References: <20230329140155.53272-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,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?1761712038394031168?= X-GMAIL-MSGID: =?utf-8?q?1761712038394031168?= When an anonymous fd is closed by user daemon, if there is a new read request for this file comes up, the anonymous fd should be re-opened to handle that read request rather than fail it directly. 1. Introduce reopening state for objects that are closed but have inflight/subsequent read requests. 2. No longer flush READ requests but only CLOSE requests when anonymous fd is closed. 3. Enqueue the reopen work to workqueue, thus user daemon could get rid of daemon_read context and handle that request smoothly. Otherwise, the user daemon will send a reopen request and wait for itself to process the request. Signed-off-by: Jia Zhu --- fs/cachefiles/internal.h | 3 ++ fs/cachefiles/ondemand.c | 98 ++++++++++++++++++++++++++++------------ 2 files changed, 72 insertions(+), 29 deletions(-) diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index b0fe76964bc0d..b9a90f1a0c015 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -47,9 +47,11 @@ struct cachefiles_volume { 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 */ + CACHEFILES_ONDEMAND_OBJSTATE_REOPENING, /* Object that was closed and is being reopened. */ }; struct cachefiles_ondemand_info { + struct work_struct ondemand_work; int ondemand_id; enum cachefiles_object_state state; struct cachefiles_object *object; @@ -326,6 +328,7 @@ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN); CACHEFILES_OBJECT_STATE_FUNCS(close, CLOSE); +CACHEFILES_OBJECT_STATE_FUNCS(reopening, REOPENING); #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 deb7e3007aa1d..8e130de952f7d 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -18,14 +18,10 @@ static int cachefiles_ondemand_fd_release(struct inode *inode, info->ondemand_id = CACHEFILES_ONDEMAND_ID_CLOSED; cachefiles_ondemand_set_object_close(object); - /* - * Flush all pending READ requests since their completion depends on - * anon_fd. - */ - xas_for_each(&xas, req, ULONG_MAX) { + /* Only flush CACHEFILES_REQ_NEW marked req to avoid race with daemon_read */ + xas_for_each_marked(&xas, req, ULONG_MAX, CACHEFILES_REQ_NEW) { if (req->msg.object_id == object_id && - req->msg.opcode == CACHEFILES_OP_READ) { - req->error = -EIO; + req->msg.opcode == CACHEFILES_OP_CLOSE) { complete(&req->done); xas_store(&xas, NULL); } @@ -179,6 +175,7 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args) trace_cachefiles_ondemand_copen(req->object, id, size); cachefiles_ondemand_set_object_open(req->object); + wake_up_all(&cache->daemon_pollwq); out: complete(&req->done); @@ -222,7 +219,6 @@ 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->ondemand_id = object_id; cachefiles_get_unbind_pincount(cache); @@ -238,6 +234,43 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req) return ret; } +static void ondemand_object_worker(struct work_struct *work) +{ + struct cachefiles_ondemand_info *info = + container_of(work, struct cachefiles_ondemand_info, ondemand_work); + + cachefiles_ondemand_init_object(info->object); +} + +/* + * If there are any inflight or subsequent READ requests on the + * closed object, reopen it. + * Skip read requests whose related object is reopening. + */ +static struct cachefiles_req *cachefiles_ondemand_select_req(struct xa_state *xas, + unsigned long xa_max) +{ + struct cachefiles_req *req; + struct cachefiles_object *object; + struct cachefiles_ondemand_info *info; + + xas_for_each_marked(xas, req, xa_max, CACHEFILES_REQ_NEW) { + if (req->msg.opcode != CACHEFILES_OP_READ) + return req; + object = req->object; + info = object->ondemand; + if (cachefiles_ondemand_object_is_close(object)) { + cachefiles_ondemand_set_object_reopening(object); + queue_work(fscache_wq, &info->ondemand_work); + continue; + } + if (cachefiles_ondemand_object_is_reopening(object)) + continue; + return req; + } + return NULL; +} + ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, char __user *_buffer, size_t buflen) { @@ -248,16 +281,16 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, int ret = 0; XA_STATE(xas, &cache->reqs, cache->req_id_next); + xa_lock(&cache->reqs); /* * Cyclically search for a request that has not ever been processed, * to prevent requests from being processed repeatedly, and make * request distribution fair. */ - xa_lock(&cache->reqs); - req = xas_find_marked(&xas, UINT_MAX, CACHEFILES_REQ_NEW); + req = cachefiles_ondemand_select_req(&xas, ULONG_MAX); if (!req && cache->req_id_next > 0) { xas_set(&xas, 0); - req = xas_find_marked(&xas, cache->req_id_next - 1, CACHEFILES_REQ_NEW); + req = cachefiles_ondemand_select_req(&xas, cache->req_id_next - 1); } if (!req) { xa_unlock(&cache->reqs); @@ -277,14 +310,18 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, xa_unlock(&cache->reqs); id = xas.xa_index; - msg->msg_id = id; if (msg->opcode == CACHEFILES_OP_OPEN) { ret = cachefiles_ondemand_get_fd(req); - if (ret) + if (ret) { + cachefiles_ondemand_set_object_close(req->object); goto error; + } } + msg->msg_id = id; + msg->object_id = req->object->ondemand->ondemand_id; + if (copy_to_user(_buffer, msg, n) != 0) { ret = -EFAULT; goto err_put_fd; @@ -317,19 +354,23 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object, void *private) { struct cachefiles_cache *cache = object->volume->cache; - struct cachefiles_req *req; + struct cachefiles_req *req = NULL; XA_STATE(xas, &cache->reqs, 0); int ret; if (!test_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags)) return 0; - if (test_bit(CACHEFILES_DEAD, &cache->flags)) - return -EIO; + if (test_bit(CACHEFILES_DEAD, &cache->flags)) { + ret = -EIO; + goto out; + } req = kzalloc(sizeof(*req) + data_len, GFP_KERNEL); - if (!req) - return -ENOMEM; + if (!req) { + ret = -ENOMEM; + goto out; + } req->object = object; init_completion(&req->done); @@ -367,7 +408,7 @@ 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 && + if (opcode == CACHEFILES_OP_CLOSE && !cachefiles_ondemand_object_is_open(object)) { WARN_ON_ONCE(object->ondemand->ondemand_id == 0); xas_unlock(&xas); @@ -392,7 +433,15 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object, wake_up_all(&cache->daemon_pollwq); wait_for_completion(&req->done); ret = req->error; + kfree(req); + return ret; out: + /* Reset the object to close state in error handling path. + * If error occurs after creating the anonymous fd, + * cachefiles_ondemand_fd_release() will set object to close. + */ + if (opcode == CACHEFILES_OP_OPEN) + cachefiles_ondemand_set_object_close(object); kfree(req); return ret; } @@ -439,7 +488,6 @@ 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->ondemand_id; trace_cachefiles_ondemand_close(object, &req->msg); return 0; } @@ -455,16 +503,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->ondemand_id; - - /* Stop enqueuing requests when daemon has closed anon_fd. */ - if (!cachefiles_ondemand_object_is_open(object)) { - WARN_ON_ONCE(object_id == 0); - pr_info_once("READ: anonymous fd closed prematurely.\n"); - return -EIO; - } - req->msg.object_id = object_id; load->off = read_ctx->off; load->len = read_ctx->len; trace_cachefiles_ondemand_read(object, &req->msg, load); @@ -513,6 +552,7 @@ int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object, return -ENOMEM; object->ondemand->object = object; + INIT_WORK(&object->ondemand->ondemand_work, ondemand_object_worker); return 0; } From patchwork Wed Mar 29 14:01:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 76591 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp447918vqo; Wed, 29 Mar 2023 07:17:27 -0700 (PDT) X-Google-Smtp-Source: AKy350aWSgrltdsyvSnJnbZZX1gm38WQEU9u/B3vnwoJJbi6UYRPYktNbKulsrUVjj2PwC2Pev0Z X-Received: by 2002:a17:902:fac7:b0:19c:eaab:653d with SMTP id ld7-20020a170902fac700b0019ceaab653dmr1836409plb.15.1680099447428; Wed, 29 Mar 2023 07:17:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680099447; cv=none; d=google.com; s=arc-20160816; b=Rvk1fFEn/ayeLaAdP0fMTIe9XJ5o55AjXa55tJlO6Ve6FVGrlfwjr8clJhxazGvm20 vop8Zc7iD/MW3Vs79p2Usuh4WXMrgvG12UltfKKXIrqzZ5ycsvcmLWkIYBXZrehHrUdn 86Au5y+mScpLM1VcE3ajk9HhjmdcG28pVvynx7wEAHpH2Ymjc+lIChBRQdQ6tmToRT4h vwLbvtsTRdsQZFf/cVfLqgR3bQ9pQ/SR5yhITaHdpo+IJ5T/1ISlKCMgOdnAQoJUCTmj oTU7xZtaqlFnnboXaaDYpBTs6Whr30fce1S6sauciLwpIXMTMgdwyXdfcjeG+RMP+i94 kvCA== 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=201B13UZk/ur2kBlvNBkJlC5f80F32l3qYGjPhn9UGk=; b=lsN09Ee6OKenVHbFFu+DpOOs86SFp+ze3LzYlwQfG0o9tyo+08bzq7UWqrqa3bvjzn bTtPe9HgNMOTPdMc8hYCRa999rkro5kRavKQhLRZPjTFAv1kfL6z2/TZnAnMll0vWu23 gbh9aZuhhtrOqSgXgUKcIOksNL+0UXqa7vc6Pyn5Br3ViB4OzfD4BadK6xNTrCyuDKhR S+Uid8rED2FcGvOp/LUhToP+zsP3sCqyOgDBnSRRjcHwtNrm2Sd7ZGkQbYQ7KCvT7y1J 9y1+Ev/7eY/nAZKOYNKaWO+tTfuaC/+KaCuTgCRzivp+zrdW9zedn5B1/oCA48ZBcchv AkTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=l589k9Vc; 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=pass (p=QUARANTINE sp=QUARANTINE 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 3-20020a630403000000b005133f64cc71si9486917pge.726.2023.03.29.07.17.14; Wed, 29 Mar 2023 07:17:27 -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 header.s=google header.b=l589k9Vc; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230121AbjC2OD2 (ORCPT + 99 others); Wed, 29 Mar 2023 10:03:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbjC2ODR (ORCPT ); Wed, 29 Mar 2023 10:03:17 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7951755BA for ; Wed, 29 Mar 2023 07:02:26 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id z10so9323789pgr.8 for ; Wed, 29 Mar 2023 07:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1680098546; 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=201B13UZk/ur2kBlvNBkJlC5f80F32l3qYGjPhn9UGk=; b=l589k9VceQVCSfGGt2mtcUk/mgCXBRxnZzNxeJPJ96SxR+hNJU+zRlqO7ZSCA9MSqR 3PQaFvQiKRzgTCpXLUHVWPBoW47FdIIuKzGfg/deTBcaD6ZvUwjbddQU2QNgNiDa7vK5 L54qu5HyIldHsuUKHaLR42uDwP6ugyJCnlotGlL0qYGZLWA9yEd1SABFZTHZE9DGiAcJ aQnjiPJ79C1dKUetzeHNeftJpdYhUExwemT5Y5x8NKb8p1zViRIAdn3V5ClQmBHBUn9I VVup8Tt1GSoNvyEgJnCH/thPhHF4ZnhiJG3otqlIxad26l3VhEZbNAGutOexfbMWvR0X Qbbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680098546; 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=201B13UZk/ur2kBlvNBkJlC5f80F32l3qYGjPhn9UGk=; b=mbxjSMIJS1RvqeXefpvZuq1xgcvXzmmMaoutwtjB2kYMexvch2GgeeI/7bxNISIK+K Ej9+ot6Aa9ya3nZ7dHrrS/pO4db6YOI4Koy9Kq7l8cIQWq0FyEXiqFrL3Fb4U8fHrDqX S+pryolI+1hqVjGu0xidBwTwNGkrrK5KMfkW4dYi7bUlpKMd4ozlbiBNMII8DvIfL/Ul dUpINiHDuziN+s3Grqt8x1cs9PJzZ3cx6iXcrnHNRlvunij0rJp01SFY5TbTLsZh4OU7 GCCUZVywDU0oiGj194UdmqtUJyOhHWnsIXYcj+kLLhdwnFFqwlbH0GJTO6Jo9AV8KRYg T+9g== X-Gm-Message-State: AAQBX9d59o78RqVJE21LTmlYYq7baR/bsrgs/e1EEBEtdGrd9Uzvk9G5 l5jELQ3NwagixYB1jCuqwW3iGA== X-Received: by 2002:a05:6a00:1d0f:b0:629:3f28:ead1 with SMTP id a15-20020a056a001d0f00b006293f28ead1mr2194928pfx.12.1680098545899; Wed, 29 Mar 2023 07:02:25 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.213.176.14]) by smtp.gmail.com with ESMTPSA id y17-20020aa78051000000b006288ca3cadfsm5399468pfm.35.2023.03.29.07.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:02:25 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, jefflexu@linux.alibaba.com, hsiangkao@linux.alibaba.com, yinxin.x@bytedance.com, Jia Zhu Subject: [PATCH V5 4/5] cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode Date: Wed, 29 Mar 2023 22:01:54 +0800 Message-Id: <20230329140155.53272-5-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230329140155.53272-1-zhujia.zj@bytedance.com> References: <20230329140155.53272-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,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?1761711958056337953?= X-GMAIL-MSGID: =?utf-8?q?1761711958056337953?= Don't trigger EPOLLIN when there are only reopening read requests in xarray. Suggested-by: Xin Yin Signed-off-by: Jia Zhu --- fs/cachefiles/daemon.c | 15 +++++++++++++-- fs/cachefiles/internal.h | 12 ++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index aa4efcabb5e37..86892f471e761 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -355,14 +355,25 @@ static __poll_t cachefiles_daemon_poll(struct file *file, struct poll_table_struct *poll) { struct cachefiles_cache *cache = file->private_data; + struct xarray *xa = &cache->reqs; + struct cachefiles_req *req; + unsigned long index; __poll_t mask; poll_wait(file, &cache->daemon_pollwq, poll); mask = 0; if (cachefiles_in_ondemand_mode(cache)) { - if (!xa_empty(&cache->reqs)) - mask |= EPOLLIN; + if (!xa_empty(xa)) { + rcu_read_lock(); + xa_for_each_marked(xa, index, req, CACHEFILES_REQ_NEW) { + if (!cachefiles_ondemand_is_reopening_read(req)) { + mask |= EPOLLIN; + break; + } + } + rcu_read_unlock(); + } } else { if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags)) mask |= EPOLLIN; diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index b9a90f1a0c015..26e5f8f123ef1 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -329,6 +329,13 @@ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN); CACHEFILES_OBJECT_STATE_FUNCS(close, CLOSE); CACHEFILES_OBJECT_STATE_FUNCS(reopening, REOPENING); + +static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req) +{ + return cachefiles_ondemand_object_is_reopening(req->object) && + req->msg.opcode == CACHEFILES_OP_READ; +} + #else static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, char __user *_buffer, size_t buflen) @@ -359,6 +366,11 @@ static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_object *ob static inline void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *obj) { } + +static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req) +{ + return false; +} #endif /* From patchwork Wed Mar 29 14:01:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 76593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp448200vqo; Wed, 29 Mar 2023 07:17:52 -0700 (PDT) X-Google-Smtp-Source: AK7set/kHoVyDZJNzYD23jEIvQVgvznY6suKHU776Tg0ttJY+V2IJOvL4RppIJyE7eLCo/EMyq9v X-Received: by 2002:a05:6a20:a82a:b0:db:1b41:704 with SMTP id cb42-20020a056a20a82a00b000db1b410704mr15553862pzb.16.1680099472065; Wed, 29 Mar 2023 07:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680099472; cv=none; d=google.com; s=arc-20160816; b=LSQWlzRjynNtpY8/pMzgMXtmtW4fkjS58wSj1HyJehLXrEhDAkB9LgqEXqPzuy9PpM Aj4vNPWXt/bYHNwYAfWGROwlwPPqxXFUKRlKxbC+rQ+PyAerFIe40vOoaUIArcsCOw86 DrnzIgZcUeIDlGTMQ3nvNd+IeLWplpNNW+pwf/tFl2HuWBjBktI5NE5+pxeNkBwFEWFy CcYQWrBGAlntbiJRVbk0LtYFo6UhUNf96TunaSCoyav0NUhKZPZ3YFqX4l8LhU++q1D1 Yc4eHYJBT3IMWPufKmC0hU7RB2yhmKjWOPjwf2l2YjHOdaZfuVaDTrW9/WJtVue0jbOY vNyQ== 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=sqFkGHmM/dJ9kF1cZmCY3mrpL1ZG3gGE12XFAvwXSFw=; b=MGS6dHoq28xUi/2QnZpf5UTdb2ADtaHN0p6Bafdlo0UyWtZVzPWfWe/GxQOhfOzhl7 vfLkcQY4UMGIagjj7yc5puCtlvF6drxYYBIG+vTxuwAr7RBTs3MpCn8SvMH2IUNGsW2R k8GYa+mXjGrCrCHrCAANvEOkLzqIjAEEm8fD7cK9FKFQ7Gw+cpWj2R/DZhLY9CuPEWUu p5yP8PCQ8C00LNOLUAnUqZtPYVDEGA4ZFeDFLmbubIOL4MIKDCTSXrViM60dw0V4KPfs vrUxXmTo6FxkKiLyrHVFBBIWaeTIh0PLXpFDsGF7bmi9XUspFiz2SJVQQWOlhX15sN91 GJFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=HisIVLRz; 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=pass (p=QUARANTINE sp=QUARANTINE 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 g1-20020a056a001a0100b00625e8ef7241si31920585pfv.30.2023.03.29.07.17.39; Wed, 29 Mar 2023 07:17:52 -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 header.s=google header.b=HisIVLRz; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229942AbjC2OC7 (ORCPT + 99 others); Wed, 29 Mar 2023 10:02:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230121AbjC2OC5 (ORCPT ); Wed, 29 Mar 2023 10:02:57 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22B9349C7 for ; Wed, 29 Mar 2023 07:02:30 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id fb38so10354869pfb.7 for ; Wed, 29 Mar 2023 07:02:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1680098549; 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=sqFkGHmM/dJ9kF1cZmCY3mrpL1ZG3gGE12XFAvwXSFw=; b=HisIVLRzBGWL4CTLcww9FAC1lhsk226n5Y41WJOtDooXQq5Mt/FuBCKZVe9LKUHeM6 KOjnzJ4IF7WbCVXkRHYxkA//f8+WyCeVttTF9wSXc8bvBigOfPbV1+XPtgi8osHoF3vT ViY41U4S0hj29xCR1WWWk0ylrPzTtxBJuKvE3lIoZsH/a+WTP7ataKW+30i2GU2P0VIf Ec1hToZP79eigouQgKZOtwmzWnIdUv3Kse1/UH7G4912tD+dqaTgL6LLMQvBlPJgu80+ W8wnUbhCXgxrv5Drk5Bo+c7eo6PXXTTvkuh0u6pt6ouCK3CyI/cUYVisjMuwhJAkUbVt xcTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680098549; 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=sqFkGHmM/dJ9kF1cZmCY3mrpL1ZG3gGE12XFAvwXSFw=; b=j4etMBuk8ORjcbhVqJDvm1xWt2mY/yqX8QyVWlPzyUeO/Ucd/wrJLVRMv3A+yWOxjX dm8942G0/tJbRhrOdTnXxe7YMc4oJQd8cyQDU6F7zzn1O9GHJwOB2dPg40ln42SB+6vX S5fmz/SHndbMdb0+92XNfAECCgPSIkl83pgE31FLcHwzWnsHdoMJI2zPYqKZRkYEiUiV x1nmeFetlSNzGjF26WKEkEjCgwvE9u5/F/LrqozMJkwKKs9kXA1s2l/V/KrkQ/rbXYqE 8NTg3cVQACX6iRtUWiRwkSTHGM6uoLtAeTuLfB3mSH5sXAlhWwHY/nC8KchkIOIYKDSl XAEA== X-Gm-Message-State: AAQBX9ep43bspq71NdBibVVHf88b45b0+2aUPzwuLTkHzcNH4qTK84p8 Loiye8ZFg5LidBugf1iaCClTpw== X-Received: by 2002:a62:cfc1:0:b0:625:ebc3:b26c with SMTP id b184-20020a62cfc1000000b00625ebc3b26cmr15854390pfg.22.1680098549382; Wed, 29 Mar 2023 07:02:29 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.213.176.14]) by smtp.gmail.com with ESMTPSA id y17-20020aa78051000000b006288ca3cadfsm5399468pfm.35.2023.03.29.07.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:02:28 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, jefflexu@linux.alibaba.com, hsiangkao@linux.alibaba.com, yinxin.x@bytedance.com, Jia Zhu Subject: [PATCH V5 5/5] cachefiles: add restore command to recover inflight ondemand read requests Date: Wed, 29 Mar 2023 22:01:55 +0800 Message-Id: <20230329140155.53272-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230329140155.53272-1-zhujia.zj@bytedance.com> References: <20230329140155.53272-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,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?1761711983914978557?= X-GMAIL-MSGID: =?utf-8?q?1761711983914978557?= Previously, in ondemand read scenario, if the anonymous fd was closed by user daemon, inflight and subsequent read requests would return EIO. As long as the device connection is not released, user daemon can hold and restore inflight requests by setting the request flag to CACHEFILES_REQ_NEW. Suggested-by: Gao Xiang Signed-off-by: Jia Zhu Signed-off-by: Xin Yin Reviewed-by: Jingbo Xu --- fs/cachefiles/daemon.c | 1 + fs/cachefiles/internal.h | 3 +++ fs/cachefiles/ondemand.c | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index 86892f471e761..b0f4dd6384128 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -77,6 +77,7 @@ static const struct cachefiles_daemon_cmd cachefiles_daemon_cmds[] = { { "tag", cachefiles_daemon_tag }, #ifdef CONFIG_CACHEFILES_ONDEMAND { "copen", cachefiles_ondemand_copen }, + { "restore", cachefiles_ondemand_restore }, #endif { "", NULL } }; diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 26e5f8f123ef1..4a87c9d714a94 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -303,6 +303,9 @@ extern ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, extern int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args); +extern int cachefiles_ondemand_restore(struct cachefiles_cache *cache, + char *args); + extern int cachefiles_ondemand_init_object(struct cachefiles_object *object); extern void cachefiles_ondemand_clean_object(struct cachefiles_object *object); diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 8e130de952f7d..b8fbbb1961bbc 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -182,6 +182,29 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args) return ret; } +int cachefiles_ondemand_restore(struct cachefiles_cache *cache, char *args) +{ + struct cachefiles_req *req; + + XA_STATE(xas, &cache->reqs, 0); + + if (!test_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags)) + return -EOPNOTSUPP; + + /* + * Reset the requests to CACHEFILES_REQ_NEW state, so that the + * requests have been processed halfway before the crash of the + * user daemon could be reprocessed after the recovery. + */ + xas_lock(&xas); + xas_for_each(&xas, req, ULONG_MAX) + xas_set_mark(&xas, CACHEFILES_REQ_NEW); + xas_unlock(&xas); + + wake_up_all(&cache->daemon_pollwq); + return 0; +} + static int cachefiles_ondemand_get_fd(struct cachefiles_req *req) { struct cachefiles_object *object;