block/sheepdog: Propagate errors through do_sd_create()

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:22 +02:00 committed by Stefan Hajnoczi
parent 318df29e10
commit 7d2d3e74e5

View File

@ -1481,19 +1481,17 @@ out:
return ret; return ret;
} }
static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot) static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot,
Error **errp)
{ {
Error *local_err = NULL;
SheepdogVdiReq hdr; SheepdogVdiReq hdr;
SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr; SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;
int fd, ret; int fd, ret;
unsigned int wlen, rlen = 0; unsigned int wlen, rlen = 0;
char buf[SD_MAX_VDI_LEN]; char buf[SD_MAX_VDI_LEN];
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);
return fd; return fd;
} }
@ -1522,11 +1520,12 @@ static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot)
closesocket(fd); closesocket(fd);
if (ret) { if (ret) {
error_setg_errno(errp, -ret, "create failed");
return ret; return ret;
} }
if (rsp->result != SD_RES_SUCCESS) { if (rsp->result != SD_RES_SUCCESS) {
error_report("%s, %s", sd_strerror(rsp->result), s->inode.name); error_setg(errp, "%s, %s", sd_strerror(rsp->result), s->inode.name);
return -EIO; return -EIO;
} }
@ -1731,15 +1730,19 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
bdrv_unref(bs); bdrv_unref(bs);
} }
ret = do_sd_create(s, &vid, 0); ret = do_sd_create(s, &vid, 0, &local_err);
if (!prealloc || ret) { if (ret) {
qerror_report_err(local_err);
error_free(local_err);
goto out; goto out;
} }
ret = sd_prealloc(filename, &local_err); if (prealloc) {
if (ret < 0) { ret = sd_prealloc(filename, &local_err);
qerror_report_err(local_err); if (ret < 0) {
error_free(local_err); qerror_report_err(local_err);
error_free(local_err);
}
} }
out: out:
g_free(s); g_free(s);
@ -1928,8 +1931,10 @@ static int sd_create_branch(BDRVSheepdogState *s)
* false bail out. * false bail out.
*/ */
deleted = sd_delete(s); deleted = sd_delete(s);
ret = do_sd_create(s, &vid, !deleted); ret = do_sd_create(s, &vid, !deleted, &local_err);
if (ret) { if (ret) {
qerror_report_err(local_err);
error_free(local_err);
goto out; goto out;
} }
@ -2197,8 +2202,10 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
goto cleanup; goto cleanup;
} }
ret = do_sd_create(s, &new_vid, 1); ret = do_sd_create(s, &new_vid, 1, &local_err);
if (ret < 0) { if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
error_report("failed to create inode for snapshot. %s", error_report("failed to create inode for snapshot. %s",
strerror(errno)); strerror(errno));
goto cleanup; goto cleanup;