qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: Wen Congyang <wency@cn.fujitsu.com>
Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/5] runstate: Print state transition when invalid
Date: Wed, 19 Oct 2011 10:56:19 -0200	[thread overview]
Message-ID: <20111019105619.4e0813fa@doriath> (raw)
In-Reply-To: <4E9E1D35.7040202@cn.fujitsu.com>

On Wed, 19 Oct 2011 08:43:33 +0800
Wen Congyang <wency@cn.fujitsu.com> wrote:

> At 10/15/2011 01:26 AM, Luiz Capitulino Write:
> > Makes it easier to debug.
> > 
> > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> > ---
> >  vl.c |    4 +++-
> >  1 files changed, 3 insertions(+), 1 deletions(-)
> > 
> > diff --git a/vl.c b/vl.c
> > index dbf7778..6645720 100644
> > --- a/vl.c
> > +++ b/vl.c
> > @@ -397,7 +397,9 @@ void runstate_set(RunState new_state)
> >  {
> >      if (new_state >= RUN_STATE_MAX ||
> >          !runstate_valid_transitions[current_run_state][new_state]) {
> > -        fprintf(stderr, "invalid runstate transition\n");
> > +        fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
> > +                RunState_lookup[current_run_state],
> > +                RunState_lookup[new_state]);
> 
> If new_state >= RUN_STATE_MAX, we can not use RunState_lookup.

Good catch!

> I think it's better to use:
>     new_state >= RUN_STATE_MAX ? "invalid state" : RunState_lookup[new_state]

I prefer to do the following instead:

diff --git a/vl.c b/vl.c
index 2dce3ae..2a634a7 100644
--- a/vl.c
+++ b/vl.c
@@ -393,9 +393,12 @@ void runstate_init(void)
 /* This function will abort() on invalid state transitions */
 void runstate_set(RunState new_state)
 {
-    if (new_state >= RUN_STATE_MAX ||
-        !runstate_valid_transitions[current_run_state][new_state]) {
-        fprintf(stderr, "invalid runstate transition\n");
+    assert(new_state < RUN_STATE_MAX);
+
+    if (!runstate_valid_transitions[current_run_state][new_state]) {
+        fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
+                RunState_lookup[current_run_state],
+                RunState_lookup[new_state]);
         abort();
     }
 
-- 
1.7.7.rc3


> 
> Thanks
> Wen Congyang
> 
> >          abort();
> >      }
> >  
> 

  reply	other threads:[~2011-10-19 12:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-14 17:26 [Qemu-devel] [PULL 0/5]: QMP queue Luiz Capitulino
2011-10-14 17:26 ` [Qemu-devel] [PATCH 1/5] QMP: Fix blockdev-snapshot-sync doc example Luiz Capitulino
2011-10-14 17:26 ` [Qemu-devel] [PATCH 2/5] runstate: Print state transition when invalid Luiz Capitulino
2011-10-19  0:43   ` Wen Congyang
2011-10-19 12:56     ` Luiz Capitulino [this message]
2011-10-14 17:26 ` [Qemu-devel] [PATCH 3/5] runstate: Allow to transition from paused to postmigrate Luiz Capitulino
2011-10-14 17:26 ` [Qemu-devel] [PATCH 4/5] savevm: qemu_savevm_state(): Drop stop VM logic Luiz Capitulino
2011-10-14 17:26 ` [Qemu-devel] [PATCH 5/5] runstate: Allow user to migrate twice Luiz Capitulino
2011-10-14 19:47   ` Paolo Bonzini
2011-10-20 15:01 ` [Qemu-devel] [PULL 0/5]: QMP queue Anthony Liguori
  -- strict thread matches above, loose matches on Subject: below --
2011-10-19 12:56 [Qemu-devel] [RESEND PULL " Luiz Capitulino
2011-10-19 12:56 ` [Qemu-devel] [PATCH 2/5] runstate: Print state transition when invalid Luiz Capitulino

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=20111019105619.4e0813fa@doriath \
    --to=lcapitulino@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wency@cn.fujitsu.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).