Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp674838rwe; Fri, 14 Apr 2023 08:16:27 -0700 (PDT) X-Google-Smtp-Source: AKy350Y31qoJpVPk+4POOYPJk3GxMW3GVOht6/1wDonAljwwTtrnx3h+0VKI2SZaCxa23rzpeYJv X-Received: by 2002:a05:6a20:3ca5:b0:ee:4618:2df5 with SMTP id b37-20020a056a203ca500b000ee46182df5mr2697899pzj.4.1681485387350; Fri, 14 Apr 2023 08:16:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681485387; cv=none; d=google.com; s=arc-20160816; b=bDrbM5s6SluPyGh14ZlF0rpYPR7BqCuBhXCWa1sGoVJEwlbrqUbi9OYa3rD9CgAYtT xZ7lfd0pi0zaEE629MWQCelsjQiRSRXqkaUMPWsovV0wbhbH14g6URw2c7ZLwws1RhwE Vyw3OFNvLKsNIYslZSM1GjYYMm4OMa0rYLcMI9m7ytfLD3rtfXst8wLIGCX65991VysW Hn9wsjR8dZPwSXENBiet7JQiCxloR6gJ47YzrUf1THWr/w2PcDayD2/Ngh9R0mxgQX+m 7QrATYj18eImFvDhkEeBsfSgnZhEWNEzpDiDX9lJ5qap2RnKx6c647xugOaN5adzF0bM 4q8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=7E15TZKBUj7LhKJ72c7EvYGt3lCtMNYU30GwoWvGVWc=; b=F1egjebRLw9W8b7MvwGd4TKS2UqI+0ZjXdMWJMHg7oY9thFo5gQkgkrW5ywHQRtkh/ fbQZHKe4fFRcr13GJr09zRV2Kfz7OnRicedMCE3oNRLcwuHf8rZnhIwKehh/R4h4IIYV kSchA/hrR671rXTukDB5pa85Mw+Q4G1guMXAVp/o1tpsv3Xn7y5saX8GpHNGtVziza/g 0VbdbVcqSeAvRiqQWwsg7J08JeOx9ep+Fxo9PdA7v8A3M+3lC0OXWNs5Si/AWfN3AYiw 6yvb4zMlMYP7Rifyy9AYFxiKfObKGH2t8d30FdC7Y03C5ry89tTtmcTiAyJFQkPBu62u ld2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=SwfEYPmd; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k189-20020a6384c6000000b0051913578d67si5079706pgd.737.2023.04.14.08.16.12; Fri, 14 Apr 2023 08:16:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=SwfEYPmd; 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 S229874AbjDNPNv (ORCPT + 99 others); Fri, 14 Apr 2023 11:13:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbjDNPNs (ORCPT ); Fri, 14 Apr 2023 11:13:48 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8537A5CE for ; Fri, 14 Apr 2023 08:13:01 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1a69f686345so1574745ad.2 for ; Fri, 14 Apr 2023 08:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681485181; x=1684077181; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=7E15TZKBUj7LhKJ72c7EvYGt3lCtMNYU30GwoWvGVWc=; b=SwfEYPmd8IRm9u4LIVjSicWRhIutWoRBZqFRWlvcMNDlssOMFULhbOGPAqWwmiVri5 CmWC5762Km5wIjFXpzI6QjxUGpWMfxzcUPdOgnfdExMTlDRL3aXRXr9rEK0AD5peGYzY GLvGqSGHGLfUzRYt/7RNrnu0Lv1LMvCvDeOY6Mu5NiKjHGFY64g9YsEiw6tFaV5ICZtA HYN+Foop8qrpcko+chagArltME3j6R+/RxbkwDGEPuJGc0uBEWS6l86SOH1D9RBlWo8h kaTtkJT4CIqZM9O2sbyqYdeegGdZCAAe5SiJswLnWn37HhjAZ9zVVeb9gbN9mowhBmoF ttXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681485181; x=1684077181; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=7E15TZKBUj7LhKJ72c7EvYGt3lCtMNYU30GwoWvGVWc=; b=FH6GZToyXFir+vXnAlduXQPqH+YG8DWxJlnVc2csHJJ3on1mPYI+5ImI+jA2PEFVmz Mus1YYp9A0uFxPA2wgygsyYQR1dCUk4tksQIdUxrx9j63Pult6HM002ym8ugX++4C/HB nPWI0swvSWkR2JVsnMmtt0PgxJTdrfNyovTAbPkwWzcplro6xUwsxoeDX9Z/Hkd/5Ojq QVBgLR0XXkIaY2lsGfuXcsnDUdWy8Q17q2TPU3VZ34iMJtk6qDHPDL6UJLXJr57+7vZH vJyBKjSqkeq645JpnDdYq4JcMHs5qPCnEueTaEtKsrtue2U1qdynMaCfrj0a/RgQ7wfZ egOA== X-Gm-Message-State: AAQBX9chUakPXauAifrP/OBzpLP427pz/nEECGUwvdJQu2fe2um86S/W iQhbJFHPvoq6siqNAUL4i/Lo9UMjUJmYi7QtnHlY/A== X-Received: by 2002:a05:6a00:2e1d:b0:636:ea6c:68d8 with SMTP id fc29-20020a056a002e1d00b00636ea6c68d8mr8600263pfb.27.1681485181079; Fri, 14 Apr 2023 08:13:01 -0700 (PDT) Received: from [10.255.185.5] ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id 5-20020aa79105000000b0063b1bb2e0a7sm3129352pfh.203.2023.04.14.08.12.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 Apr 2023 08:13:00 -0700 (PDT) Message-ID: <65f424ca-d7cd-f53b-cefc-684ec0393bce@bytedance.com> Date: Fri, 14 Apr 2023 23:12:55 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: Re: [PATCH V5 5/5] cachefiles: add restore command to recover inflight ondemand read requests To: David Howells Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, jefflexu@linux.alibaba.com, hsiangkao@linux.alibaba.com, yinxin.x@bytedance.com, zhujia.zj@bytedance.com References: <20230329140155.53272-6-zhujia.zj@bytedance.com> <20230329140155.53272-1-zhujia.zj@bytedance.com> <1250439.1681480404@warthog.procyon.org.uk> From: Jia Zhu In-Reply-To: <1250439.1681480404@warthog.procyon.org.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 在 2023/4/14 21:53, David Howells 写道: > Jia Zhu wrote: > >> +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; >> +} > > Should there be a check to see if this is needed? > > David I've considered whether to add a check here, since the user could invoke 'restore' through ioctl at any time. If 'restore' is called without user daemon crashing. Then the req being processed by the user daemon will be reset to CACHEFILES_REQ_NEW and could be re-read and processed by the user daemon. For OPEN req: The user daemon will ignore this repeated req since the related anonymous fd is the same. For READ req: The user daemon will read the same part of the data again and write it to fscache (this will not cause any error) For CLOSE req: Actually the user daemon will close this anonymous fd, but fortunately [PATCH 3/5] could handle this case by reopening it automatically. Thus "restore" could be called at any time without error, checks might introduce extra race conditions. Jia >