From patchwork Fri Oct 14 08:05:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 2566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp58236wrs; Fri, 14 Oct 2022 01:07:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7QV4QTavIppMqf0Gi1XjYxIVSpkyEvddOT+veVIYIsKnpJ1nNi0ogJJieh778aJq83iZ7H X-Received: by 2002:a17:902:b78c:b0:17a:ec9:51da with SMTP id e12-20020a170902b78c00b0017a0ec951damr4119651pls.159.1665734861693; Fri, 14 Oct 2022 01:07:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665734861; cv=none; d=google.com; s=arc-20160816; b=Velw0SowIqWg1Dv6wz2yNhMXdDRI6wja6GsddCG+eAEoNNO9S8ldJ/6V9eQG0mDG/Z NUDx5RG0w10AjogPnbIix9YJzTV0dvxyrmMNmDRA/kjIeO4MkIVVCO97iB1SU+2jnfxC tOaOg96qHFvcjWA7ypbL5G3DaKVpqq2srtOjtvEAQE7ICUZWOaN97f2Ha32E1+Jeto5T gCf4IvmWI3VmxQiciMeO8Pu9zSLHlWWnwDOQyhjSS0uBpZsYBmuO+0u14vIr/pldWQkT hCeH524sYUcLAfRLyB0q8gk7l50q7uKOLKIkltdljPvWW5OqQUolHfYSmlZoE/GV7jiE jtCw== 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=fNcrPzu+uKXnduESO+DuwK3jbFzibhJrS7INeKZTCZc=; b=MsHt2Vlq5/8KPYKyRiTtMnPNfh9OvSknQSy607VoKmnF6yvln5rDePtDN/ML/mC+wi 1Wn88q0CNB8Ly9751R76J4FqbxIioi935FglzadsQ6uXkF5JaFrG3eVpvJofE1G6bqvm I9LyCJxYok+1q3wL3Zh9vMl3fI1uCelZAwbwCmz4wmOFN7P/706kPnA97vXvA+DGZL4E ppJwFhZHXb2y4/OpavaxA+5AN3od42bUcck8sjQ9EJD/8dtkU9dY9ijVipcjGUTylOHh HZ4h1331yrBj4FQ+J8IkaQITJOozASPkgoAz1n1F1A87OZLI5fJKbUNGchtvesRJQABw J0Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=s6mTcuzx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d2-20020a654242000000b0045c19daa33esi1887665pgq.355.2022.10.14.01.07.27; Fri, 14 Oct 2022 01:07:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=s6mTcuzx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbiJNIGn (ORCPT + 99 others); Fri, 14 Oct 2022 04:06:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbiJNIGi (ORCPT ); Fri, 14 Oct 2022 04:06:38 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDA4423BFD for ; Fri, 14 Oct 2022 01:06:37 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id q1so3662689pgl.11 for ; Fri, 14 Oct 2022 01:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fNcrPzu+uKXnduESO+DuwK3jbFzibhJrS7INeKZTCZc=; b=s6mTcuzxdQgjMZE+5rWYB3WrBeBE0mZ0uh+9CoMVdSZf/Rer1uclsQsj1VpvUf88H2 I3CVtWquR0qeE0e0qpqx7LHQWmP911nP/15f3lsxYpurPX3vWxmZcm1k33VDR6u08183 nt1pDo5AACmby1uPOceFFJqqIBHeYzlibk57ZQbRC4++rn++5jkOK9Q/L/jSgBf0OVij NE9tAeBAsBxcGfjY8HF0lht0puF1ZPdyAKg7/fFSB4lfyBCV/QFinmAZBFpyNO3S8XOv WezHwXuVe259W19+ecN3fU3vSg6g7v1yGhHLecR+0KSONAMdSDeohqpnvcxtzhFVwP0C eHxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fNcrPzu+uKXnduESO+DuwK3jbFzibhJrS7INeKZTCZc=; b=Ls4wx+0iKUEsFbvymyzFTQR5Bn734dwadqIeI8XXS5BYVSHRt+7mWSvOyOx7b6xV0B xPkWoOS8kSYdXYMiPT0K27/e1d9/Q4xHVt1avdedR2t7C32Ee++1dz/YNWYnwUyOLaUW rk4Umym+i6c1ZycTCuELFJ4SAq1wPnniNEXc4xTiXufjgIX0nbPwjuzkE/YwHVZRuK9L tgfc172NEHnGR3sjsSdoHDL3fwDkjVks+8PPhIEh6oQmrNI60pgPTN4UnznzPIcA7XYO H9Bv6q98I5FghA6sINfoeu6+QQ6WZCUfl9fv/Swmp18wMHYIEg1d+7UQHbiZg+0UITXH HtDA== X-Gm-Message-State: ACrzQf0vmTarNG5z2bGI83iFPLt4JTvSa8neJAmJr4FV5Vq8Rzd5joTY tf/w1J5FeF9n/aur/wd1gxblpA== X-Received: by 2002:a63:f07:0:b0:440:5c6e:5833 with SMTP id e7-20020a630f07000000b004405c6e5833mr3564382pgl.375.1665734797311; Fri, 14 Oct 2022 01:06:37 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([63.216.146.188]) by smtp.gmail.com with ESMTPSA id ik20-20020a170902ab1400b001730a1af0fbsm1119196plb.23.2022.10.14.01.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 01:06:37 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, xiang@kernel.org, jefflexu@linux.alibaba.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, Jia Zhu Subject: [PATCH V3 1/5] cachefiles: introduce object ondemand state Date: Fri, 14 Oct 2022 16:05:55 +0800 Message-Id: <20221014080559.42108-2-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20221014080559.42108-1-zhujia.zj@bytedance.com> References: <20221014080559.42108-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746649598355936448?= X-GMAIL-MSGID: =?utf-8?q?1746649598355936448?= 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 Reviewed-by: Xin Yin Reviewed-by: Jingbo Xu --- 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 2ad58c465208..b9c76a935ecd 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) \ +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); +CACHEFILES_OBJECT_STATE_FUNCS(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 0254ed39f68c..90456b8a4b3e 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 Oct 14 08:05:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 2567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp58631wrs; Fri, 14 Oct 2022 01:08:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7t1m+MvzZOrMxWZasmkzTZTAflk86Jwysr3SLE35Lsym8DqK7x3MuVZKdNUgBwayRPcbXo X-Received: by 2002:a17:90b:3588:b0:20b:590:46a2 with SMTP id mm8-20020a17090b358800b0020b059046a2mr4410019pjb.14.1665734927515; Fri, 14 Oct 2022 01:08:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665734927; cv=none; d=google.com; s=arc-20160816; b=so44A2ECqOexHjbgVStymxkEIvjgXHId14XHALjH3uP6fMU4VhN7BhyV6twgeOQdTN /RGS0IXNiYgrMLr7MXKWaWZKvCTIx+25HRerBsOb8+eW9/xXhX8oDlD4UfGJXiYw8lML oIfxY0s3CmSNJSB49UChKaiZYPp6j5nzidYk7JrNz9EPC9PO47w6D8K5Odk4cWoZ8QiM LTSTrxGnOvrLiAAc/gLSEWorX6Hx5OvBeLsHFjduPcU1HtRdetvU5X5t1eLlHJvlisVx mrltBZM0fdSgqvrYySiMZBGv5irrmO9freWfsuayTL6oyS//C+4tfHBBBXGc/0AbV9WT CHdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BUNmB6S9jkYzZMjtNGXZtdFizVu+vOEWVlJtmuAd/sM=; b=VD9lMMtAGnSsb4J2wjpGapTD56DtlHQ1KRdwc9stbBgd4HNU51LwG03dogZx0qcaDj vCFN3N4/AagT6r8GFhEmNpA/Ui0WUM8SFWZ05J0JBFpm2hqtmDxhXOrTXs4QcB99QS+j hwQW4TZdzTH+P5AdyxCjgN5/FpAt6LAE96qaq3IYbNShj0jMRDvVfJXdSBIpf3w/qjUj jDHLUe2MGShMe491/B60yxv7OQ49A7Tdyu5R5OoFSuopfn5cPYiLKkYUhLkH2IvosoiD 4jD2Ik+HgltQu9hOrlznjPhtzkI/AScjP5OybtecEoPYZNXyGds8NggpX8ogYLegcHdk Ohow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=K1qiidBa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l6-20020a056a00140600b005618039550fsi2110940pfu.271.2022.10.14.01.08.31; Fri, 14 Oct 2022 01:08:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=K1qiidBa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230092AbiJNIGz (ORCPT + 99 others); Fri, 14 Oct 2022 04:06:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230075AbiJNIGq (ORCPT ); Fri, 14 Oct 2022 04:06:46 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EB671BF84B for ; Fri, 14 Oct 2022 01:06:41 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id c24so4084688plo.3 for ; Fri, 14 Oct 2022 01:06:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BUNmB6S9jkYzZMjtNGXZtdFizVu+vOEWVlJtmuAd/sM=; b=K1qiidBafyGVJuBIrZZf5epw6s41L5yPdv6+KQS8m67IMUDq2vow0B9ByUHGf7ZNXw zgj7P2o8VH2/T33qOjIBGnZp7LYi7JgzDJjnMQ6/voXJNuUJ1LeuFN6A4EXksf4h6EqL 9FzSX/ZkwMVBjlB76mTVqhrz4LH9BxBTjymprtDVGBOilBakxcZjwxsY0ivJ+9CuWb5T vIjEAPwWdTyUYU++vqhfYueCkxLhXrjo4ID6wb32bB87pGGiPnR2ZpTKAUAI4wv8Lxcy GO9+DvilKlGqMklov1dvWdVlAAIVlvhj6Di5vHgickhzro+mz1+4f/9Eeoya5XFDvqSn nDyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BUNmB6S9jkYzZMjtNGXZtdFizVu+vOEWVlJtmuAd/sM=; b=wI5PutZ+dkSwkBZbKjCDc8sP0hJCCrQqXtO6yNSgqYeyCTNML/9yIDJirh0CRjeLEC V6JHZm+sQ3C+9xVxgOYAntJS28Xa1A6MXpXQmlYT2CWW/+ogJvi26qFhwc8jT+WnzxZA DzlU2o6luzpopgz4M1gvAV1tkb/xZExYHBNqSm2osz21C5YEZv2Byd3GrNDwZA7OdQQG BrMQYkXgJnC8I1WMwOgK3r5XDL50zdBVzDki6Z5UpW01eKHTUrRbWQKO/Gy3qfEold6q qymhFa9GbswEPU05DTvKGR+GPX99vx0BUajUPIWfGQC4ikU4mn9Qdc4FLwwRFqat60pt MYwQ== X-Gm-Message-State: ACrzQf3DjlBzr2SxGBsPAjF1+T7iudMumTtSwy4qQPKwL2M1JtXK2KCW 3eV4YFfuSKYEczqb2OZc+sqN/g== X-Received: by 2002:a17:903:11cc:b0:178:aec1:18c3 with SMTP id q12-20020a17090311cc00b00178aec118c3mr4226294plh.91.1665734800983; Fri, 14 Oct 2022 01:06:40 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([63.216.146.188]) by smtp.gmail.com with ESMTPSA id ik20-20020a170902ab1400b001730a1af0fbsm1119196plb.23.2022.10.14.01.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 01:06:40 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, xiang@kernel.org, jefflexu@linux.alibaba.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, Jia Zhu Subject: [PATCH V3 2/5] cachefiles: extract ondemand info field from cachefiles_object Date: Fri, 14 Oct 2022 16:05:56 +0800 Message-Id: <20221014080559.42108-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20221014080559.42108-1-zhujia.zj@bytedance.com> References: <20221014080559.42108-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746649667430602536?= X-GMAIL-MSGID: =?utf-8?q?1746649667430602536?= We'll introduce a @work_struct field for @object in subsequent patches, it will enlarge the size of @object. As the result of that, this commit extracts ondemand info field from @object. Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/cachefiles/interface.c | 6 ++++++ fs/cachefiles/internal.h | 24 ++++++++++++++++++------ fs/cachefiles/ondemand.c | 28 ++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c index a69073a1d3f0..690e3e1ee661 100644 --- a/fs/cachefiles/interface.c +++ b/fs/cachefiles/interface.c @@ -31,6 +31,11 @@ struct cachefiles_object *cachefiles_alloc_object(struct fscache_cookie *cookie) if (!object) return NULL; + if (cachefiles_ondemand_init_obj_info(object, volume)) { + kmem_cache_free(cachefiles_object_jar, object); + return NULL; + } + refcount_set(&object->ref, 1); spin_lock_init(&object->lock); @@ -88,6 +93,7 @@ void cachefiles_put_object(struct cachefiles_object *object, ASSERTCMP(object->file, ==, NULL); kfree(object->d_name); + kfree(object->private); cache = object->volume->cache->cache; fscache_put_cookie(object->cookie, fscache_cookie_put_object); diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index b9c76a935ecd..beaf3a8785ce 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -49,6 +49,12 @@ enum cachefiles_object_state { CACHEFILES_ONDEMAND_OBJSTATE_open, /* Anonymous fd associated with object is available */ }; +struct cachefiles_ondemand_info { + int ondemand_id; + enum cachefiles_object_state state; + struct cachefiles_object *object; +}; + /* * Backing file state. */ @@ -65,10 +71,7 @@ struct cachefiles_object { enum cachefiles_content content_info:8; /* Info about content presence */ unsigned long flags; #define CACHEFILES_OBJECT_USING_TMPFILE 0 /* Have an unlinked tmpfile */ -#ifdef CONFIG_CACHEFILES_ONDEMAND - int ondemand_id; - enum cachefiles_object_state state; -#endif + struct cachefiles_ondemand_info *private; }; #define CACHEFILES_ONDEMAND_ID_CLOSED -1 @@ -302,17 +305,20 @@ extern void cachefiles_ondemand_clean_object(struct cachefiles_object *object); extern int cachefiles_ondemand_read(struct cachefiles_object *object, loff_t pos, size_t len); +extern int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object, + struct cachefiles_volume *volume); + #define CACHEFILES_OBJECT_STATE_FUNCS(_state) \ static inline bool \ cachefiles_ondemand_object_is_##_state(const struct cachefiles_object *object) \ { \ - return object->state == CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ + return object->private->state == CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ } \ \ static inline void \ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ { \ - object->state = CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ + object->private->state = CACHEFILES_ONDEMAND_OBJSTATE_##_state; \ } CACHEFILES_OBJECT_STATE_FUNCS(open); @@ -338,6 +344,12 @@ static inline int cachefiles_ondemand_read(struct cachefiles_object *object, { return -EOPNOTSUPP; } + +static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object, + struct cachefiles_volume *volume) +{ + return 0; +} #endif /* diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 90456b8a4b3e..6e47667c6690 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -9,12 +9,13 @@ static int cachefiles_ondemand_fd_release(struct inode *inode, { struct cachefiles_object *object = file->private_data; struct cachefiles_cache *cache = object->volume->cache; - int object_id = object->ondemand_id; + struct cachefiles_ondemand_info *info = object->private; + int object_id = info->ondemand_id; struct cachefiles_req *req; XA_STATE(xas, &cache->reqs, 0); xa_lock(&cache->reqs); - object->ondemand_id = CACHEFILES_ONDEMAND_ID_CLOSED; + info->ondemand_id = CACHEFILES_ONDEMAND_ID_CLOSED; cachefiles_ondemand_set_object_close(object); /* @@ -222,7 +223,7 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req) load = (void *)req->msg.data; load->fd = fd; req->msg.object_id = object_id; - object->ondemand_id = object_id; + object->private->ondemand_id = object_id; cachefiles_get_unbind_pincount(cache); trace_cachefiles_ondemand_open(object, &req->msg, load); @@ -368,7 +369,7 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object, if (opcode != CACHEFILES_OP_OPEN && !cachefiles_ondemand_object_is_open(object)) { - WARN_ON_ONCE(object->ondemand_id == 0); + WARN_ON_ONCE(object->private->ondemand_id == 0); xas_unlock(&xas); ret = -EIO; goto out; @@ -438,7 +439,7 @@ static int cachefiles_ondemand_init_close_req(struct cachefiles_req *req, if (!cachefiles_ondemand_object_is_open(object)) return -ENOENT; - req->msg.object_id = object->ondemand_id; + req->msg.object_id = object->private->ondemand_id; trace_cachefiles_ondemand_close(object, &req->msg); return 0; } @@ -454,7 +455,7 @@ static int cachefiles_ondemand_init_read_req(struct cachefiles_req *req, struct cachefiles_object *object = req->object; struct cachefiles_read *load = (void *)req->msg.data; struct cachefiles_read_ctx *read_ctx = private; - int object_id = object->ondemand_id; + int object_id = object->private->ondemand_id; /* Stop enqueuing requests when daemon has closed anon_fd. */ if (!cachefiles_ondemand_object_is_open(object)) { @@ -500,6 +501,21 @@ void cachefiles_ondemand_clean_object(struct cachefiles_object *object) cachefiles_ondemand_init_close_req, NULL); } +int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object, + struct cachefiles_volume *volume) +{ + if (!cachefiles_in_ondemand_mode(volume->cache)) + return 0; + + object->private = kzalloc(sizeof(struct cachefiles_ondemand_info), + GFP_KERNEL); + if (!object->private) + return -ENOMEM; + + object->private->object = object; + return 0; +} + int cachefiles_ondemand_read(struct cachefiles_object *object, loff_t pos, size_t len) { From patchwork Fri Oct 14 08:05:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 2568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp58632wrs; Fri, 14 Oct 2022 01:08:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4yCVSBkS0wXxFSP6c6VStnOOHNANvS4qKGvaiKPhPEVTL564GFWVW3Z1wzQgBa+NTw6dzc X-Received: by 2002:a17:902:9005:b0:181:898b:646d with SMTP id a5-20020a170902900500b00181898b646dmr4144923plp.97.1665734927513; Fri, 14 Oct 2022 01:08:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665734927; cv=none; d=google.com; s=arc-20160816; b=ecCTZ58AGffS++8uxywCnSUWiHuv0KZU/HMi1wI3GGIEp7WWN/UhRL2bwT2At61yDc tgkSAjPaGcdUI0smklo54kQp+3jFT/pcaNn7eoBbYMH8uO2jM61mSvPOZojF2JOF1no/ DZWjneC7UEJrGQH/h6Er3zeo8Zt8sEF0DCsgl2JQ3cZE7RsDdtMrOf1Mz6sastD3o4Ej x6LD3VX0giLAfZhpDkM9NJavbVqIhvYlsQuBbZQUqvy3jbccKFflzQfgaxeSyOfJnidd CvewfvvNv5l/gxNgueurqLQP9Kv9cuUNShH49nCeK/kt/5W62Q356VNL67Vqm6cGUMcx kdlA== 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=HGVULqlnaPjYkF0USjRnqm7ODLg1ZE1u+sEwjtklJtE=; b=MoYgLUvuNKRj9zJe8I0x19YDulbwhFIAYyggTKz4f24e2829tFsyrnkvPjfhapX9h+ cMitmjS+vtuNF/jY/YrcBuL4azv1ltu808z9/DylrUZnCfg/XB9RQsPOmgiyhvHmtdVO gdK5QGxXOI6P8rVjVp7PtMEOMkI78Gs+q/jzmLZy2XHjkuxCu9WdEikXdINFMosm7s/J t3Tv4AlCv5uvGx089MJhVihSQvmLZW/LpUl7w6KF4nIemK5SKqSgvfgVuOouy2rWRAXd 4c9+2vQai1XXmX8EEOiRQqzSz9TYs5EO9OH4DXfwG67Fe319w/1HCmhYmZH+7kwDRzhc uNhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=ZnaHc80F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pa10-20020a17090b264a00b001f06a6fdb2fsi7404411pjb.27.2022.10.14.01.08.32; Fri, 14 Oct 2022 01:08:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=ZnaHc80F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230130AbiJNIHJ (ORCPT + 99 others); Fri, 14 Oct 2022 04:07:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbiJNIGy (ORCPT ); Fri, 14 Oct 2022 04:06:54 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C2041BE1CA for ; Fri, 14 Oct 2022 01:06:45 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id i3so4206528pfc.11 for ; Fri, 14 Oct 2022 01:06:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HGVULqlnaPjYkF0USjRnqm7ODLg1ZE1u+sEwjtklJtE=; b=ZnaHc80F0z74ccZGbRte282qVkE7AVhNLGE7GTpp/5BKYUmhGsjOZVollPs0yJH3kX MbijmBqRRRmOB4inoSVzXydRct/bJQmTjjVR6SSNbFjvjpuWlA6j2ituZ3XZ9f/xikUD ymsrksLwFpheMq+rkEq063Oc3kw4iB0nGfNzG+v74DfIG4kGZxfn9AWF2HvY0wY+HQCy 10M18tPXRRT4e1QyCx4zIStN3MEs21JhKFszyYolXjZRDFCZWlWsbNY/C1UO5BI/vp8h 3nauLISt3vaR8T7ZH0gg7pwnhXojsdh3KHrJjQaxT8u5RYnf4rOsAoagPRGfJ2vQc261 6FcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HGVULqlnaPjYkF0USjRnqm7ODLg1ZE1u+sEwjtklJtE=; b=1HQMdhupE0fMvTSmqTfD3uGa1O85W2rseETGNavybQVKvZSnJE/vb0MiAR0mwTzvuo 52NzfsugBtsRsKoVRntbYyRZumfou1zyzvGwBMEONaUU62DcPJKmSpRQ0km1Dit1DEjP BX+Q7yS15Ho6TECL2JEhTgeZ4+iYHiePb+qop47wmXsOVDaUP0YHUIrb0/nn1JHA7kpk EtyQ+NTBvZS3oKQXm1qVPUkYlySd7fOhVZU/zvJ8BqJDIDyVDEDjcJYgMWEENQuFMAGk wgX4jbZI6F8nfaOboNFYIw7Yn8PDJZli0QDYRPHxLDyeK+F7BbRdMWzEiT6HO0DkoDDk 6L5w== X-Gm-Message-State: ACrzQf2RNV1k2UoTwHS/rIDp5NqstAzuyWfTkug8lTQAYd5YeccHU4cs 71l6Rb1HwCw/YaSr6RTmN+axyw== X-Received: by 2002:a05:6a00:1809:b0:565:adc8:a5c4 with SMTP id y9-20020a056a00180900b00565adc8a5c4mr3929879pfa.65.1665734804458; Fri, 14 Oct 2022 01:06:44 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([63.216.146.188]) by smtp.gmail.com with ESMTPSA id ik20-20020a170902ab1400b001730a1af0fbsm1119196plb.23.2022.10.14.01.06.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 01:06:44 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, xiang@kernel.org, jefflexu@linux.alibaba.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, Jia Zhu Subject: [PATCH V3 3/5] cachefiles: resend an open request if the read request's object is closed Date: Fri, 14 Oct 2022 16:05:57 +0800 Message-Id: <20221014080559.42108-4-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20221014080559.42108-1-zhujia.zj@bytedance.com> References: <20221014080559.42108-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746649667373752975?= X-GMAIL-MSGID: =?utf-8?q?1746649667373752975?= 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 Reviewed-by: Xin Yin Reviewed-by: Jingbo Xu --- fs/cachefiles/internal.h | 3 ++ fs/cachefiles/ondemand.c | 96 ++++++++++++++++++++++++++++------------ 2 files changed, 70 insertions(+), 29 deletions(-) diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index beaf3a8785ce..2ed836d4169e 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 work; int ondemand_id; enum cachefiles_object_state state; struct cachefiles_object *object; @@ -323,6 +325,7 @@ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ CACHEFILES_OBJECT_STATE_FUNCS(open); CACHEFILES_OBJECT_STATE_FUNCS(close); +CACHEFILES_OBJECT_STATE_FUNCS(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 6e47667c6690..d8dce55d907c 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->private->ondemand_id = object_id; cachefiles_get_unbind_pincount(cache); @@ -238,6 +234,41 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req) return ret; } +static void ondemand_object_worker(struct work_struct *work) +{ + struct cachefiles_object *object = + ((struct cachefiles_ondemand_info *)work)->object; + + cachefiles_ondemand_init_object(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_ondemand_info *info; + + xas_for_each_marked(xas, req, xa_max, CACHEFILES_REQ_NEW) { + if (req->msg.opcode != CACHEFILES_OP_READ) + return req; + info = req->object->private; + if (info->state == CACHEFILES_ONDEMAND_OBJSTATE_close) { + cachefiles_ondemand_set_object_reopening(req->object); + queue_work(fscache_wq, &info->work); + continue; + } else if (info->state == CACHEFILES_ONDEMAND_OBJSTATE_reopening) { + continue; + } + return req; + } + return NULL; +} + ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, char __user *_buffer, size_t buflen) { @@ -248,16 +279,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 +308,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->private->ondemand_id; + if (copy_to_user(_buffer, msg, n) != 0) { ret = -EFAULT; goto err_put_fd; @@ -317,19 +352,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 +406,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->private->ondemand_id == 0); xas_unlock(&xas); @@ -392,7 +431,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(req->object); kfree(req); return ret; } @@ -439,7 +486,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->private->ondemand_id; trace_cachefiles_ondemand_close(object, &req->msg); return 0; } @@ -455,16 +501,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->private->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 +550,7 @@ int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object, return -ENOMEM; object->private->object = object; + INIT_WORK(&object->private->work, ondemand_object_worker); return 0; } From patchwork Fri Oct 14 08:05:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 2569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp62204wrs; Fri, 14 Oct 2022 01:20:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6dRno4y1/QLnlJyVEKTVUn1JWT868WhLrcqgNS2u1FxQBqWd1m02WX63Z51ghbcf+xZzU8 X-Received: by 2002:a50:fd16:0:b0:458:bf43:8dc7 with SMTP id i22-20020a50fd16000000b00458bf438dc7mr3267554eds.400.1665735626638; Fri, 14 Oct 2022 01:20:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665735626; cv=none; d=google.com; s=arc-20160816; b=XzCNfPVpejE/xZnw7YEjBYTGCNYAaHjd39qjKWHiycVvnDP19SdCriRyqJ5tFKaiRA 94NZATslc4T+wJrXLqNhtJ8nhhltwh5qzUTucRulBXpaIv+91cf4IE5LsYhdRotlekbn 18DpIIneDxm65LPEG6eDbHQJ0ulCKEF2HW3tsoVv04bGNfsTetofPctPwZWaVmRevO1w OjCBDqsLYNIwryOr8206wCknI8sXyzQZxINUTyCjsCbZY/HY4bWnc5nD35v0RLmcY1s4 KgiTFBn/Wj5t3Oodlh9G3mt2lfIeCYkrHOkbHiKnCJbaD5Au8i+Z6OUFdHtMaxthEg5G A+/g== 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=8u8C9HdOyOb3+ICBwFZcrFBPJwehJIZsy+qDOHaF19g=; b=uvJ9Tk6cGfghf7aizGpPRmJM7dXluxel//cYRFJE4U0QShsgagvErXPDg5vJkqRMIg HfqymKT8qHqVsAliF0JOFMAeTZWxICuV+106xwAYl7I8+eeYNnSPG0yO2oYIB2ihby2i xeBmTfm4sRPpWl+BgLGlImqSpm4y5zMZKcTfwn/Lxi0ZQ34EHjBrk9sXxOkFZTeRB0Sy nwz50l0S+fIGXtu1oX5o6ZfQXaolNI2h4sfYJesAk0E55p+nqQ3aeYfUrjPjnzPIXX51 4j5Ncf+atLvCMdK6CqdTSiigkjvjKcVu2gUpplMh8cE2AEQ5xVYLYarKI+lTn/G8QS8D v97w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="PR9/JKqA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a170906644f00b00771d781fb88si1596577ejn.411.2022.10.14.01.19.52; Fri, 14 Oct 2022 01:20:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="PR9/JKqA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230057AbiJNIHN (ORCPT + 99 others); Fri, 14 Oct 2022 04:07:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbiJNIGz (ORCPT ); Fri, 14 Oct 2022 04:06:55 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B21B1BE1DA for ; Fri, 14 Oct 2022 01:06:48 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id h10so4083954plb.2 for ; Fri, 14 Oct 2022 01:06:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8u8C9HdOyOb3+ICBwFZcrFBPJwehJIZsy+qDOHaF19g=; b=PR9/JKqA3+BUVhsO9JjYtGBtjxZi6CZawKro8WxV/0VxazHeT12xhp3alzz7CcN/vE knyqS/WNxyrwZ6WBVJAhIOGy9XpFWo15nnMqQIk+/acXb3/SeYy3QFly9jhTjQOCvZBD SlbDyFfwjhZXE+zZSEH/q2Hf4WKMDv5IjHBtWoEuCCknzdNmLXSo6UsSxXjZFPGZJKkE AxUZ7JRU6rdZfWzIANN+B2LEGuvx/jQwto7FKT6WeAS3QrHTepOUv9ljgAgYHp8dSWKj dnVcqoV8pNmlCvHlbhqmFcxn1Bymi7WwZKpYyCpjgghgVkGolVB/ntojWYCZVCd6+h7B lFmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8u8C9HdOyOb3+ICBwFZcrFBPJwehJIZsy+qDOHaF19g=; b=dQswAExKxzGu4kXWZPX4oxvDYdLqH5h+gIJ65BcqDOkHQQLb7YjwWXDXZ2cDRhxWpv LC+GMMLPDNqieA0R17QT+9G2CYa9TdK9NG0ZcZPm7WL18OoIxmA8y5M+7gmkLs0HzhNg T2s8xQkAFn2yAe+yEQ3RyAbKPzeZKCkIHpe40FrBCfbUqyn2Y+iw00NLe1g9nGpFQIha TKiknU3+jcb+z993yGFcaEiMpNniMzhmkuyTRresvJplT7Z2Rd1OMOTc8RZSeWA9xGld F2bv0F7bjK2kX6BG/DnBC6rOWhU9TWxtPLEPMdLwhPKdXdA5gqDNbuxMjN4fTrswpXHN voeA== X-Gm-Message-State: ACrzQf3U+02a9dblR8eajTZTvUBQp2vGIp5UQnAYAfjJoNNOnOVXi8Ik 6fI4YCRWghEzeAnksAqiOuugPw== X-Received: by 2002:a17:902:b901:b0:184:5b9a:24f0 with SMTP id bf1-20020a170902b90100b001845b9a24f0mr4142759plb.17.1665734807934; Fri, 14 Oct 2022 01:06:47 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([63.216.146.188]) by smtp.gmail.com with ESMTPSA id ik20-20020a170902ab1400b001730a1af0fbsm1119196plb.23.2022.10.14.01.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 01:06:47 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, xiang@kernel.org, jefflexu@linux.alibaba.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, Jia Zhu Subject: [PATCH V3 4/5] cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode Date: Fri, 14 Oct 2022 16:05:58 +0800 Message-Id: <20221014080559.42108-5-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20221014080559.42108-1-zhujia.zj@bytedance.com> References: <20221014080559.42108-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746650400203000437?= X-GMAIL-MSGID: =?utf-8?q?1746650400203000437?= Don't trigger EPOLLIN when there are only reopening read requests in xarray. Suggested-by: Xin Yin Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/cachefiles/daemon.c | 13 +++++++++++-- fs/cachefiles/internal.h | 12 ++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index aa4efcabb5e3..c74bd1f4ecf5 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -355,14 +355,23 @@ 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)) { + xa_for_each_marked(xa, index, req, CACHEFILES_REQ_NEW) { + if (!cachefiles_ondemand_is_reopening_read(req)) { + mask |= EPOLLIN; + break; + } + } + } } else { if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags)) mask |= EPOLLIN; diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 2ed836d4169e..3d94990a8b38 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -326,6 +326,13 @@ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ CACHEFILES_OBJECT_STATE_FUNCS(open); CACHEFILES_OBJECT_STATE_FUNCS(close); CACHEFILES_OBJECT_STATE_FUNCS(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) @@ -353,6 +360,11 @@ static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_object *ob { return 0; } + +static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req) +{ + return false; +} #endif /* From patchwork Fri Oct 14 08:05:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 2573 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp63827wrs; Fri, 14 Oct 2022 01:25:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM46j3Ob/E5IC8Y0qPv7HJYvTo0Gc3sRXX9C4XfEoaKFx7hmMRfy3jT13hnQEN/2ZUBKl9Yy X-Received: by 2002:a17:907:2da6:b0:78d:3cf1:9132 with SMTP id gt38-20020a1709072da600b0078d3cf19132mr2710579ejc.299.1665735929463; Fri, 14 Oct 2022 01:25:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665735929; cv=none; d=google.com; s=arc-20160816; b=fPoFzdH08XMj0rT95ByFOifeaLRwOZDYXP3b7zxFJuRaOjNnVgyOleKkFghwKUlj8b +gnujXDZLFbCj0p+JPgWS7xaTZEe2yv+GDXLWGq5MwY7AfGST02OAuv7malVZVIau3Mo tEAcq7k9dn30kNoFXqp6+/j+kH+PGpp4R2rt7e3yww2aMy+noC3Ma8f9uLY5XDSP71Di QqbxbtsEXx14Meoq6vzp+xEno9EflPyuj5XMPcZqfZSirJ/b5S/rx27ok0GaatPsZucP HV37NhdQfpWw2ttJawiVBmev5xZeOfE2cY3w7fvpq35Z3gTyF0jdybDw9Khv2JVgd2+M nWjQ== 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=mJhr9GEso5XW6jomGaYhGKFuz4nHt5uQZJthz4evrwY=; b=y4rovHjYTYbZmFMduQcL7d79lblUNLHrz6Y0uS3S69iVq2uRVsKuVzbbpx0s1C7p9P GlVs+/88qiL+Yl4tdxSGcwMMGa13BehCqJp6T1QkmqSowzbE2AmsJ1cTngqTMpxzLJ+C hGHigaitWR8uQ4PrKHsmwQbrMHaOsWlCmjGH/b4CiM41vc/s+4B3mYzoisCI0rPxP6W9 mUL3FP1jGorWDybFCZZAQA4QXjklnDYycT0Ov/BP1DMi1wl+k7eb7YPfAwM2LNhg6MQO cHt+wzLxe6yzPUQdZL6XSPm/rISDodL9iTZyTEs8X3uz2R78rtkZjjCZHld8IfZzOPAF 4QSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=qVTtmipa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd10-20020a170907968a00b0078d8c03a5a6si2143439ejc.759.2022.10.14.01.25.04; Fri, 14 Oct 2022 01:25:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=qVTtmipa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230058AbiJNIHZ (ORCPT + 99 others); Fri, 14 Oct 2022 04:07:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230113AbiJNIHH (ORCPT ); Fri, 14 Oct 2022 04:07:07 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E6931BE1FE for ; Fri, 14 Oct 2022 01:06:53 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id m6so4273064pfb.0 for ; Fri, 14 Oct 2022 01:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mJhr9GEso5XW6jomGaYhGKFuz4nHt5uQZJthz4evrwY=; b=qVTtmipam3rM6KfQlKjS9oB81qvNT4EbK05pZ/u8KhqTeMxi1fgQuugD0vIdferh4A YbPU1ZdtYPR/ZPK5WVwhOLx0PTxgdovGreGSp3BwRvbk/eVN1SZMEkZTSXOGevy3iugB AogReglRz/ngZipTLIK2lRwUlzQ7E6noznmewO+dUqWDsZMVyqKhugFDig/QBvybFt8t Vsx7w7v2uUUB5MSDzYmRU6/oD4TB2PLfO4YaDpnr5j9n7LFnLE8L91zITpD9smh490eb 0/OSLFJHUGkje4f/2tYzx91hXBA5zHhogkFUEypk+BKxWcCeQ66erKddmZAiYYVM9FTE hyHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mJhr9GEso5XW6jomGaYhGKFuz4nHt5uQZJthz4evrwY=; b=va9eDGHIkjBjM3EqwwyQdW8Y3KyBsQhi4FAVhZvBADGq8/ij0ri6VQ5ELIoC4CBeim rrNl9uJIUG/ErT25p450TSlVStnzNOfxJkV8sAPo2gFMGNyJ7BiRMZXWlYW6d7u4lC29 t7FRqaYO8S8ly4Rz/pztTPPgD8+BrVD6Oztbk5p4Tvtz4BLdhh42UgWwGoaYq4TUbOJq +X3HCWbei/TCqWJK8SlXIvOzAsBR8keuHiCXbnUvBHYRmQq61KhvKXPyVSSV2z2R9o6U 67mWADUBnUhlQU7anfafECpJaBDULB4VUQp0nL+s6OVjUEfyic74EX5WtJ4wVv/c/6z7 sOGw== X-Gm-Message-State: ACrzQf3U8SYEQi/5ey/b9iD2ppyZvFIktauuMXyFi2DTVnWZfVSfJX+I cnQs11WjOEYF2QlGWk2Ji4JkMg== X-Received: by 2002:a05:6a00:1a0e:b0:547:1cf9:40e8 with SMTP id g14-20020a056a001a0e00b005471cf940e8mr3894976pfv.82.1665734811751; Fri, 14 Oct 2022 01:06:51 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([63.216.146.188]) by smtp.gmail.com with ESMTPSA id ik20-20020a170902ab1400b001730a1af0fbsm1119196plb.23.2022.10.14.01.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 01:06:51 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, xiang@kernel.org, jefflexu@linux.alibaba.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, Jia Zhu , Gao Xiang Subject: [PATCH V3 5/5] cachefiles: add restore command to recover inflight ondemand read requests Date: Fri, 14 Oct 2022 16:05:59 +0800 Message-Id: <20221014080559.42108-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20221014080559.42108-1-zhujia.zj@bytedance.com> References: <20221014080559.42108-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746650717945299936?= X-GMAIL-MSGID: =?utf-8?q?1746650717945299936?= 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 c74bd1f4ecf5..014369266cb2 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 3d94990a8b38..e1f8bd47a315 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -301,6 +301,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 d8dce55d907c..c773ea940cc1 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;