diff mbox series

btrfs-progs: Simplified unit_mode check in print_scrub_summary

Message ID 20250214152332.20057-1-racz.zoli@gmail.com (mailing list archive)
State New
Headers show
Series btrfs-progs: Simplified unit_mode check in print_scrub_summary | expand

Commit Message

Racz Zoltan Feb. 14, 2025, 3:23 p.m. UTC
Extracting the unit_mode == UNITS_RAW check from the current if/else
statement reduces redundancy in printing the rate and limit values. This
also will make it easier to implement JSON output formatting with less
redundancy in the print_scrub_summary function.

--
 cmds/scrub.c | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)
diff mbox series

Patch

diff --git a/cmds/scrub.c b/cmds/scrub.c
index 508eafb7..f769188a 100644
--- a/cmds/scrub.c
+++ b/cmds/scrub.c
@@ -209,30 +209,18 @@  static void print_scrub_summary(struct btrfs_scrub_progress *p, struct scrub_sta
 	 * Rate and size units are disproportionate so they are affected only
 	 * by --raw, otherwise it's human readable (respecting the SI or IEC mode).
 	 */
-	if (unit_mode == UNITS_RAW) {
-		pr_verbose(LOG_DEFAULT, "Rate:             %s/s",
-			pretty_size_mode(bytes_per_sec, UNITS_RAW));
-		if (limit > 1)
-			pr_verbose(LOG_DEFAULT, " (limit %s/s)",
-				   pretty_size_mode(limit, UNITS_RAW));
-		else if (limit == 1)
-			pr_verbose(LOG_DEFAULT, " (some device limits set)");
-		pr_verbose(LOG_DEFAULT, "\n");
-	} else {
-		unsigned int mode = UNITS_HUMAN_DECIMAL;
-
-		if (unit_mode & UNITS_BINARY)
-			mode = UNITS_HUMAN_BINARY;
-
-		pr_verbose(LOG_DEFAULT, "Rate:             %s/s",
-			pretty_size_mode(bytes_per_sec, mode));
-		if (limit > 1)
-			pr_verbose(LOG_DEFAULT, " (limit %s/s)",
-				   pretty_size_mode(limit, mode));
-		else if (limit == 1)
-			pr_verbose(LOG_DEFAULT, " (some device limits set)");
-		pr_verbose(LOG_DEFAULT, "\n");
-	}
+	unsigned int mode = UNITS_RAW;
+	if (unit_mode != UNITS_RAW) 
+		mode = unit_mode & UNITS_BINARY ? UNITS_HUMAN_BINARY : UNITS_HUMAN_DECIMAL;
+
+	pr_verbose(LOG_DEFAULT, "Rate:             %s/s",
+		pretty_size_mode(bytes_per_sec, mode));
+	if (limit > 1)
+		pr_verbose(LOG_DEFAULT, " (limit %s/s)",
+				pretty_size_mode(limit, mode));
+	else if (limit == 1)
+		pr_verbose(LOG_DEFAULT, " (some device limits set)");
+	pr_verbose(LOG_DEFAULT, "\n");
 
 	pr_verbose(LOG_DEFAULT, "Error summary:   ");
 	if (err_cnt || err_cnt2) {