Received: by 10.192.165.156 with SMTP id m28csp235282imm; Tue, 10 Apr 2018 20:35:38 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+84Q/YyZ4XyXfHWr7KN1MX8DVDpGY2CguKpe3WkbAYsZypASwaQmFIcAtUoVF5cDAU0Jl7 X-Received: by 10.101.78.194 with SMTP id w2mr2195927pgq.242.1523417738190; Tue, 10 Apr 2018 20:35:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523417738; cv=none; d=google.com; s=arc-20160816; b=kU9mUYnhiJhkUAy82FGG0TI1PlPAM+b40e0wR0QjODiLC41jLhnUyEOC/usaQDKlyV kQ1L8OcTp9nd+yj1CY/+VUO8dtaL+vEyjLBFKH9qN65CyAp/2i9MNEQhLWhIQwK/loqQ RmUKWLYJgrNLwWWLQ/vjsCaIPDMx41dBtOYOlfQZ90vNlqvMSEMrLR7/JPOKHbXIDHXd RvVAeHISDToxWJALdUz3asVucdI3hwVeQyj8qfrW02Tq/g2/At6Ja6Bx68giFTv2Wjvl RNrf3m+56fg2puJywVbMHFzLFSZ2C7B2wz75ZDs0Jv0aaLuISvUjN2LOMlK4M5rrn6f7 t7dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=l8kDVyzY0/pEJ91LTzp6d5z5iicbEV5ASZhyexPCqZI=; b=ZWnT7pjcj8RsLuUp+HPGtksawJ0J6ZMGD7ORDMVroHSHfS/bwNxA1QRs+xda8wENN1 /NplyFAtyFyQEEydyaa0YEWUi5xO5cyj8YgpbYsLcp06Vq1E3ck+FGLCuSaNmmO5Gv2v Rv/kmeCxJWzqIIg/Wsc6eBiAOs/yoHAtfaroJE4kU9tCsKuajIfvhUAK5lBsKeHFut9m evAJcVhyibp71VJV4QBB8q3tILjuLfolkXoD8RaIO+7m8G12c6sm0+fveSHV/RNxtPtR NhS++CP+dNhRPAxmmVfmUgmJpqCEkCNsnk7qOAMlOmvtJ/cpa506Uwxo2aKQtYNXBJBE Iy6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i81si144805pfd.261.2018.04.10.20.35.01; Tue, 10 Apr 2018 20:35:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754564AbeDJWaY (ORCPT + 99 others); Tue, 10 Apr 2018 18:30:24 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:39946 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754547AbeDJWaV (ORCPT ); Tue, 10 Apr 2018 18:30:21 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id DB2D4D4F; Tue, 10 Apr 2018 22:30:20 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hua Rui , Michael Lyle , Jens Axboe , Sasha Levin Subject: [PATCH 4.15 072/168] bcache: ret IOERR when read meets metadata error Date: Wed, 11 Apr 2018 00:23:34 +0200 Message-Id: <20180410212803.260884103@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180410212800.144079021@linuxfoundation.org> References: <20180410212800.144079021@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rui Hua [ Upstream commit b221fc130c49c50f4c2250d22e873420765a9fa2 ] The read request might meet error when searching the btree, but the error was not handled in cache_lookup(), and this kind of metadata failure will not go into cached_dev_read_error(), finally, the upper layer will receive bi_status=0. In this patch we judge the metadata error by the return value of bch_btree_map_keys(), there are two potential paths give rise to the error: 1. Because the btree is not totally cached in memery, we maybe get error when read btree node from cache device (see bch_btree_node_get()), the likely errno is -EIO, -ENOMEM 2. When read miss happens, bch_btree_insert_check_key() will be called to insert a "replace_key" to btree(see cached_dev_cache_miss(), just for doing preparatory work before insert the missed data to cache device), a failure can also happen in this situation, the likely errno is -ENOMEM bch_btree_map_keys() will return MAP_DONE in normal scenario, but we will get either -EIO or -ENOMEM in above two cases. if this happened, we should NOT recover data from backing device (when cache device is dirty) because we don't know whether bkeys the read request covered are all clean. And after that happened, s->iop.status is still its initially value(0) before we submit s->bio.bio, we set it to BLK_STS_IOERR, so it can go into cached_dev_read_error(), and finally it can be passed to upper layer, or recovered by reread from backing device. [edit by mlyle: patch formatting, word-wrap, comment spelling, commit log format] Signed-off-by: Hua Rui Reviewed-by: Michael Lyle Signed-off-by: Michael Lyle Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/md/bcache/request.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c @@ -576,6 +576,7 @@ static void cache_lookup(struct closure { struct search *s = container_of(cl, struct search, iop.cl); struct bio *bio = &s->bio.bio; + struct cached_dev *dc; int ret; bch_btree_op_init(&s->op, -1); @@ -588,6 +589,27 @@ static void cache_lookup(struct closure return; } + /* + * We might meet err when searching the btree, If that happens, we will + * get negative ret, in this scenario we should not recover data from + * backing device (when cache device is dirty) because we don't know + * whether bkeys the read request covered are all clean. + * + * And after that happened, s->iop.status is still its initial value + * before we submit s->bio.bio + */ + if (ret < 0) { + BUG_ON(ret == -EINTR); + if (s->d && s->d->c && + !UUID_FLASH_ONLY(&s->d->c->uuids[s->d->id])) { + dc = container_of(s->d, struct cached_dev, disk); + if (dc && atomic_read(&dc->has_dirty)) + s->recoverable = false; + } + if (!s->iop.status) + s->iop.status = BLK_STS_IOERR; + } + closure_return(cl); }