[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 6/9] migration: create new section to store glob
From: |
Dr. David Alan Gilbert |
Subject: |
Re: [Qemu-devel] [PATCH 6/9] migration: create new section to store global state |
Date: |
Mon, 18 May 2015 11:23:30 +0100 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
* Juan Quintela (address@hidden) wrote:
> This includes a new section that for now just stores the current qemu state.
>
> Right now, there are only one way to control what is the state of the
> target after migration.
>
> - If you run the target qemu with -S, it would start stopped.
> - If you run the target qemu without -S, it would run just after migration
> finishes.
>
> The problem here is what happens if we start the target without -S and
> there happens one error during migration that puts current state as
> -EIO. Migration would ends (notice that the error happend doing block
> IO, network IO, i.e. nothing related with migration), and when
> migration finish, we would just "continue" running on destination,
> probably hanging the guest/corruption data, whatever.
>
> Signed-off-by: Juan Quintela <address@hidden>
> ---
> include/migration/migration.h | 4 ++
> migration/migration.c | 85
> +++++++++++++++++++++++++++++++++++++++++--
> vl.c | 1 +
> 3 files changed, 87 insertions(+), 3 deletions(-)
>
> diff --git a/include/migration/migration.h b/include/migration/migration.h
> index a6e025a..785c2dc 100644
> --- a/include/migration/migration.h
> +++ b/include/migration/migration.h
> @@ -180,4 +180,8 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t
> block_offset,
> ram_addr_t offset, size_t size,
> uint64_t *bytes_sent);
>
> +void register_global_state(void);
> +void global_state_store(void);
> +char *global_state_get_runstate(void);
> +
> #endif
> diff --git a/migration/migration.c b/migration/migration.c
> index 732d229..ab69f81 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -133,10 +133,20 @@ static void process_incoming_migration_co(void *opaque)
> exit(EXIT_FAILURE);
> }
>
> - if (autostart) {
> + /* runstate == "" means that we haven't received it through the
> + * wire, so we obey autostart. runstate == runing means that we
> + * need to run it, we need to make sure that we do it after
> + * everything else has finished. Every other state change is done
> + * at the post_load function */
> +
> + if (strcmp(global_state_get_runstate(), "running") == 0) {
> vm_start();
> - } else {
> - runstate_set(RUN_STATE_PAUSED);
> + } else if (strcmp(global_state_get_runstate(), "") == 0) {
> + if (autostart) {
> + vm_start();
> + } else {
> + runstate_set(RUN_STATE_PAUSED);
> + }
> }
> migrate_decompress_threads_join();
> }
> @@ -760,6 +770,7 @@ static void *migration_thread(void *opaque)
> qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
> old_vm_running = runstate_is_running();
>
> + global_state_store();
> ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
> if (ret >= 0) {
> qemu_file_set_rate_limit(s->file, INT64_MAX);
> @@ -855,3 +866,71 @@ void migrate_fd_connect(MigrationState *s)
> qemu_thread_create(&s->thread, "migration", migration_thread, s,
> QEMU_THREAD_JOINABLE);
> }
> +
> +typedef struct {
> + int32_t size;
> + uint8_t runstate[100];
> +} GlobalState;
unsigned for size? Could use something smaller than a int32_t
I guess for a 100 byte buffer.
> +
> +static GlobalState global_state;
> +
> +void global_state_store(void)
> +{
> + if (runstate_store((char *)global_state.runstate,
> + sizeof(global_state.runstate)) == -1) {
> + error_report("Runstate is too big: %s\n", global_state.runstate);
error_report's don't need the \n
> + exit(-1);
> + }
> +}
> +
> +char *global_state_get_runstate(void)
> +{
> + return (char *)global_state.runstate;
> +}
Is that needed outside of this file - if not then just make
it static or use the data directly?
> +
> +static int global_state_post_load(void *opaque, int version_id)
> +{
> + GlobalState *s = opaque;
> + int ret = 0;
> + char *runstate = (char *)s->runstate;
> +
> + if (strcmp(runstate, "running") != 0) {
> +
> + RunState r = runstate_index(runstate);
> +
> + if (r == -1) {
> + error_report("Unknown received state %s\n", runstate);
error_report's don't need the \n
> + return -1;
> + }
> + ret = vm_stop_force_state(r);
Why do this here, rather than in process_incoming_migration_co;
that would seem neater to keep the state change in one place.
Dave
> + }
> +
> + return ret;
> +}
> +
> +static void global_state_pre_save(void *opaque)
> +{
> + GlobalState *s = opaque;
> +
> + s->size = strlen((char *)s->runstate) + 1;
> +}
> +
> +static const VMStateDescription vmstate_globalstate = {
> + .name = "globalstate",
> + .version_id = 1,
> + .minimum_version_id = 1,
> + .post_load = global_state_post_load,
> + .pre_save = global_state_pre_save,
> + .fields = (VMStateField[]) {
> + VMSTATE_INT32(size, GlobalState),
> + VMSTATE_BUFFER(runstate, GlobalState),
> + VMSTATE_END_OF_LIST()
> + },
> +};
> +
> +void register_global_state(void)
> +{
> + /* We would use it independently that we receive it */
> + strcpy((char *)&global_state.runstate, "");
> + vmstate_register(NULL, 0, &vmstate_globalstate, &global_state);
> +}
> diff --git a/vl.c b/vl.c
> index b8844f6..8af6c79 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -4387,6 +4387,7 @@ int main(int argc, char **argv, char **envp)
> return 0;
> }
>
> + register_global_state();
> if (incoming) {
> Error *local_err = NULL;
> qemu_start_incoming_migration(incoming, &local_err);
> --
> 2.4.0
>
>
--
Dr. David Alan Gilbert / address@hidden / Manchester, UK
- Re: [Qemu-devel] [PATCH 3/9] runstate: Add runstate store, (continued)
- [Qemu-devel] [PATCH 4/9] runstate: create runstate_index function, Juan Quintela, 2015/05/14
- [Qemu-devel] [PATCH 5/9] runstate: migration allows more transitions now, Juan Quintela, 2015/05/14
- [Qemu-devel] [PATCH 1/9] migration: create savevm_state, Juan Quintela, 2015/05/14
- [Qemu-devel] [PATCH 6/9] migration: create new section to store global state, Juan Quintela, 2015/05/14
- Re: [Qemu-devel] [PATCH 6/9] migration: create new section to store global state,
Dr. David Alan Gilbert <=
- [Qemu-devel] [PATCH 7/9] global_state: Make section optional, Juan Quintela, 2015/05/14
- [Qemu-devel] [PATCH 8/9] vmstate: Create optional sections, Juan Quintela, 2015/05/14
- [Qemu-devel] [PATCH 2/9] migration: Use normal VMStateDescriptions for Subsections, Juan Quintela, 2015/05/14
- [Qemu-devel] [PATCH 9/9] migration: Add configuration section, Juan Quintela, 2015/05/14