From: Pavel Hrdina <phrdina@redhat.com>
To: qemu-devel@nongnu.org
Cc: phrdina@redhat.com, armbru@redhat.com, lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH 08/11] block: update error reporting for bdrv_snapshot_create() and related functions
Date: Tue, 16 Apr 2013 18:05:20 +0200 [thread overview]
Message-ID: <acd6e17b7efc83e76a24f14ba8cfe8a55c370224.1366127809.git.phrdina@redhat.com> (raw)
In-Reply-To: <cover.1366127809.git.phrdina@redhat.com>
In-Reply-To: <cover.1366127809.git.phrdina@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
block.c | 23 ++++++++++++++---------
block/qcow2-snapshot.c | 18 ++++++++++++------
block/qcow2.h | 4 +++-
block/rbd.c | 20 +++++++++++---------
block/sheepdog.c | 22 +++++++++++-----------
include/block/block.h | 5 +++--
include/block/block_int.h | 5 +++--
qemu-img.c | 8 +++-----
savevm.c | 9 +++++----
9 files changed, 65 insertions(+), 49 deletions(-)
diff --git a/block.c b/block.c
index a760a2f..7cf24f5 100644
--- a/block.c
+++ b/block.c
@@ -3352,17 +3352,22 @@ BlockDriverState *bdrv_snapshots(void)
return NULL;
}
-int bdrv_snapshot_create(BlockDriverState *bs,
- QEMUSnapshotInfo *sn_info)
+void bdrv_snapshot_create(BlockDriverState *bs,
+ QEMUSnapshotInfo *sn_info,
+ Error **errp)
{
BlockDriver *drv = bs->drv;
- if (!drv)
- return -ENOMEDIUM;
- if (drv->bdrv_snapshot_create)
- return drv->bdrv_snapshot_create(bs, sn_info);
- if (bs->file)
- return bdrv_snapshot_create(bs->file, sn_info);
- return -ENOTSUP;
+
+ if (!drv) {
+ error_setg(errp, "device '%s' has no medium", bdrv_get_device_name(bs));
+ } else if (drv->bdrv_snapshot_create) {
+ drv->bdrv_snapshot_create(bs, sn_info, errp);
+ } else if (bs->file) {
+ bdrv_snapshot_create(bs->file, sn_info, errp);
+ } else {
+ error_setg(errp, "snapshots are not supported on device '%s'",
+ bdrv_get_device_name(bs));
+ }
}
void bdrv_snapshot_goto(BlockDriverState *bs,
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 4a69b88..bb6a35d 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -315,7 +315,9 @@ static int find_snapshot_by_id_or_name(BlockDriverState *bs, const char *name)
}
/* if no id is provided, a new one is constructed */
-int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
+void qcow2_snapshot_create(BlockDriverState *bs,
+ QEMUSnapshotInfo *sn_info,
+ Error **errp)
{
BDRVQcowState *s = bs->opaque;
QCowSnapshot *new_snapshot_list = NULL;
@@ -334,7 +336,8 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
/* Check that the ID is unique */
if (find_snapshot_by_id(bs, sn_info->id_str) >= 0) {
- return -EEXIST;
+ error_setg(errp, "qcow2: parameter 'id' has to be unique ID");
+ return;
}
/* Populate sn with passed data */
@@ -350,7 +353,8 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
/* Allocate the L1 table of the snapshot and copy the current one there. */
l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t));
if (l1_table_offset < 0) {
- ret = l1_table_offset;
+ error_setg_errno(errp, -l1_table_offset,
+ "qcow2: failed to allocate L1 table");
goto fail;
}
@@ -365,6 +369,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
ret = bdrv_pwrite(bs->file, sn->l1_table_offset, l1_table,
s->l1_size * sizeof(uint64_t));
if (ret < 0) {
+ error_setg_errno(errp, -ret, "qcow2: failed to save L1 table");
goto fail;
}
@@ -378,6 +383,8 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
*/
ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1);
if (ret < 0) {
+ error_setg_errno(errp, -ret,
+ "qcow2: failed to update snapshot refcount");
goto fail;
}
@@ -395,6 +402,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
if (ret < 0) {
g_free(s->snapshots);
s->snapshots = old_snapshot_list;
+ error_setg_errno(errp, -ret, "qcow2: failed to write new snapshot");
goto fail;
}
@@ -406,14 +414,12 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
qcow2_check_refcounts(bs, &result, 0);
}
#endif
- return 0;
+ return;
fail:
g_free(sn->id_str);
g_free(sn->name);
g_free(l1_table);
-
- return ret;
}
/* copy the snapshot 'snapshot_name' into the current disk image */
diff --git a/block/qcow2.h b/block/qcow2.h
index ae62953..c194cff 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -382,7 +382,9 @@ int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors);
/* qcow2-snapshot.c functions */
-int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
+void qcow2_snapshot_create(BlockDriverState *bs,
+ QEMUSnapshotInfo *sn_info,
+ Error **errp);
void qcow2_snapshot_goto(BlockDriverState *bs,
const char *snapshot_id,
Error **errp);
diff --git a/block/rbd.c b/block/rbd.c
index 9259621..1f073fe 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -839,14 +839,16 @@ static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset)
return 0;
}
-static int qemu_rbd_snap_create(BlockDriverState *bs,
- QEMUSnapshotInfo *sn_info)
+static void qemu_rbd_snap_create(BlockDriverState *bs,
+ QEMUSnapshotInfo *sn_info,
+ Error **errp)
{
BDRVRBDState *s = bs->opaque;
int r;
if (sn_info->name[0] == '\0') {
- return -EINVAL; /* we need a name for rbd snapshots */
+ error_setg(errp, "rbd: parameter 'name' cannot be empty");
+ return;
}
/*
@@ -855,20 +857,20 @@ static int qemu_rbd_snap_create(BlockDriverState *bs,
*/
if (sn_info->id_str[0] != '\0' &&
strcmp(sn_info->id_str, sn_info->name) != 0) {
- return -EINVAL;
+ error_setg(errp, "rbd: ID and name have to be equal");
+ return;
}
if (strlen(sn_info->name) >= sizeof(sn_info->id_str)) {
- return -ERANGE;
+ error_setg(errp, "rbd: parameter 'name' has to be shorter than %zd "
+ "chars", sizeof(sn_info->id_str));
+ return;
}
r = rbd_snap_create(s->image, sn_info->name);
if (r < 0) {
- error_report("failed to create snap: %s", strerror(-r));
- return r;
+ error_setg_errno(errp, -r, "rbd: failed to create snapshot");
}
-
- return 0;
}
static void qemu_rbd_snap_remove(BlockDriverState *bs,
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 3d44575..996441d 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1767,7 +1767,9 @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs)
return acb->ret;
}
-static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
+static void sd_snapshot_create(BlockDriverState *bs,
+ QEMUSnapshotInfo *sn_info,
+ Error **errp)
{
BDRVSheepdogState *s = bs->opaque;
int ret, fd;
@@ -1780,10 +1782,10 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
s->name, sn_info->vm_state_size, s->is_snapshot);
if (s->is_snapshot) {
- error_report("You can't create a snapshot of a snapshot VDI, "
- "%s (%" PRIu32 ").", s->name, s->inode.vdi_id);
-
- return -EINVAL;
+ error_setg(errp, "sd: you can't create a snapshot '%s' of a snapshot "
+ "VDI %s (%" PRIu32 ")", sn_info->name, s->name,
+ s->inode.vdi_id);
+ return;
}
dprintf("%s %s\n", sn_info->name, sn_info->id_str);
@@ -1800,22 +1802,21 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
/* refresh inode. */
fd = connect_to_sdog(s);
if (fd < 0) {
- ret = fd;
+ error_setg_errno(errp, -fd, "sd: failed to connect to sdog");
goto cleanup;
}
ret = write_object(fd, (char *)&s->inode, vid_to_vdi_oid(s->inode.vdi_id),
s->inode.nr_copies, datalen, 0, false, s->cache_flags);
if (ret < 0) {
- error_report("failed to write snapshot's inode.");
+ error_setg_errno(errp, -ret, "sd: failed to write snapshot's inode");
goto cleanup;
}
ret = do_sd_create(s, s->name, s->inode.vdi_size, s->inode.vdi_id, &new_vid,
1);
if (ret < 0) {
- error_report("failed to create inode for snapshot. %s",
- strerror(errno));
+ error_setg_errno(errp, -ret, "sd: failed to create inode for snapshot");
goto cleanup;
}
@@ -1825,7 +1826,7 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
s->inode.nr_copies, datalen, 0, s->cache_flags);
if (ret < 0) {
- error_report("failed to read new inode info. %s", strerror(errno));
+ error_setg_errno(errp, -ret, "sd: failed to read new inode info");
goto cleanup;
}
@@ -1835,7 +1836,6 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
cleanup:
closesocket(fd);
- return ret;
}
static void sd_snapshot_goto(BlockDriverState *bs,
diff --git a/include/block/block.h b/include/block/block.h
index 33d498b..fb5a864 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -333,8 +333,9 @@ BlockStats *bdrv_query_stats(const BlockDriverState *bs);
int bdrv_can_snapshot(BlockDriverState *bs);
int bdrv_is_snapshot(BlockDriverState *bs);
BlockDriverState *bdrv_snapshots(void);
-int bdrv_snapshot_create(BlockDriverState *bs,
- QEMUSnapshotInfo *sn_info);
+void bdrv_snapshot_create(BlockDriverState *bs,
+ QEMUSnapshotInfo *sn_info,
+ Error **errp);
void bdrv_snapshot_goto(BlockDriverState *bs,
const char *snapshot_id,
Error **errp);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index c56d923..9903874 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -153,8 +153,9 @@ struct BlockDriver {
int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
const uint8_t *buf, int nb_sectors);
- int (*bdrv_snapshot_create)(BlockDriverState *bs,
- QEMUSnapshotInfo *sn_info);
+ void (*bdrv_snapshot_create)(BlockDriverState *bs,
+ QEMUSnapshotInfo *sn_info,
+ Error **errp);
void (*bdrv_snapshot_goto)(BlockDriverState *bs,
const char *snapshot_id,
Error **errp);
diff --git a/qemu-img.c b/qemu-img.c
index 06cd8af..2e420f3 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2024,11 +2024,9 @@ static int img_snapshot(int argc, char **argv)
sn.date_sec = tv.tv_sec;
sn.date_nsec = tv.tv_usec * 1000;
- ret = bdrv_snapshot_create(bs, &sn);
- if (ret) {
- error_report("Could not create snapshot '%s': %d (%s)",
- snapshot_name, ret, strerror(-ret));
- }
+ bdrv_snapshot_create(bs, &sn, &local_err);
+ ret = qemu_img_handle_error("qemu-img snapshot create failed",
+ local_err);
break;
case SNAPSHOT_APPLY:
diff --git a/savevm.c b/savevm.c
index 1258f5f..a8e7d60 100644
--- a/savevm.c
+++ b/savevm.c
@@ -2283,6 +2283,7 @@ void do_savevm(Monitor *mon, const QDict *qdict)
qemu_timeval tv;
struct tm tm;
const char *name = qdict_get_try_str(qdict, "name");
+ Error *local_err = NULL;
/* Verify if there is a device that doesn't support snapshots and is writable */
bs = NULL;
@@ -2355,10 +2356,10 @@ void do_savevm(Monitor *mon, const QDict *qdict)
if (bdrv_can_snapshot(bs1)) {
/* Write VM state size only to the image that contains the state */
sn->vm_state_size = (bs == bs1 ? vm_state_size : 0);
- ret = bdrv_snapshot_create(bs1, sn);
- if (ret < 0) {
- monitor_printf(mon, "Error while creating snapshot on '%s'\n",
- bdrv_get_device_name(bs1));
+ bdrv_snapshot_create(bs1, sn, &local_err);
+ if (error_is_set(&local_err)) {
+ monitor_printf(mon, "'%s'\n", error_get_pretty(local_err));
+ error_free(local_err);
}
}
}
--
1.8.1.4
next prev parent reply other threads:[~2013-04-16 16:05 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-16 16:05 [Qemu-devel] [PATCH 00/11] covert savevm, loadvm and delvm into qapi Pavel Hrdina
2013-04-16 16:05 ` [Qemu-devel] [PATCH 01/11] qemu-img: introduce qemu_img_handle_error() Pavel Hrdina
2013-04-16 16:46 ` Eric Blake
2013-04-18 11:44 ` Kevin Wolf
2013-04-18 11:52 ` Pavel Hrdina
2013-04-18 12:59 ` Kevin Wolf
2013-04-18 13:09 ` Pavel Hrdina
2013-04-18 15:23 ` Luiz Capitulino
2013-04-16 16:05 ` [Qemu-devel] [PATCH 02/11] block: update error reporting for bdrv_snapshot_delete() and related functions Pavel Hrdina
2013-04-16 17:14 ` Eric Blake
2013-04-18 12:55 ` Kevin Wolf
2013-04-18 13:09 ` Eric Blake
2013-04-18 13:51 ` Kevin Wolf
2013-04-18 13:19 ` Pavel Hrdina
2013-04-18 13:41 ` Kevin Wolf
2013-04-16 16:05 ` [Qemu-devel] [PATCH 03/11] savevm: update bdrv_snapshot_find() to find snapshot by id or name Pavel Hrdina
2013-04-16 17:34 ` Eric Blake
2013-04-18 13:17 ` Kevin Wolf
2013-04-16 16:05 ` [Qemu-devel] [PATCH 04/11] qapi: Convert delvm Pavel Hrdina
2013-04-16 19:39 ` Eric Blake
2013-04-18 13:28 ` Kevin Wolf
2013-04-16 16:05 ` [Qemu-devel] [PATCH 05/11] block: update error reporting for bdrv_snapshot_goto() and related functions Pavel Hrdina
2013-04-16 20:48 ` Eric Blake
2013-04-23 14:08 ` Kevin Wolf
2013-04-16 16:05 ` [Qemu-devel] [PATCH 06/11] savevm: update error reporting for qemu_loadvm_state() Pavel Hrdina
2013-04-16 21:42 ` Eric Blake
2013-04-16 16:05 ` [Qemu-devel] [PATCH 07/11] qapi: Convert loadvm Pavel Hrdina
2013-04-16 23:43 ` Eric Blake
2013-04-18 10:34 ` Pavel Hrdina
2013-04-16 16:05 ` Pavel Hrdina [this message]
2013-04-16 23:54 ` [Qemu-devel] [PATCH 08/11] block: update error reporting for bdrv_snapshot_create() and related functions Eric Blake
2013-04-16 16:05 ` [Qemu-devel] [PATCH 09/11] savevm: update error reporting off qemu_savevm_state() " Pavel Hrdina
2013-04-17 0:02 ` Eric Blake
2013-04-16 16:05 ` [Qemu-devel] [PATCH 10/11] qapi: Convert savevm Pavel Hrdina
2013-04-16 16:05 ` [Qemu-devel] [PATCH 11/11] savevm: remove backward compatibility from bdrv_snapshot_find() Pavel Hrdina
2013-04-17 2:53 ` Wenchao Xia
2013-04-17 7:52 ` Pavel Hrdina
2013-04-17 10:19 ` Wenchao Xia
2013-04-17 10:51 ` Pavel Hrdina
2013-04-17 18:14 ` Eric Blake
2013-04-17 18:22 ` Eric Blake
2013-04-18 4:31 ` Wenchao Xia
2013-04-18 7:20 ` Wenchao Xia
2013-04-18 10:22 ` Pavel Hrdina
2013-04-19 0:28 ` Wenchao Xia
2013-04-24 3:51 ` Wenchao Xia
2013-04-24 9:37 ` Pavel Hrdina
2013-04-16 16:33 ` [Qemu-devel] [PATCH 00/11] covert savevm, loadvm and delvm into qapi Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=acd6e17b7efc83e76a24f14ba8cfe8a55c370224.1366127809.git.phrdina@redhat.com \
--to=phrdina@redhat.com \
--cc=armbru@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).