提交 318df29e 编写于 作者: M Markus Armbruster 提交者: Stefan Hajnoczi

block/sheepdog: Propagate errors through sd_prealloc()

Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
上级 356b4ca2
...@@ -1537,21 +1537,18 @@ static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot) ...@@ -1537,21 +1537,18 @@ static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot)
return 0; return 0;
} }
static int sd_prealloc(const char *filename) static int sd_prealloc(const char *filename, Error **errp)
{ {
BlockDriverState *bs = NULL; BlockDriverState *bs = NULL;
uint32_t idx, max_idx; uint32_t idx, max_idx;
int64_t vdi_size; int64_t vdi_size;
void *buf = g_malloc0(SD_DATA_OBJ_SIZE); void *buf = g_malloc0(SD_DATA_OBJ_SIZE);
Error *local_err = NULL;
int ret; int ret;
ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
NULL, &local_err); NULL, errp);
if (ret < 0) { if (ret < 0) {
qerror_report_err(local_err); goto out_with_err_set;
error_free(local_err);
goto out;
} }
vdi_size = bdrv_getlength(bs); vdi_size = bdrv_getlength(bs);
...@@ -1575,7 +1572,12 @@ static int sd_prealloc(const char *filename) ...@@ -1575,7 +1572,12 @@ static int sd_prealloc(const char *filename)
goto out; goto out;
} }
} }
out: out:
if (ret < 0) {
error_setg_errno(errp, -ret, "Can't pre-allocate");
}
out_with_err_set:
if (bs) { if (bs) {
bdrv_unref(bs); bdrv_unref(bs);
} }
...@@ -1734,7 +1736,11 @@ static int sd_create(const char *filename, QEMUOptionParameter *options, ...@@ -1734,7 +1736,11 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
goto out; goto out;
} }
ret = sd_prealloc(filename); ret = sd_prealloc(filename, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
}
out: out:
g_free(s); g_free(s);
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册