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 4/6] btrfs-progs: Added json output format for _print_scrub_ss and print_scrub_dev
Date: Fri, 14 Feb 2025 18:47:07 +0200 [thread overview]
Message-ID: <20250214164709.51465-5-racz.zoli@gmail.com> (raw)
In-Reply-To: <20250214164709.51465-1-racz.zoli@gmail.com>
---
cmds/scrub.c | 79 +++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 59 insertions(+), 20 deletions(-)
diff --git a/cmds/scrub.c b/cmds/scrub.c
index 5c05d00f..1f3f032f 100644
--- a/cmds/scrub.c
+++ b/cmds/scrub.c
@@ -403,32 +403,61 @@ static void _print_scrub_ss(struct scrub_stats *ss)
struct tm tm;
time_t seconds;
unsigned hours;
+ char *status;
+
+ const bool json_output = (bconf.output_format == CMD_FORMAT_JSON);
if (!ss || !ss->t_start) {
- pr_verbose(LOG_DEFAULT, "\tno stats available\n");
+ if (!json_output)
+ pr_verbose(LOG_DEFAULT, "\tno stats available\n");
+
return;
}
+
+ if (json_output)
+ fmt_print_start_group(&fctx, "info", JSON_TYPE_MAP);
+
if (ss->t_resumed) {
- localtime_r(&ss->t_resumed, &tm);
- strftime(t, sizeof(t), "%c", &tm);
- t[sizeof(t) - 1] = '\0';
- pr_verbose(LOG_DEFAULT, "Scrub resumed: %s\n", t);
+ if (json_output)
+ fmt_print(&fctx, "resumed-at", ss->t_resumed);
+ else {
+ localtime_r(&ss->t_resumed, &tm);
+ strftime(t, sizeof(t), "%c", &tm);
+ t[sizeof(t) - 1] = '\0';
+
+ pr_verbose(LOG_DEFAULT, "Scrub resumed: %s\n", t);
+ }
} else {
- localtime_r(&ss->t_start, &tm);
- strftime(t, sizeof(t), "%c", &tm);
- t[sizeof(t) - 1] = '\0';
- pr_verbose(LOG_DEFAULT, "Scrub started: %s\n", t);
- }
-
- seconds = ss->duration;
- hours = ss->duration / (60 * 60);
- gmtime_r(&seconds, &tm);
- strftime(t, sizeof(t), "%M:%S", &tm);
- pr_verbose(LOG_DEFAULT, "Status: %s\n",
- (ss->in_progress ? "running" :
+ if (json_output)
+ fmt_print(&fctx, "started-at", ss->t_start);
+ else {
+ localtime_r(&ss->t_start, &tm);
+ strftime(t, sizeof(t), "%c", &tm);
+ t[sizeof(t) - 1] = '\0';
+
+ pr_verbose(LOG_DEFAULT, "Scrub started: %s\n", t);
+ }
+ }
+
+ status = (ss->in_progress ? "running" :
(ss->canceled ? "aborted" :
- (ss->finished ? "finished" : "interrupted"))));
- pr_verbose(LOG_DEFAULT, "Duration: %u:%s\n", hours, t);
+ (ss->finished ? "finished" : "interrupted")));
+
+
+ if (json_output) {
+ fmt_print(&fctx, "status", status);
+ fmt_print(&fctx, "duration", ss->duration);
+ fmt_print_end_group(&fctx, "info");
+ } else {
+ seconds = ss->duration;
+ hours = ss->duration / (60 * 60);
+ gmtime_r(&seconds, &tm);
+ strftime(t, sizeof(t), "%M:%S", &tm);
+
+ pr_verbose(LOG_DEFAULT, "Status: %s\n", status);
+ pr_verbose(LOG_DEFAULT, "Duration: %u:%s\n", hours, t);
+ }
+
}
static void print_scrub_dev(struct btrfs_ioctl_dev_info_args *di,
@@ -436,7 +465,14 @@ static void print_scrub_dev(struct btrfs_ioctl_dev_info_args *di,
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);
@@ -461,6 +497,9 @@ 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");
}
/*
--
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 ` Racz Zoltan [this message]
2025-02-14 16:47 ` [PATCH 5/6] btrfs-progs: Added json output format for cmd_scrub_status Racz Zoltan
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-5-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