From: Pavel Hrdina <phrdina@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, phrdina@redhat.com, armbru@redhat.com,
	lcapitulino@redhat.com, xiawenc@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v2 10/12] savevm: update error reporting of qemu_savevm_state() and related functions
Date: Wed, 24 Apr 2013 17:32:08 +0200	[thread overview]
Message-ID: <4c63abcaa4ffbb1e36a27521812c780fe084731b.1366817130.git.phrdina@redhat.com> (raw)
In-Reply-To: <cover.1366817130.git.phrdina@redhat.com>
In-Reply-To: <cover.1366817130.git.phrdina@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 include/sysemu/sysemu.h |  7 ++++---
 migration.c             |  6 +++---
 savevm.c                | 38 +++++++++++++++++++-------------------
 3 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 913f49f..0e3f30a 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -72,9 +72,10 @@ void qemu_announce_self(void);
 
 bool qemu_savevm_state_blocked(Error **errp);
 void qemu_savevm_state_begin(QEMUFile *f,
-                             const MigrationParams *params);
-int qemu_savevm_state_iterate(QEMUFile *f);
-void qemu_savevm_state_complete(QEMUFile *f);
+                             const MigrationParams *params,
+                             Error **errp);
+int qemu_savevm_state_iterate(QEMUFile *f, Error **errp);
+void qemu_savevm_state_complete(QEMUFile *f, Error **errp);
 void qemu_savevm_state_cancel(void);
 uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size);
 void qemu_loadvm_state(QEMUFile *f, Error **errp);
diff --git a/migration.c b/migration.c
index 0279911..15ecd3f 100644
--- a/migration.c
+++ b/migration.c
@@ -508,7 +508,7 @@ static void *migration_thread(void *opaque)
     bool old_vm_running = false;
 
     DPRINTF("beginning savevm\n");
