qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: kwolf@redhat.com, aliguori@us.ibm.com, jan.kiszka@siemens.com,
	qemu-devel@nongnu.org, armbru@redhat.com, amit.shah@redhat.com,
	vilanova@ac.upc.edu
Subject: Re: [Qemu-devel] [PATCH 4/9] runstate_set(): Check for valid transitions
Date: Wed, 14 Sep 2011 00:06:48 -0300	[thread overview]
Message-ID: <20110914000648.03fbcd96@doriath> (raw)
In-Reply-To: <1315599946-27081-5-git-send-email-lcapitulino@redhat.com>

On Fri,  9 Sep 2011 17:25:41 -0300
Luiz Capitulino <lcapitulino@redhat.com> wrote:

> This commit could have been folded with the previous one, however
> doing it separately will allow for easy bisect and revert if needed.
> 
> Checking and testing all valid transitions wasn't trivial, chances
> are this will need broader testing to become more stable.
> 
> This is a transition table as suggested by Lluís Vilanova.
> 
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>

Would be nice to get a reviewed-by for this patch, as it wasn't trivial
to get it right and tested...

> ---
>  sysemu.h |    1 +
>  vl.c     |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 74 insertions(+), 1 deletions(-)
> 
> diff --git a/sysemu.h b/sysemu.h
> index 19088aa..a01ddac 100644
> --- a/sysemu.h
> +++ b/sysemu.h
> @@ -36,6 +36,7 @@ extern uint8_t qemu_uuid[];
>  int qemu_uuid_parse(const char *str, uint8_t *uuid);
>  #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
>  
> +void runstate_init(void);
>  bool runstate_check(RunState state);
>  void runstate_set(RunState new_state);
>  typedef struct vm_change_state_entry VMChangeStateEntry;
> diff --git a/vl.c b/vl.c
> index 9926d2a..4a8edc7 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -327,14 +327,84 @@ static int default_driver_check(QemuOpts *opts, void *opaque)
>  
>  static RunState current_run_state = RSTATE_NO_STATE;
>  
> +typedef struct {
> +    RunState from;
> +    RunState to;
> +} RunStateTransition;
> +
> +static const RunStateTransition runstate_transitions_def[] = {
> +    /*     from      ->     to      */
> +    { RSTATE_NO_STATE, RSTATE_RUNNING },
> +    { RSTATE_NO_STATE, RSTATE_IN_MIGRATE },
> +    { RSTATE_NO_STATE, RSTATE_PRE_LAUNCH },
> +
> +    { RSTATE_DEBUG, RSTATE_RUNNING },
> +
> +    { RSTATE_IN_MIGRATE, RSTATE_RUNNING },
> +    { RSTATE_IN_MIGRATE, RSTATE_PRE_LAUNCH },
> +
> +    { RSTATE_PANICKED, RSTATE_PAUSED },
> +
> +    { RSTATE_IO_ERROR, RSTATE_RUNNING },
> +
> +    { RSTATE_PAUSED, RSTATE_RUNNING },
> +
> +    { RSTATE_POST_MIGRATE, RSTATE_RUNNING },
> +
> +    { RSTATE_PRE_LAUNCH, RSTATE_RUNNING },
> +    { RSTATE_PRE_LAUNCH, RSTATE_POST_MIGRATE },
> +
> +    { RSTATE_PRE_MIGRATE, RSTATE_RUNNING },
> +    { RSTATE_PRE_MIGRATE, RSTATE_POST_MIGRATE },
> +
> +    { RSTATE_RESTORE, RSTATE_RUNNING },
> +
> +    { RSTATE_RUNNING, RSTATE_DEBUG },
> +    { RSTATE_RUNNING, RSTATE_PANICKED },
> +    { RSTATE_RUNNING, RSTATE_IO_ERROR },
> +    { RSTATE_RUNNING, RSTATE_PAUSED },
> +    { RSTATE_RUNNING, RSTATE_PRE_MIGRATE },
> +    { RSTATE_RUNNING, RSTATE_RESTORE },
> +    { RSTATE_RUNNING, RSTATE_SAVEVM },
> +    { RSTATE_RUNNING, RSTATE_SHUTDOWN },
> +    { RSTATE_RUNNING, RSTATE_WATCHDOG },
> +
> +    { RSTATE_SAVEVM, RSTATE_RUNNING },
> +
> +    { RSTATE_SHUTDOWN, RSTATE_PAUSED },
> +
> +    { RSTATE_WATCHDOG, RSTATE_RUNNING },
> +
> +    { RSTATE_MAX, RSTATE_MAX },
> +};
> +
> +static bool runstate_valid_transitions[RSTATE_MAX][RSTATE_MAX];
> +
>  bool runstate_check(RunState state)
>  {
>      return current_run_state == state;
>  }
>  
> +void runstate_init(void)
> +{
> +    const RunStateTransition *p;
> +
> +    memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
> +
> +    for (p = &runstate_transitions_def[0]; p->from != RSTATE_MAX; p++) {
> +        runstate_valid_transitions[p->from][p->to] = true;
> +    }
> +}
> +
> +/* This function will abort() on invalid state transitions */
>  void runstate_set(RunState new_state)
>  {
> -    assert(new_state < RSTATE_MAX);
> +    if (new_state >= RSTATE_MAX ||
> +        !runstate_valid_transitions[current_run_state][new_state]) {
> +        fprintf(stderr, "invalid runstate transition\n");
> +        abort();
> +    }
> +
>      current_run_state = new_state;
>  }
>  
> @@ -2218,6 +2288,8 @@ int main(int argc, char **argv, char **envp)
>  
>      g_mem_set_vtable(&mem_trace);
>  
> +    runstate_init();
> +
>      init_clocks();
>  
>      qemu_cache_utils_init(envp);

  reply	other threads:[~2011-09-14  3:07 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-09 20:25 [Qemu-devel] [PATCH v5 0/9]: Introduce the RunState type Luiz Capitulino
2011-09-09 20:25 ` [Qemu-devel] [PATCH 1/9] Move vm_state_notify() prototype from cpus.h to sysemu.h Luiz Capitulino
2011-09-09 20:25 ` [Qemu-devel] [PATCH 2/9] Replace the VMSTOP macros with a proper state type Luiz Capitulino
2011-09-09 20:25 ` [Qemu-devel] [PATCH 3/9] RunState: Add additional states Luiz Capitulino
2011-09-09 20:25 ` [Qemu-devel] [PATCH 4/9] runstate_set(): Check for valid transitions Luiz Capitulino
2011-09-14  3:06   ` Luiz Capitulino [this message]
2011-09-14 19:55     ` Blue Swirl
2011-09-14 20:23       ` Luiz Capitulino
2011-09-09 20:25 ` [Qemu-devel] [PATCH 5/9] Drop the incoming_expected global variable Luiz Capitulino
2011-09-09 20:25 ` [Qemu-devel] [PATCH 6/9] Drop the vm_running " Luiz Capitulino
2011-09-09 20:25 ` [Qemu-devel] [PATCH 7/9] Monitor/QMP: Don't allow cont on bad VM state Luiz Capitulino
2011-09-09 20:25 ` [Qemu-devel] [PATCH 8/9] QMP: query-status: Introduce 'status' key Luiz Capitulino
2011-09-09 20:25 ` [Qemu-devel] [PATCH 9/9] HMP: info status: Print the VM state Luiz Capitulino
  -- strict thread matches above, loose matches on Subject: below --
2011-09-15 20:05 [Qemu-devel] [PULL 0/9]: QMP queue Luiz Capitulino
2011-09-15 20:05 ` [Qemu-devel] [PATCH 4/9] runstate_set(): Check for valid transitions Luiz Capitulino
2011-09-14 20:49 [Qemu-devel] [PULL 0/9]: QMP queue Luiz Capitulino
2011-09-14 20:49 ` [Qemu-devel] [PATCH 4/9] runstate_set(): Check for valid transitions Luiz Capitulino
2011-09-06 13:14 [Qemu-devel] [PATCH v4 0/9]: Introduce the RunState type Luiz Capitulino
2011-09-06 13:14 ` [Qemu-devel] [PATCH 4/9] runstate_set(): Check for valid transitions Luiz Capitulino
2011-09-06 15:55   ` Jan Kiszka
2011-09-06 16:47     ` Luiz Capitulino
2011-09-06 17:42       ` Lluís Vilanova
2011-09-09 12:58         ` 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=20110914000648.03fbcd96@doriath \
    --to=lcapitulino@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=amit.shah@redhat.com \
    --cc=armbru@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vilanova@ac.upc.edu \
    /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).