From patchwork Fri Apr 14 17:22:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 83542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp546678vqo; Fri, 14 Apr 2023 10:30:57 -0700 (PDT) X-Google-Smtp-Source: AKy350YHY4yuuaOBSBX9JTz2UiFryVxcBS6Zk9isQmBeeyGFugq4R390+HxjOZcz5Q6urJVx1971 X-Received: by 2002:a05:6a20:8e09:b0:ec:87ce:1146 with SMTP id y9-20020a056a208e0900b000ec87ce1146mr7277217pzj.37.1681493456903; Fri, 14 Apr 2023 10:30:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681493456; cv=none; d=google.com; s=arc-20160816; b=YhGiqFah53/EXub5C74c19HzLwaLw6UYhMAJmW/mavl96DA18KjTgVfYC1NNuxCIoW U67Af4hUkoRT+KEQC3RAo6d5O4EfoIWT4bHcqk8dgeob6pVBHdkA0sa7werv4GebSdMw M77PPtEhjj5/xAj0fkUxaHjZUCgaOOQYroCEx1i4YiNa3ZmCaySiM3yHAQMvDtxuDzZp kMerEDP03jdH54iVb2YP/3UPUSQedKIjtUGBUpIywi8RqIMHoeSt9JOS/h8p79sXsqQF R913dQzSTXup31uNQG5r+qQiliTmjqP6JHw36u8nkpUKPe9EbaUFMB1fw/5rme5JE2K/ dTYQ== 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=iHnlRfQ11A0T1qQ+WeGIi9uEwxCa9o9DTCxHuc9T2C6sHQ0zeLIxBMbx3TgBoTi4Xx NXman7MCRauwG3//m9FLT6LchVdWT3xmA3jHCMaqPMXmQVBmhSxYZf4cTu7AVPu9tv1e G/ZcVGbQpRpBpJuXW0EFGCQ1T9jJozYkGGPjrv+JrNdd7c4AqFAUBgztTYefrT2JycVS FO8uLPpfe+fRUzmlgwMCIPt7CVwK77Rz2AEeH0Bke0oNjH+OjnYH4IDFYxTSFiWtOC4y E03JK19ScrSouoJBO604APW+YW9guz0ziTrXUOTlwATrBMlUO0KDzoTJiqM3gNv60Dc6 ne4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=AIipzAJf; 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 z23-20020a634c17000000b004ff6eee7176si4895376pga.261.2023.04.14.10.30.44; Fri, 14 Apr 2023 10:30:56 -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=AIipzAJf; 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 S230081AbjDNRX2 (ORCPT + 99 others); Fri, 14 Apr 2023 13:23:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjDNRXY (ORCPT ); Fri, 14 Apr 2023 13:23:24 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C98016A5E for ; Fri, 14 Apr 2023 10:23:22 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id hg14-20020a17090b300e00b002471efa7a8fso5678574pjb.0 for ; Fri, 14 Apr 2023 10:23:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681493002; x=1684085002; 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=AIipzAJf7XKNk+M8FHlQLcwlGgE+JSGaHPiF8CepatLjwqRTV/bqqk9I2Rf7HKREqD BZdO597TmZQf6gGGYTKbQ+mXvRDF4+eTRvAFDcKXYxHtQfZYjLN43SLF9a0/+AhUmcvZ WmZnJZWycAHdLpCdjfFiwErskCDLNcnM4O2/elLIgoVJGUhTs7ACP1egFxOoSpWk9xqg OXG7bwxJ+uSAxNzqD1iky0G/xG8WMqCtt4DXd9TgnKh7T7494+xRGRexcHBri6llRm6t N8wlisxjx3mV+7T/q+tnGQWC3h4pv8fQW+Sl1V/QVBg0YofvhGII9lA5uu/brRKxQF+N hWYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681493002; x=1684085002; 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=HWf7w4hrO/teD8OA33KCMiECDgNjxDRSgx8JrR1cHMHpW4StD2wQ4ToM8KkNcBY+Bu nJX3qXfj6YZ3EM6+kUBm284YHlH3CvSppkVT+N2/nq4Srnk4hC04pHVkUoeRj1IlIRqM L4RktjnK9UjNpXv1yrql59L4ku4gGf9/kc8r0q/1zUQjkVjKM69m8x8vZEHe6zlDpMpU 4YXp/VVpVqV1kein+q/yay3LbbMaxXOH1LoXAfPqJ1gL4kffAxUIYNLtJ8ga9Q06mTqM JhG2tVRT7Rfyyg+pdOScYMkglzZg6viWqmUA4vJ4+X+w8wwFLNCQJEuPBD7O4xky4JgS 3KwA== X-Gm-Message-State: AAQBX9ejA9Ix4/epjnkxDtgfqH0wnCikRDjPiKbADnkvI0iLWoWuvUUS Ag0RWxNKZp36cwX2JjlXBAOtYQ== X-Received: by 2002:a17:903:200b:b0:1a5:2640:10fe with SMTP id s11-20020a170903200b00b001a5264010femr2818290pla.67.1681493002303; Fri, 14 Apr 2023 10:23:22 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id q12-20020a631f4c000000b0051b8172fa68sm370315pgm.38.2023.04.14.10.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 10:23:21 -0700 (PDT) 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 1/5] cachefiles: introduce object ondemand state Date: Sat, 15 Apr 2023 01:22:35 +0800 Message-Id: <20230414172239.33743-2-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230414172239.33743-1-zhujia.zj@bytedance.com> References: <20230414172239.33743-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1763173682944710936?= X-GMAIL-MSGID: =?utf-8?q?1763173682944710936?= 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 Fri Apr 14 17:22:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 83538 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp543908vqo; Fri, 14 Apr 2023 10:25:59 -0700 (PDT) X-Google-Smtp-Source: AKy350acfYYUl9bOtcZt7TLWEyqDhIpc4Jqydfn6+v6zjMca7ccWTT/5N8r5ux374vkOwB6F1vKl X-Received: by 2002:a05:6a20:6d83:b0:de:808e:8f3d with SMTP id gl3-20020a056a206d8300b000de808e8f3dmr5575791pzb.13.1681493159222; Fri, 14 Apr 2023 10:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681493159; cv=none; d=google.com; s=arc-20160816; b=scmTTmNcjAu6zFlXRfCadtC4DVsMrz4z5KPx8lvI8NTDgZDcvIniggwRL/1yxdxn5w f560+D53JY0Sz3vI6+18JPTtMQbMnxvZsfBUVic+6uo+paDPcZyTlHOZNcyMQRpmFbKm r48DUsk55Qg/KNqvS+YuCf/LmddxVnXiLUTkn67NT/WypBoXTBUP/bBPZcpMUIcTKNYB ejIlK6rFDzgfxHL/ST3zHBEawZws2xKDyETHvTuTFSCK+5y5wIcsxYLMriG1EQ7jsSk/ 6rvsLJXCXPvNlRhqJn7JbVG7hMO7L2qKA4DP4HiGolp9nOuD2Ww/N+rfKF/CHHCwoILd DvWQ== 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=VfNqMjmI+U4R8UYz6oU1vmhlId6hEPdroEswGdLFt8MWOApjfA8jNewHZ6ArVeXCkv qL1kcvc430Uz6ZY2vAOnc5ZjcEljkmoaX8FP3baGs8Ljn7zvuOMqD+RaAOZejwwtVgxh xQIHrb/7o5rWzXfeUl85NSK5MV7+mw+zxcBSKs5gBXTiHklRInJmLeCQ+/Dm+u/IQD9c mHpDeTZQqv0ztL00IGcuh+Uqj0Ai1CkpkTazV3beejpCXtEwc5jC5370Et2OwO3eMR73 zjsmGz/6Y0HNkKkwTA8vzRsNOGgWdaS4ZNnC97u6CTUPRnSztPlEhK0Fobqs00eyvSvX RPsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=UJtia1KQ; 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 i5-20020a6561a5000000b0051398cda533si5355696pgv.388.2023.04.14.10.25.44; Fri, 14 Apr 2023 10:25:59 -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=UJtia1KQ; 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 S230322AbjDNRX7 (ORCPT + 99 others); Fri, 14 Apr 2023 13:23:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230271AbjDNRXv (ORCPT ); Fri, 14 Apr 2023 13:23:51 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48EA97ED0 for ; Fri, 14 Apr 2023 10:23:26 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id pm7-20020a17090b3c4700b00246f00dace2so11448104pjb.2 for ; Fri, 14 Apr 2023 10:23:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681493005; x=1684085005; 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=UJtia1KQNMp+f1pQPPMLsnb+GlxRBpCYjWKbpTipdlVqr4IFLObia0bV2jaSv2k/UO BcgIYDiTRKUX97NTnRegq++/W8nQxMFHZacpOG4jyOg7kqNWUIc5zClsm1l4Qf859C7l DTAGC5pleH34yyBMpv+2WSBi4AvwYIqWVlgUoekKhhpx+DzxEzIPZ+nw4LxkZnPCdmL9 M5n6Yois3ueil+35lzARM2SN6hvYCN/WPL47hdpURqKLVN12QTBq58kYDxJEmKNc+E4M KQvP7AZDZ9OPEF65/w8MZzMb83YfpVqwkzQ0kBwuolYmEx4KZ46owHZh+zvpH8QHIsjQ O7Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681493005; x=1684085005; 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=UoBbtKPhWocGhSfmDgGqEX5yVZPsUPg02Bn7dnSqBl3JkxvLv4TcMbJay2+h31BKKF avWVGK/HQvP3m/2oIuShMth8VJGSvm/p7oGzlk5fpCek3lPgERnR7pPTiqBxW1cDqCCe JYeEWUv/jGUM7deplVIK0vaD+jMakIRrOX/6tdNYhlGLq6VTPu6X0hiVX2nCDNSstkep jcSIQJ0nBrHf2pPp/AdlkUIItFR1/5KbBngc4W4B+4dEwQcVPDMWKoqoFRKf9uIXyRx8 8XjLjjFhG0m1mXRv262rRXECQvQ8HyXGwofDF+RJOWpl5cBS/hGswvuz4dKrXptNVTd3 2cvg== X-Gm-Message-State: AAQBX9dUpE+Zsz+G4CpvRzLxnqX2riiujwGwmFEP0cP6Me0n0jZX7VtE rcdBZpwvfDOfyHNsgvNLzufbzw== X-Received: by 2002:a05:6a20:4694:b0:dc:925f:62f1 with SMTP id el20-20020a056a20469400b000dc925f62f1mr5685706pzb.6.1681493005739; Fri, 14 Apr 2023 10:23:25 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id q12-20020a631f4c000000b0051b8172fa68sm370315pgm.38.2023.04.14.10.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 10:23:25 -0700 (PDT) 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 2/5] cachefiles: extract ondemand info field from cachefiles_object Date: Sat, 15 Apr 2023 01:22:36 +0800 Message-Id: <20230414172239.33743-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230414172239.33743-1-zhujia.zj@bytedance.com> References: <20230414172239.33743-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1763173371002655341?= X-GMAIL-MSGID: =?utf-8?q?1763173371002655341?= 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 Fri Apr 14 17:22:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 83539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp545761vqo; Fri, 14 Apr 2023 10:29:35 -0700 (PDT) X-Google-Smtp-Source: AKy350aRpHGFjfsjZLc5tAQhZhXltOGD2JUaGvezxmc0ik8bFtJ8/woks51caTBP1RP9enhLzAXM X-Received: by 2002:a05:6a20:af0a:b0:ec:3e6f:9f3 with SMTP id dr10-20020a056a20af0a00b000ec3e6f09f3mr5997537pzb.8.1681493375676; Fri, 14 Apr 2023 10:29:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681493375; cv=none; d=google.com; s=arc-20160816; b=w0BPjr93TQ1G6vZ+g2mA/wTMT/CUF0JmR5GoSsar7IA8904H41I3RHZQetlROAl/6R RJIuZ21HvreAknQHaEKsbzRBGs8DFvora7kSPA1p76zWrftertq560Lr/qiAgg7bwrxT NJaHztvdpHspFSUSaZ/lW0aSg2JEZ6h8q/arTLBOY76ODtS8BBHw+VCvq9CwXAdFa9OY 2GAcvQZ7IIUFjcbDPvOXYgHqnO04ENMrhBCeMbI1WnE46d6N7u9n9IiCEPW/BGK6z9co 7NrE1z/Ibz+LcxQG25qqPCjprQ/agXgMf1LVyqTl3VZgvEDRKYqT+6wC+tQSy/dLN1En x56Q== 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=TCjKkgBt4I3wo5QnBcVsQZXVBOEYI47Oe4hhWf4tOxC3nYSZKV7nXnKcVf+l7iWjZd CZ6jOiqh/pd/60lGkjk8JRhhprr0vFeobPbFPzLed7u4dxyLx69v3KoB8vrprLKlh2UO /m0L5hhEMqrg+dfJ+7RjGSG0A+hkZsnDrK/ZzKYUGwsNEiR20rv91mRAyyHHCKptTK/T RF9uvG/i8ZV6vjCErDh7jSk59mxP+utDysg+75Oav7VHXXiHVzpEUSa1fJqqspaI1GG1 pBd1ZdeZsBhZsf3jsfBilm1z4O0AR+3HY2nBwSb41FiXW+zX6hJ1ZALPY4D1fYxlz1Ny SEJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=GwvrOTtJ; 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 a8-20020a656548000000b0050b508f68d8si4738742pgw.206.2023.04.14.10.29.22; Fri, 14 Apr 2023 10:29:35 -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=GwvrOTtJ; 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 S230379AbjDNRYU (ORCPT + 99 others); Fri, 14 Apr 2023 13:24:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbjDNRX4 (ORCPT ); Fri, 14 Apr 2023 13:23:56 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8265902A for ; Fri, 14 Apr 2023 10:23:29 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id my14-20020a17090b4c8e00b0024708e8e2ddso8441003pjb.4 for ; Fri, 14 Apr 2023 10:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681493009; x=1684085009; 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=GwvrOTtJ/qpLMxFnCQ9BNbH6VmRUx6fBicNS3ilywFLg7uhNJHZz/euh0PpduinHca mVzeJETlDXk9MICZ41xp5R4ySy026Ji6VYxLBAELLM6IhUgIbfvKzp1UUQfy9TQI3rAs bDYDGhZlQDqnkkxs2W8GWKCYc3Le1t4guIjxa9WgT4v86RnE/BlnhIKikjdlcAQxwmqZ exQcS4bmfvdRg9CP2O796tHKjkq4+cgfKoChX8biLVopb9T2bjwkclYioHRyD9lMgwEM SEoEICJqmtNABkTdegIgsBEQw3uzB8vrJAl2Zz715GwJE2h23zcUW/HD5TnNeou8K/7G Q7Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681493009; x=1684085009; 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=Ak4IotQbHzncAZe+icA2UTXJs0qGlLce5Z8CLLiZxhtiul7mZejRqBY38QL3g7ZeAc VHpWmV8AAlrwY0JKWIZmy7TwTFmtnfkgdA2uTQIyhhx/ZlsjJ+2GWjgZmA/yuNWdN7+3 y6WX1iyCAPsUkoPJL9fXVE/SSJHeOEItfPbSTgGuDemBLnal9xvYdA2iOrS/fcKFid/G cLXVkjyQWwvGTBDbSn4/q+slSXWpv/JQhCsLJkk4wZOEcWp5As8L6lWd7JhrpvUnNaML 2xwKLBQHClt7Hr90k/6+IcgjzLRxTi8iy26sN1znnW/01J/MXGOlFYG1mb2aYXUg03gd 9zEQ== X-Gm-Message-State: AAQBX9dQK3w8nyzZ/kG0gSAUqybgimpj8HMVDs9eq3GUopNobDCjjd+M /QxpbAtanDctwYkYmzd4Rw/cepw8Sv9dLZYKNw5+pg== X-Received: by 2002:a17:90a:460e:b0:23f:7e2e:fe13 with SMTP id w14-20020a17090a460e00b0023f7e2efe13mr6442173pjg.0.1681493009218; Fri, 14 Apr 2023 10:23:29 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id q12-20020a631f4c000000b0051b8172fa68sm370315pgm.38.2023.04.14.10.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 10:23:28 -0700 (PDT) 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 3/5] cachefiles: resend an open request if the read request's object is closed Date: Sat, 15 Apr 2023 01:22:37 +0800 Message-Id: <20230414172239.33743-4-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230414172239.33743-1-zhujia.zj@bytedance.com> References: <20230414172239.33743-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1763173598049994438?= X-GMAIL-MSGID: =?utf-8?q?1763173598049994438?= 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 Fri Apr 14 17:22:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 83537 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp543683vqo; Fri, 14 Apr 2023 10:25:32 -0700 (PDT) X-Google-Smtp-Source: AKy350bThn26gjeN3CJgrpXxxR6SN3rufVvuQ2vyWhBsbxsI/82Mq3hLONVDHKenPZdrmGBD9AUN X-Received: by 2002:a17:90a:fa02:b0:23f:7625:49b6 with SMTP id cm2-20020a17090afa0200b0023f762549b6mr6242003pjb.37.1681493132105; Fri, 14 Apr 2023 10:25:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681493132; cv=none; d=google.com; s=arc-20160816; b=HmtLyE+ZbIzRUzT+FvasX+K4jVyAdzNg08WTdIYbrQAm7eKwQ8+0wu1TWOMrt1Hxp7 DT/StbOQq3rsii3NvY6JulCqi1HsmGQPB6YZxYhYHHyNQ6r9xgX5cVtLALwP2q8TNmKm A/I8fl/y45ZvowHw7k8DPoRzilKj9db0svhjVWuGr4GA2mMja2tM/CaRKeRxM/3GcBNq fZ2ga61gtMjGFTqmpPlFBnmgRTBOhsb+l/3QNKC/1zJ9gnCiyGp/KHxln6yjaXiRWjhM fSfqagFb/Sf0KLomDMk3xRacwx0QwtnmLjrG9CcEfqncS8z0McF7m07xbHwFPBVo3DZ6 +igQ== 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=jLxzEPuRQOpnZLaEq6SfAsMRmsFnFoLhYkxVpQU9ODc=; b=e44PAepvDHfFrLL/9Ann5WCak4Co4+FtNw4YQTQan0E5hGPm5QtWLwgXI0JvWBfckR 7B4eW4CwS/cixpHy4GOYx2iAO3eCxizVfQuZ8VZGcIE9oriCYaUpxcsIGFuxVaNamLA7 cMX/f2FfSi8jsQPZymO9zzw/yGDKmEXgW2VflsGv6AuH+VEF9sHRua/sktV15JsWOyrE FX9r2cuNQIWK/576khivlJMA8NPNfUVORO7Jwq3jiQeIDeziCOY5shm3PxvSI8LymFRa sXDb7b5YsH/uUSJOAQPe0ztYv2u2pMiP1222Yet+0JmuJWIiTK80SFDyiwGDLkQkXwzN EMVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=BRc8Yf2c; 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 cl3-20020a17090af68300b00246bd5445d7si4975964pjb.104.2023.04.14.10.25.17; Fri, 14 Apr 2023 10:25:32 -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=BRc8Yf2c; 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 S229839AbjDNRXm (ORCPT + 99 others); Fri, 14 Apr 2023 13:23:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjDNRXk (ORCPT ); Fri, 14 Apr 2023 13:23:40 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0959AD2D for ; Fri, 14 Apr 2023 10:23:33 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id y11-20020a17090a600b00b0024693e96b58so18264622pji.1 for ; Fri, 14 Apr 2023 10:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681493013; x=1684085013; 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=jLxzEPuRQOpnZLaEq6SfAsMRmsFnFoLhYkxVpQU9ODc=; b=BRc8Yf2ckf5lO1OvMNsi2GkZVI1sUHHIDltwlGPKACNCk2hxZYP/2q9ufEFgfGe1Or xu4A8QcOoUfxEbg2hhp7/ABNsHHUmPVfdSW6w+bSy1/eAwuabrxosHFmZprBL+3okRGB jFUBYONWr5DWLd5EzT82YnoOYRtfeVPw3ykOmYXtk59XYAa7kM2DcIJNbMnvZWrN2VsO sNpcT7ALv+c0DAvVkTbO+7v5ixjLbGDC54ch1VQiLWOKbryDhpiVBCpBpXONm36qMKDN umkVSBDGT5zvnuhKVqqetE4d0+mbpfT1lH0hjGbZvIWkAkfy4cWGt4GMiwjhyD56ljra Om0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681493013; x=1684085013; 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=jLxzEPuRQOpnZLaEq6SfAsMRmsFnFoLhYkxVpQU9ODc=; b=OEXU5wGnNKfynb7PAfEL8PisRjYl239CTLNM4bW6a7iJ9dTjd6jDdvbeOONnWZNRYv snNbizVs0gH01BDnqikmYIZOYJq55Y+AotQFs+h2yewmAFpRexCp9ne6lU8s9oCfxReF evY0Nk2vDe5d5JCDZ8ATK0pp5/gnTbHghDE/HFieqltb88xp2B5yJ+O4A+6mnmSZ/vZW 8gU1m7D8iPFn6mVITjNWZQ9BF6Dm69bsbiCfSH7e6Y6Dg5hQ0TZ+cQBaNmIXFvAgaGE/ FH1cbq8fTESXL79L8UKa4A67lqRACs6hemGFQjpNvvnTfle1YK8jSZBixpKxD3//3Jq5 z67w== X-Gm-Message-State: AAQBX9fJ/m0p9A0H8ouKTLCZiupYl+S933NZN1EdTaqxBZUgCnNSh+ZV p+JD47qhEiKT2Plsm1oPzkv5Zg== X-Received: by 2002:a05:6a20:7347:b0:ee:818a:3497 with SMTP id v7-20020a056a20734700b000ee818a3497mr1941553pzc.35.1681493013176; Fri, 14 Apr 2023 10:23:33 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id q12-20020a631f4c000000b0051b8172fa68sm370315pgm.38.2023.04.14.10.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 10:23:32 -0700 (PDT) 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 , Xin Yin Subject: [PATCH V6 4/5] cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode Date: Sat, 15 Apr 2023 01:22:38 +0800 Message-Id: <20230414172239.33743-5-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230414172239.33743-1-zhujia.zj@bytedance.com> References: <20230414172239.33743-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1763173342294359119?= X-GMAIL-MSGID: =?utf-8?q?1763173342294359119?= 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 | 14 ++++++++++++-- fs/cachefiles/internal.h | 12 ++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index aa4efcabb5e37..70caa1946207d 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -355,14 +355,24 @@ static __poll_t cachefiles_daemon_poll(struct file *file, struct poll_table_struct *poll) { struct cachefiles_cache *cache = file->private_data; + XA_STATE(xas, &cache->reqs, 0); + struct cachefiles_req *req; __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(&cache->reqs)) { + rcu_read_lock(); + xas_for_each_marked(&xas, req, ULONG_MAX, 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 Fri Apr 14 17:22:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 83540 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp546134vqo; Fri, 14 Apr 2023 10:30:13 -0700 (PDT) X-Google-Smtp-Source: AKy350aTR/ZJel1IZ7MrKpRTlDu7kn6ARpgAOuWIdL3hC4fub1/gFv5YCKJoYMe6H43pgz6zgxD5 X-Received: by 2002:a17:902:f7d3:b0:1a6:6fe3:df91 with SMTP id h19-20020a170902f7d300b001a66fe3df91mr3376978plw.50.1681493413200; Fri, 14 Apr 2023 10:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681493413; cv=none; d=google.com; s=arc-20160816; b=apJ+kvof2Gy765744esfU0h8ndvcT9pPpgSVObx2Yi0t7X0VwQ8+Q0lPzroMozrLIS qiGw9TPEx39IjJDST4hBs0sH8aOX1q96iTboGEMt43SuzVH+lXWWPlpf0JZF2II3lglb n5Etlxf0njO4gtfb7W7WK0zuTWIQxJaGTiht+h9JOXXSscLnd64g7Iu38tGqUJnh5m1x GQAxojn+7zh9N27snfw2Al9+4GBJGQn6IJvjhWoKNW0g2hgNzNK/Kw3tI2aEwn4mG4dC kdbfaM4r4zAC7RMmYa49uGTgbX3+WTkOX2bveNFRlxHT2GvZ8UKHpdkSeff0ivKvPmcg 3ezw== 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=qgUvM997QJXfBj7OoFl5jxJ2P02ysazlJ3MfSoqKoTg=; b=0YuBYtqSeFdqy1C6GjnfS2yAzYrnx2LYoK51eZX7Usr0aPTSpU5i5VWEZT8cLZoJyn Wm1iXpdWWG39xjxJUNa9tMdvx+/meHFOJCnPM8XfEQ2CH8xk0+oNwmIcs5E0xh7sSb1a F1u6wY2Igcy7xWpDcvTbiIhzOGo88vhp+T5dbCv/enVaOyEFTtkOiZjW3ey+KRpSb5T2 YSlUOtH4bS33NVUa+J17+pwmbpPqWuPLE5/euBdhwkgbXCRUxGmh7oKGSFnCSu2Nnlq1 2Jx6y3PaqmUJRmuHoaqs1mcc35Zm+/daEYsIQAA6f9S23qXQH1vDnLhM+Zo8vUgQivNO 9rCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=T3zZn09j; 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 r19-20020a170902be1300b001a1e308a820si4779462pls.624.2023.04.14.10.29.59; Fri, 14 Apr 2023 10:30:13 -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=T3zZn09j; 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 S230430AbjDNRY1 (ORCPT + 99 others); Fri, 14 Apr 2023 13:24:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbjDNRYI (ORCPT ); Fri, 14 Apr 2023 13:24:08 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BF5183D2 for ; Fri, 14 Apr 2023 10:23:37 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id o2so18964415plg.4 for ; Fri, 14 Apr 2023 10:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681493017; x=1684085017; 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=qgUvM997QJXfBj7OoFl5jxJ2P02ysazlJ3MfSoqKoTg=; b=T3zZn09jU30v3X8gm7zDVFka4YxfNrNYqbfTW7odCAvrYSgeHu3+TWK/Uex+lInrl0 ZR1SLxQQ2glTEULCFiZ8A/qnkb3MFe92XInJENc/PcgdijaRXP2jIN6X1kDLUnP++6IQ QxplK7Pa9BQFppNM64xGUztMw2VnSlZCV2zATAGfF/9q2HqmOLCVZbagxFdEGTigAVE7 RRP7UH3QmA5SfzjT8wMk+gaqYPYHMimKUVP4jk4csTXP/FrA5rfpwAOvMO2aZza7K1yL I+DdpAxZdgWcfk37FG8L7ECQ6ETodw8zhueKCA6Z7daSTQ1CBJEUdu45EQFDRCXK1SVa kMig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681493017; x=1684085017; 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=qgUvM997QJXfBj7OoFl5jxJ2P02ysazlJ3MfSoqKoTg=; b=i+Tt5l1SFhYqzoe4mnSLr4llv5hYaWBAv3SxCjBpzWDP+EG73i44JLPCQWoL/KGfer nWU8WDz3UfqnHbs0x+a4eyVlcRxmh42sBLY2bEuGmmsbjkj7hrhC+gz0gAjcrIroMCdD OHZW7XuU/KoFm1tFBfHGPKjI2BlSCCknvt0kY7o0118320mexBrW3u3mFR9VOubYSiSw KGpfg9xh3yXq2tE6Bpkl32CeZYc5XNrCKkOr7HqdAq3bMuOs6OiM9SqwvQedXY1Jm2Zc voTQ4TElAXS3UjnsUOEcX4KtiPgISmZMz/vbNIMfW64nJ6YOdA3lTl5Z+5lJsDRF1ieo EBcA== X-Gm-Message-State: AAQBX9ff7DO+ub3FGwfQG9/gKhUvOWg+ebqnXhLMVAqlSd0jkfCLbvdH pPD8CVOlcvwSOY9qqtWHszKzIQ== X-Received: by 2002:a05:6a20:8f2a:b0:ee:b24e:a40b with SMTP id b42-20020a056a208f2a00b000eeb24ea40bmr335653pzk.53.1681493017046; Fri, 14 Apr 2023 10:23:37 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id q12-20020a631f4c000000b0051b8172fa68sm370315pgm.38.2023.04.14.10.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 10:23:36 -0700 (PDT) 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 , Xin Yin Subject: [PATCH V6 5/5] cachefiles: add restore command to recover inflight ondemand read requests Date: Sat, 15 Apr 2023 01:22:39 +0800 Message-Id: <20230414172239.33743-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230414172239.33743-1-zhujia.zj@bytedance.com> References: <20230414172239.33743-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763173637316339072?= X-GMAIL-MSGID: =?utf-8?q?1763173637316339072?= 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 70caa1946207d..3f24905f40661 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;