From patchwork Mon Jul 10 11:18:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 9832785 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 41B7F60350 for ; Mon, 10 Jul 2017 11:18:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35BF7283C3 for ; Mon, 10 Jul 2017 11:18:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AB1A283C4; Mon, 10 Jul 2017 11:18:43 +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,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 65BB728421 for ; Mon, 10 Jul 2017 11:18:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753817AbdGJLSl (ORCPT ); Mon, 10 Jul 2017 07:18:41 -0400 Received: from mx2.suse.de ([195.135.220.15]:39868 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753819AbdGJLSl (ORCPT ); Mon, 10 Jul 2017 07:18:41 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 86EA5AABA; Mon, 10 Jul 2017 11:18:34 +0000 (UTC) From: Coly Li To: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org Cc: Coly Li Subject: [PATCH] bcache: only recovery I/O error for writethrough mode Date: Mon, 10 Jul 2017 19:18:28 +0800 Message-Id: <20170710111828.97918-1-colyli@suse.de> X-Mailer: git-send-email 2.12.0 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 If a read bio to cache device gets failed, bcache will try to recovery it by forward the read bio to backing device. If backing device responses read request successfully then the bio contains data from backing device will be returned to uppper layer. The recovery effort in cached_dev_read_error() is not correct, and there is report that corrupted data may returned when a dirty cache device goes offline during reading I/O. For writeback cache mode, before dirty data are wrote back to backing device, data blocks on backing device are not updated and consistent. If a dirty cache device dropped and a read bio gets failed, bcache will return its stale version from backing device. This is mistaken behavior that applications don't expected, especially for data base workload. This patch fixes the issue by only permit recoverable I/O when cached device is in writethough mode, and s->recoverable is set. For other cache mode, recovery I/O failure by reading backing device does not make sense, bache just simply returns -EIO immediately. Reported-by: Arne Wolf Signed-off-by: Coly Li --- drivers/md/bcache/request.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c index 019b3df9f1c6..6edacac9b00d 100644 --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c @@ -702,8 +702,11 @@ 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); + unsigned mode = cache_mode(dc, NULL); - if (s->recoverable) { + if (s->recoverable && + (mode == CACHE_MODE_WRITETHROUGH)) { /* Retry from the backing device: */ trace_bcache_read_retry(s->orig_bio);