All of lore.kernel.org
 help / color / mirror / Atom feed
From: Coly Li <colyli@suse.de>
To: linux-bcache@vger.kernel.org
Cc: linux-block@vger.kernel.org, Coly Li <colyli@suse.de>,
	Junhui Tang <tang.junhui@zte.com.cn>,
	Michael Lyle <mlyle@lyle.org>
Subject: [PATCH v3 09/13] bcache: stop all attached bcache devices for a retired cache set
Date: Sun, 14 Jan 2018 22:42:32 +0800	[thread overview]
Message-ID: <20180114144236.28213-10-colyli@suse.de> (raw)
In-Reply-To: <20180114144236.28213-1-colyli@suse.de>

When there are too many I/O errors on cache device, current bcache code
will retire the whole cache set, and detach all bcache devices. But the
detached bcache devices are not stopped, which is problematic when bcache
is in writeback mode.

If the retired cache set has dirty data of backing devices, continue
writing to bcache device will write to backing device directly. If the
LBA of write request has a dirty version cached on cache device, next time
when the cache device is re-registered and backing device re-attached to
it again, the stale dirty data on cache device will be written to backing
device, and overwrite latest directly written data. This situation causes
a quite data corruption.

This patch checkes whether cache_set->io_disable is true in
__cache_set_unregister(). If cache_set->io_disable is true, it means cache
set is unregistering by too many I/O errors, then all attached bcache
devices will be stopped as well. If cache_set->io_disable is not true, it
means __cache_set_unregister() is triggered by writing 1 to sysfs file
/sys/fs/bcache/<UUID>/bcache/stop. This is an exception because users do
it explicitly, this patch keeps existing behavior and does not stop any
bcache device.

Even the failed cache device has no dirty data, stopping bcache device is
still a desired behavior by many Ceph and data base users. Then their
application will report I/O errors due to disappeared bcache device, and
operation people will know the cache device is broken or disconnected.

Changelog:
v2: add Reviewed-by from Hannes.
v1: initial version for review.

Signed-off-by: Coly Li <colyli@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Cc: Junhui Tang <tang.junhui@zte.com.cn>
Cc: Michael Lyle <mlyle@lyle.org>
---
 drivers/md/bcache/super.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 4204d75aee7b..97e3bb8e1aee 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1478,6 +1478,14 @@ static void __cache_set_unregister(struct closure *cl)
 				dc = container_of(c->devices[i],
 						  struct cached_dev, disk);
 				bch_cached_dev_detach(dc);
+				/*
+				 * If we come here by too many I/O errors,
+				 * bcache device should be stopped too, to
+				 * keep data consistency on cache and
+				 * backing devices.
+				 */
+				if (test_bit(CACHE_SET_IO_DISABLE, &c->flags))
+					bcache_device_stop(c->devices[i]);
 			} else {
 				bcache_device_stop(c->devices[i]);
 			}
-- 
2.15.1

  parent reply	other threads:[~2018-01-14 14:44 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-14 14:42 [PATCH v3 00/13] bcache: device failure handling improvement Coly Li
2018-01-14 14:42 ` [PATCH v3 01/13] bcache: set writeback_rate_update_seconds in range [1, 60] seconds Coly Li
2018-01-16  9:03   ` Hannes Reinecke
2018-01-14 14:42 ` [PATCH v3 02/13] bcache: properly set task state in bch_writeback_thread() Coly Li
2018-01-16  9:02   ` Hannes Reinecke
2018-01-14 14:42 ` [PATCH v3 03/13] bcache: set task properly in allocator_wait() Coly Li
2018-01-16  9:05   ` Hannes Reinecke
2018-01-16  9:29     ` Coly Li
2018-01-14 14:42 ` [PATCH v3 04/13] bcache: fix cached_dev->count usage for bch_cache_set_error() Coly Li
2018-01-14 14:42 ` [PATCH v3 05/13] bcache: quit dc->writeback_thread when BCACHE_DEV_DETACHING is set Coly Li
2018-01-16  9:11   ` Hannes Reinecke
2018-01-26  6:21     ` Coly Li
2018-01-14 14:42 ` [PATCH v3 06/13] bcache: stop dc->writeback_rate_update properly Coly Li
2018-01-14 14:42 ` [PATCH v3 07/13] bcache: set error_limit correctly Coly Li
2018-01-14 14:42 ` [PATCH v3 08/13] bcache: add CACHE_SET_IO_DISABLE to struct cache_set flags Coly Li
2018-01-14 14:42 ` Coly Li [this message]
2018-01-14 14:42 ` [PATCH v3 10/13] bcache: fix inaccurate io state for detached bcache devices Coly Li
2018-01-16  9:27   ` Hannes Reinecke
2018-01-14 14:42 ` [PATCH v3 11/13] bcache: add backing_request_endio() for bi_end_io of attached backing device I/O Coly Li
2018-01-16  9:28   ` Hannes Reinecke
2018-01-14 14:42 ` [PATCH v3 12/13] bcache: add io_disable to struct cached_dev Coly Li
2018-01-16  9:32   ` Hannes Reinecke
2018-01-14 14:42 ` [PATCH v3 13/13] bcache: stop bcache device when backing device is offline Coly Li
2018-01-16  9:33   ` Hannes Reinecke
2018-01-24 22:23 ` [PATCH v3 00/13] bcache: device failure handling improvement Nix
2018-01-25  3:35   ` Re[2]: " Pavel Goran
2018-01-25 18:57     ` Nix
2018-01-26  4:15       ` Re[2]: " Pavel Goran
2018-01-26  4:56         ` Coly Li
2018-01-26  5:51           ` Michael Lyle
2018-01-26  6:23             ` Coly Li
2018-02-16 12:11           ` Nix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180114144236.28213-10-colyli@suse.de \
    --to=colyli@suse.de \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=mlyle@lyle.org \
    --cc=tang.junhui@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.