-    qemu_savevm_state_begin(s->file, &s->params);
+    qemu_savevm_state_begin(s->file, &s->params, NULL);
 
     while (s->state == MIG_STATE_ACTIVE) {
         int64_t current_time;
@@ -519,7 +519,7 @@ static void *migration_thread(void *opaque)
             pending_size = qemu_savevm_state_pending(s->file, max_size);
             DPRINTF("pending size %lu max %lu\n", pending_size, max_size);
             if (pending_size && pending_size >= max_size) {
-                qemu_savevm_state_iterate(s->file);
+                qemu_savevm_state_iterate(s->file, NULL);
             } else {
                 DPRINTF("done iterating\n");
                 qemu_mutex_lock_iothread();
@@ -528,7 +528,7 @@ static void *migration_thread(void *opaque)
                 old_vm_running = runstate_is_running();
                 vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
                 qemu_file_set_rate_limit(s->file, INT_MAX);
-                qemu_savevm_state_complete(s->file);
+                qemu_savevm_state_complete(s->file, NULL);
                 qemu_mutex_unlock_iothread();
                 if (!qemu_file_get_error(s->file)) {
                     migrate_finish_set_state(s, MIG_STATE_COMPLETED);
diff --git a/savevm.c b/savevm.c
index 6458621..749d49d 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1795,7 +1795,8 @@ bool qemu_savevm_state_blocked(Error **errp)
 }
 
 void qemu_savevm_state_begin(QEMUFile *f,
-                             const MigrationParams *params)
+                             const MigrationParams *params,
+                             Error **errp)
 {
     SaveStateEntry *se;
     int ret;
@@ -1836,6 +1837,7 @@ void qemu_savevm_state_begin(QEMUFile *f,
         ret = se->ops->save_live_setup(f, se->opaque);
         if (ret < 0) {
             qemu_file_set_error(f, ret);
+            error_setg_errno(errp, -ret, "Failed to begin vmstate save");
             break;
         }
     }
@@ -1847,7 +1849,7 @@ void qemu_savevm_state_begin(QEMUFile *f,
  *   0 : We haven't finished, caller have to go again
  *   1 : We have finished, we can go to complete phase
  */
-int qemu_savevm_state_iterate(QEMUFile *f)
+int qemu_savevm_state_iterate(QEMUFile *f, Error **errp)
 {
     SaveStateEntry *se;
     int ret = 1;
@@ -1874,6 +1876,7 @@ int qemu_savevm_state_iterate(QEMUFile *f)
 
         if (ret < 0) {
             qemu_file_set_error(f, ret);
+            error_setg_errno(errp, -ret, "Failed to iterate vmstate save");
         }
         if (ret <= 0) {
             /* Do not proceed to the next vmstate before this one reported
@@ -1886,7 +1889,7 @@ int qemu_savevm_state_iterate(QEMUFile *f)
     return ret;
 }
 
-void qemu_savevm_state_complete(QEMUFile *f)
+void qemu_savevm_state_complete(QEMUFile *f, Error **errp)
 {
     SaveStateEntry *se;
     int ret;
@@ -1911,6 +1914,7 @@ void qemu_savevm_state_complete(QEMUFile *f)
         trace_savevm_section_end(se->section_id);
         if (ret < 0) {
             qemu_file_set_error(f, ret);
+            error_setg_errno(errp, -ret, "Failed to complete vmstate save");
             return;
         }
     }
@@ -1972,37 +1976,33 @@ void qemu_savevm_state_cancel(void)
     }
 }
 
-static int qemu_savevm_state(QEMUFile *f)
+static void qemu_savevm_state(QEMUFile *f, Error **errp)
 {
-    int ret;
     MigrationParams params = {
         .blk = 0,
         .shared = 0
     };
 
-    if (qemu_savevm_state_blocked(NULL)) {
-        return -EINVAL;
+    if (qemu_savevm_state_blocked(errp)) {
+        return;
     }
 
     qemu_mutex_unlock_iothread();
-    qemu_savevm_state_begin(f, ¶ms);
+    qemu_savevm_state_begin(f, ¶ms, errp);
     qemu_mutex_lock_iothread();
 
     while (qemu_file_get_error(f) == 0) {
-        if (qemu_savevm_state_iterate(f) > 0) {
+        if (qemu_savevm_state_iterate(f, errp) > 0) {
             break;
         }
     }
 
-    ret = qemu_file_get_error(f);
-    if (ret == 0) {
-        qemu_savevm_state_complete(f);
-        ret = qemu_file_get_error(f);
+    if (!qemu_file_get_error(f)) {
+        qemu_savevm_state_complete(f, errp);
     }
-    if (ret != 0) {
+    if (qemu_file_get_error(f)) {
         qemu_savevm_state_cancel();
     }
-    return ret;
 }
 
 static int qemu_save_device_state(QEMUFile *f)
@@ -2358,7 +2358,6 @@ void do_savevm(Monitor *mon, const QDict *qdict)
 {
     BlockDriverState *bs, *bs1;
     QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
-    int ret;
     QEMUFile *f;
     int saved_vm_running;
     uint64_t vm_state_size;
@@ -2423,11 +2422,12 @@ void do_savevm(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, "Could not open VM state file\n");
         goto the_end;
     }
-    ret = qemu_savevm_state(f);
+    qemu_savevm_state(f, &local_err);
     vm_state_size = qemu_ftell(f);
     qemu_fclose(f);
-    if (ret < 0) {
-        monitor_printf(mon, "Error %d while writing VM\n", ret);
+    if (error_is_set(&local_err)) {
+        qerror_report_err(local_err);
+        error_free(local_err);
         goto the_end;
     }
 
-- 
1.8.1.4
next prev parent reply	other threads:[~2013-04-24 15:32 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-24 15:31 [Qemu-devel] [PATCH v2 00/12] covert savevm, loadvm and delvm into qapi Pavel Hrdina
2013-04-24 15:31 ` [Qemu-devel] [PATCH v2 01/12] qemu-img: introduce qemu_img_handle_error() Pavel Hrdina
2013-04-24 16:44   ` Eric Blake
2013-04-25  2:53     ` Wenchao Xia
2013-04-25  3:00       ` Eric Blake
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 02/12] block: update error reporting for bdrv_snapshot_delete() and related functions Pavel Hrdina
2013-04-24 20:05   ` Eric Blake
2013-04-25  3:19   ` Wenchao Xia
2013-04-25 13:42   ` Stefan Hajnoczi
2013-05-03  9:53   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 03/12] savevm: update bdrv_snapshot_find() to find snapshot by id or name and add error parameter Pavel Hrdina
2013-04-24 21:26   ` Eric Blake
2013-04-25  6:46     ` Pavel Hrdina
2013-04-25  8:18       ` Pavel Hrdina
2013-04-25  6:31   ` Wenchao Xia
2013-04-25  6:52     ` Pavel Hrdina
2013-04-25 12:16     ` Eric Blake
2013-04-26  2:37       ` Wenchao Xia
2013-05-03 10:24   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 04/12] qapi: Convert delvm Pavel Hrdina
2013-04-24 22:54   ` Eric Blake
2013-04-25  6:58     ` Wenchao Xia
2013-04-25 12:21       ` Eric Blake
2013-04-26  2:39         ` Wenchao Xia
2013-05-03 10:50   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 05/12] block: update error reporting for bdrv_snapshot_goto() and related functions Pavel Hrdina
2013-04-25 17:06   ` Eric Blake
2013-05-03 11:03   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 06/12] block: update error reporting for bdrv_snapshot_list() " Pavel Hrdina
2013-04-25 18:55   ` Eric Blake
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 07/12] savevm: update error reporting for qemu_loadvm_state() Pavel Hrdina
2013-05-03 11:17   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 08/12] qapi: Convert loadvm Pavel Hrdina
2013-05-03 11:31   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 09/12] block: update error reporting for bdrv_snapshot_create() and related functions Pavel Hrdina
2013-04-24 15:32 ` Pavel Hrdina [this message]
2013-05-03 12:40   ` [Qemu-devel] [PATCH v2 10/12] savevm: update error reporting of qemu_savevm_state() " Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 11/12] qapi: Convert savevm Pavel Hrdina
2013-05-03 12:52   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 12/12] savevm: remove backward compatibility from bdrv_snapshot_find() Pavel Hrdina
2013-05-03 12:55   ` Kevin Wolf
2013-04-24 16:15 ` [Qemu-devel] [PATCH v2 00/12] covert savevm, loadvm and delvm into qapi Eric Blake
2013-04-24 17:12   ` Luiz Capitulino
2013-04-25 13:34 ` Stefan Hajnoczi
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=4c63abcaa4ffbb1e36a27521812c780fe084731b.1366817130.git.phrdina@redhat.com \
    --to=phrdina@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xiawenc@linux.vnet.ibm.com \
    /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).