From: Racz Zoltan <racz.zoli@gmail.com>
To: dsterba@suse.cz
Cc: linux-btrfs@vger.kernel.org, Racz Zoltan <racz.zoli@gmail.com>
Subject: [PATCH 5/6] btrfs-progs: Added json output format for cmd_scrub_status
Date: Fri, 14 Feb 2025 18:47:08 +0200 [thread overview]
Message-ID: <20250214164709.51465-6-racz.zoli@gmail.com> (raw)
In-Reply-To: <20250214164709.51465-1-racz.zoli@gmail.com>
---
cmds/scrub.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/cmds/scrub.c b/cmds/scrub.c
index 1f3f032f..e47c1869 100644
--- a/cmds/scrub.c
+++ b/cmds/scrub.c
@@ -1991,6 +1991,8 @@ static int cmd_scrub_status(const struct cmd_struct *cmd, int argc, char **argv)
int fdres = -1;
int err = 0;
+ const bool json_output = (bconf.output_format == CMD_FORMAT_JSON);
+
unit_mode = get_unit_mode_from_arg(&argc, argv, 0);
optind = 0;
@@ -2069,9 +2071,18 @@ static int cmd_scrub_status(const struct cmd_struct *cmd, int argc, char **argv)
}
in_progress = is_scrub_running_in_kernel(fdmnt, di_args, fi_args.num_devices);
- pr_verbose(LOG_DEFAULT, "UUID: %s\n", fsid);
+
+ if (json_output) {
+ fmt_start(&fctx, scrub_status_rowspec, 1, 0);
+ fmt_print_start_group(&fctx, "scrub-status", JSON_TYPE_MAP);
+ fmt_print(&fctx, "uuid", fsid);
+ } else
+ 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;
@@ -2089,6 +2100,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;
@@ -2116,10 +2131,16 @@ static int cmd_scrub_status(const struct cmd_struct *cmd, int argc, char **argv)
/* This is still slightly off for RAID56 */
total_bytes_used += sp->used_bytes * factor;
}
+
print_fs_stat(&fs_stat, print_raw, total_bytes_used,
fi_args.num_devices, limit);
}
+ if (json_output) {
+ fmt_print_end_group(&fctx, "scrub-status");
+ fmt_end(&fctx);
+ }
+
out:
free_history(past_scrubs);
free(di_args);
@@ -2130,7 +2151,7 @@ out:
return !!err;
}
-static DEFINE_SIMPLE_COMMAND(scrub_status, "status");
+static DEFINE_COMMAND_WITH_FLAGS(scrub_status, "status", CMD_FORMAT_JSON);
static const char * const cmd_scrub_limit_usage[] = {
"btrfs scrub limit [options] <path>",
--
2.48.1
next prev parent reply other threads:[~2025-02-14 16:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-14 16:47 [PATCH 0/6] btrfs-progs: V2 scrub status: add json output format Racz Zoltan
2025-02-14 16:47 ` [PATCH 1/6] btrfs-progs: Added rowspec struct and neccesary include file for " Racz Zoltan
2025-02-14 16:47 ` [PATCH 2/6] btrfs-progs: Added json output format for print_scrub_full Racz Zoltan
2025-02-14 16:47 ` [PATCH 3/6] btrfs-progs: Added json output format for print_scrub_summary Racz Zoltan
2025-02-14 16:47 ` [PATCH 4/6] btrfs-progs: Added json output format for _print_scrub_ss and print_scrub_dev Racz Zoltan
2025-02-14 16:47 ` Racz Zoltan [this message]
2025-02-14 16:47 ` [PATCH 6/6] btrfs-progs: Corrected a minor JSON string error in print_scrub_dev Racz Zoltan
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=20250214164709.51465-6-racz.zoli@gmail.com \
--to=racz.zoli@gmail.com \
--cc=dsterba@suse.cz \
--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