Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10423882ybi; Wed, 24 Jul 2019 22:59:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwuc/KOlICx6rK6pKfT21QioAhSTbBmqqq+QJdA+bEp58AryvpetENebeuaVhGmMvNduJv X-Received: by 2002:a17:902:b944:: with SMTP id h4mr13220589pls.179.1564034341153; Wed, 24 Jul 2019 22:59:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564034341; cv=none; d=google.com; s=arc-20160816; b=cNxKjVPLSVV5W0wN6j68ge/gw8zS4cvcBR7q/L8PNFjoiD8c//W+wLlgXTq1qwdkqC mpXY5bM8169/y5STm7y83UkGtTOwoeqeqNIfcSgnq6BJzYCXDKscYDUl6xnWbnuUzfsX cj+ndBsKFt8Byh6gC17886WwQOOUWWuMDQtZ7Ys476ud/DZhvT203Q0nBCqILGAkdVs1 gOVdjnTR8VzHP/LWfJBtKBjpP6oZ5GkVHxY3/WUralcc/BHfhDqAhKFbI1M5Ik484Taq Tn0HGP4NsFRT6F1Gap3cremvpnt9CnKEZJBJUEjjTzVagkg03+G0U8ZXYZ8aep89WFSE mRyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4Or7rRds7lADLrZjDX9Tzzcn10x80uqNp3N3FCj+hKc=; b=GnsxQbj3JZ+MER0WrVN3Ra38JXjThQqnhFaqZ6KY4t6tkZeeuOPcY/fNIMnSnRWPsy OVdr09flk1GQ4+QgHbKmdmuzQihhy48V8R5qUfE+9e585vCCPPBQlj2tIUBpDmUJiXr+ Wqr+AxQpPb2mCP8AbDEFJ7rv+GCpSZgTsNJE2zA0cfRlR2IE0NQlkRlF57EeM5IdyCRX 9b7fcQuPjDIdSQOKALJ+varJD0Z6hQ9BXfXyheEmkJiyZwa1+K+Gr9wYKAqcfDEZWg41 x7+R9ICNiAIuxG7Ng3kVOkzgwRT0IqCOgswDUU3viWeD/Ui8BZkXEA+8LL8aPNvTnHXL Y1Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qTxHTKF3; 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 32si14045968plc.152.2019.07.24.22.58.47; Wed, 24 Jul 2019 22:59:01 -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; dkim=pass header.i=@kernel.org header.s=default header.b=qTxHTKF3; 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 S2404566AbfGYFlN (ORCPT + 99 others); Thu, 25 Jul 2019 01:41:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:55928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404534AbfGYFlL (ORCPT ); Thu, 25 Jul 2019 01:41:11 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DF92F22BF3; Thu, 25 Jul 2019 05:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564033270; bh=01qyR8q1qcmNZMZN8DfT208IbnjjFId6g0x+quyxSl0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qTxHTKF3g4YikHCqUmfQ3FGT7ShBeqvlWP6HhZFOdnB0hv0td/r/ydXj4KbIuLncf tCaDvwdimttCKLyFjFnBL93+J+E7NuBvMLJ3KVTLZL0tta+U6yPTy913somWEUM98s Iuh0r/S5ITWj88DlI1YCBIE/1es+EHH2PrnusUFo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Coly Li , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 124/271] bcache: check CACHE_SET_IO_DISABLE in allocator code Date: Wed, 24 Jul 2019 21:19:53 +0200 Message-Id: <20190724191705.898378775@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit e775339e1ae1205b47d94881db124c11385e597c ] If CACHE_SET_IO_DISABLE of a cache set flag is set by too many I/O errors, currently allocator routines can still continue allocate space which may introduce inconsistent metadata state. This patch checkes CACHE_SET_IO_DISABLE bit in following allocator routines, - bch_bucket_alloc() - __bch_bucket_alloc_set() Once CACHE_SET_IO_DISABLE is set on cache set, the allocator routines may reject allocation request earlier to avoid potential inconsistent metadata. Signed-off-by: Coly Li Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/alloc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c index de85b3af3b39..9c3beb1e382b 100644 --- a/drivers/md/bcache/alloc.c +++ b/drivers/md/bcache/alloc.c @@ -393,6 +393,11 @@ long bch_bucket_alloc(struct cache *ca, unsigned int reserve, bool wait) struct bucket *b; long r; + + /* No allocation if CACHE_SET_IO_DISABLE bit is set */ + if (unlikely(test_bit(CACHE_SET_IO_DISABLE, &ca->set->flags))) + return -1; + /* fastpath */ if (fifo_pop(&ca->free[RESERVE_NONE], r) || fifo_pop(&ca->free[reserve], r)) @@ -484,6 +489,10 @@ int __bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve, { int i; + /* No allocation if CACHE_SET_IO_DISABLE bit is set */ + if (unlikely(test_bit(CACHE_SET_IO_DISABLE, &c->flags))) + return -1; + lockdep_assert_held(&c->bucket_lock); BUG_ON(!n || n > c->caches_loaded || n > 8); -- 2.20.1