diff mbox

[04/11] migration: return real error code

Message ID 5529f9bd516a73e64eb7f9761e85cd2240030dfd.1316781876.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela Sept. 23, 2011, 12:50 p.m. UTC
make functions propaget errno, instead of just using -EIO.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration.c |    6 +++++-
 savevm.c    |   33 +++++++++++++++------------------
 2 files changed, 20 insertions(+), 19 deletions(-)

Comments

Anthony Liguori Oct. 4, 2011, 6:08 p.m. UTC | #1
On 09/23/2011 07:50 AM, Juan Quintela wrote:
> make functions propaget errno, instead of just using -EIO.
>
> Signed-off-by: Juan Quintela<quintela@redhat.com>

qemu_file_has_error() implies a boolean response.  Wouldn't 
qemu_file_get_error() make more sense if you're going to rely on the return value?

Regards,

Anthony Liguori

> ---
>   migration.c |    6 +++++-
>   savevm.c    |   33 +++++++++++++++------------------
>   2 files changed, 20 insertions(+), 19 deletions(-)
>
> diff --git a/migration.c b/migration.c
> index ea7bcc8..9498e20 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -363,6 +363,7 @@ void migrate_fd_connect(FdMigrationState *s)
>   void migrate_fd_put_ready(void *opaque)
>   {
>       FdMigrationState *s = opaque;
> +    int ret;
>
>       if (s->state != MIG_STATE_ACTIVE) {
>           DPRINTF("put_ready returning because of non-active state\n");
> @@ -370,7 +371,10 @@ void migrate_fd_put_ready(void *opaque)
>       }
>
>       DPRINTF("iterate\n");
> -    if (qemu_savevm_state_iterate(s->mon, s->file) == 1) {
> +    ret = qemu_savevm_state_iterate(s->mon, s->file);
> +    if (ret<  0) {
> +        migrate_fd_error(s);
> +    } else if (ret == 1) {
>           int old_vm_running = runstate_is_running();
>
>           DPRINTF("done iterating\n");
> diff --git a/savevm.c b/savevm.c
> index 46f2447..c382076 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -1466,6 +1466,7 @@ int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,
>                               int shared)
>   {
>       SaveStateEntry *se;
> +    int ret;
>
>       QTAILQ_FOREACH(se,&savevm_handlers, entry) {
>           if(se->set_params == NULL) {
> @@ -1497,13 +1498,13 @@ int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,
>
>           se->save_live_state(mon, f, QEMU_VM_SECTION_START, se->opaque);
>       }
> -
> -    if (qemu_file_has_error(f)) {
> +    ret = qemu_file_has_error(f);
> +    if (ret != 0) {
>           qemu_savevm_state_cancel(mon, f);
> -        return -EIO;
>       }
>
> -    return 0;
> +    return ret;
> +
>   }
>
>   int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f)
> @@ -1528,16 +1529,14 @@ int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f)
>               break;
>           }
>       }
> -
> -    if (ret)
> -        return 1;
> -
> -    if (qemu_file_has_error(f)) {
> +    if (ret != 0) {
> +        return ret;
> +    }
> +    ret = qemu_file_has_error(f);
> +    if (ret != 0) {
>           qemu_savevm_state_cancel(mon, f);
> -        return -EIO;
>       }
> -
> -    return 0;
> +    return ret;
>   }
>
>   int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)
> @@ -1580,10 +1579,7 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)
>
>       qemu_put_byte(f, QEMU_VM_EOF);
>
> -    if (qemu_file_has_error(f))
> -        return -EIO;
> -
> -    return 0;
> +    return qemu_file_has_error(f);
>   }
>
>   void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f)
> @@ -1623,8 +1619,9 @@ static int qemu_savevm_state(Monitor *mon, QEMUFile *f)
>       ret = qemu_savevm_state_complete(mon, f);
>
>   out:
> -    if (qemu_file_has_error(f))
> -        ret = -EIO;
> +    if (ret == 0) {
> +        ret = qemu_file_has_error(f);
> +    }
>
>       if (!ret&&  saved_vm_running)
>           vm_start();
Juan Quintela Oct. 4, 2011, 6:35 p.m. UTC | #2
Anthony Liguori <anthony@codemonkey.ws> wrote:
> On 09/23/2011 07:50 AM, Juan Quintela wrote:
>> make functions propaget errno, instead of just using -EIO.
>>
>> Signed-off-by: Juan Quintela<quintela@redhat.com>
>
> qemu_file_has_error() implies a boolean response.  Wouldn't
> qemu_file_get_error() make more sense if you're going to rely on the
> return value?

I just didn't want to change more things on the same patch.
I can add a patch on top of this series?

