Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9983686ybi; Wed, 24 Jul 2019 13:32:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyHQ1b6maCcW0BMka1kNkMNw/SOyW9WXbHaRav+zVFK8IR3l4olw7/SfeiKxf8irHKDpdue X-Received: by 2002:a63:593:: with SMTP id 141mr81269961pgf.78.1564000321783; Wed, 24 Jul 2019 13:32:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000321; cv=none; d=google.com; s=arc-20160816; b=wJ1agRIbDkS9DFpk6fSpK5C1m7od8Hqv+QK0n6ACDI/u7G1lRPisghr9ANTXSeQ6Bv qohlWvGrTBAO5FzC4HcuZ6A+jnQ7hXtUVMY1zdKojO4eVsPWgCQqcpgHAHdf08jJJVKV /8qw6vTk0Qpu9M1W/Znb87BO48sMrP0tsFLrUGZwfwUEpdT8fccxgDIBUBcM+jYD1GaS RBx1t2HiQmY523cSWjfolPq1c9Ww+iOW0oqV3iKDqJiUkqM764hoNRj/6Ot3kb4AZnnx sQKFO6x9VZ10SkakgJ2Os8HtZ1Ilgs5xawvevJrUWxHif2fS6+D9Z7H3zXf9awjyjmXF n+4g== 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=GnRPLg07QIzAe53mnNSdDJE1YQWlACKDO6WqDSNRYDc=; b=DJWVifmD4rAiyOq+xNt3hM3KGUrcBvZXpanoF+3pakQhx1I1Wbs+kByb8mkdsTbdnU Zs/dNoAjSpNYgHM6wabqD1jdnV3V64NivPJwVWcKlcGk7DtbOM+rbgiXAjCn/ie8rd0P 9aiLTa5M5aXDaH8snacL62YVeMfo4RYsEX1jOrbzs8TWmzrd4W+YsbJR0eb1VxO8P9qM rV/8zWY6wSaCI5+mMlsCfZSgOooEizKa7wNbV6z7Pjtn1Zz9Fy5P/uCcSzOzvRO1jvu3 NbDEgPRRLsjOt/iNrtCr+Hw4Ql/+VogYdeRVYFY8mUwqL3f5AyKGxVYlMt4+6PNPe0A7 zdqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zHEmiHE8; 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 r9si13816010pjq.35.2019.07.24.13.31.46; Wed, 24 Jul 2019 13:32: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=zHEmiHE8; 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 S2388535AbfGXTbr (ORCPT + 99 others); Wed, 24 Jul 2019 15:31:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:52848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388518AbfGXTbn (ORCPT ); Wed, 24 Jul 2019 15:31:43 -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 4298E229F4; Wed, 24 Jul 2019 19:31:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996702; bh=sFckYkiWGAE7EeWjN8SGcOWGU+aX2nOc+kIauULy8C8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zHEmiHE8WeIrpdVvmrJLuO1lcoKy6mqM14JeRq+PWB9ozMdmGAcZTIxqMfFY6Angw JuuLhTnlsz7EAk4Jn0b4/9QNLipBBE6rL0Nimnqg7KoHQLJNI5mL33/xifqu5MQ/Ti IE0kiZcMmm7NUpbvwaxMnZr4eS1M+3hVZ9eLGP1E= 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 5.2 187/413] bcache: check CACHE_SET_IO_DISABLE in allocator code Date: Wed, 24 Jul 2019 21:17:58 +0200 Message-Id: <20190724191748.098005704@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@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 f8986effcb50..6f776823b9ba 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 > MAX_CACHES_PER_SET); -- 2.20.1