]> git.hungrycats.org Git - bees/commitdiff
extent scan: don't divide by zero if there were no loops
authorZygo Blaxell <bees@furryterror.org>
Fri, 14 Feb 2025 04:41:31 +0000 (23:41 -0500)
committerZygo Blaxell <bees@furryterror.org>
Fri, 14 Feb 2025 04:59:42 +0000 (23:59 -0500)
Commit 183b6a5361e040d7cc70c3b3391f43e0d126bc33 ("extent scan: refactor
BeesCrawl, BeesScanMode*") moved some statistics calculations out of
the loop in `find_next_extent`, but did not ensure that the statistics
would not be calculated if the loop had not executed any iterations.

In rare instances, the function returns without entering the loop at all,
which results in divide by zero.  Add a check just before doing that.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
src/bees-roots.cc

index d72531ec7464472ac128509ac7e0d87084a3eb15..c4b2381c6e1166439f3637efdb043b01beba0bc5 100644 (file)
@@ -948,22 +948,24 @@ BeesScanModeExtent::SizeTier::find_next_extent()
                const auto search_calls = BtrfsIoctlSearchKey::s_calls - init_s_calls;
                const auto search_loops = BtrfsIoctlSearchKey::s_loops - init_s_loops;
                if (crawl_time.age() > 1) {
-                       BEESLOGDEBUG(
-                               "loop_count " << loop_count
-                               << " size_low_count " << size_low_count
-                               << " size_high_count " << size_high_count
-                               << " gen_low_count " << gen_low_count
-                               << " gen_high_count " << gen_high_count
-                               << " search_calls " << search_calls
-                               << " search_loops " << search_loops
-                               << " skips " << skip_count
-                               << " flops " << flop_count
-                               << " time " << crawl_time
-                               << " subvol " << m_subvol
-                               << " search/loop " << pretty(search_calls / loop_count)
-                               << " skip/loop " << (100 * skip_count / loop_count) << "%"
-                               << " flop/loop " << (100 * flop_count / loop_count) << "%"
-                       );
+                       if (loop_count) {
+                               BEESLOGDEBUG(
+                                       "loop_count " << loop_count
+                                       << " size_low_count " << size_low_count
+                                       << " size_high_count " << size_high_count
+                                       << " gen_low_count " << gen_low_count
+                                       << " gen_high_count " << gen_high_count
+                                       << " search_calls " << search_calls
+                                       << " search_loops " << search_loops
+                                       << " skips " << skip_count
+                                       << " flops " << flop_count
+                                       << " time " << crawl_time
+                                       << " subvol " << m_subvol
+                                       << " search/loop " << pretty(search_calls / loop_count)
+                                       << " skip/loop " << (100 * skip_count / loop_count) << "%"
+                                       << " flop/loop " << (100 * flop_count / loop_count) << "%"
+                               );
+                       }
                        if (debug_oss) {
                                BEESLOGDEBUG("debug oss trace:\n" << debug_oss->str());
                        }