block/sheepdog: Propagate errors to open and create methods

Completes the conversion to Error started in commit 015a103^..d5124c0,
except for a few bugs fixed in the next commit.

Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Markus Armbruster 2014-05-16 11:00:24 +02:00 committed by Stefan Hajnoczi
parent dc83cd427b
commit e67c399363
1 changed files with 12 additions and 28 deletions

View File

@ -1391,8 +1391,7 @@ static int sd_open(BlockDriverState *bs, QDict *options, int flags,
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err); qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) { if (local_err) {
qerror_report_err(local_err); error_propagate(errp, local_err);
error_free(local_err);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
@ -1415,18 +1414,14 @@ static int sd_open(BlockDriverState *bs, QDict *options, int flags,
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }
s->fd = get_sheep_fd(s, &local_err); s->fd = get_sheep_fd(s, errp);
if (s->fd < 0) { if (s->fd < 0) {
qerror_report_err(local_err);
error_free(local_err);
ret = s->fd; ret = s->fd;
goto out; goto out;
} }
ret = find_vdi_name(s, vdi, snapid, tag, &vid, true, &local_err); ret = find_vdi_name(s, vdi, snapid, tag, &vid, true, errp);
if (ret) { if (ret) {
qerror_report_err(local_err);
error_free(local_err);
goto out; goto out;
} }
@ -1445,10 +1440,8 @@ static int sd_open(BlockDriverState *bs, QDict *options, int flags,
s->is_snapshot = true; s->is_snapshot = true;
} }
fd = connect_to_sdog(s, &local_err); fd = connect_to_sdog(s, errp);
if (fd < 0) { if (fd < 0) {
qerror_report_err(local_err);
error_free(local_err);
ret = fd; ret = fd;
goto out; goto out;
} }
@ -1651,7 +1644,6 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
char tag[SD_MAX_VDI_TAG_LEN]; char tag[SD_MAX_VDI_TAG_LEN];
uint32_t snapid; uint32_t snapid;
bool prealloc = false; bool prealloc = false;
Error *local_err = NULL;
s = g_malloc0(sizeof(BDRVSheepdogState)); s = g_malloc0(sizeof(BDRVSheepdogState));
@ -1676,7 +1668,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
} else if (!strcmp(options->value.s, "full")) { } else if (!strcmp(options->value.s, "full")) {
prealloc = true; prealloc = true;
} else { } else {
error_report("Invalid preallocation mode: '%s'", error_setg(errp, "Invalid preallocation mode: '%s'",
options->value.s); options->value.s);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
@ -1693,7 +1685,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
} }
if (s->inode.vdi_size > SD_MAX_VDI_SIZE) { if (s->inode.vdi_size > SD_MAX_VDI_SIZE) {
error_report("too big image size"); error_setg(errp, "too big image size");
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
@ -1706,24 +1698,22 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
/* Currently, only Sheepdog backing image is supported. */ /* Currently, only Sheepdog backing image is supported. */
drv = bdrv_find_protocol(backing_file, true); drv = bdrv_find_protocol(backing_file, true);
if (!drv || strcmp(drv->protocol_name, "sheepdog") != 0) { if (!drv || strcmp(drv->protocol_name, "sheepdog") != 0) {
error_report("backing_file must be a sheepdog image"); error_setg(errp, "backing_file must be a sheepdog image");
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
bs = NULL; bs = NULL;
ret = bdrv_open(&bs, backing_file, NULL, NULL, BDRV_O_PROTOCOL, NULL, ret = bdrv_open(&bs, backing_file, NULL, NULL, BDRV_O_PROTOCOL, NULL,
&local_err); errp);
if (ret < 0) { if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
goto out; goto out;
} }
base = bs->opaque; base = bs->opaque;
if (!is_snapshot(&base->inode)) { if (!is_snapshot(&base->inode)) {
error_report("cannot clone from a non snapshot vdi"); error_setg(errp, "cannot clone from a non snapshot vdi");
bdrv_unref(bs); bdrv_unref(bs);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
@ -1732,19 +1722,13 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
bdrv_unref(bs); bdrv_unref(bs);
} }
ret = do_sd_create(s, &vid, 0, &local_err); ret = do_sd_create(s, &vid, 0, errp);
if (ret) { if (ret) {
qerror_report_err(local_err);
error_free(local_err);
goto out; goto out;
} }
if (prealloc) { if (prealloc) {
ret = sd_prealloc(filename, &local_err); ret = sd_prealloc(filename, errp);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
}
} }
out: out:
g_free(s); g_free(s);