Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp13756rwi; Thu, 13 Oct 2022 20:28:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5UgoC3kj66gf8gLBTr+BwZyAsbPYiLi0SSSqKXk7ZvTiU51UpMpyWl2bG+9Jq/dxTOqoN0 X-Received: by 2002:a17:906:8479:b0:78d:cf17:2d70 with SMTP id hx25-20020a170906847900b0078dcf172d70mr1964033ejc.319.1665718086079; Thu, 13 Oct 2022 20:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665718086; cv=none; d=google.com; s=arc-20160816; b=n9XAutTLwyMHp6R9CHrQbROqJujVc8Xxq31lh398srPSeuWQYe0VC81h8pKZOJau46 N+jSHNS33b/dz1/M0WChAHoP1pUBp9ZH4ZJrZxpBMwqi4I8eAOkeWKaRUxtej7nqkoXB neYbmi5q5N6XEaKJSWG6SbLV4OJl6SlHQDTrfGUgntbZL2u8SZMwHPakhU1QuVmlX5Qh 1j/IQkcOD5EZg5+7AV6l/dQa+oCAFMkIcgXNNmcsd5JYr6OiWCuH7r9SoEIUk+CHBK6T 4te6cZeopHaKJ8H82OpRcviaB3K77sqvM2MHSIAZ/ChUE5zwVLbjCUpNrofBX8e8PMpm AplQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=tR+LEXzrwnagFeN1X0qgpjAc8sXMoTZWp+ylsCx2Q8o=; b=K1buVitHdvKfPdbPgXlRwZemE4fwzcGdzqanZ/eK/zzy+KPRHz7YRWN1OS7GA53fmT VsYPwqTmLOWqsLuvEMulefXclcAzsbmN9GZGTLsIn7I9xd91cyWkUy9DCr68wLCrS1k9 2z2+VgeWFt87b1kAULGYs0cr/zmb9gbWpdVUW3qu/uOSIqwgFw+EmLOqWsQwC8NVAe14 0D56zWlFR4GvpDnS0tdQMnuNdr+YrIvaXYmLWhh9blSSBOyxKKzYc9JV8r5SbxZ2SR4b c5vfUn6ddPJA+0v8q+nyoH1CXZkymo0XaPhpgqYzik2DKo7O2z4HcQvPgd8fuYJj8eV4 eD2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=j7OAaYtj; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp31-20020a1709073e1f00b007877f3132d9si1412833ejc.438.2022.10.13.20.27.31; Thu, 13 Oct 2022 20:28:06 -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=j7OAaYtj; 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 S229460AbiJNDIV (ORCPT + 99 others); Thu, 13 Oct 2022 23:08:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbiJNDIT (ORCPT ); Thu, 13 Oct 2022 23:08:19 -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 B57CD18A3D5 for ; Thu, 13 Oct 2022 20:07:59 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id l4so3544764plb.8 for ; Thu, 13 Oct 2022 20:07:59 -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:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tR+LEXzrwnagFeN1X0qgpjAc8sXMoTZWp+ylsCx2Q8o=; b=j7OAaYtj4gywSty7236efJMlTd/eu1sIqqWbPt8D+9YFUIliYfpSpcCP0RVtqISuqu EUApBFrH2c13AslkzH2kxWWxVhadCyNF/XhwEb1+wO1wlOTaN9UmHTqGz6A7dGpsv7YF it1z3ccyiqrCduYkbdGYj6lFMob/8GWFUxSCLiEfqRHYmzWYMz69f2joQ1gse4CahmQo B0QilVGK3KBdC876cBFng16Xiyd/XBhGL3l+BQpBzVtwxcRpIqlzRC0RzVLV7IIzDFrN seYRGXSdBD8Bnk7v8XEuCwP6nYfyx4K0Y2PGOehom5FlQdP1PnCIfIsZ1rHUoEYjSv2F SSGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tR+LEXzrwnagFeN1X0qgpjAc8sXMoTZWp+ylsCx2Q8o=; b=BYaJbLIJfVWMk6clCez/G6Vz7DC2s/dTYw31ae7Rc7ouTuK8FTPBN+B+zQ+HrbZAGm ziqocr0NlZwFAqzF0wzUlQeFVHgcY6zb8ESZW2BIHU0aooUeD3cG/h2Ias8XK0z/9JT4 qGdsiGR9BQZOrQaej4p44NZ0yq7xiV7zAZVQUpx4FGuXC++vcmp12029h2WcaC/cGuq0 yYxGruUAUjMmHvuNY4ryGHvRYC+EcqC+PylQsC07UanByr3IXY/8MYGrpr0jBo63oCvY AUV650hpNGM6GDZImnHCuNKz16p3UOBR2zeimv2u2bDxKC0/XkWQd3I+WDPVs1cuOc30 1nbw== X-Gm-Message-State: ACrzQf2aTg7TWEs+s6ILJx8oC+ZRQDWnBTHLpg6WgFXKgLtRXUmdXcWP 8YfXqCzbcbHDHLLmuT/E31buaw== X-Received: by 2002:a17:903:2307:b0:17f:78a5:5484 with SMTP id d7-20020a170903230700b0017f78a55484mr2957038plh.15.1665716879180; Thu, 13 Oct 2022 20:07:59 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([63.216.146.183]) by smtp.gmail.com with ESMTPSA id h4-20020a17090a710400b0020ae09e9724sm425524pjk.53.2022.10.13.20.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 20:07:58 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, xiang@kernel.org, jefflexu@linux.alibaba.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, Jia Zhu Subject: [PATCH V2 0/5] Introduce daemon failover mechanism to recover from crashing Date: Fri, 14 Oct 2022 11:07:40 +0800 Message-Id: <20221014030745.25748-1-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Changes since V1: 1. Extract cachefiles_ondemand_select_req() from cachefiles_ondemand_daemon_read() to make the code more readable. 2. Fix a UAF bug reported by JeffleXu. 3. Modify some code comments. [Background] ============ In ondemand read mode, if user daemon closes anonymous fd(e.g. daemon crashes), subsequent read and inflight requests based on these fd will return -EIO. Even if above mentioned case is tolerable for some individual users, but when it happenens in real cloud service production environment, such IO errors will be passed to cloud service users and impact its working jobs. It's terrible for cloud service stability. [Design] ======== This patchset introduce three states for ondemand object: CLOSE: Object which just be allocated or closed by user daemon. OPEN: Object which related OPEN request has been processed correctly. REOPENING: Object which has been closed, and is drived to open by a read request. [Flow Path] =========== [Daemon Crash] 0. Daemon use UDS send/receive fd to keep and pass the fd reference of "/dev/cachefiles". 1. User daemon crashes -> restart and recover dev fd's reference. 2. User daemon write "restore" to device. 2.1 Reset the object's state from CLOSE to OPENING. 2.2 Init a work which reinit the object and add it to wq. (daemon can get rid of kernel space and handle that open request). 3. The user of upper filesystem won't notice that the daemon ever crashed since the inflight IO is restored and handled correctly. [Daemon Close fd] 1. User daemon closes an anonymous fd. 2. User daemon reads a READ request which the associated anonymous fd was closed and init a work which re-open the object. 3. User daemon handles above open request normally. 4. The user of upper filesystem won't notice that the daemon ever closed any fd since the closed object is re-opened and related request was handled correctly. [Test] ====== There is a testcase for above mentioned scenario. A user process read the file by fscache ondemand reading. At the same time, we kill the daemon constantly. The expected result is that the file read by user is consistent with original, and the user doesn't notice that daemon has ever been killed. https://github.com/userzj/demand-read-cachefilesd/commits/failover-test [GitWeb] ======== https://github.com/userzj/linux/tree/fscache-failover-v3 Jia Zhu (5): cachefiles: introduce object ondemand state cachefiles: extract ondemand info field from cachefiles_object cachefiles: resend an open request if the read request's object is closed cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode cachefiles: add restore command to recover inflight ondemand read requests fs/cachefiles/daemon.c | 14 +++- fs/cachefiles/interface.c | 6 ++ fs/cachefiles/internal.h | 58 +++++++++++++- fs/cachefiles/ondemand.c | 156 ++++++++++++++++++++++++++++---------- 4 files changed, 188 insertions(+), 46 deletions(-) -- 2.20.1