Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Li Zhang <zhanglikernel@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Li Zhang <zhanglikernel@gmail.com>
Subject: [PATCH] btrfs-prog: scrub: print message when scrubbing a read-only filesystem without r option
Date: Thu,  4 Jul 2024 01:47:01 +0800	[thread overview]
Message-ID: <1720028821-3094-1-git-send-email-zhanglikernel@gmail.com> (raw)

issue:666

[enhancement]
When scrubbing a filesystem mounted read-only and without r
option, it aborts and there is no message associated with it.
So we need to print an error message when scrubbing a read-only
filesystem to tell the user what is going on here.

[implementation]
Move the error message from the main thread to each scrub thread,
previously the message was printed after all scrub threads
finished and without background mode.

[test]
Mount dev in read-only mode, then scrub it without r option

$ sudo mount /dev/vdb -o ro /mnt/
$ sudo btrfs scrub start  /mnt/
scrub started on /mnt/, fsid f7c26803-a68d-4a96-91c4-a629b57b7f64 (pid=2892)
Starting scrub on devid 1
Starting scrub on devid 2
Starting scrub on devid 3
scrub on devid 1 failed ret=-1 errno=30 (Read-only file system)
scrub on devid 2 failed ret=-1 errno=30 (Read-only file system)
scrub on devid 3 failed ret=-1 errno=30 (Read-only file system)

Signed-off-by: Li Zhang <zhanglikernel@gmail.com>
---
 cmds/scrub.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/cmds/scrub.c b/cmds/scrub.c
index d54e11f..e0400dd 100644
--- a/cmds/scrub.c
+++ b/cmds/scrub.c
@@ -957,7 +957,10 @@ static void *scrub_one_dev(void *ctx)
 		warning("setting ioprio failed: %m (ignored)");
 
 	ret = ioctl(sp->fd, BTRFS_IOC_SCRUB, &sp->scrub_args);
-        pr_verbose(LOG_DEFAULT, "scrub ioctl devid:%llu ret:%d errno:%d\n",sp->scrub_args.devid, ret, errno);
+	if (ret){
+		pr_verbose(LOG_DEFAULT, "scrub on devid %llu failed ret=%d errno=%d (%m)\n", 
+			sp->scrub_args.devid, ret, errno);
+	}
 	gettimeofday(&tv, NULL);
 	sp->ret = ret;
 	sp->stats.duration = tv.tv_sec - sp->stats.t_start;
@@ -1596,13 +1599,6 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
 				++err;
 				break;
 			default:
-				if (do_print) {
-					errno = sp[i].ioctl_errno;
-					error(
-		"scrubbing %s failed for device id %lld: ret=%d, errno=%d (%m)",
-						path, devid, sp[i].ret,
-						sp[i].ioctl_errno);
-				}
 				++err;
 				continue;
 			}
-- 
1.8.3.1


             reply	other threads:[~2024-07-03 17:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-03 17:47 Li Zhang [this message]
2024-07-03 23:26 ` [PATCH] btrfs-prog: scrub: print message when scrubbing a read-only filesystem without r option Qu Wenruo
2024-07-04  0:13   ` David Sterba
2024-07-04  0:19     ` Qu Wenruo
2024-07-04  0:22       ` David Sterba
2024-07-05 16:06         ` li zhang

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=1720028821-3094-1-git-send-email-zhanglikernel@gmail.com \
    --to=zhanglikernel@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