[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 05/18] block: add error parameter to bdrv_snapshot_l
From: |
Pavel Hrdina |
Subject: |
[Qemu-devel] [PATCH 05/18] block: add error parameter to bdrv_snapshot_list() and related functions |
Date: |
Wed, 15 Aug 2012 09:41:46 +0200 |
Signed-off-by: Pavel Hrdina <address@hidden>
---
block.c | 25 +++++++++++++++++--------
block.h | 3 ++-
block/qcow2-snapshot.c | 4 +++-
block/qcow2.h | 4 +++-
block/rbd.c | 4 +++-
block/sheepdog.c | 11 +++++++++--
block_int.h | 3 ++-
qemu-img.c | 2 +-
savevm.c | 4 ++--
9 files changed, 42 insertions(+), 18 deletions(-)
diff --git a/block.c b/block.c
index 1480777..aa2965d 100644
--- a/block.c
+++ b/block.c
@@ -2735,16 +2735,25 @@ int bdrv_snapshot_delete(BlockDriverState *bs,
}
int bdrv_snapshot_list(BlockDriverState *bs,
- QEMUSnapshotInfo **psn_info)
+ QEMUSnapshotInfo **psn_info,
+ Error **errp)
{
BlockDriver *drv = bs->drv;
- if (!drv)
- return -ENOMEDIUM;
- if (drv->bdrv_snapshot_list)
- return drv->bdrv_snapshot_list(bs, psn_info);
- if (bs->file)
- return bdrv_snapshot_list(bs->file, psn_info);
- return -ENOTSUP;
+ int ret;
+
+ if (!drv) {
+ error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, bdrv_get_device_name(bs));
+ ret = -ENOMEDIUM;
+ } else if (drv->bdrv_snapshot_list) {
+ ret = drv->bdrv_snapshot_list(bs, psn_info, errp);
+ } else if (bs->file) {
+ ret = bdrv_snapshot_list(bs->file, psn_info, errp);
+ } else {
+ error_set(errp, QERR_NOT_SUPPORTED);
+ ret = -ENOTSUP;
+ }
+
+ return ret;
}
int bdrv_snapshot_load_tmp(BlockDriverState *bs,
diff --git a/block.h b/block.h
index 72586f2..da34af0 100644
--- a/block.h
+++ b/block.h
@@ -305,7 +305,8 @@ int bdrv_snapshot_delete(BlockDriverState *bs,
const char *snapshot_id,
Error **errp);
int bdrv_snapshot_list(BlockDriverState *bs,
- QEMUSnapshotInfo **psn_info);
+ QEMUSnapshotInfo **psn_info,
+ Error **errp);
int bdrv_snapshot_load_tmp(BlockDriverState *bs,
const char *snapshot_name);
char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 9162a5b..9708eb5 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -607,7 +607,9 @@ int qcow2_snapshot_delete(BlockDriverState *bs,
return 0;
}
-int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
+int qcow2_snapshot_list(BlockDriverState *bs,
+ QEMUSnapshotInfo **psn_tab,
+ Error **errp)
{
BDRVQcowState *s = bs->opaque;
QEMUSnapshotInfo *sn_tab, *sn_info;
diff --git a/block/qcow2.h b/block/qcow2.h
index 8dfdbb7..2fe5687 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -317,7 +317,9 @@ int qcow2_snapshot_goto(BlockDriverState *bs,
int qcow2_snapshot_delete(BlockDriverState *bs,
const char *snapshot_id,
Error **errp);
-int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
+int qcow2_snapshot_list(BlockDriverState *bs,
+ QEMUSnapshotInfo **psn_tab,
+ Error **errp);
int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name);
void qcow2_free_snapshots(BlockDriverState *bs);
diff --git a/block/rbd.c b/block/rbd.c
index 448d68d..d068e56 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -885,7 +885,8 @@ static int qemu_rbd_snap_rollback(BlockDriverState *bs,
}
static int qemu_rbd_snap_list(BlockDriverState *bs,
- QEMUSnapshotInfo **psn_tab)
+ QEMUSnapshotInfo **psn_tab,
+ Error **errp)
{
BDRVRBDState *s = bs->opaque;
QEMUSnapshotInfo *sn_info, *sn_tab = NULL;
@@ -902,6 +903,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs,
} while (snap_count == -ERANGE);
if (snap_count <= 0) {
+ error_set(errp, QERR_OPEN_FILE_FAILED, bdrv_get_device_name(bs));
goto done;
}
diff --git a/block/sheepdog.c b/block/sheepdog.c
index f864071..0835b11 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1880,7 +1880,9 @@ static int sd_snapshot_delete(BlockDriverState *bs,
return 0;
}
-static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
+static int sd_snapshot_list(BlockDriverState *bs,
+ QEMUSnapshotInfo **psn_tab,
+ Error **errp)
{
BDRVSheepdogState *s = bs->opaque;
SheepdogReq req;
@@ -1898,6 +1900,7 @@ static int sd_snapshot_list(BlockDriverState *bs,
QEMUSnapshotInfo **psn_tab)
fd = connect_to_sdog(s->addr, s->port);
if (fd < 0) {
+ error_set(errp, QERR_GENERIC_ERROR, fd);
ret = fd;
goto out;
}
@@ -1914,6 +1917,7 @@ static int sd_snapshot_list(BlockDriverState *bs,
QEMUSnapshotInfo **psn_tab)
closesocket(fd);
if (ret) {
+ error_set(errp, QERR_GENERIC_ERROR, ret);
goto out;
}
@@ -1925,7 +1929,7 @@ static int sd_snapshot_list(BlockDriverState *bs,
QEMUSnapshotInfo **psn_tab)
fd = connect_to_sdog(s->addr, s->port);
if (fd < 0) {
- error_report("failed to connect");
+ error_set(errp, QERR_GENERIC_ERROR, fd);
ret = fd;
goto out;
}
@@ -1965,6 +1969,9 @@ out:
g_free(vdi_inuse);
if (ret < 0) {
+ if (!error_is_set(errp)) {
+ error_set(errp, QERR_GENERIC_ERROR, ret);
+ }
return ret;
}
diff --git a/block_int.h b/block_int.h
index 4799abd..2c1c6e8 100644
--- a/block_int.h
+++ b/block_int.h
@@ -215,7 +215,8 @@ struct BlockDriver {
const char *snapshot_id,
Error **errp);
int (*bdrv_snapshot_list)(BlockDriverState *bs,
- QEMUSnapshotInfo **psn_info);
+ QEMUSnapshotInfo **psn_info,
+ Error **errp);
int (*bdrv_snapshot_load_tmp)(BlockDriverState *bs,
const char *snapshot_name);
int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
diff --git a/qemu-img.c b/qemu-img.c
index 6ac1904..20a9b60 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1090,7 +1090,7 @@ static void dump_snapshots(BlockDriverState *bs)
int nb_sns, i;
char buf[256];
- nb_sns = bdrv_snapshot_list(bs, &sn_tab);
+ nb_sns = bdrv_snapshot_list(bs, &sn_tab, NULL);
if (nb_sns <= 0)
return;
printf("Snapshot list:\n");
diff --git a/savevm.c b/savevm.c
index 4cf92d5..92da274 100644
--- a/savevm.c
+++ b/savevm.c
@@ -2022,7 +2022,7 @@ static int bdrv_snapshot_find(BlockDriverState *bs,
QEMUSnapshotInfo *sn_info,
int nb_sns, i, ret;
ret = -ENOENT;
- nb_sns = bdrv_snapshot_list(bs, &sn_tab);
+ nb_sns = bdrv_snapshot_list(bs, &sn_tab, NULL);
if (nb_sns < 0)
return ret;
for(i = 0; i < nb_sns; i++) {
@@ -2328,7 +2328,7 @@ void do_info_snapshots(Monitor *mon)
return;
}
- nb_sns = bdrv_snapshot_list(bs, &sn_tab);
+ nb_sns = bdrv_snapshot_list(bs, &sn_tab, NULL);
if (nb_sns < 0) {
monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
return;
--
1.7.11.2
[Qemu-devel] [PATCH 05/18] block: add error parameter to bdrv_snapshot_list() and related functions,
Pavel Hrdina <=
[Qemu-devel] [PATCH 04/18] block: add error parameter to bdrv_snapshot_delete() and related functions, Pavel Hrdina, 2012/08/15
[Qemu-devel] [PATCH 06/18] block: add error parameter to bdrv_snapshot_find(), Pavel Hrdina, 2012/08/15
[Qemu-devel] [PATCH 07/18] block: add error parameter to del_existing_snapshots(), Pavel Hrdina, 2012/08/15
[Qemu-devel] [PATCH 03/18] block: add error parameter to bdrv_snapshot_goto() and related functions, Pavel Hrdina, 2012/08/15
[Qemu-devel] [PATCH 08/18] savevm: add error parameter to qemu_savevm_state_begin(), Pavel Hrdina, 2012/08/15
[Qemu-devel] [PATCH 12/18] savevm: add error parameter to qemu_loadvm_state(), Pavel Hrdina, 2012/08/15
[Qemu-devel] [PATCH 11/18] savevm: add error parameter to qemu_savevm_state(), Pavel Hrdina, 2012/08/15
[Qemu-devel] [PATCH 09/18] savevm: add error parameter to qemu_savevm_state_iterate(), Pavel Hrdina, 2012/08/15