Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Sidong Yang <realwakka@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Sidong Yang <realwakka@gmail.com>
Subject: [PATCH] btrfs-progs: scrub: warn if scrub started on a device has mq-deadline
Date: Sat,  5 Dec 2020 18:49:29 +0000	[thread overview]
Message-ID: <20201205184929.22412-1-realwakka@gmail.com> (raw)

Warn if scurb stared on a device that has mq-deadline as io-scheduler
and point documentation. mq-deadline doesn't work with ionice value and
it results performance loss. This warning helps users figure out the
situation. This patch implements the function that gets io-scheduler
from sysfs and check when scrub stars with the function.

Signed-off-by: Sidong Yang <realwakka@gmail.com>
---
 cmds/scrub.c          |  8 ++++++++
 common/device-utils.c | 28 ++++++++++++++++++++++++++++
 common/device-utils.h |  1 +
 3 files changed, 37 insertions(+)

diff --git a/cmds/scrub.c b/cmds/scrub.c
index e96dc998..1932b097 100644
--- a/cmds/scrub.c
+++ b/cmds/scrub.c
@@ -40,6 +40,7 @@
 #include "kernel-shared/ctree.h"
 #include "ioctl.h"
 #include "common/utils.h"
+#include "common/device-utils.h"
 #include "kernel-shared/volumes.h"
 #include "kernel-shared/disk-io.h"
 
@@ -1188,6 +1189,7 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
 	DIR *dirstream = NULL;
 	int force = 0;
 	int nothing_to_resume = 0;
+	char scheduler_name[256];
 
 	while ((c = getopt(argc, argv, "BdqrRc:n:f")) != -1) {
 		switch (c) {
@@ -1314,6 +1316,12 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
 
 	for (i = 0; i < fi_args.num_devices; ++i) {
 		devid = di_args[i].devid;
+		if (!btrfs_io_scheduler((char*)di_args[i].path, scheduler_name, 256))
+			if (!strcmp(scheduler_name, "mq-deadline"))
+				warning_on(!do_quiet,
+					   "ionice doesn't work with current "
+					   "mq-deadline scheduler "
+					   "(see btrfs-scrub(8) manpage)");
 		ret = pthread_mutex_init(&sp[i].progress_mutex, NULL);
 		if (ret) {
 			errno = ret;
diff --git a/common/device-utils.c b/common/device-utils.c
index c860b946..3cd5ca4a 100644
--- a/common/device-utils.c
+++ b/common/device-utils.c
@@ -252,3 +252,31 @@ u64 get_partition_size(const char *dev)
 	return result;
 }
 
+int btrfs_io_scheduler(const char *dev, char *scheduler, int max_len)
+{
+	char path[PATH_MAX];
+	char names[256];
+	FILE *file;
+	char fmt[20];
+	char *this_char, *save_ptr;
+
+	snprintf(path, PATH_MAX, "/sys/block/%s/queue/scheduler",
+		 basename(dev));
+	if ((file = fopen(path, "r"))) {
+		if (fgets(names, 255, file)) {
+			for (this_char = strtok_r(names, " ", &save_ptr);
+			     this_char != NULL;
+			     this_char = strtok_r(NULL, " ", &save_ptr)) {
+				snprintf(fmt, 20, "[%%%i[a-z-]", max_len - 1);
+				if (sscanf(this_char, fmt, scheduler)) {
+					fclose(file);
+					return 0;
+				}
+			}
+
+		}
+		fclose(file);
+	}
+
+	return -1;
+}
diff --git a/common/device-utils.h b/common/device-utils.h
index 70d19cae..bd892d54 100644
--- a/common/device-utils.h
+++ b/common/device-utils.h
@@ -29,5 +29,6 @@ u64 disk_size(const char *path);
 u64 btrfs_device_size(int fd, struct stat *st);
 int btrfs_prepare_device(int fd, const char *file, u64 *block_count_ret,
 		u64 max_block_count, unsigned opflags);
+int btrfs_io_scheduler(const char *dev, char *scheduler, int max_len);
 
 #endif
-- 
2.25.1


             reply	other threads:[~2020-12-05 18:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-05 18:49 Sidong Yang [this message]
2020-12-07  7:23 ` [PATCH] btrfs-progs: scrub: warn if scrub started on a device has mq-deadline Johannes Thumshirn
2020-12-10 20:20   ` David Sterba
2020-12-11  6:50     ` Johannes Thumshirn
2020-12-11 15:53       ` David Sterba
2020-12-11 16:02         ` Johannes Thumshirn
2020-12-11 16:42           ` Johannes Thumshirn
2020-12-11 17:04             ` Graham Cobb
2020-12-12 10:34               ` Johannes Thumshirn
2020-12-12 11:05                 ` Damien Le Moal
2020-12-12 16:44                   ` Sidong Yang
2020-12-14  7:11                     ` Johannes Thumshirn
2020-12-07  8:00 ` Nikolay Borisov
2020-12-10 20:16   ` David Sterba

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=20201205184929.22412-1-realwakka@gmail.com \
    --to=realwakka@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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