Skip to content

Commit

Permalink
fs-randomfail: Fixed assert-crash in fs_write_stream_abort_error()
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Sep 9, 2016
1 parent 063b8d8 commit bd64561
Showing 1 changed file with 24 additions and 71 deletions.
95 changes: 24 additions & 71 deletions src/lib-fs/fs-randomfail.c
Expand Up @@ -25,7 +25,7 @@ struct randomfail_fs {

struct randomfail_fs_file {
struct fs_file file;
struct fs_file *super, *super_read;
struct fs_file *super_read;
struct istream *input;
bool op_pending[FS_OP_COUNT];

Expand Down Expand Up @@ -218,43 +218,19 @@ fs_randomfail_file_init(struct fs *_fs, const char *path,
file = i_new(struct randomfail_fs_file, 1);
file->file.fs = _fs;
file->file.path = i_strdup(path);
file->super = fs_file_init(_fs->parent, path, mode | flags);
file->file.parent = fs_file_init(_fs->parent, path, mode | flags);
return &file->file;
}

static void fs_randomfail_file_deinit(struct fs_file *_file)
{
struct randomfail_fs_file *file = (struct randomfail_fs_file *)_file;

fs_file_deinit(&file->super);
fs_file_deinit(&file->file.parent);
i_free(file->file.path);
i_free(file);
}

static void fs_randomfail_file_close(struct fs_file *_file)
{
struct randomfail_fs_file *file = (struct randomfail_fs_file *)_file;

fs_file_close(file->super);
}

static const char *fs_randomfail_file_get_path(struct fs_file *_file)
{
struct randomfail_fs_file *file = (struct randomfail_fs_file *)_file;

return fs_file_path(file->super);
}

static void
fs_randomfail_set_async_callback(struct fs_file *_file,
fs_file_async_callback_t *callback,
void *context)
{
struct randomfail_fs_file *file = (struct randomfail_fs_file *)_file;

fs_file_set_async_callback(file->super, callback, context);
}

static bool fs_random_fail(struct fs *_fs, int divider, enum fs_op op)
{
struct randomfail_fs *fs = (struct randomfail_fs *)_fs;
Expand Down Expand Up @@ -303,22 +279,6 @@ fs_random_fail_range(struct fs *_fs, enum fs_op op, uoff_t *offset_r)
return TRUE;
}

static int fs_randomfail_wait_async(struct fs *_fs)
{
if (fs_random_fail(_fs, 1, FS_OP_WAIT))
return -1;
return fs_wait_async(_fs->parent);
}

static void
fs_randomfail_set_metadata(struct fs_file *_file, const char *key,
const char *value)
{
struct randomfail_fs_file *file = (struct randomfail_fs_file *)_file;

fs_set_metadata(file->super, key, value);
}

static int
fs_randomfail_get_metadata(struct fs_file *_file,
const ARRAY_TYPE(fs_metadata) **metadata_r)
Expand All @@ -328,17 +288,15 @@ fs_randomfail_get_metadata(struct fs_file *_file,

if (fs_file_random_fail_begin(file, FS_OP_METADATA))
return -1;
ret = fs_get_metadata(file->super, metadata_r);
ret = fs_get_metadata(_file->parent, metadata_r);
return fs_file_random_fail_end(file, ret, FS_OP_METADATA);
}

static bool fs_randomfail_prefetch(struct fs_file *_file, uoff_t length)
{
struct randomfail_fs_file *file = (struct randomfail_fs_file *)_file;

if (fs_random_fail(_file->fs, 1, FS_OP_PREFETCH))
return TRUE;
return fs_prefetch(file->super, length);
return fs_prefetch(_file->parent, length);
}

static ssize_t fs_randomfail_read(struct fs_file *_file, void *buf, size_t size)
Expand All @@ -348,18 +306,17 @@ static ssize_t fs_randomfail_read(struct fs_file *_file, void *buf, size_t size)

if (fs_file_random_fail_begin(file, FS_OP_READ))
return -1;
ret = fs_read(file->super, buf, size);
ret = fs_read(_file->parent, buf, size);
return fs_file_random_fail_end(file, ret, FS_OP_READ);
}

static struct istream *
fs_randomfail_read_stream(struct fs_file *_file, size_t max_buffer_size)
{
struct randomfail_fs_file *file = (struct randomfail_fs_file *)_file;
struct istream *input, *input2;
uoff_t offset;

input = fs_read_stream(file->super, max_buffer_size);
input = fs_read_stream(_file->parent, max_buffer_size);
if (!fs_random_fail_range(_file->fs, FS_OP_READ, &offset))
return input;
input2 = i_stream_create_failure_at(input, offset, RANDOMFAIL_ERROR);
Expand All @@ -374,7 +331,7 @@ static int fs_randomfail_write(struct fs_file *_file, const void *data, size_t s

if (fs_file_random_fail_begin(file, FS_OP_WRITE))
return -1;
ret = fs_write(file->super, data, size);
ret = fs_write(_file->parent, data, size);
return fs_file_random_fail_end(file, ret, FS_OP_EXISTS);
}

Expand All @@ -385,7 +342,7 @@ static void fs_randomfail_write_stream(struct fs_file *_file)

i_assert(_file->output == NULL);

file->super_output = fs_write_stream(file->super);
file->super_output = fs_write_stream(_file->parent);
if (!fs_random_fail_range(_file->fs, FS_OP_WRITE, &offset))
_file->output = file->super_output;
else {
Expand All @@ -408,21 +365,19 @@ static int fs_randomfail_write_stream_finish(struct fs_file *_file, bool success
return -1;
}
if (!fs_random_fail(_file->fs, 1, FS_OP_WRITE)) {
fs_write_stream_abort_error(file->super, &file->super_output, RANDOMFAIL_ERROR);
fs_write_stream_abort_error(_file->parent, &file->super_output, RANDOMFAIL_ERROR);
return -1;
}
}
return fs_write_stream_finish(file->super, &file->super_output);
return fs_write_stream_finish(_file->parent, &file->super_output);
}

static int
fs_randomfail_lock(struct fs_file *_file, unsigned int secs, struct fs_lock **lock_r)
{
struct randomfail_fs_file *file = (struct randomfail_fs_file *)_file;

if (fs_random_fail(_file->fs, 1, FS_OP_LOCK))
return -1;
return fs_lock(file->super, secs, lock_r);
return fs_lock(_file->parent, secs, lock_r);
}

static void fs_randomfail_unlock(struct fs_lock *_lock ATTR_UNUSED)
Expand All @@ -437,7 +392,7 @@ static int fs_randomfail_exists(struct fs_file *_file)

if (fs_file_random_fail_begin(file, FS_OP_EXISTS))
return -1;
ret = fs_exists(file->super);
ret = fs_exists(_file->parent);
return fs_file_random_fail_end(file, ret, FS_OP_EXISTS);
}

