From: Timo Sirainen Date: Tue, 17 Aug 2021 09:12:18 +0000 (+0300) Subject: lib-fs: Fix fs_stats.copy_count tracking with fs_default_copy() X-Git-Tag: 2.3.17~187 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=730b2a449f8253d44fb761f9939b62a41f631523;p=thirdparty%2Fdovecot%2Fcore.git lib-fs: Fix fs_stats.copy_count tracking with fs_default_copy() The copy_count could have been decreased too many times with async operations. --- diff --git a/src/lib-fs/fs-api-private.h b/src/lib-fs/fs-api-private.h index 07545253b0..76eb2c5a32 100644 --- a/src/lib-fs/fs-api-private.h +++ b/src/lib-fs/fs-api-private.h @@ -141,6 +141,7 @@ struct fs_file { bool read_or_prefetch_counted:1; bool lookup_metadata_counted:1; bool stat_counted:1; + bool copy_counted:1; bool istream_open:1; bool last_error_changed:1; }; diff --git a/src/lib-fs/fs-api.c b/src/lib-fs/fs-api.c index 048d22af6c..1b47ded6c5 100644 --- a/src/lib-fs/fs-api.c +++ b/src/lib-fs/fs-api.c @@ -1095,9 +1095,9 @@ int fs_get_nlinks(struct fs_file *file, nlink_t *nlinks_r) int fs_default_copy(struct fs_file *src, struct fs_file *dest) { int tmp_errno; - /* we're going to be counting this as read+write, so remove the - copy_count we just added */ - dest->fs->stats.copy_count--; + /* we're going to be counting this as read+write, so don't update + copy_count */ + dest->copy_counted = TRUE; if (dest->copy_src != NULL) { i_assert(src == NULL || src == dest->copy_src); @@ -1163,7 +1163,10 @@ int fs_copy(struct fs_file *src, struct fs_file *dest) } T_END; if (!(ret < 0 && errno == EAGAIN)) { fs_file_timing_end(dest, FS_OP_COPY); - dest->fs->stats.copy_count++; + if (dest->copy_counted) + dest->copy_counted = FALSE; + else + dest->fs->stats.copy_count++; dest->metadata_changed = FALSE; } return ret; @@ -1178,7 +1181,10 @@ int fs_copy_finish_async(struct fs_file *dest) } T_END; if (!(ret < 0 && errno == EAGAIN)) { fs_file_timing_end(dest, FS_OP_COPY); - dest->fs->stats.copy_count++; + if (dest->copy_counted) + dest->copy_counted = FALSE; + else + dest->fs->stats.copy_count++; dest->metadata_changed = FALSE; } return ret;