From nobody Tue Feb 10 07:41:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496352719953908.1749721004832; Thu, 1 Jun 2017 14:31:59 -0700 (PDT) Received: from localhost ([::1]:46696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGXhG-0001Fg-9v for importer@patchew.org; Thu, 01 Jun 2017 17:31:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGXfN-0008QY-TM for qemu-devel@nongnu.org; Thu, 01 Jun 2017 17:30:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGXfM-00086W-5D for qemu-devel@nongnu.org; Thu, 01 Jun 2017 17:30:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52168) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGXfL-000857-SK for qemu-devel@nongnu.org; Thu, 01 Jun 2017 17:30:00 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9B16C0467CF for ; Thu, 1 Jun 2017 21:29:58 +0000 (UTC) Received: from secure.mitica (ovpn-117-3.ams2.redhat.com [10.36.117.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31B1651DE3; Thu, 1 Jun 2017 21:29:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D9B16C0467CF Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D9B16C0467CF From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 23:29:18 +0200 Message-Id: <20170601212921.30241-9-quintela@redhat.com> In-Reply-To: <20170601212921.30241-1-quintela@redhat.com> References: <20170601212921.30241-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 01 Jun 2017 21:29:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/11] migration: create global_state.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It don't belong anywhere else, just the global state where everybody can stick other things. Signed-off-by: Juan Quintela Reviewed-by: Laurent Vivier --- hw/i386/pc_piix.c | 1 + hw/ppc/spapr.c | 1 + hw/xen/xen-common.c | 1 + include/migration/global_state.h | 25 +++++++ include/migration/migration.h | 4 -- migration/Makefile.objs | 2 +- migration/global_state.c | 140 +++++++++++++++++++++++++++++++++++= ++++ migration/migration.c | 121 +-------------------------------- migration/savevm.c | 1 + vl.c | 1 + 10 files changed, 172 insertions(+), 125 deletions(-) create mode 100644 include/migration/global_state.h create mode 100644 migration/global_state.c diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 2234bd0..dc19d96 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -52,6 +52,7 @@ #include #include "hw/xen/xen_pt.h" #endif +#include "migration/global_state.h" #include "migration/migration.h" #include "kvm_i386.h" #include "sysemu/numa.h" diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index a44efbf..ac8a317 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -39,6 +39,7 @@ #include "sysemu/hw_accel.h" #include "kvm_ppc.h" #include "migration/migration.h" +#include "migration/global_state.h" #include "migration/register.h" #include "mmu-hash64.h" #include "mmu-book3s-v3.h" diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c index a9055e9..e265445 100644 --- a/hw/xen/xen-common.c +++ b/hw/xen/xen-common.c @@ -14,6 +14,7 @@ #include "sysemu/char.h" #include "sysemu/accel.h" #include "migration/migration.h" +#include "migration/global_state.h" =20 //#define DEBUG_XEN =20 diff --git a/include/migration/global_state.h b/include/migration/global_st= ate.h new file mode 100644 index 0000000..90faea7 --- /dev/null +++ b/include/migration/global_state.h @@ -0,0 +1,25 @@ +/* + * Global State configuration + * + * Copyright (c) 2014-2017 Red Hat Inc + * + * Authors: + * Juan Quintela + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_MIGRATION_GLOBAL_STATE_H +#define QEMU_MIGRATION_GLOBAL_STATE_H + +#include "sysemu/sysemu.h" + +void register_global_state(void); +void global_state_set_optional(void); +int global_state_store(void); +void global_state_store_running(void); +bool global_state_received(void); +RunState global_state_get_runstate(void); + +#endif diff --git a/include/migration/migration.h b/include/migration/migration.h index cb894b8..5050454 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -172,10 +172,6 @@ void migrate_send_rp_req_pages(MigrationIncomingState = *mis, const char* rbname, ram_addr_t start, size_t len); =20 void savevm_skip_section_footers(void); -void register_global_state(void); -void global_state_set_optional(void); void savevm_skip_configuration(void); -int global_state_store(void); -void global_state_store_running(void); =20 #endif diff --git a/migration/Makefile.objs b/migration/Makefile.objs index 90f8c1f..1c7770d 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -2,7 +2,7 @@ common-obj-y +=3D migration.o socket.o fd.o exec.o common-obj-y +=3D tls.o channel.o savevm.o common-obj-y +=3D colo-comm.o colo.o colo-failover.o common-obj-y +=3D vmstate.o vmstate-types.o page_cache.o -common-obj-y +=3D qemu-file.o +common-obj-y +=3D qemu-file.o global_state.o common-obj-y +=3D qemu-file-channel.o common-obj-y +=3D xbzrle.o postcopy-ram.o common-obj-y +=3D qjson.o diff --git a/migration/global_state.c b/migration/global_state.c new file mode 100644 index 0000000..16ac63f --- /dev/null +++ b/migration/global_state.c @@ -0,0 +1,140 @@ +/* + * Global State configuration + * + * Copyright (c) 2014-2017 Red Hat Inc + * + * Authors: + * Juan Quintela + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include "qemu/error-report.h" +#include "qapi/error.h" +#include "qapi/util.h" +#include "migration/global_state.h" +#include "migration/vmstate.h" +#include "sysemu/sysemu.h" +#include "trace.h" + +typedef struct { + bool optional; + uint32_t size; + uint8_t runstate[100]; + RunState state; + bool received; +} GlobalState; + +static GlobalState global_state; + +int global_state_store(void) +{ + if (!runstate_store((char *)global_state.runstate, + sizeof(global_state.runstate))) { + error_report("runstate name too big: %s", global_state.runstate); + trace_migrate_state_too_big(); + return -EINVAL; + } + return 0; +} + +void global_state_store_running(void) +{ + const char *state =3D RunState_lookup[RUN_STATE_RUNNING]; + strncpy((char *)global_state.runstate, + state, sizeof(global_state.runstate)); +} + +bool global_state_received(void) +{ + return global_state.received; +} + +RunState global_state_get_runstate(void) +{ + return global_state.state; +} + +void global_state_set_optional(void) +{ + global_state.optional =3D true; +} + +static bool global_state_needed(void *opaque) +{ + GlobalState *s =3D opaque; + char *runstate =3D (char *)s->runstate; + + /* If it is not optional, it is mandatory */ + + if (s->optional =3D=3D false) { + return true; + } + + /* If state is running or paused, it is not needed */ + + if (strcmp(runstate, "running") =3D=3D 0 || + strcmp(runstate, "paused") =3D=3D 0) { + return false; + } + + /* for any other state it is needed */ + return true; +} + +static int global_state_post_load(void *opaque, int version_id) +{ + GlobalState *s =3D opaque; + Error *local_err =3D NULL; + int r; + char *runstate =3D (char *)s->runstate; + + s->received =3D true; + trace_migrate_global_state_post_load(runstate); + + r =3D qapi_enum_parse(RunState_lookup, runstate, RUN_STATE__MAX, + -1, &local_err); + + if (r =3D=3D -1) { + if (local_err) { + error_report_err(local_err); + } + return -EINVAL; + } + s->state =3D r; + + return 0; +} + +static void global_state_pre_save(void *opaque) +{ + GlobalState *s =3D opaque; + + trace_migrate_global_state_pre_save((char *)s->runstate); + s->size =3D strlen((char *)s->runstate) + 1; +} + +static const VMStateDescription vmstate_globalstate =3D { + .name =3D "globalstate", + .version_id =3D 1, + .minimum_version_id =3D 1, + .post_load =3D global_state_post_load, + .pre_save =3D global_state_pre_save, + .needed =3D global_state_needed, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(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, ""); + global_state.received =3D false; + vmstate_register(NULL, 0, &vmstate_globalstate, &global_state); +} diff --git a/migration/migration.c b/migration/migration.c index 603d39d..6a7620b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -23,6 +23,7 @@ #include "socket.h" #include "rdma.h" #include "ram.h" +#include "migration/global_state.h" #include "migration/migration.h" #include "savevm.h" #include "qemu-file-channel.h" @@ -164,126 +165,6 @@ void migration_incoming_state_destroy(void) qemu_event_destroy(&mis->main_thread_load_event); } =20 - -typedef struct { - bool optional; - uint32_t size; - uint8_t runstate[100]; - RunState state; - bool received; -} GlobalState; - -static GlobalState global_state; - -int global_state_store(void) -{ - if (!runstate_store((char *)global_state.runstate, - sizeof(global_state.runstate))) { - error_report("runstate name too big: %s", global_state.runstate); - trace_migrate_state_too_big(); - return -EINVAL; - } - return 0; -} - -void global_state_store_running(void) -{ - const char *state =3D RunState_lookup[RUN_STATE_RUNNING]; - strncpy((char *)global_state.runstate, - state, sizeof(global_state.runstate)); -} - -static bool global_state_received(void) -{ - return global_state.received; -} - -static RunState global_state_get_runstate(void) -{ - return global_state.state; -} - -void global_state_set_optional(void) -{ - global_state.optional =3D true; -} - -static bool global_state_needed(void *opaque) -{ - GlobalState *s =3D opaque; - char *runstate =3D (char *)s->runstate; - - /* If it is not optional, it is mandatory */ - - if (s->optional =3D=3D false) { - return true; - } - - /* If state is running or paused, it is not needed */ - - if (strcmp(runstate, "running") =3D=3D 0 || - strcmp(runstate, "paused") =3D=3D 0) { - return false; - } - - /* for any other state it is needed */ - return true; -} - -static int global_state_post_load(void *opaque, int version_id) -{ - GlobalState *s =3D opaque; - Error *local_err =3D NULL; - int r; - char *runstate =3D (char *)s->runstate; - - s->received =3D true; - trace_migrate_global_state_post_load(runstate); - - r =3D qapi_enum_parse(RunState_lookup, runstate, RUN_STATE__MAX, - -1, &local_err); - - if (r =3D=3D -1) { - if (local_err) { - error_report_err(local_err); - } - return -EINVAL; - } - s->state =3D r; - - return 0; -} - -static void global_state_pre_save(void *opaque) -{ - GlobalState *s =3D opaque; - - trace_migrate_global_state_pre_save((char *)s->runstate); - s->size =3D strlen((char *)s->runstate) + 1; -} - -static const VMStateDescription vmstate_globalstate =3D { - .name =3D "globalstate", - .version_id =3D 1, - .minimum_version_id =3D 1, - .post_load =3D global_state_post_load, - .pre_save =3D global_state_pre_save, - .needed =3D global_state_needed, - .fields =3D (VMStateField[]) { - VMSTATE_UINT32(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, ""); - global_state.received =3D false; - vmstate_register(NULL, 0, &vmstate_globalstate, &global_state); -} - static void migrate_generate_event(int new_state) { if (migrate_use_events()) { diff --git a/migration/savevm.c b/migration/savevm.c index 543635b..265e908 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -38,6 +38,7 @@ #include "migration/snapshot.h" #include "migration/misc.h" #include "migration/register.h" +#include "migration/global_state.h" #include "ram.h" #include "qemu-file-channel.h" #include "qemu-file.h" diff --git a/vl.c b/vl.c index 80b86c0..bf9aa6a 100644 --- a/vl.c +++ b/vl.c @@ -88,6 +88,7 @@ int main(int argc, char **argv) #include "hw/block/block.h" #include "migration/misc.h" #include "migration/snapshot.h" +#include "migration/global_state.h" #include "sysemu/tpm.h" #include "sysemu/dma.h" #include "hw/audio/soundhw.h" --=20 2.9.4