[PATCH] bcache: set io_disable to true when stop bcache device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stop is an operation that cannot be aborted. If there are still
IO requests being processed, we can never stop the device.
So, all new IO requests should fail when we set io_disable to true.
However, sysfs has been unlinked at this time, user cannot modify
io_disable via sysfs.

Signed-off-by: mingzhe <mingzhe.zou@xxxxxxxxxxxx>
---
 drivers/md/bcache/request.c | 16 ++++++++++++++++
 drivers/md/bcache/super.c   |  9 +++++++++
 2 files changed, 25 insertions(+)

diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index 67a2e29e0b40..9b85aad20022 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -758,6 +758,15 @@ static void cached_dev_bio_complete(struct closure *cl)
 	search_free(cl);
 }
 
+static void cached_dev_bio_fail(struct closure *cl)
+{
+	struct search *s = container_of(cl, struct search, cl);
+	struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
+
+	s->iop.status = BLK_STS_IOERR;
+	cached_dev_bio_complete(cl);
+}
+
 /* Process reads */
 
 static void cached_dev_read_error_done(struct closure *cl)
@@ -971,6 +980,9 @@ static void cached_dev_write(struct cached_dev *dc, struct search *s)
 	struct bkey start = KEY(dc->disk.id, bio->bi_iter.bi_sector, 0);
 	struct bkey end = KEY(dc->disk.id, bio_end_sector(bio), 0);
 
+	if (unlikely((dc->io_disable)))
+		goto fail_bio;
+
 	bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys, &start, &end);
 
 	down_read_non_owner(&dc->writeback_lock);
@@ -1046,6 +1058,10 @@ static void cached_dev_write(struct cached_dev *dc, struct search *s)
 insert_data:
 	closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
 	continue_at(cl, cached_dev_write_complete, NULL);
+	return;
+
+fail_bio:
+	continue_at(cl, cached_dev_bio_fail, NULL);
 }
 
 static void cached_dev_nodata(struct closure *cl)
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index ba3909bb6bea..a2a82942f85b 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1389,6 +1389,15 @@ static void cached_dev_flush(struct closure *cl)
 	bch_cache_accounting_destroy(&dc->accounting);
 	kobject_del(&d->kobj);
 
+	/*
+	 * Stop is an operation that cannot be aborted. If there are still
+	 * IO requests being processed, we can never stop the device.
+	 * So, all new IO requests should fail when we set io_disable to true.
+	 * However, sysfs has been unlinked at this time, user cannot modify
+	 * io_disable via sysfs.
+	 */
+	dc->io_disable = true;
+
 	continue_at(cl, cached_dev_free, system_wq);
 }
 
-- 
2.17.1.windows.2




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux ARM Kernel]     [Linux Filesystem Development]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux