Skip to content

Commit

Permalink
lib-fs: Added asserts to make sure async writes are finished before c…
Browse files Browse the repository at this point in the history
…lose
  • Loading branch information
sirainen committed May 12, 2016
1 parent 8b8534c commit d4a85e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib-fs/fs-api-private.h
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/lib-fs/fs-api.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d4a85e1

Please sign in to comment.