Expand All @@ -448,7 +403,7 @@ static int fs_randomfail_stat(struct fs_file *_file, struct stat *st_r)

if (fs_file_random_fail_begin(file, FS_OP_STAT))
return -1;
ret = fs_stat(file->super, st_r);
ret = fs_stat(_file->parent, st_r);
return fs_file_random_fail_end(file, ret, FS_OP_STAT);
}

Expand All @@ -459,35 +414,33 @@ static int fs_randomfail_get_nlinks(struct fs_file *_file, nlink_t *nlinks_r)

if (fs_file_random_fail_begin(file, FS_OP_STAT))
return -1;
ret = fs_get_nlinks(file->super, nlinks_r);
ret = fs_get_nlinks(_file->parent, nlinks_r);
return fs_file_random_fail_end(file, ret, FS_OP_STAT);
}

static int fs_randomfail_copy(struct fs_file *_src, struct fs_file *_dest)
{
struct randomfail_fs_file *src = (struct randomfail_fs_file *)_src;
struct randomfail_fs_file *dest = (struct randomfail_fs_file *)_dest;
int ret;

if (fs_file_random_fail_begin(dest, FS_OP_COPY))
return -1;

if (_src != NULL)
ret = fs_copy(src->super, dest->super);
ret = fs_copy(_src->parent, _dest->parent);
else
ret = fs_copy_finish_async(dest->super);
ret = fs_copy_finish_async(_dest->parent);
return fs_file_random_fail_end(dest, ret, FS_OP_COPY);
}

static int fs_randomfail_rename(struct fs_file *_src, struct fs_file *_dest)
{
struct randomfail_fs_file *src = (struct randomfail_fs_file *)_src;
struct randomfail_fs_file *dest = (struct randomfail_fs_file *)_dest;
int ret;

if (fs_file_random_fail_begin(dest, FS_OP_RENAME))
return -1;
ret = fs_rename(src->super, dest->super);
ret = fs_rename(_src->parent, _dest->parent);
return fs_file_random_fail_end(dest, ret, FS_OP_RENAME);
}

Expand All @@ -498,7 +451,7 @@ static int fs_randomfail_delete(struct fs_file *_file)

if (fs_file_random_fail_begin(file, FS_OP_DELETE))
return -1;
ret = fs_delete(file->super);
ret = fs_delete(_file->parent);
return fs_file_random_fail_end(file, ret, FS_OP_DELETE);
}

Expand Down Expand Up @@ -561,11 +514,11 @@ const struct fs fs_class_randomfail = {
fs_randomfail_get_properties,
fs_randomfail_file_init,
fs_randomfail_file_deinit,
fs_randomfail_file_close,
fs_randomfail_file_get_path,
fs_randomfail_set_async_callback,
fs_randomfail_wait_async,
fs_randomfail_set_metadata,
fs_wrapper_file_close,
fs_wrapper_file_get_path,
fs_wrapper_set_async_callback,
fs_wrapper_wait_async,
fs_wrapper_set_metadata,
fs_randomfail_get_metadata,
fs_randomfail_prefetch,
fs_randomfail_read,
Expand Down

0 comments on commit bd64561

Please sign in to comment.