From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3foX-0008IA-V9 for qemu-devel@nongnu.org; Tue, 13 Sep 2011 23:07:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R3foW-0006xN-LP for qemu-devel@nongnu.org; Tue, 13 Sep 2011 23:07:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10069) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3foW-0006xA-EQ for qemu-devel@nongnu.org; Tue, 13 Sep 2011 23:07:04 -0400 Date: Wed, 14 Sep 2011 00:06:48 -0300 From: Luiz Capitulino Message-ID: <20110914000648.03fbcd96@doriath> In-Reply-To: <1315599946-27081-5-git-send-email-lcapitulino@redhat.com> References: <1315599946-27081-1-git-send-email-lcapitulino@redhat.com> <1315599946-27081-5-git-send-email-lcapitulino@redhat.com> 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: Luiz Capitulino 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 Fri, 9 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. >=20 > Checking and testing all valid transitions wasn't trivial, chances > are this will need broader testing to become more stable. >=20 > This is a transition table as suggested by Llu=EDs Vilanova. >=20 > 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... > --- > sysemu.h | 1 + > vl.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++- > 2 files changed, 74 insertions(+), 1 deletions(-) >=20 > 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-%02= hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" > =20 > +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, voi= d *opaque) > =20 > static RunState current_run_state =3D RSTATE_NO_STATE; > =20 > +typedef struct { > + RunState from; > + RunState to; > +} RunStateTransition; > + > +static const RunStateTransition runstate_transitions_def[] =3D { > + /* 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 =3D=3D state; > } > =20 > +void runstate_init(void) > +{ > + const RunStateTransition *p; > + > + memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transit= ions)); > + > + for (p =3D &runstate_transitions_def[0]; p->from !=3D RSTATE_MAX; p+= +) { > + runstate_valid_transitions[p->from][p->to] =3D true; > + } > +} > + > +/* This function will abort() on invalid state transitions */ > void runstate_set(RunState new_state) > { > - assert(new_state < RSTATE_MAX); > + if (new_state >=3D RSTATE_MAX || > + !runstate_valid_transitions[current_run_state][new_state]) { > + fprintf(stderr, "invalid runstate transition\n"); > + abort(); > + } > + > current_run_state =3D new_state; > } > =20 > @@ -2218,6 +2288,8 @@ int main(int argc, char **argv, char **envp) > =20 > g_mem_set_vtable(&mem_trace); > =20 > + runstate_init(); > + > init_clocks(); > =20 > qemu_cache_utils_init(envp);