Patchwork [resend,3/3] arch_init: right return for ram_save_iterate

login
register
mail settings
Submitter Lei Li
Date Aug. 23, 2013, 1:30 p.m.
Message ID <1377264653-31031-3-git-send-email-lilei@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/269452/
State New
Headers show

Comments

Lei Li - Aug. 23, 2013, 1:30 p.m.
Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
---
 arch_init.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)
Paolo Bonzini - Aug. 26, 2013, 8:27 a.m.
Il 23/08/2013 15:30, Lei Li ha scritto:
> -    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
Lei Li - Aug. 26, 2013, 9:22 a.m.
On 08/26/2013 04:27 PM, Paolo Bonzini wrote:
> Il 23/08/2013 15:30, Lei Li ha scritto:
>> -    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)".

Yes, you are right.

>
> Paolo
>

Patch

diff --git a/arch_init.c b/arch_init.c
index 94d45e1..a34437c 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -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)