* [Qemu-devel] [PATCH] block: Add error handling to bdrv_invalidate_cache()
@ 2014-03-12 15:00 Kevin Wolf
2014-03-12 15:40 ` Eric Blake
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Kevin Wolf @ 2014-03-12 15:00 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha, quintela
If it returns an error, the migrated VM will not be started, but qemu
exits with an error message.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 28 ++++++++++++++++++++++------
block/qcow2.c | 22 +++++++++++++++++++---
block/qed.c | 21 ++++++++++++++++++---
include/block/block.h | 4 ++--
include/block/block_int.h | 2 +-
migration.c | 8 +++++++-
6 files changed, 69 insertions(+), 16 deletions(-)
diff --git a/block.c b/block.c
index 7b306fb..5f816e5 100644
--- a/block.c
+++ b/block.c
@@ -4774,27 +4774,43 @@ flush_parent:
return bdrv_co_flush(bs->file);
}
-void bdrv_invalidate_cache(BlockDriverState *bs)
+void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
{
+ Error *local_err = NULL;
+ int ret;
+
if (!bs->drv) {
return;
}
if (bs->drv->bdrv_invalidate_cache) {
- bs->drv->bdrv_invalidate_cache(bs);
+ bs->drv->bdrv_invalidate_cache(bs, &local_err);
} else if (bs->file) {
- bdrv_invalidate_cache(bs->file);
+ bdrv_invalidate_cache(bs->file, &local_err);
+ }
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
- refresh_total_sectors(bs, bs->total_sectors);
+ ret = refresh_total_sectors(bs, bs->total_sectors);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Could not refresh total sector count");
+ return;
+ }
}
-void bdrv_invalidate_cache_all(void)
+void bdrv_invalidate_cache_all(Error **errp)
{
BlockDriverState *bs;
+ Error *local_err = NULL;
QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
- bdrv_invalidate_cache(bs);
+ bdrv_invalidate_cache(bs, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
}
}
diff --git a/block/qcow2.c b/block/qcow2.c
index c75bb39..b8f951a 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1280,7 +1280,7 @@ static void qcow2_close(BlockDriverState *bs)
qcow2_free_snapshots(bs);
}
-static void qcow2_invalidate_cache(BlockDriverState *bs)
+static void qcow2_invalidate_cache(BlockDriverState *bs, Error **errp)
{
BDRVQcowState *s = bs->opaque;
int flags = s->flags;
@@ -1288,6 +1288,8 @@ static void qcow2_invalidate_cache(BlockDriverState *bs)
AES_KEY aes_decrypt_key;
uint32_t crypt_method = 0;
QDict *options;
+ Error *local_err = NULL;
+ int ret;
/*
* Backing files are read-only which makes all of their metadata immutable,
@@ -1302,11 +1304,25 @@ static void qcow2_invalidate_cache(BlockDriverState *bs)
qcow2_close(bs);
- bdrv_invalidate_cache(bs->file);
+ bdrv_invalidate_cache(bs->file, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
memset(s, 0, sizeof(BDRVQcowState));
options = qdict_clone_shallow(bs->options);
- qcow2_open(bs, options, flags, NULL);
+
+ ret = qcow2_open(bs, options, flags, &local_err);
+ if (local_err) {
+ error_setg(errp, "Could not reopen qcow2 layer: %s",
+ error_get_pretty(local_err));
+ error_free(local_err);
+ return;
+ } else if (ret < 0) {
+ error_setg_errno(errp, -ret, "Could not reopen qcow2 layer");
+ return;
+ }
QDECREF(options);
diff --git a/block/qed.c b/block/qed.c
index 837accd..3bd9db9 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1558,16 +1558,31 @@ static int bdrv_qed_change_backing_file(BlockDriverState *bs,
return ret;
}
-static void bdrv_qed_invalidate_cache(BlockDriverState *bs)
+static void bdrv_qed_invalidate_cache(BlockDriverState *bs, Error **errp)
{
BDRVQEDState *s = bs->opaque;
+ Error *local_err = NULL;
+ int ret;
bdrv_qed_close(bs);
- bdrv_invalidate_cache(bs->file);
+ bdrv_invalidate_cache(bs->file, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
memset(s, 0, sizeof(BDRVQEDState));
- bdrv_qed_open(bs, NULL, bs->open_flags, NULL);
+ ret = bdrv_qed_open(bs, NULL, bs->open_flags, &local_err);
+ if (local_err) {
+ error_setg(errp, "Could not reopen qed layer: %s",
+ error_get_pretty(local_err));
+ error_free(local_err);
+ return;
+ } else if (ret < 0) {
+ error_setg_errno(errp, -ret, "Could not reopen qed layer");
+ return;
+ }
}
static int bdrv_qed_check(BlockDriverState *bs, BdrvCheckResult *result,
diff --git a/include/block/block.h b/include/block/block.h
index 780f48b..e2b5df1 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -338,8 +338,8 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
BlockDriverCompletionFunc *cb, void *opaque);
/* Invalidate any cached metadata used by image formats */
-void bdrv_invalidate_cache(BlockDriverState *bs);
-void bdrv_invalidate_cache_all(void);
+void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
+void bdrv_invalidate_cache_all(Error **errp);
void bdrv_clear_incoming_migration_all(void);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 0bcf1c9..93d2518 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -153,7 +153,7 @@ struct BlockDriver {
/*
* Invalidate any cached meta-data.
*/
- void (*bdrv_invalidate_cache)(BlockDriverState *bs);
+ void (*bdrv_invalidate_cache)(BlockDriverState *bs, Error **errp);
/*
* Flushes all data that was already written to the OS all the way down to
diff --git a/migration.c b/migration.c
index 00f465e..e0e24d4 100644
--- a/migration.c
+++ b/migration.c
@@ -101,6 +101,7 @@ void qemu_start_incoming_migration(const char *uri, Error **errp)
static void process_incoming_migration_co(void *opaque)
{
QEMUFile *f = opaque;
+ Error *local_err = NULL;
int ret;
ret = qemu_loadvm_state(f);
@@ -115,7 +116,12 @@ static void process_incoming_migration_co(void *opaque)
bdrv_clear_incoming_migration_all();
/* Make sure all file formats flush their mutable metadata */
- bdrv_invalidate_cache_all();
+ bdrv_invalidate_cache_all(&local_err);
+ if (local_err) {
+ qerror_report_err(local_err);
+ error_free(local_err);
+ exit(EXIT_FAILURE);
+ }
if (autostart) {
vm_start();
--
1.8.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] block: Add error handling to bdrv_invalidate_cache()
2014-03-12 15:00 [Qemu-devel] [PATCH] block: Add error handling to bdrv_invalidate_cache() Kevin Wolf
@ 2014-03-12 15:40 ` Eric Blake
2014-03-12 16:22 ` Juan Quintela
2014-03-18 8:57 ` Kevin Wolf
2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2014-03-12 15:40 UTC (permalink / raw)
To: Kevin Wolf, qemu-devel; +Cc: stefanha, quintela
[-- Attachment #1: Type: text/plain, Size: 1327 bytes --]
On 03/12/2014 09:00 AM, Kevin Wolf wrote:
> If it returns an error, the migrated VM will not be started, but qemu
> exits with an error message.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> block.c | 28 ++++++++++++++++++++++------
> block/qcow2.c | 22 +++++++++++++++++++---
> block/qed.c | 21 ++++++++++++++++++---
> include/block/block.h | 4 ++--
> include/block/block_int.h | 2 +-
> migration.c | 8 +++++++-
> 6 files changed, 69 insertions(+), 16 deletions(-)
>
> @@ -115,7 +116,12 @@ static void process_incoming_migration_co(void *opaque)
>
> bdrv_clear_incoming_migration_all();
> /* Make sure all file formats flush their mutable metadata */
> - bdrv_invalidate_cache_all();
> + bdrv_invalidate_cache_all(&local_err);
> + if (local_err) {
> + qerror_report_err(local_err);
> + error_free(local_err);
> + exit(EXIT_FAILURE);
Freeing before exit() is wasted cpu cycles, but doesn't hurt the common
case, and keeping the error_free() makes valgrind a bit happier, so I'm
not opposed to leaving it as-is.
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] block: Add error handling to bdrv_invalidate_cache()
2014-03-12 15:00 [Qemu-devel] [PATCH] block: Add error handling to bdrv_invalidate_cache() Kevin Wolf
2014-03-12 15:40 ` Eric Blake
@ 2014-03-12 16:22 ` Juan Quintela
2014-03-18 8:57 ` Kevin Wolf
2 siblings, 0 replies; 4+ messages in thread
From: Juan Quintela @ 2014-03-12 16:22 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel, stefanha
Kevin Wolf <kwolf@redhat.com> wrote:
> If it returns an error, the migrated VM will not be started, but qemu
> exits with an error message.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] block: Add error handling to bdrv_invalidate_cache()
2014-03-12 15:00 [Qemu-devel] [PATCH] block: Add error handling to bdrv_invalidate_cache() Kevin Wolf
2014-03-12 15:40 ` Eric Blake
2014-03-12 16:22 ` Juan Quintela
@ 2014-03-18 8:57 ` Kevin Wolf
2 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2014-03-18 8:57 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, quintela
Am 12.03.2014 um 16:00 hat Kevin Wolf geschrieben:
> If it returns an error, the migrated VM will not be started, but qemu
> exits with an error message.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-03-18 8:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-12 15:00 [Qemu-devel] [PATCH] block: Add error handling to bdrv_invalidate_cache() Kevin Wolf
2014-03-12 15:40 ` Eric Blake
2014-03-12 16:22 ` Juan Quintela
2014-03-18 8:57 ` Kevin Wolf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.