From 65a77906e54f850fe512dcea2f2c189dc5d1e8ec Mon Sep 17 00:00:00 2001
From: Juan Quintela <quintela@redhat.com>
Date: Wed, 19 Oct 2011 23:47:41 +0200
Subject: [PATCH 06/19] migration: If there is one error, it makes no sense to
 continue

RH-Author: Juan Quintela <quintela@redhat.com>
Message-id: <55f644c86174adabd3913302f0d4febcdbfcec27.1319066771.git.quintela@redhat.com>
Patchwork-id: 34432
O-Subject: [PATCH qemu-kvm RHEL-6.2 06/16] migration: If there is one error, it makes no sense to continue
Bugzilla: 669581
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>

Once there, add a comment about what each error mean.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 buffered_file.c |   12 +++++++++---
 savevm.c        |    6 +++++-
 2 files changed, 14 insertions(+), 4 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 buffered_file.c |   12 +++++++++---
 savevm.c        |    6 +++++-
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index 1836e7e..4731623 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -190,13 +190,19 @@ static int buffered_close(void *opaque)
     return ret;
 }
 
+/*
+ * The meaning of the return values is:
+ *   0: We can continue sending
+ *   1: Time to stop
+ *  -1: There has been an error
+ */
 static int buffered_rate_limit(void *opaque)
 {
     QEMUFileBuffered *s = opaque;
 
-    if (s->has_error)
-        return 0;
-
+    if (s->has_error) {
+        return -1;
+    }
     if (s->freeze_output)
         return 1;
 
diff --git a/savevm.c b/savevm.c
index 9ba63df..afa37a6 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1538,8 +1538,12 @@ int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f)
         if (se->save_live_state == NULL)
             continue;
 
-        if (qemu_file_rate_limit(f))
+        ret = qemu_file_rate_limit(f);
+        if (ret < 0) {
+            return ret;
+        } else if (ret == 1) {
             return 0;
+        }
 
         /* Section type */
         qemu_put_byte(f, QEMU_VM_SECTION_PART);
-- 
1.7.4.4

