diff options
author | Kevin Wolf | 2017-11-20 15:28:41 +0100 |
---|---|---|
committer | Kevin Wolf | 2017-11-21 14:48:22 +0100 |
commit | 0b62bcbc61c0cd4c9e7fb3863cf5dc8016b0b4ed (patch) | |
tree | 1c1bd135fafcacd62f4ae1799831242f50e2344e /block | |
parent | block: Don't request I/O permission with BDRV_O_NO_IO (diff) | |
download | qemu-0b62bcbc61c0cd4c9e7fb3863cf5dc8016b0b4ed.tar.gz qemu-0b62bcbc61c0cd4c9e7fb3863cf5dc8016b0b4ed.tar.xz qemu-0b62bcbc61c0cd4c9e7fb3863cf5dc8016b0b4ed.zip |
block: Add errp to bdrv_snapshot_goto()
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/snapshot.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/block/snapshot.c b/block/snapshot.c index be0743abac..75562df4cc 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -177,18 +177,21 @@ int bdrv_snapshot_create(BlockDriverState *bs, } int bdrv_snapshot_goto(BlockDriverState *bs, - const char *snapshot_id) + const char *snapshot_id, + Error **errp) { BlockDriver *drv = bs->drv; int ret, open_ret; int64_t len; if (!drv) { + error_setg(errp, "Block driver is closed"); return -ENOMEDIUM; } len = bdrv_getlength(bs); if (len < 0) { + error_setg_errno(errp, -len, "Cannot get block device size"); return len; } /* We should set all bits in all enabled dirty bitmaps, because dirty @@ -200,13 +203,18 @@ int bdrv_snapshot_goto(BlockDriverState *bs, bdrv_set_dirty(bs, 0, len); if (drv->bdrv_snapshot_goto) { - return drv->bdrv_snapshot_goto(bs, snapshot_id); + ret = drv->bdrv_snapshot_goto(bs, snapshot_id); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to load snapshot"); + } + return ret; } if (bs->file) { BlockDriverState *file; QDict *options = qdict_clone_shallow(bs->options); QDict *file_options; + Error *local_err = NULL; file = bs->file->bs; /* Prevent it from getting deleted when detached from bs */ @@ -220,13 +228,15 @@ int bdrv_snapshot_goto(BlockDriverState *bs, bdrv_unref_child(bs, bs->file); bs->file = NULL; - ret = bdrv_snapshot_goto(file, snapshot_id); - open_ret = drv->bdrv_open(bs, options, bs->open_flags, NULL); + ret = bdrv_snapshot_goto(file, snapshot_id, errp); + open_ret = drv->bdrv_open(bs, options, bs->open_flags, &local_err); QDECREF(options); if (open_ret < 0) { bdrv_unref(file); bs->drv = NULL; - return open_ret; + /* A bdrv_snapshot_goto() error takes precedence */ + error_propagate(errp, local_err); + return ret < 0 ? ret : open_ret; } assert(bs->file->bs == file); @@ -234,6 +244,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs, return ret; } + error_setg(errp, "Block driver does not support snapshots"); return -ENOTSUP; } @@ -467,7 +478,7 @@ int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_bs) aio_context_acquire(ctx); if (bdrv_can_snapshot(bs)) { - err = bdrv_snapshot_goto(bs, name); + err = bdrv_snapshot_goto(bs, name, NULL); } aio_context_release(ctx); if (err < 0) { |