linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: mingzhe <mingzhe.zou@easystack.cn>
To: colyli@suse.de, bcache@lists.ewheeler.net
Cc: linux-bcache@vger.kernel.org, zoumingzhe@qq.com
Subject: [PATCH] bcache: set io_disable to true when stop bcache device
Date: Wed,  8 Mar 2023 17:20:36 +0800	[thread overview]
Message-ID: <20230308092036.11024-1-mingzhe.zou@easystack.cn> (raw)

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@easystack.cn>
---
 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


             reply	other threads:[~2023-03-08  9:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08  9:20 mingzhe [this message]
2023-03-08  9:52 ` [PATCH] bcache: set io_disable to true when stop bcache device Coly Li
2023-03-08 12:16 ` kernel test robot

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=20230308092036.11024-1-mingzhe.zou@easystack.cn \
    --to=mingzhe.zou@easystack.cn \
    --cc=bcache@lists.ewheeler.net \
    --cc=colyli@suse.de \
    --cc=linux-bcache@vger.kernel.org \
    --cc=zoumingzhe@qq.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).