]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-fs: Added asserts to make sure async writes are finished before close
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 12 May 2016 11:23:04 +0000 (07:23 -0400)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 12 May 2016 11:39:00 +0000 (07:39 -0400)
src/lib-fs/fs-api-private.h
src/lib-fs/fs-api.c

index d471dc46f68124046e365f55355e0808d46dfd17..5e152988a891b783e72c203268852a65a850728b 100644 (file)
@@ -115,6 +115,7 @@ struct fs_file {
        struct timeval timing_start[FS_OP_COUNT];
 
        unsigned int write_pending:1;
+       unsigned int writing_stream:1;
        unsigned int metadata_changed:1;
 
        unsigned int read_or_prefetch_counted:1;
index 1a2a5e2a458263de1b29fcb176ff914f6b66bf68..ed7e179c02d02c6b7d80f0350cb0c28bfffce0c9 100644 (file)
@@ -262,6 +262,9 @@ void fs_file_deinit(struct fs_file **_file)
 
 void fs_file_close(struct fs_file *file)
 {
+       i_assert(!file->writing_stream);
+       i_assert(file->output == NULL);
+
        if (file->pending_read_input != NULL)
                i_stream_unref(&file->pending_read_input);
        if (file->seekable_input != NULL)
@@ -632,6 +635,10 @@ int fs_write(struct fs_file *file, const void *data, size_t size)
 
 struct ostream *fs_write_stream(struct fs_file *file)
 {
+       i_assert(!file->writing_stream);
+       i_assert(file->output == NULL);
+
+       file->writing_stream = TRUE;
        file->fs->stats.write_count++;
        T_BEGIN {
                file->fs->v.write_stream(file);
@@ -645,6 +652,8 @@ static int fs_write_stream_finish_int(struct fs_file *file, bool success)
 {
        int ret;
 
+       i_assert(file->writing_stream);
+
        fs_file_timing_start(file, FS_OP_WRITE);
        T_BEGIN {
                ret = file->fs->v.write_stream_finish(file, success);
@@ -657,6 +666,8 @@ static int fs_write_stream_finish_int(struct fs_file *file, bool success)
                   indicated a failure. */
                i_assert(success);
        }
+       if (ret != 0)
+               file->writing_stream = FALSE;
        return ret;
 }
 
@@ -908,6 +919,8 @@ int fs_delete(struct fs_file *file)
 {
        int ret;
 
+       i_assert(!file->writing_stream);
+
        fs_file_timing_start(file, FS_OP_DELETE);
        T_BEGIN {
                ret = file->fs->v.delete_file(file);