diff mbox series

[2/6] btrfs-progs: Added json output format for print_scrub_full

Message ID 20250214164709.51465-3-racz.zoli@gmail.com (mailing list archive)
State New
Headers show
Series btrfs-progs: V2 scrub status: add json output format | expand

Commit Message

Racz Zoltan Feb. 14, 2025, 4:47 p.m. UTC
---
 cmds/scrub.c | 52 +++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/cmds/scrub.c b/cmds/scrub.c
index f049e1ed..caada704 100644
--- a/cmds/scrub.c
+++ b/cmds/scrub.c
@@ -162,21 +162,43 @@  static const struct rowspec scrub_status_rowspec[] = {
 
 static void print_scrub_full(struct btrfs_scrub_progress *sp)
 {
-	pr_verbose(LOG_DEFAULT, "\tdata_extents_scrubbed: %llu\n", sp->data_extents_scrubbed);
-	pr_verbose(LOG_DEFAULT, "\ttree_extents_scrubbed: %llu\n", sp->tree_extents_scrubbed);
-	pr_verbose(LOG_DEFAULT, "\tdata_bytes_scrubbed: %llu\n", sp->data_bytes_scrubbed);
-	pr_verbose(LOG_DEFAULT, "\ttree_bytes_scrubbed: %llu\n", sp->tree_bytes_scrubbed);
-	pr_verbose(LOG_DEFAULT, "\tread_errors: %llu\n", sp->read_errors);
-	pr_verbose(LOG_DEFAULT, "\tcsum_errors: %llu\n", sp->csum_errors);
-	pr_verbose(LOG_DEFAULT, "\tverify_errors: %llu\n", sp->verify_errors);
-	pr_verbose(LOG_DEFAULT, "\tno_csum: %llu\n", sp->no_csum);
-	pr_verbose(LOG_DEFAULT, "\tcsum_discards: %llu\n", sp->csum_discards);
-	pr_verbose(LOG_DEFAULT, "\tsuper_errors: %llu\n", sp->super_errors);
-	pr_verbose(LOG_DEFAULT, "\tmalloc_errors: %llu\n", sp->malloc_errors);
-	pr_verbose(LOG_DEFAULT, "\tuncorrectable_errors: %llu\n", sp->uncorrectable_errors);
-	pr_verbose(LOG_DEFAULT, "\tunverified_errors: %llu\n", sp->unverified_errors);
-	pr_verbose(LOG_DEFAULT, "\tcorrected_errors: %llu\n", sp->corrected_errors);
-	pr_verbose(LOG_DEFAULT, "\tlast_physical: %llu\n", sp->last_physical);
+	if (bconf.output_format == CMD_FORMAT_JSON) {
+		fmt_print_start_group(&fctx, "scrub", JSON_TYPE_MAP);
+
+		fmt_print(&fctx, "data-extents-scrubbed", sp->data_extents_scrubbed);
+		fmt_print(&fctx, "tree-extents-scrubbed", sp->tree_extents_scrubbed);
+		fmt_print(&fctx, "data-bytes-scrubbed", sp->data_bytes_scrubbed);
+		fmt_print(&fctx, "tree-bytes-scrubbed", sp->tree_bytes_scrubbed);
+		fmt_print(&fctx, "read-errors", sp->read_errors);
+		fmt_print(&fctx, "csum-errors", sp->csum_errors);
+		fmt_print(&fctx, "verify-errors", sp->verify_errors);
+		fmt_print(&fctx, "no-csum", sp->no_csum);
+		fmt_print(&fctx, "csum-discards", sp->csum_discards);
+		fmt_print(&fctx, "super-errors", sp->super_errors);
+		fmt_print(&fctx, "malloc-errors", sp->malloc_errors);
+		fmt_print(&fctx, "uncorrectable-errors", sp->uncorrectable_errors);
+		fmt_print(&fctx, "unverified-errors", sp->unverified_errors);
+		fmt_print(&fctx, "corrected-errors", sp->corrected_errors);
+		fmt_print(&fctx, "last-physical", sp->last_physical);
+
+		fmt_print_end_group(&fctx, "scrub");
+	} else {
+		pr_verbose(LOG_DEFAULT, "\tdata_extents_scrubbed: %llu\n", sp->data_extents_scrubbed);
+		pr_verbose(LOG_DEFAULT, "\ttree_extents_scrubbed: %llu\n", sp->tree_extents_scrubbed);
+		pr_verbose(LOG_DEFAULT, "\tdata_bytes_scrubbed: %llu\n", sp->data_bytes_scrubbed);
+		pr_verbose(LOG_DEFAULT, "\ttree_bytes_scrubbed: %llu\n", sp->tree_bytes_scrubbed);
+		pr_verbose(LOG_DEFAULT, "\tread_errors: %llu\n", sp->read_errors);
+		pr_verbose(LOG_DEFAULT, "\tcsum_errors: %llu\n", sp->csum_errors);
+		pr_verbose(LOG_DEFAULT, "\tverify_errors: %llu\n", sp->verify_errors);
+		pr_verbose(LOG_DEFAULT, "\tno_csum: %llu\n", sp->no_csum);
+		pr_verbose(LOG_DEFAULT, "\tcsum_discards: %llu\n", sp->csum_discards);
+		pr_verbose(LOG_DEFAULT, "\tsuper_errors: %llu\n", sp->super_errors);
+		pr_verbose(LOG_DEFAULT, "\tmalloc_errors: %llu\n", sp->malloc_errors);
+		pr_verbose(LOG_DEFAULT, "\tuncorrectable_errors: %llu\n", sp->uncorrectable_errors);
+		pr_verbose(LOG_DEFAULT, "\tunverified_errors: %llu\n", sp->unverified_errors);
+		pr_verbose(LOG_DEFAULT, "\tcorrected_errors: %llu\n", sp->corrected_errors);
+		pr_verbose(LOG_DEFAULT, "\tlast_physical: %llu\n", sp->last_physical);
+	}
 }
 
 #define PRINT_SCRUB_ERROR(test, desc) do {	\