Skip to contentSkip to conversation

btrfs-progs: scrub: add basic support for SCRUB_LOGICAL

RFC PATCH New Qu Wenruo 1 participant 1 message Jun 17, 2023 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

RFC PATCH 1/1 btrfs-progs: scrub: add basic support for SCRUB_LOGICAL

This patch is only for test purpose.

It addes a new option, "-l", to "scrub start" subcommand, and only support foreground scrub and full report.

---
 cmds/scrub.c               | 33 +++++++++++++++++++++++++++++++--
 kernel-shared/uapi/btrfs.h |  3 ++-
 2 files changed, 33 insertions(+), 3 deletions(-)
cmds/scrub.c +31 -2
index 96e3bb5c..82d69975 100644
@@ -326,7 +326,8 @@ static void print_scrub_dev(struct btrfs_ioctl_dev_info_args *di,
 		if (raw)
 			print_scrub_full(p);
 		else
-			print_scrub_summary(p, ss, di->bytes_used);
+			print_scrub_summary(p, ss, p->tree_bytes_scrubbed +
+						   p->data_bytes_scrubbed);
 	}
 }
 
@@ -1146,6 +1147,24 @@ static int is_scrub_running_in_kernel(int fd,
 	return 0;
 }
 
+static int scrub_one_fs(int fd, bool readonly)
+{
+	struct btrfs_ioctl_scrub_args scrub_args = { 0 };
+	int ret;
+
+	scrub_args.flags = BTRFS_SCRUB_LOGICAL;
+	scrub_args.end = U64_MAX;
+	if (readonly)
+		scrub_args.flags |= BTRFS_SCRUB_READONLY;
+	ret = ioctl(fd, BTRFS_IOC_SCRUB, &scrub_args);
+	if (ret < 0) {
+		error("failed to do logical scrub: ret=%d errno=%d\n", ret, errno);
+		return ret;
+	}
+	print_scrub_full(&scrub_args.progress);
+	return 0;
+}
+
 static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
 		       bool resume)
 {
@@ -1164,6 +1183,7 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
 	bool do_background = true;
 	bool do_wait = false;
 	bool do_print = false;
+	bool do_logical_scrub = false;
 	int do_quiet = !bconf.verbose; /*Read the global quiet option if set*/
 	bool do_record = true;
 	bool readonly = false;
@@ -1195,7 +1215,7 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
 	bool force = false;
 	bool nothing_to_resume = false;
 
-	while ((c = getopt(argc, argv, "BdqrRc:n:f")) != -1) {
+	while ((c = getopt(argc, argv, "BdqrRc:n:fl")) != -1) {
 		switch (c) {
 		case 'B':
 			do_background = false;
@@ -1224,6 +1244,9 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
 		case 'f':
 			force = true;
 			break;
+		case 'l':
+			do_logical_scrub = true;
+			break;
 		default:
 			usage_unknown_option(cmd, argv);
 		}
@@ -1252,6 +1275,12 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
 	if (fdmnt < 0)
 		return 1;
 
+	if (do_logical_scrub) {
+		ret = scrub_one_fs(fdmnt, readonly);
+		if (ret < 0)
+			err = 1;
+		goto out;
+	}
 	ret = get_fs_info(path, &fi_args, &di_args);
 	if (ret) {
 		errno = -ret;
kernel-shared/uapi/btrfs.h +2 -1
index 0859a7cc..6038ee4c 100644
@@ -199,7 +199,8 @@ struct btrfs_scrub_progress {
 					 * Intermittent error. */
 };
 
-#define BTRFS_SCRUB_READONLY	1
+#define BTRFS_SCRUB_READONLY		(1ULL << 0)
+#define BTRFS_SCRUB_LOGICAL		(1ULL << 1)
 struct btrfs_ioctl_scrub_args {
 	__u64 devid;				/* in */
 	__u64 start;				/* in */
Signature · 1 line
2.39.0