Later, Juan.
Anthony Liguori Oct. 5, 2011, 7:52 p.m. UTC | #3
On 10/04/2011 01:35 PM, Juan Quintela wrote:
> Anthony Liguori<anthony@codemonkey.ws>  wrote:
>> On 09/23/2011 07:50 AM, Juan Quintela wrote:
>>> make functions propaget errno, instead of just using -EIO.
>>>
>>> Signed-off-by: Juan Quintela<quintela@redhat.com>
>>
>> qemu_file_has_error() implies a boolean response.  Wouldn't
>> qemu_file_get_error() make more sense if you're going to rely on the
>> return value?
>
> I just didn't want to change more things on the same patch.
> I can add a patch on top of this series?

It's terribly odd to make a function that looks like a bool return a non-boolean 
value.  It can't be that much of a change to do it in this patch, it's just a 
matter of running sed.

Regards,

Anthony Liguori

>
> Later, Juan.
Juan Quintela Oct. 5, 2011, 8:07 p.m. UTC | #4
Anthony Liguori <anthony@codemonkey.ws> wrote:
> On 10/04/2011 01:35 PM, Juan Quintela wrote:
>> Anthony Liguori<anthony@codemonkey.ws>  wrote:
>>> On 09/23/2011 07:50 AM, Juan Quintela wrote:
>>>> make functions propaget errno, instead of just using -EIO.
>>>>
>>>> Signed-off-by: Juan Quintela<quintela@redhat.com>
>>>
>>> qemu_file_has_error() implies a boolean response.  Wouldn't
>>> qemu_file_get_error() make more sense if you're going to rely on the
>>> return value?
>>
>> I just didn't want to change more things on the same patch.
>> I can add a patch on top of this series?
>
> It's terribly odd to make a function that looks like a bool return a
> non-boolean value.  It can't be that much of a change to do it in this
> patch, it's just a matter of running sed.

That is already fixed.  Problem was not doing that change, was to fix
the rejects after that on the following patches.

Later, Juan.
diff mbox

Patch

diff --git a/migration.c b/migration.c
index ea7bcc8..9498e20 100644
--- a/migration.c
+++ b/migration.c
@@ -363,6 +363,7 @@  void migrate_fd_connect(FdMigrationState *s)
 void migrate_fd_put_ready(void *opaque)
 {
     FdMigrationState *s = opaque;
+    int ret;

     if (s->state != MIG_STATE_ACTIVE) {
         DPRINTF("put_ready returning because of non-active state\n");
@@ -370,7 +371,10 @@  void migrate_fd_put_ready(void *opaque)
     }

     DPRINTF("iterate\n");
-    if (qemu_savevm_state_iterate(s->mon, s->file) == 1) {
+    ret = qemu_savevm_state_iterate(s->mon, s->file);
+    if (ret < 0) {
+        migrate_fd_error(s);
+    } else if (ret == 1) {
         int old_vm_running = runstate_is_running();

         DPRINTF("done iterating\n");
diff --git a/savevm.c b/savevm.c
index 46f2447..c382076 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1466,6 +1466,7 @@  int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,
                             int shared)
 {
     SaveStateEntry *se;
+    int ret;

     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
         if(se->set_params == NULL) {
@@ -1497,13 +1498,13 @@  int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,

         se->save_live_state(mon, f, QEMU_VM_SECTION_START, se->opaque);
     }
-
-    if (qemu_file_has_error(f)) {
+    ret = qemu_file_has_error(f);
+    if (ret != 0) {
         qemu_savevm_state_cancel(mon, f);
-        return -EIO;
     }

-    return 0;
+    return ret;
+
 }

 int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f)
@@ -1528,16 +1529,14 @@  int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f)
             break;
         }
     }
-
-    if (ret)
-        return 1;
-
-    if (qemu_file_has_error(f)) {
+    if (ret != 0) {
+        return ret;
+    }
+    ret = qemu_file_has_error(f);
+    if (ret != 0) {
         qemu_savevm_state_cancel(mon, f);
-        return -EIO;
     }
-
-    return 0;
+    return ret;
 }

 int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)
@@ -1580,10 +1579,7 @@  int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)

     qemu_put_byte(f, QEMU_VM_EOF);

-    if (qemu_file_has_error(f))
-        return -EIO;
-
-    return 0;
+    return qemu_file_has_error(f);
 }

 void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f)
@@ -1623,8 +1619,9 @@  static int qemu_savevm_state(Monitor *mon, QEMUFile *f)
     ret = qemu_savevm_state_complete(mon, f);

 out:
-    if (qemu_file_has_error(f))
-        ret = -EIO;
+    if (ret == 0) {
+        ret = qemu_file_has_error(f);
+    }

     if (!ret && saved_vm_running)
         vm_start();