From patchwork Mon Oct 30 21:46:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Lyle X-Patchwork-Id: 10033303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ABA626039A for ; Mon, 30 Oct 2017 21:47:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D35328945 for ; Mon, 30 Oct 2017 21:47:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 917EC28949; Mon, 30 Oct 2017 21:47:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB75428945 for ; Mon, 30 Oct 2017 21:46:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932695AbdJ3Vq5 (ORCPT ); Mon, 30 Oct 2017 17:46:57 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:53856 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932353AbdJ3Vq4 (ORCPT ); Mon, 30 Oct 2017 17:46:56 -0400 Received: by mail-pg0-f67.google.com with SMTP id s2so12789022pge.10 for ; Mon, 30 Oct 2017 14:46:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lyle-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QmjB1x3ZJCgljKp5pgRypRDYGRZ7LHGJX0u3dy+7U4U=; b=NORzdcLlvMjAxLZ5iaPeQ6TJXsSwQ19snyIw6i+SziAHx5H+tSDtB6fb6QxUihXEHW 18eylLWD8xtF3y2fhiqFLoqZzG9XJGxHpoLbbFtL8scHOdI3hoXWYLXWLBQin50BkoF9 Hd1ixwC3Bxa7iv74t1vd5qZzQ24Ih5Km8FE4xabJ8vpwYCf0cIKfraxVMoCHT/c8gnxg X71v3nAwibY0iStyeS/G7O7S/ECxM81mDpujAyxeiiZcXbDzNzxVXoDDq1wTKOzpcuKQ TZ+5FI0+0Pn0MPjWo1rscEjGF++PUsM5zq3J0ANXCZbjzlR/3wrf3RFZeu2czXryy/wh +WiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QmjB1x3ZJCgljKp5pgRypRDYGRZ7LHGJX0u3dy+7U4U=; b=jV8HZ6OOKspEWjslJOMdZ4MSq99ln9BKW2Ak/3Wo/47myw/qSkrjetJB+FtwEn+FUh rFx3VS72Se2DeXQtPv82JJG3cgimEey1JF9eXi00ufK19b7qxHnidBcrrSZhnXTKF+Qp bX8ULILoaHe/e72vI3rHvhQYt4EGSOxp9407Ac/zmBmF27YokQCkdFkdTewQjbPsrUWK amgd4eVVIvFuGkSuTlW4tK6yOtEqVdbzCZDJgtD8XlMdMtdpMPMKOmjfRS0wABrsSo15 amktnBPFvRV21K7WWus38XfDL+cl65mO7hBIOWIRMcKv5NEXthqUO8Tf0uDqn6hQLD89 hVcQ== X-Gm-Message-State: AMCzsaX+vl+hkkpO/X/gLtbjpkAy0Q/EzaCfyl3gcpMNISz532gnYKNd WhOMjVL7NlFwAW3Ziw3ENVzH6w== X-Google-Smtp-Source: ABhQp+TIJXm5Z5iy8ch7YHgyeCD9Yf5+e9a04YtuRCX806zpZwNknHcX6TbH3ZkC91tNbk/C349RwA== X-Received: by 10.84.224.65 with SMTP id a1mr8407606plt.421.1509400015627; Mon, 30 Oct 2017 14:46:55 -0700 (PDT) Received: from localhost.localdomain (68-189-67-104.dhcp.prtv.ca.charter.com. [68.189.67.104]) by smtp.gmail.com with ESMTPSA id t78sm23733329pgb.93.2017.10.30.14.46.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Oct 2017 14:46:54 -0700 (PDT) From: Michael Lyle To: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org Cc: axboe@fb.com, Coly Li , Michael Lyle , Kent Overstreet , Nix , Kai Krakow , Eric Wheeler , Junhui Tang , stable@vger.kernel.org Subject: [PATCH 1/5] bcache: only permit to recovery read error when cache device is clean Date: Mon, 30 Oct 2017 14:46:31 -0700 Message-Id: <20171030214635.29888-2-mlyle@lyle.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171030214635.29888-1-mlyle@lyle.org> References: <20171030214635.29888-1-mlyle@lyle.org> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Coly Li When bcache does read I/Os, for example in writeback or writethrough mode, if a read request on cache device is failed, bcache will try to recovery the request by reading from cached device. If the data on cached device is not synced with cache device, then requester will get a stale data. For critical storage system like database, providing stale data from recovery may result an application level data corruption, which is unacceptible. With this patch, for a failed read request in writeback or writethrough mode, recovery a recoverable read request only happens when cache device is clean. That is to say, all data on cached device is up to update. For other cache modes in bcache, read request will never hit cached_dev_read_error(), they don't need this patch. Please note, because cache mode can be switched arbitrarily in run time, a writethrough mode might be switched from a writeback mode. Therefore checking dc->has_data in writethrough mode still makes sense. Changelog: V4: Fix parens error pointed by Michael Lyle. v3: By response from Kent Oversteet, he thinks recovering stale data is a bug to fix, and option to permit it is unnecessary. So this version the sysfs file is removed. v2: rename sysfs entry from allow_stale_data_on_failure to allow_stale_data_on_failure, and fix the confusing commit log. v1: initial patch posted. [small change to patch comment spelling by mlyle] Signed-off-by: Coly Li Signed-off-by: Michael Lyle Reported-by: Arne Wolf Reviewed-by: Michael Lyle Cc: Kent Overstreet Cc: Nix Cc: Kai Krakow Cc: Eric Wheeler Cc: Junhui Tang Cc: stable@vger.kernel.org --- drivers/md/bcache/request.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c index 163a17a80874..886e4b6643f1 100644 --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c @@ -705,8 +705,16 @@ static void cached_dev_read_error(struct closure *cl) { struct search *s = container_of(cl, struct search, cl); struct bio *bio = &s->bio.bio; + struct cached_dev *dc = container_of(s->d, struct cached_dev, disk); - if (s->recoverable) { + /* + * If cache device is dirty (dc->has_dirty is non-zero), then + * recovery a failed read request from cached device may get a + * stale data back. So read failure recovery is only permitted + * when cache device is clean. + */ + if (s->recoverable && + (dc && !atomic_read(&dc->has_dirty))) { /* Retry from the backing device: */ trace_bcache_read_retry(s->orig_bio);