diff options
author | Kevin Wolf <kwolf@redhat.com> | 2017-02-17 20:42:32 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2017-02-28 20:47:51 +0100 |
commit | 12fa4af61fb2a08b156134c3b6717534c637c995 (patch) | |
tree | bd93d226c7af3454aa64b64bdb771b8fc5d22083 /block | |
parent | c8f6d58edb0defbe1e90d44419ec8ec6d711c341 (diff) |
block: Add Error parameter to bdrv_set_backing_hd()
Not all callers of bdrv_set_backing_hd() know for sure that attaching
the backing file will be allowed by the permission system. Return the
error from the function rather than aborting.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Acked-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/commit.c | 14 | ||||
-rw-r--r-- | block/mirror.c | 7 | ||||
-rw-r--r-- | block/stream.c | 9 | ||||
-rw-r--r-- | block/vvfat.c | 2 |
4 files changed, 22 insertions, 10 deletions
diff --git a/block/commit.c b/block/commit.c index 1e0f5318a4..22a0a4db98 100644 --- a/block/commit.c +++ b/block/commit.c @@ -121,7 +121,7 @@ static void commit_complete(BlockJob *job, void *opaque) * filter driver from the backing chain. Do this as the final step so that * the 'consistent read' permission can be granted. */ if (remove_commit_top_bs) { - bdrv_set_backing_hd(overlay_bs, top); + bdrv_set_backing_hd(overlay_bs, top, &error_abort); } } @@ -316,8 +316,8 @@ void commit_start(const char *job_id, BlockDriverState *bs, goto fail; } - bdrv_set_backing_hd(commit_top_bs, top); - bdrv_set_backing_hd(overlay_bs, commit_top_bs); + bdrv_set_backing_hd(commit_top_bs, top, &error_abort); + bdrv_set_backing_hd(overlay_bs, commit_top_bs, &error_abort); s->commit_top_bs = commit_top_bs; bdrv_unref(commit_top_bs); @@ -390,7 +390,7 @@ fail: blk_unref(s->top); } if (commit_top_bs) { - bdrv_set_backing_hd(overlay_bs, top); + bdrv_set_backing_hd(overlay_bs, top, &error_abort); } block_job_unref(&s->common); } @@ -451,8 +451,8 @@ int bdrv_commit(BlockDriverState *bs) goto ro_cleanup; } - bdrv_set_backing_hd(commit_top_bs, backing_file_bs); - bdrv_set_backing_hd(bs, commit_top_bs); + bdrv_set_backing_hd(commit_top_bs, backing_file_bs, &error_abort); + bdrv_set_backing_hd(bs, commit_top_bs, &error_abort); ret = blk_insert_bs(backing, backing_file_bs, &local_err); if (ret < 0) { @@ -532,7 +532,7 @@ ro_cleanup: blk_unref(backing); if (backing_file_bs) { - bdrv_set_backing_hd(bs, backing_file_bs); + bdrv_set_backing_hd(bs, backing_file_bs, &error_abort); } bdrv_unref(commit_top_bs); blk_unref(src); diff --git a/block/mirror.c b/block/mirror.c index 869212daac..8497e0db83 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -503,6 +503,7 @@ static void mirror_exit(BlockJob *job, void *opaque) BlockDriverState *src = s->source; BlockDriverState *target_bs = blk_bs(s->target); BlockDriverState *mirror_top_bs = s->mirror_top_bs; + Error *local_err = NULL; /* Make sure that the source BDS doesn't go away before we called * block_job_completed(). */ @@ -516,7 +517,11 @@ static void mirror_exit(BlockJob *job, void *opaque) if (s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) { BlockDriverState *backing = s->is_none_mode ? src : s->base; if (backing_bs(target_bs) != backing) { - bdrv_set_backing_hd(target_bs, backing); + bdrv_set_backing_hd(target_bs, backing, &local_err); + if (local_err) { + error_report_err(local_err); + data->ret = -EPERM; + } } } diff --git a/block/stream.c b/block/stream.c index b9c2f43c57..0113710845 100644 --- a/block/stream.c +++ b/block/stream.c @@ -68,6 +68,7 @@ static void stream_complete(BlockJob *job, void *opaque) StreamCompleteData *data = opaque; BlockDriverState *bs = blk_bs(job->blk); BlockDriverState *base = s->base; + Error *local_err = NULL; if (!block_job_is_cancelled(&s->common) && data->reached_end && data->ret == 0) { @@ -79,9 +80,15 @@ static void stream_complete(BlockJob *job, void *opaque) } } data->ret = bdrv_change_backing_file(bs, base_id, base_fmt); - bdrv_set_backing_hd(bs, base); + bdrv_set_backing_hd(bs, base, &local_err); + if (local_err) { + error_report_err(local_err); + data->ret = -EPERM; + goto out; + } } +out: /* Reopen the image back in read-only mode if necessary */ if (s->bs_flags != bdrv_get_flags(bs)) { /* Give up write permissions before making it read-only */ diff --git a/block/vvfat.c b/block/vvfat.c index 72b482cb1f..aa61c329e7 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3041,7 +3041,7 @@ static int enable_write_target(BlockDriverState *bs, Error **errp) &error_abort); *(void**) backing->opaque = s; - bdrv_set_backing_hd(s->bs, backing); + bdrv_set_backing_hd(s->bs, backing, &error_abort); bdrv_unref(backing); return 0; |