Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp238615ybi; Wed, 29 May 2019 20:24:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPcgkIc0R9yBQoOrjBYYjk2cKIG8adrMLOoy8vH7bq+yR//cvUDdBV92fhoA7YVMhJ9qhg X-Received: by 2002:a17:90b:d97:: with SMTP id bg23mr1376332pjb.87.1559186681436; Wed, 29 May 2019 20:24:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559186681; cv=none; d=google.com; s=arc-20160816; b=RfqKkWob1kycE0PQjMt6bYqimGiH9iHyIB97WQM65f39/tpKVkqHqBi4fqSRPGMK7E lzccBikmUiI7wMuI+sqGXTgEASS3clUFJBPOGSANpofdaehvKGGUT7lDxdenOc94AI66 j/4SENZqmVJgPxXVBVBuE28/wKYnWHBfM4OPRQ7jxB/tOiP3xswpeNssjIhJddi1hv/V nHSkrc0d+hXR7h1f8Lz8gagmS2LQD+ErLo0B4YW2IwAI7XrbORmTeG9jsAZ/frGGsF1N 2kGVFmcLywrFQBUAypfJwUKzRsvjmPGmjRFHK8EBuk5AAYfn1zB0a8zpHy+bWjPPk6dy aJvg== 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=2hf/sTAlNr/hCDhoQs/5HXtI0qr4OiZ7PeW3pZoNhtw=; b=W93VoEayHqSlbw2Pq8oVVyIteaIDI2EIDIG3r3NDUXvKhj9hIzuyb3Ml2H9bgxIxh0 2WDI2vbEKcZzr4l9vJL8ZfnbFs9JZ0S2LU8RNqxwN2ohv3MSBhkCuLQvQpmAEC9bEod6 d6twggudbfiW9bPz2uZ46ZZ18Ir2K3r13GKGwxbI3YryERGbcSFZB3+8eJjfPSdPOLwD h+TsuecdwULcelywsZfHYuxIryIwNc08wmhVeqYEWHNaj1xw4vDlix1VvfYVUlDY9Pfr yJv4WnRXT+Rf1feMmwyzUMs4vbvA9qnhqXTOpIspBDQjQG0hQmcV+aaAj3QSC1z5ZG/d VWsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mWeglRWc; 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 z33si1888906pgk.516.2019.05.29.20.24.24; Wed, 29 May 2019 20:24:41 -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=mWeglRWc; 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 S1732873AbfE3DWi (ORCPT + 99 others); Wed, 29 May 2019 23:22:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:44396 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729909AbfE3DQ5 (ORCPT ); Wed, 29 May 2019 23:16:57 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 E1A4E24645; Thu, 30 May 2019 03:16:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186217; bh=eMfYIMmN8IRYeFVqqs0Ntci4tZ4bgEYCeE5PmwQgDkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mWeglRWcu/r0mppLQnEdoyv7PhV1uniS8UQENaHbcU8q69Wq4Pq32qHtkHHNTqe/X t0nwM6hne4fmSCUPJ+2CttASDPlZpWAvsqFn0iB7YM+PJLRafFqov8nDK9D2qAngf7 QEf4bq8zWrOTuyaK9OB5yd0CZ0BeF2Anj546DBsA= 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 105/276] bcache: add failure check to run_cache_set() for journal replay Date: Wed, 29 May 2019 20:04:23 -0700 Message-Id: <20190530030532.608636349@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@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 ce3e4cfb59cb382f8e5ce359238aa580d4ae7778 ] Currently run_cache_set() has no return value, if there is failure in bch_journal_replay(), the caller of run_cache_set() has no idea about such failure and just continue to execute following code after run_cache_set(). The internal failure is triggered inside bch_journal_replay() and being handled in async way. This behavior is inefficient, while failure handling inside bch_journal_replay(), cache register code is still running to start the cache set. Registering and unregistering code running as same time may introduce some rare race condition, and make the code to be more hard to be understood. This patch adds return value to run_cache_set(), and returns -EIO if bch_journal_rreplay() fails. Then caller of run_cache_set() may detect such failure and stop registering code flow immedidately inside register_cache_set(). If journal replay fails, run_cache_set() can report error immediately to register_cache_set(). This patch makes the failure handling for bch_journal_replay() be in synchronized way, easier to understand and debug, and avoid poetential race condition for register-and-unregister in same time. Signed-off-by: Coly Li Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/super.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index d8190804aee9b..2409507d7bff8 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -1770,7 +1770,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb) return NULL; } -static void run_cache_set(struct cache_set *c) +static int run_cache_set(struct cache_set *c) { const char *err = "cannot allocate memory"; struct cached_dev *dc, *t; @@ -1866,7 +1866,9 @@ static void run_cache_set(struct cache_set *c) if (j->version < BCACHE_JSET_VERSION_UUID) __uuid_write(c); - bch_journal_replay(c, &journal); + err = "bcache: replay journal failed"; + if (bch_journal_replay(c, &journal)) + goto err; } else { pr_notice("invalidating existing data"); @@ -1934,7 +1936,7 @@ static void run_cache_set(struct cache_set *c) flash_devs_run(c); set_bit(CACHE_SET_RUNNING, &c->flags); - return; + return 0; err: while (!list_empty(&journal)) { l = list_first_entry(&journal, struct journal_replay, list); @@ -1945,6 +1947,8 @@ static void run_cache_set(struct cache_set *c) closure_sync(&cl); /* XXX: test this, it's broken */ bch_cache_set_error(c, "%s", err); + + return -EIO; } static bool can_attach_cache(struct cache *ca, struct cache_set *c) @@ -2008,8 +2012,11 @@ static const char *register_cache_set(struct cache *ca) ca->set->cache[ca->sb.nr_this_dev] = ca; c->cache_by_alloc[c->caches_loaded++] = ca; - if (c->caches_loaded == c->sb.nr_in_set) - run_cache_set(c); + if (c->caches_loaded == c->sb.nr_in_set) { + err = "failed to run cache set"; + if (run_cache_set(c) < 0) + goto err; + } return NULL; err: -- 2.20.1