All of lore.kernel.org
 help / color / mirror / Atom feed
From: Coly Li <colyli@suse.de>
To: linux-bcache@vger.kernel.org, axboe@kernel.dk
Cc: linux-block@vger.kernel.org, Shenghui Wang <shhuiw@foxmail.com>,
	Coly Li <colyli@suse.de>
Subject: [PATCH 06/12] bcache: cannot set writeback_running via sysfs if no writeback kthread created
Date: Thu, 13 Dec 2018 22:53:51 +0800	[thread overview]
Message-ID: <20181213145357.38528-7-colyli@suse.de> (raw)
In-Reply-To: <20181213145357.38528-1-colyli@suse.de>

From: Shenghui Wang <shhuiw@foxmail.com>

"echo 1 > writeback_running" marks writeback_running even if no writeback
kthread created as "d_strtoul(writeback_running)" will simply set dc->
writeback_running without checking the existence of dc->writeback_thread.

Add check for setting writeback_running via sysfs: if no writeback kthread
available, reject setting to 1.

v2 -> v3:
  * Make message on wrong assignment more clear.
  * Print name of bcache device instead of name of backing device.

Signed-off-by: Shenghui Wang <shhuiw@foxmail.com>
Signed-off-by: Coly Li <colyli@suse.de>
---
 drivers/md/bcache/sysfs.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
index d2e5c9892d4d..9d5fe12f0c9c 100644
--- a/drivers/md/bcache/sysfs.c
+++ b/drivers/md/bcache/sysfs.c
@@ -384,8 +384,25 @@ STORE(bch_cached_dev)
 	mutex_lock(&bch_register_lock);
 	size = __cached_dev_store(kobj, attr, buf, size);
 
-	if (attr == &sysfs_writeback_running)
-		bch_writeback_queue(dc);
+	if (attr == &sysfs_writeback_running) {
+		/* dc->writeback_running changed in __cached_dev_store() */
+		if (IS_ERR_OR_NULL(dc->writeback_thread)) {
+			/*
+			 * reject setting it to 1 via sysfs if writeback
+			 * kthread is not created yet.
+			 */
+			if (dc->writeback_running) {
+				dc->writeback_running = false;
+				pr_err("%s: failed to run non-existent writeback thread",
+						dc->disk.disk->disk_name);
+			}
+		} else
+			/*
+			 * writeback kthread will check if dc->writeback_running
+			 * is true or false.
+			 */
+			bch_writeback_queue(dc);
+	}
 
 	if (attr == &sysfs_writeback_percent)
 		if (!test_and_set_bit(BCACHE_DEV_WB_RUNNING, &dc->disk.flags))
-- 
2.16.4


  parent reply	other threads:[~2018-12-13 14:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-13 14:53 [PATCH 00/12] bcache patches for Linux v4.21 Coly Li
2018-12-13 14:53 ` [PATCH 01/12] bcache: add comment for cache_set->fill_iter Coly Li
2018-12-13 14:53 ` [PATCH 02/12] bcache: do not check if debug dentry is ERR or NULL explicitly on remove Coly Li
2018-12-13 14:53 ` [PATCH 03/12] bcache: update comment for bch_data_insert Coly Li
2018-12-13 14:53 ` [PATCH 04/12] bcache: update comment in sysfs.c Coly Li
2018-12-13 14:53 ` [PATCH 05/12] bcache: do not mark writeback_running until backing dev attached to cache_set Coly Li
2018-12-13 14:53 ` Coly Li [this message]
2018-12-13 14:53 ` [PATCH 07/12] bcache: introduce force_wake_up_gc() Coly Li
2018-12-13 14:53 ` [PATCH 08/12] bcache: option to automatically run gc thread after writeback accomplished Coly Li
2018-12-13 14:53 ` [PATCH 09/12] bcache: add MODULE_DESCRIPTION information Coly Li
2018-12-13 14:53 ` [PATCH 10/12] bcache: make cutoff_writeback and cutoff_writeback_sync tunnable Coly Li
2018-12-13 14:53 ` [PATCH 11/12] bcache: set writeback_percent in a flexible range Coly Li
2018-12-13 14:53 ` [PATCH 12/12] bcache: print number of keys in trace_bcache_journal_write Coly Li
2018-12-13 15:16 ` [PATCH 00/12] bcache patches for Linux v4.21 Jens Axboe
2018-12-14  8:25   ` Coly Li

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=20181213145357.38528-7-colyli@suse.de \
    --to=colyli@suse.de \
    --cc=axboe@kernel.dk \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=shhuiw@foxmail.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 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.