On Fri, 02 Sep 2011 16:32:25 +0200 Jan Kiszka <jan.kis...@siemens.com> wrote:
> On 2011-09-02 16:28, Luiz Capitulino wrote: > > On Thu, 01 Sep 2011 22:58:51 +0200 > > Jan Kiszka <jan.kis...@web.de> wrote: > > > >> On 2011-09-01 20:39, Luiz Capitulino wrote: > >>> On Thu, 01 Sep 2011 20:30:57 +0200 > >>> Jan Kiszka <jan.kis...@siemens.com> wrote: > >>> > >>>> On 2011-09-01 20:12, Luiz Capitulino wrote: > >>>>> Currently, only vm_start() and vm_stop() change the VM state. > >>>>> That's, the state is only changed when starting or stopping the VM. > >>>>> > >>>>> This commit adds the runstate_set() function, which makes it possible > >>>>> to also do state transitions when the VM is stopped or running. > >>>>> > >>>>> Additional states are also added and the current state is stored. > >>>>> > >>>>> Signed-off-by: Luiz Capitulino <lcapitul...@redhat.com> > >>>>> --- > >>>>> cpus.c | 1 + > >>>>> migration.c | 8 +++++++- > >>>>> sysemu.h | 10 +++++++++- > >>>>> vl.c | 20 ++++++++++++++++++++ > >>>>> 4 files changed, 37 insertions(+), 2 deletions(-) > >>>>> > >>>> > >>>> ... > >>>> > >>>>> diff --git a/vl.c b/vl.c > >>>>> index f0b56a4..59f71fc 100644 > >>>>> --- a/vl.c > >>>>> +++ b/vl.c > >>>>> @@ -321,6 +321,22 @@ static int default_driver_check(QemuOpts *opts, > >>>>> void *opaque) > >>>>> } > >>>>> > >>>>> /***********************************************************/ > >>>>> +/* QEMU state */ > >>>>> + > >>>>> +static RunState current_run_state = RSTATE_NO_STATE; > >>>>> + > >>>>> +bool runstate_check(RunState state) > >>>>> +{ > >>>>> + return current_run_state == state; > >>>>> +} > >>>>> + > >>>>> +void runstate_set(RunState state) > >>>>> +{ > >>>>> + assert(state < RSTATE_MAX); > >>>>> + current_run_state = state; > >>>> > >>>> I still think this should check for valid state transitions instead of > >>>> blindly accepting what the caller passes in. > >>> > >>> I thought your comment where more like a future enhancement than > >>> a request for change. > >> > >> I think we want this now to document at a central place which > >> transitions are valid and which not. State machines without such checks > >> break sooner or later, subtly. > > > > Ok, I'll do it. > > > > Do you have any suggestion on the preferred way to document it? > > Should I use english or try some ascii art? > > My idea is programmatic: > > void runstate_set(RunState new_state) > { > switch (current_state) { > case X: > /* potential comment on why only X->Y or ... is valid */ > if (new_state == Y || ...) { > break; > } else { > abort(); > } Ah, ok. I was thinking in having some fancy graph as documentation, but let's do the simpler way then.