From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:33852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3vzG-0005gR-Ix for qemu-devel@nongnu.org; Wed, 14 Sep 2011 16:23:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R3vzF-0001AM-CI for qemu-devel@nongnu.org; Wed, 14 Sep 2011 16:23:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19524) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3vzF-00019P-57 for qemu-devel@nongnu.org; Wed, 14 Sep 2011 16:23:13 -0400 Date: Wed, 14 Sep 2011 17:23:06 -0300 From: Luiz Capitulino Message-ID: <20110914172306.19146d75@doriath> In-Reply-To: References: <1315599946-27081-1-git-send-email-lcapitulino@redhat.com> <1315599946-27081-5-git-send-email-lcapitulino@redhat.com> <20110914000648.03fbcd96@doriath> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 4/9] runstate_set(): Check for valid transitions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl 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 On Wed, 14 Sep 2011 19:55:25 +0000 Blue Swirl wrote: > On Wed, Sep 14, 2011 at 3:06 AM, Luiz Capitulino = wrote: > > On Fri, =A09 Sep 2011 17:25:41 -0300 > > Luiz Capitulino 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=EDs Vilanova. > >> > >> Signed-off-by: Luiz Capitulino > > > > Would be nice to get a reviewed-by for this patch, as it wasn't trivial > > to get it right and tested... > > > >> --- > >> =A0sysemu.h | =A0 =A01 + > >> =A0vl.c =A0 =A0 | =A0 74 +++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++- > >> =A02 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[]; > >> =A0int qemu_uuid_parse(const char *str, uint8_t *uuid); > >> =A0#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hh= x-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" > >> > >> +void runstate_init(void); > >> =A0bool runstate_check(RunState state); > >> =A0void runstate_set(RunState new_state); > >> =A0typedef 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) > >> > >> =A0static RunState current_run_state =3D RSTATE_NO_STATE; > >> > >> +typedef struct { > >> + =A0 =A0RunState from; > >> + =A0 =A0RunState to; > >> +} RunStateTransition; > >> + > >> +static const RunStateTransition runstate_transitions_def[] =3D { > >> + =A0 =A0/* =A0 =A0 from =A0 =A0 =A0-> =A0 =A0 to =A0 =A0 =A0*/ > >> + =A0 =A0{ RSTATE_NO_STATE, RSTATE_RUNNING }, > >> + =A0 =A0{ RSTATE_NO_STATE, RSTATE_IN_MIGRATE }, > >> + =A0 =A0{ RSTATE_NO_STATE, RSTATE_PRE_LAUNCH }, > >> + > >> + =A0 =A0{ RSTATE_DEBUG, RSTATE_RUNNING }, > >> + > >> + =A0 =A0{ RSTATE_IN_MIGRATE, RSTATE_RUNNING }, > >> + =A0 =A0{ RSTATE_IN_MIGRATE, RSTATE_PRE_LAUNCH }, > >> + > >> + =A0 =A0{ RSTATE_PANICKED, RSTATE_PAUSED }, > >> + > >> + =A0 =A0{ RSTATE_IO_ERROR, RSTATE_RUNNING }, > >> + > >> + =A0 =A0{ RSTATE_PAUSED, RSTATE_RUNNING }, > >> + > >> + =A0 =A0{ RSTATE_POST_MIGRATE, RSTATE_RUNNING }, > >> + > >> + =A0 =A0{ RSTATE_PRE_LAUNCH, RSTATE_RUNNING }, > >> + =A0 =A0{ RSTATE_PRE_LAUNCH, RSTATE_POST_MIGRATE }, > >> + > >> + =A0 =A0{ RSTATE_PRE_MIGRATE, RSTATE_RUNNING }, > >> + =A0 =A0{ RSTATE_PRE_MIGRATE, RSTATE_POST_MIGRATE }, > >> + > >> + =A0 =A0{ RSTATE_RESTORE, RSTATE_RUNNING }, > >> + > >> + =A0 =A0{ RSTATE_RUNNING, RSTATE_DEBUG }, > >> + =A0 =A0{ RSTATE_RUNNING, RSTATE_PANICKED }, > >> + =A0 =A0{ RSTATE_RUNNING, RSTATE_IO_ERROR }, > >> + =A0 =A0{ RSTATE_RUNNING, RSTATE_PAUSED }, > >> + =A0 =A0{ RSTATE_RUNNING, RSTATE_PRE_MIGRATE }, > >> + =A0 =A0{ RSTATE_RUNNING, RSTATE_RESTORE }, > >> + =A0 =A0{ RSTATE_RUNNING, RSTATE_SAVEVM }, > >> + =A0 =A0{ RSTATE_RUNNING, RSTATE_SHUTDOWN }, > >> + =A0 =A0{ RSTATE_RUNNING, RSTATE_WATCHDOG }, > >> + > >> + =A0 =A0{ RSTATE_SAVEVM, RSTATE_RUNNING }, > >> + > >> + =A0 =A0{ RSTATE_SHUTDOWN, RSTATE_PAUSED }, > >> + > >> + =A0 =A0{ RSTATE_WATCHDOG, RSTATE_RUNNING }, > >> + > >> + =A0 =A0{ RSTATE_MAX, RSTATE_MAX }, >=20 > I don't see a state which requires a system_reset to recover, which I > think was the original motivation. Do I miss something? That's done by patch 7/9 Monitor/QMP: Don't allow cont on bad VM state. > Otherwise the patch looks fine. Thanks! >=20 > >> +}; > >> + > >> +static bool runstate_valid_transitions[RSTATE_MAX][RSTATE_MAX]; > >> + > >> =A0bool runstate_check(RunState state) > >> =A0{ > >> =A0 =A0 =A0return current_run_state =3D=3D state; > >> =A0} > >> > >> +void runstate_init(void) > >> +{ > >> + =A0 =A0const RunStateTransition *p; > >> + > >> + =A0 =A0memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_= transitions)); > >> + > >> + =A0 =A0for (p =3D &runstate_transitions_def[0]; p->from !=3D RSTATE_= MAX; p++) { > >> + =A0 =A0 =A0 =A0runstate_valid_transitions[p->from][p->to] =3D true; > >> + =A0 =A0} > >> +} > >> + > >> +/* This function will abort() on invalid state transitions */ > >> =A0void runstate_set(RunState new_state) > >> =A0{ > >> - =A0 =A0assert(new_state < RSTATE_MAX); > >> + =A0 =A0if (new_state >=3D RSTATE_MAX || > >> + =A0 =A0 =A0 =A0!runstate_valid_transitions[current_run_state][new_st= ate]) { > >> + =A0 =A0 =A0 =A0fprintf(stderr, "invalid runstate transition\n"); > >> + =A0 =A0 =A0 =A0abort(); > >> + =A0 =A0} > >> + > >> =A0 =A0 =A0current_run_state =3D new_state; > >> =A0} > >> > >> @@ -2218,6 +2288,8 @@ int main(int argc, char **argv, char **envp) > >> > >> =A0 =A0 =A0g_mem_set_vtable(&mem_trace); > >> > >> + =A0 =A0runstate_init(); > >> + > >> =A0 =A0 =A0init_clocks(); > >> > >> =A0 =A0 =A0qemu_cache_utils_init(envp); > > > > > > >=20