@@ -128,6 +128,8 @@ struct format_ctx fctx;
static const struct rowspec scrub_status_rowspec[] = {
{ .key = "uuid", .fmt = "%s", .out_json = "uuid"},
+ { .key = "dev", .fmt = "%s", .out_json = "dev"},
+ { .key = "id", .fmt = "%llu", .out_json = "id"},
{ .key = "status", .fmt = "%s", .out_json = "status"},
{ .key = "duration", .fmt = "%u:%s", .out_json = "duration"},
{ .key = "started_at", .fmt = "%s", .out_json = "started-at"},
@@ -402,8 +404,10 @@ static void _print_scrub_ss(struct scrub_stats *ss)
const bool json_output = (bconf.output_format == CMD_FORMAT_JSON);
- if ((!ss || !ss->t_start) && !json_output) {
- pr_verbose(LOG_DEFAULT, "\tno stats available\n");
+ if (!ss || !ss->t_start) {
+ if (!json_output)
+ pr_verbose(LOG_DEFAULT, "\tno stats available\n");
+
return;
}
@@ -455,10 +459,19 @@ static void print_scrub_dev(struct btrfs_ioctl_dev_info_args *di,
struct btrfs_scrub_progress *p, int raw,
const char *append, struct scrub_stats *ss,
u64 limit)
-{
- pr_verbose(LOG_DEFAULT, "\nScrub device %s (id %llu) %s\n", di->path, di->devid,
+{
+
+ const bool json_output = (bconf.output_format == CMD_FORMAT_JSON);
+
+ if (json_output) {
+ fmt_print_start_group(&fctx, "device", JSON_TYPE_MAP);
+ fmt_print(&fctx, "dev", di->path);
+ fmt_print(&fctx, "id", di->devid);
+ } else
+ pr_verbose(LOG_DEFAULT, "\nScrub device %s (id %llu) %s\n", di->path, di->devid,
append ? append : "");
+
_print_scrub_ss(ss);
if (p) {
@@ -481,6 +494,10 @@ static void print_scrub_dev(struct btrfs_ioctl_dev_info_args *di,
print_scrub_summary(p, ss, di->bytes_used, limit);
}
}
+
+ if (json_output)
+ fmt_print_end_group(&fctx, "device");
+
}
/*
@@ -2032,6 +2049,9 @@ static int cmd_scrub_status(const struct cmd_struct *cmd, int argc, char **argv)
pr_verbose(LOG_DEFAULT, "UUID: %s\n", fsid);
if (do_stats_per_dev) {
+ if (json_output)
+ fmt_print_start_group(&fctx, "devices", JSON_TYPE_ARRAY);
+
for (i = 0; i < fi_args.num_devices; ++i) {
u64 limit;
@@ -2049,6 +2069,10 @@ static int cmd_scrub_status(const struct cmd_struct *cmd, int argc, char **argv)
"history" : "status",
&last_scrub->stats, limit);
}
+
+ if (json_output)
+ fmt_print_end_group(&fctx, "devices");
+
} else {
u64 total_bytes_used = 0;
struct btrfs_ioctl_space_info *sp = si_args->spaces;