Skip to contentSkip to conversation

btrfs-progs: Simplified unit_mode check in print_scrub_summary

PATCH New Racz Zoltan 1 participant 1 message Feb 14, 2025 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: Simplified unit_mode check in print_scrub_summary

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(-)
cmds/scrub.c +12 -24
index 508eafb7..f769188a 100644
@@ -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) {
Signature · 1 line
2.48.1