Skip to contentSkip to conversation

savevm: add comments for qemu_file_get_error()

PATCH RESEND Superseded Lei Li 3 participants 7 messages Aug 23, 2013 – Aug 26, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
author
#4 lore raw

PATCH RESEND 3/3 arch_init: right return for ram_save_iterate

In reply to Lei Li
---
 arch_init.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)
arch_init.c +1 -6
index 94d45e1..a34437c 100644
@@ -709,16 +709,11 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
      */
     ram_control_after_iterate(f, RAM_CONTROL_ROUND);
 
-    if (ret < 0) {
-        bytes_transferred += total_sent;
-        return ret;
-    }
-
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
     total_sent += 8;
     bytes_transferred += total_sent;
 
-    return total_sent;
+    return qemu_file_get_error(f);
 }
 
 static int ram_save_complete(QEMUFile *f, void *opaque)
Signature · 1 line
1.7.7.6
author
#1 lore raw

PATCH RESEND 2/3 savevm: fix wrong error set by ram_control_load_hook()

In reply to Lei Li

It should set negative error value if there has been an error.

---
 savevm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
savevm.c +1 -1
index 95a11f9..a0be109 100644
@@ -649,7 +649,7 @@ void ram_control_after_iterate(QEMUFile *f, uint64_t flags)
 
 void ram_control_load_hook(QEMUFile *f, uint64_t flags)
 {
-    int ret = 0;
+    int ret = -EINVAL;
 
     if (f->ops->hook_ram_load) {
         ret = f->ops->hook_ram_load(f, f->opaque, flags);
Signature · 1 line
1.7.7.6

Lei Li

author
#0 lore raw

PATCH RESEND 1/3 savevm: add comments for qemu_file_get_error()

Add comments for qemu_file_get_error(), as its return value is not very clear.

---
 savevm.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
savevm.c +7 -0
index 03fc4d9..95a11f9 100644
@@ -566,6 +566,13 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops)
     return f;
 }
 
+/*
+ * Get last error for stream f
+ *
+ * Return negative error value if there has been an error on previous
+ * operations, return 0 if no error happened.
+ *
+ */
 int qemu_file_get_error(QEMUFile *f)
 {
     return f->last_error;
Signature · 1 line
1.7.7.6
#2 lore raw

Re: [Qemu-devel] [PATCH resend 2/3] savevm: fix wrong error set by ram_control_load_hook()

In reply to Lei Li
Quoted 20 lines · Lei Li

It should set negative error value if there has been an error.

---
  savevm.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
savevm.c +1 -1
index 95a11f9..a0be109 100644
@@ -649,7 +649,7 @@ void ram_control_after_iterate(QEMUFile *f, uint64_t flags)
 
  void ram_control_load_hook(QEMUFile *f, uint64_t flags)
  {
-    int ret = 0;
+    int ret = -EINVAL;
 
      if (f->ops->hook_ram_load) {
          ret = f->ops->hook_ram_load(f, f->opaque, flags);
Reviewed-by on v1 2/3
#3 lore raw

Re: [Qemu-devel] [PATCH resend 2/3] savevm: fix wrong error set by ram_control_load_hook()

In reply to Lei Li
Quoted 12 lines · Lei Li

It should set negative error value if there has been an error.

---
  savevm.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
savevm.c +0 -0
index 95a11f9..a0be109 100644

savevm.c void ram_control_after_iterate(QEMUFile *f, uint64_t flags) · line 655

Quoted 8 lines
savevm.c +1 -1
@@ -649,7 +649,7 @@ void ram_control_after_iterate(QEMUFile *f, uint64_t flags)
 
  void ram_control_load_hook(QEMUFile *f, uint64_t flags)
  {
-    int ret = 0;
+    int ret = -EINVAL;
 
      if (f->ops->hook_ram_load) {
          ret = f->ops->hook_ram_load(f, f->opaque, flags);
#5 lore raw

Re: [Qemu-devel] [PATCH resend 3/3] arch_init: right return for ram_save_iterate

In reply to Lei Li

Il 23/08/2013 15:30, Lei Li ha scritto:

arch_init.c static int ram_save_iterate(QEMUFile *f, void *opaque) · line 716

Quoted 11 lines
arch_init.c +1 -6
-    if (ret < 0) {
-        bytes_transferred += total_sent;
-        return ret;
-    }
-
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
     total_sent += 8;
     bytes_transferred += total_sent;
 
-    return total_sent;
+    return qemu_file_get_error(f);

No, this will never make ram_save_iterate (and thus qemu_savevm_state_iterate) return a positive, non-zero value. Thus:

    ret = qemu_file_get_error(f);
    if (ret < 0) {
        return ret;
    }
    return total_sent;

If you look at the code, you can see that it never returns zero. Probably it should do something like

    bytes_transferred += total_sent;

    /* Do not count these 8 bytes into total_sent, so that we can
     * return 0 if no page had been dirtied.
     */
    qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
    bytes_transferred += 8;

and then proceed as above with "ret = qemu_file_get_error(f)".

Paolo

author
#6 lore raw

Re: [Qemu-devel] [PATCH resend 3/3] arch_init: right return for ram_save_iterate

Quoted 32 lines · Paolo Bonzini

Il 23/08/2013 15:30, Lei Li ha scritto:

arch_init.c static int ram_save_iterate(QEMUFile *f, void *opaque) · line 716

Quoted 11 lines
arch_init.c +1 -6
-    if (ret < 0) {
-        bytes_transferred += total_sent;
-        return ret;
-    }
-
      qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
      total_sent += 8;
      bytes_transferred += total_sent;
 
-    return total_sent;
+    return qemu_file_get_error(f);

No, this will never make ram_save_iterate (and thus qemu_savevm_state_iterate) return a positive, non-zero value. Thus:

     ret = qemu_file_get_error(f);
     if (ret < 0) {
         return ret;
     }
     return total_sent;

If you look at the code, you can see that it never returns zero. Probably it should do something like

     bytes_transferred += total_sent;

     /* Do not count these 8 bytes into total_sent, so that we can
      * return 0 if no page had been dirtied.
      */
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
     bytes_transferred += 8;
Quoted 1 line

and then proceed as above with "ret = qemu_file_get_error(f)".

Yes, you are right.

Quoted 3 lines

Paolo

Signature · 1 line
Lei