Whamcloud - gitweb
e4defrag: adjust total count when files change during the run
authorTheodore Ts'o <tytso@mit.edu>
Fri, 4 Jan 2019 04:06:42 +0000 (23:06 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 4 Jan 2019 04:06:42 +0000 (23:06 -0500)
If files are created while e4defrag is running, it's quite possible
for succeed_cnt to be larger than total_count, in which case the
number of failures (calculated via total_count - succeed_cnt) will
overflow and become a very large unsigned number.

The way we calculate statistics is a bit silly, since when recurse
into directories is counted, it's counted as a "failure".  But we'll
ignore this from now, and avoid the unsigned overflow.

Address-Debian-Bug: #888899

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/e4defrag.c

index 9d237da..b0a825f 100644 (file)
@@ -1055,6 +1055,8 @@ static int file_statistic(const char *file, const struct stat64 *buf,
        struct fiemap_extent_list *logical_list_head = NULL;
 
        defraged_file_count++;
+       if (defraged_file_count > total_count)
+               total_count = defraged_file_count;
 
        if (mode_flag & DETAIL) {
                if (total_count == 1 && regular_count == 1)
@@ -1421,6 +1423,8 @@ static int file_defrag(const char *file, const struct stat64 *buf,
        struct fiemap_extent_group      *orig_group_tmp = NULL;
 
        defraged_file_count++;
+       if (defraged_file_count > total_count)
+               total_count = defraged_file_count;
 
        if (mode_flag & DETAIL) {
                printf("[%u/%u]", defraged_file_count, total_count);