qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Peter Lieven <pl@kamp.de>, Juan Quintela <quintela@redhat.com>,
	qemu-devel@nongnu.org, Amit Shah <amit.shah@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 6/6] migration: catch unknown flags in ram_load
Date: Tue, 17 Jun 2014 14:32:53 -0600	[thread overview]
Message-ID: <53A0A5F5.4060505@redhat.com> (raw)
In-Reply-To: <53A00AEF.2090304@kamp.de>

[-- Attachment #1: Type: text/plain, Size: 2302 bytes --]

On 06/17/2014 03:31 AM, Peter Lieven wrote:
>> Among other things, switching from a chain of if-else to a switch might
>> make it easier to document explicit supported combinations of flags and
>> reject other values from an invalid stream.
>>
> 
> Is this what you have in mind?
> 
> diff --git a/arch_init.c b/arch_init.c
> index 8ddaf35..925cc66 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -1039,7 +1039,7 @@ void ram_handle_compressed(void *host, uint8_t ch,
> uint64_t size)
>  static int ram_load(QEMUFile *f, void *opaque, int version_id)
>  {
>      ram_addr_t addr;
> -    int flags, ret = 0;
> +    int flags = 0, ret = 0;
>      static uint64_t seq_iter;
> 
>      seq_iter++;
> @@ -1048,97 +1048,96 @@ static int ram_load(QEMUFile *f, void *opaque,
> int version_id)
>          ret = -EINVAL;
>      }
> 
> -    while (!ret) {
> +    while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) {

> -                            ret =  -EINVAL;
> +        if (flags & RAM_SAVE_FLAG_HOOK) {
> +            ram_control_load_hook(f, flags);

Can RAM_SAVE_FLAG_HOOK | RAM_SAVE_FLAG_EOS ever be true?  If so, you
abort the loop early. (One possibility: solve it by adding 'flags = 0;'
here.)

Also, this patch was harder to read than necessary, because it
reindented everything, and threw off git's diff algorithm.  Use 'git
diff --patience' to make it a bit more legible as a bulk delete/replace
instead of dividing into hunks around common but unrelated context
lines.  Or even rewrite it slightly so that the bulk of the code is
still at the same indentation, perhaps by rearranging this if statement
to instead appear inside the default label of the switch:

while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) {
    flags = ...;
    switch (flags & ~RAM_SAVE_FLAG_CONTINUE) {
 ...
    default:
        if (flags & RAM_SAVE_FLAG_HOOK) {
            ram_control_load_hook(f, flags);
            flags = 0;
        } else {
            report error on unknown flags
        }
        break;
    }
    ret = qemu_file_get_error(f);
}

But yes, this is what I had in mind - propose it as a formal patch with
S-o-B, and I'll review it.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2014-06-17 20:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-16  3:15 [Qemu-devel] [PULL 0/6] migration queue Juan Quintela
2014-06-16  3:15 ` [Qemu-devel] [PATCH 1/6] savevm: Remove all the unneeded version_minimum_id_old (ppc) Juan Quintela
2014-06-16  3:15 ` [Qemu-devel] [PATCH 2/6] savevm: Remove all the unneeded version_minimum_id_old (x86) Juan Quintela
2014-06-16  3:15 ` [Qemu-devel] [PATCH 3/6] vmstate: Refactor opening of files Juan Quintela
2014-06-16  3:15 ` [Qemu-devel] [PATCH 4/6] migration: Increase default max_downtime from 30ms to 300ms Juan Quintela
2014-06-16  3:15 ` [Qemu-devel] [PATCH 5/6] rdma: Fix block during rdma migration Juan Quintela
2014-06-16  3:15 ` [Qemu-devel] [PATCH 6/6] migration: catch unknown flags in ram_load Juan Quintela
2014-06-16 17:31   ` Eric Blake
2014-06-17  9:31     ` Peter Lieven
2014-06-17 20:32       ` Eric Blake [this message]
2014-06-16 10:39 ` [Qemu-devel] [PULL 0/6] migration queue Peter Maydell

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=53A0A5F5.4060505@redhat.com \
    --to=eblake@redhat.com \
    --cc=amit.shah@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.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).