Skip to contentSkip to conversation

migration: objectify MigrationState

PATCH Superseded Peter Xu 2 participants 23 messages Jun 23, 2017 – Jun 27, 2017

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

v5 cover migration: objectify MigrationState

v5:
- add r-b for Juan on patch 4,5,7-10
- patch 2: introduce register_compat_props_array() that may be further used by machine codes [Eduardo]
- patch 2: fix english error [Eduardo]

v4:
- dropped lots of patches related to AccelState.global_props. Now I am using AccelClass.global_props, and only use it in Xen codes.
- one patch is added to clean up the global property registerations, with some comment to show the ordering.
- one patch is added to dump migration globals in "info migrate" unconditionally (last patch).
- changed all the following xen_init() patches to use AccelClass.global_props.
- (since most of the patches are either touched-up again, or threw away, so no much r-b added, only one for Juan on the only_migratable patch, anyway, thanks for reviewing the old codes!)

------------

The main goal of this series is to let MigrationState be a QDev.

It helps in many use cases.

First of all, we can remove many legacy tricky functions. To name
some: savevm_skip_section_footers(), savevm_skip_configuration(), etc. They didn't do much thing but setup a bool value. If MigrationState can be a QDev, then these things can be setup by the HW_COMPAT_* magic with some lines like:

{
.driver = "migration",
.property = "send-configuration",
.value = "off",
}

Next, if this can be merged and okay, we can move on to convert more things into properties for migration. A very attractive use case of it is, we will be able to do this for migration:

-global migration.postcopy=on

Then we don't need to use either HMP/QMP interface to enable it. It greatly simplifies the migration test scripts.

Why QDev not QObject? The answer is simple: all the magic that we want for migration is bound to QDev (HW_COMPAT, "-global"). If one day we want to move these features from QDev to QObject, that'll be fine and easy for MigrationState. But before that, let's have MigrationState a QDev. :-)

Please kindly review. Thanks.

Peter Xu (10):
machine: export register_compat_prop()
accel: introduce AccelClass.global_props
vl: clean up global property registerations
migration: let MigrationState be a qdev
migration: move global_state.optional out
migration: move only_migratable to MigrationState
migration: move skip_configuration out
migration: move skip_section_footers
migration: merge enforce_config_section somewhat
migration: hmp: dump globals

 accel/accel.c                    |   6 ++
 hmp.c                            |   3 +
 hw/core/machine.c                |  13 -----
 hw/core/qdev-properties.c        |  20 +++++++
 hw/i386/pc_piix.c                |   3 -
 hw/ppc/spapr.c                   |   3 -
 hw/xen/xen-common.c              |  25 +++++++--
 include/hw/compat.h              |  12 ++++
 include/hw/qdev-properties.h     |   4 ++
 include/migration/global_state.h |   1 -
 include/migration/misc.h         |   6 +-
 include/sysemu/accel.h           |  10 ++++
 include/sysemu/sysemu.h          |   1 -
 migration/global_state.c         |   9 +--
 migration/migration.c            | 118 +++++++++++++++++++++++++++++++--------
 migration/migration.h            |  33 +++++++++++
 migration/savevm.c               |  32 ++---------
 vl.c                             |  41 ++++++++++++--
 18 files changed, 250 insertions(+), 90 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v5 1/10 machine: export register_compat_prop()

We have HW_COMPAT_*, however that's only bound to machines, not other things (like accelerators). Behind it, it was register_compat_prop() that played the trick. Let's export the function for further use outside HW_COMPAT_* magic.

Meanwhile, move it to qdev-properties.c where seems more proper (since it'll be used not only in machine codes).

---
 hw/core/machine.c            | 13 -------------
 hw/core/qdev-properties.c    | 13 +++++++++++++
 include/hw/qdev-properties.h |  3 +++
 3 files changed, 16 insertions(+), 13 deletions(-)
hw/core/machine.c +0 -13
index 2e7e977..ecb5552 100644
@@ -770,19 +770,6 @@ static void machine_class_finalize(ObjectClass *klass, void *data)
     g_free(mc->name);
 }
 
-static void register_compat_prop(const char *driver,
-                                 const char *property,
-                                 const char *value)
-{
-    GlobalProperty *p = g_new0(GlobalProperty, 1);
-    /* Machine compat_props must never cause errors: */
-    p->errp = &error_abort;
-    p->driver = driver;
-    p->property = property;
-    p->value = value;
-    qdev_prop_register_global(p);
-}
-
 static void machine_register_compat_for_subclass(ObjectClass *oc, void *opaque)
 {
     GlobalProperty *p = opaque;
hw/core/qdev-properties.c +13 -0
index 9f1a497..6ff1ac3 100644
@@ -1047,6 +1047,19 @@ void qdev_prop_register_global(GlobalProperty *prop)
     global_props = g_list_append(global_props, prop);
 }
 
+void register_compat_prop(const char *driver,
+                          const char *property,
+                          const char *value)
+{
+    GlobalProperty *p = g_new0(GlobalProperty, 1);
+    /* Machine compat_props must never cause errors: */
+    p->errp = &error_abort;
+    p->driver = driver;
+    p->property = property;
+    p->value = value;
+    qdev_prop_register_global(p);
+}
+
 void qdev_prop_register_global_list(GlobalProperty *props)
 {
     int i;
include/hw/qdev-properties.h +3 -0
index d206fc9..1722ca4 100644
@@ -201,6 +201,9 @@ void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value);
 
+void register_compat_prop(const char *driver, const char *property,
+                          const char *value);
+
 /**
  * qdev_property_add_static:
  * @dev: Device to add the property to.
Signature · 1 line
2.7.4
author
#4 lore raw

PATCH v5 2/10 accel: introduce AccelClass.global_props

In reply to Peter Xu

Introduce this new field for the accelerator classes so that each specific accelerator in the future can register its own global properties to be used further by the system. It works just like how the old machine compatible properties do, but only tailored for accelerators.

Introduce register_compat_props_array() for it. Export it so that it may be used in other codes as well in the future.

---
 accel/accel.c                |  6 ++++++
 hw/core/qdev-properties.c    |  7 +++++++
 include/hw/qdev-properties.h |  1 +
 include/sysemu/accel.h       | 10 ++++++++++
 vl.c                         |  1 +
 5 files changed, 25 insertions(+)
accel/accel.c +6 -0
index 7c079a5..fa85844 100644
@@ -120,6 +120,12 @@ void configure_accelerator(MachineState *ms)
     }
 }
 
+void accel_register_compat_props(AccelState *accel)
+{
+    AccelClass *class = ACCEL_GET_CLASS(accel);
+    register_compat_props_array(class->global_props);
+}
+
 static void register_accel_types(void)
 {
     type_register_static(&accel_type);
hw/core/qdev-properties.c +7 -0
index 6ff1ac3..19fa335 100644
@@ -1060,6 +1060,13 @@ void register_compat_prop(const char *driver,
     qdev_prop_register_global(p);
 }
 
+void register_compat_props_array(GlobalProperty *prop)
+{
+    for (; prop && prop->driver; prop++) {
+        register_compat_prop(prop->driver, prop->property, prop->value);
+    }
+}
+
 void qdev_prop_register_global_list(GlobalProperty *props)
 {
     int i;
include/hw/qdev-properties.h +1 -0
index 1722ca4..2bac6a0 100644
@@ -203,6 +203,7 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
 
 void register_compat_prop(const char *driver, const char *property,
                           const char *value);
+void register_compat_props_array(GlobalProperty *prop);
 
 /**
  * qdev_property_add_static:
include/sysemu/accel.h +10 -0
index 15944c1..effcd7f 100644
@@ -24,6 +24,7 @@
 #define HW_ACCEL_H
 
 #include "qom/object.h"
+#include "hw/qdev-properties.h"
 
 typedef struct AccelState {
     /*< private >*/
@@ -40,6 +41,13 @@ typedef struct AccelClass {
     int (*available)(void);
     int (*init_machine)(MachineState *ms);
     bool *allowed;
+    /*
+     * Array of global properties that would be applied when specific
+     * accelerator is chosen. It works just like
+     * MachineClass.compat_props but it's for accelerators not
+     * machines.
+     */
+    GlobalProperty *global_props;
 } AccelClass;
 
 #define TYPE_ACCEL "accel"
@@ -57,5 +65,7 @@ typedef struct AccelClass {
 extern int tcg_tb_size;
 
 void configure_accelerator(MachineState *ms);
+/* Register accelerator specific global properties */
+void accel_register_compat_props(AccelState *accel);
 
 #endif
vl.c +1 -0
index 59fea15..4452d7a 100644
@@ -4571,6 +4571,7 @@ int main(int argc, char **argv, char **envp)
             exit (i == 1 ? 1 : 0);
     }
 
+    accel_register_compat_props(current_machine->accelerator);
     machine_register_compat_props(current_machine);
 
     qemu_opts_foreach(qemu_find_opts("global"),
Signature · 1 line
2.7.4
author
#8 lore raw

PATCH v5 3/10 vl: clean up global property registerations

In reply to Peter Xu

It's not that clear on how the global properties are registered to global_props (and also its priority relationship). Let's provide a single function to be called in main() for that, with comment to explain it a bit.

---
 vl.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)
vl.c +24 -5
index 4452d7a..cdd2ec8 100644
@@ -2969,6 +2969,25 @@ static int qemu_read_default_config_file(void)
     return 0;
 }
 
+static void user_register_compat_props(void)
+{
+    qemu_opts_foreach(qemu_find_opts("global"),
+                      global_init_func, NULL, NULL);
+}
+
+/*
+ * Note: we should see that these compat properties are actually
+ * having a priority: accel < machine < user. This means e.g. when
+ * user specifies something in "-global", it'll always be used with
+ * highest priority.
+ */
+static void register_global_properties(MachineState *ms)
+{
+    accel_register_compat_props(ms->accelerator);
+    machine_register_compat_props(ms);
+    user_register_compat_props();
+}
+
 int main(int argc, char **argv, char **envp)
 {
     int i;
@@ -4571,11 +4590,11 @@ int main(int argc, char **argv, char **envp)
             exit (i == 1 ? 1 : 0);
     }
 
-    accel_register_compat_props(current_machine->accelerator);
-    machine_register_compat_props(current_machine);
-
-    qemu_opts_foreach(qemu_find_opts("global"),
-                      global_init_func, NULL, NULL);
+    /*
+     * Register all the global properties, including accel properties,
+     * machine properties, and user-specified ones.
+     */
+    register_global_properties(current_machine);
 
     /* This checkpoint is required by replay to separate prior clock
        reading from the other reads, because timer polling functions query
Signature · 1 line
2.7.4
author
#11 lore raw

PATCH v5 4/10 migration: let MigrationState be a qdev

In reply to Peter Xu

Let the old man "MigrationState" join the object family. Direct benefit is that we can start to use all the property features derived from current QDev, like: HW_COMPAT_* bits, command line setup for migration parameters (so will never need to set them up each time using HMP/QMP, this is really, really attractive for test writters), etc.

I see no reason to disallow this happen yet. So let's start from this one, to see whether it would be anything good.

Now we init the MigrationState struct statically in main() to make sure it's initialized after global properties are applied, since we'll use them during creation of the object.

No functional change at all.

---
 include/migration/misc.h |  1 +
 migration/migration.c    | 78 ++++++++++++++++++++++++++++++++++--------------
 migration/migration.h    | 19 ++++++++++++
 vl.c                     |  6 ++++
 4 files changed, 81 insertions(+), 23 deletions(-)
include/migration/misc.h +1 -0
index 65c7070..2d36cf5 100644
@@ -45,6 +45,7 @@ void savevm_skip_section_footers(void);
 void savevm_skip_configuration(void);
 
 /* migration/migration.c */
+void migration_object_init(void);
 void qemu_start_incoming_migration(const char *uri, Error **errp);
 bool migration_is_idle(void);
 void add_migration_state_change_notifier(Notifier *notify);
migration/migration.c +55 -23

90 lines not on this page · raw message

migration/migration.h +19 -0
index d9a268a..3fca364 100644
@@ -19,6 +19,7 @@
 #include "qapi-types.h"
 #include "exec/cpu-common.h"
 #include "qemu/coroutine_int.h"
+#include "hw/qdev.h"
 
 /* State for the incoming migration */
 struct MigrationIncomingState {
@@ -62,8 +63,26 @@ struct MigrationIncomingState {
 MigrationIncomingState *migration_incoming_get_current(void);
 void migration_incoming_state_destroy(void);
 
+#define TYPE_MIGRATION "migration"
+
+#define MIGRATION_CLASS(klass) \
+    OBJECT_CLASS_CHECK(MigrationClass, (klass), TYPE_MIGRATION)
+#define MIGRATION_OBJ(obj) \
+    OBJECT_CHECK(MigrationState, (obj), TYPE_MIGRATION)
+#define MIGRATION_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(MigrationClass, (obj), TYPE_MIGRATION)
+
+typedef struct MigrationClass {
+    /*< private >*/
+    DeviceClass parent_class;
+} MigrationClass;
+
 struct MigrationState
 {
+    /*< private >*/
+    DeviceState parent_obj;
+
+    /*< public >*/
     size_t bytes_xfer;
     size_t xfer_limit;
     QemuThread thread;
vl.c +6 -0
index cdd2ec8..9b04ba7 100644
@@ -4596,6 +4596,12 @@ int main(int argc, char **argv, char **envp)
      */
     register_global_properties(current_machine);
 
+    /*
+     * Migration object can only be created after global properties
+     * are applied correctly.
+     */
+    migration_object_init();
+
     /* This checkpoint is required by replay to separate prior clock
        reading from the other reads, because timer polling functions query
        clock values from the log. */
Signature · 1 line
2.7.4
author
#15 lore raw

PATCH v5 5/10 migration: move global_state.optional out

In reply to Peter Xu

Put it into MigrationState then we can use the properties to specify whether to enable storing global state.

Removing global_state_set_optional() since now we can use HW_COMPAT_2_3 for x86/power, and AccelClass.global_props for Xen.

---
 hw/i386/pc_piix.c                |  1 -
 hw/ppc/spapr.c                   |  1 -
 hw/xen/xen-common.c              | 11 ++++++++++-
 include/hw/compat.h              |  4 ++++
 include/migration/global_state.h |  1 -
 migration/global_state.c         |  9 ++-------
 migration/migration.c            |  7 +++++++
 migration/migration.h            |  6 ++++++
 8 files changed, 29 insertions(+), 11 deletions(-)
hw/i386/pc_piix.c +0 -1
index 46a2bc4..3b51297 100644
@@ -318,7 +318,6 @@ static void pc_compat_2_3(MachineState *machine)
     if (kvm_enabled()) {
         pcms->smm = ON_OFF_AUTO_OFF;
     }
-    global_state_set_optional();
     savevm_skip_configuration();
 }
 
hw/ppc/spapr.c +0 -1
index e877d45..edbdbfd 100644
@@ -3580,7 +3580,6 @@ static void spapr_machine_2_3_instance_options(MachineState *machine)
 {
     spapr_machine_2_4_instance_options(machine);
     savevm_skip_section_footers();
-    global_state_set_optional();
     savevm_skip_configuration();
 }
 
hw/xen/xen-common.c +10 -1
index d3fa705..9163a0a 100644
@@ -139,19 +139,28 @@ static int xen_init(MachineState *ms)
     }
     qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
 
-    global_state_set_optional();
     savevm_skip_configuration();
     savevm_skip_section_footers();
 
     return 0;
 }
 
+GlobalProperty xen_compat_props[] = {
+    {
+        .driver = "migration",
+        .property = "store-global-state",
+        .value = "off",
+    },
+    { .driver = NULL, .property = NULL, .value = NULL },
+};
+
 static void xen_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "Xen";
     ac->init_machine = xen_init;
     ac->allowed = &xen_allowed;
+    ac->global_props = xen_compat_props;
 }
 
 #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
include/hw/compat.h +4 -0
index 26cd585..a506a74 100644
@@ -181,6 +181,10 @@
         .driver   = TYPE_PCI_DEVICE,\
         .property = "x-pcie-lnksta-dllla",\
         .value    = "off",\
+    },{\
+        .driver   = "migration",\
+        .property = "store-global-state",\
+        .value    = "off",\
     },
 
 #define HW_COMPAT_2_2 \
include/migration/global_state.h +0 -1
index 90faea7..d307de8 100644
@@ -16,7 +16,6 @@
 #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);
migration/global_state.c +2 -7
index f792cf5..dcbbcb2 100644
@@ -15,12 +15,12 @@
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qapi/util.h"
+#include "migration.h"
 #include "migration/global_state.h"
 #include "migration/vmstate.h"
 #include "trace.h"
 
 typedef struct {
-    bool optional;
     uint32_t size;
     uint8_t runstate[100];
     RunState state;
@@ -57,11 +57,6 @@ RunState global_state_get_runstate(void)
     return global_state.state;
 }
 
-void global_state_set_optional(void)
-{
-    global_state.optional = true;
-}
-
 static bool global_state_needed(void *opaque)
 {
     GlobalState *s = opaque;
@@ -69,7 +64,7 @@ static bool global_state_needed(void *opaque)
 
     /* If it is not optional, it is mandatory */
 
-    if (s->optional == false) {
+    if (migrate_get_current()->store_global_state) {
         return true;
     }
 
migration/migration.c +7 -0
index 2c25927..221b22c 100644
@@ -1976,11 +1976,18 @@ void migrate_fd_connect(MigrationState *s)
     s->migration_thread_running = true;
 }
 
+static Property migration_properties[] = {
+    DEFINE_PROP_BOOL("store-global-state", MigrationState,
+                     store_global_state, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void migration_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->user_creatable = false;
+    dc->props = migration_properties;
 }
 
 static void migration_instance_init(Object *obj)
migration/migration.h +6 -0
index 3fca364..4b898e9 100644
@@ -133,6 +133,12 @@ struct MigrationState
     /* Do we have to clean up -b/-i from old migrate parameters */
     /* This feature is deprecated and will be removed */
     bool must_remove_block_options;
+
+    /*
+     * Global switch on whether we need to store the global state
+     * during migration.
+     */
+    bool store_global_state;
 };
 
 void migrate_set_state(int *state, int old_state, int new_state);
Signature · 1 line
2.7.4
author
#18 lore raw

PATCH v5 6/10 migration: move only_migratable to MigrationState

In reply to Peter Xu

One less global variable, and it does only matter with migration.

We keep the old "--only-migratable" option, but also now we support:

-global migration.only-migratable=true

Currently still keep the old interface.

Hmm, now vl.c has no way to access migrate_get_current(). Export a function for it to setup only_migratable.

---
 include/migration/misc.h | 2 ++
 include/sysemu/sysemu.h  | 1 -
 migration/migration.c    | 8 +++++++-
 migration/migration.h    | 3 +++
 migration/savevm.c       | 2 +-
 vl.c                     | 9 +++++++--
 6 files changed, 20 insertions(+), 5 deletions(-)
include/migration/misc.h +2 -0
index 2d36cf5..6ac3307 100644
@@ -55,4 +55,6 @@ bool migration_has_finished(MigrationState *);
 bool migration_has_failed(MigrationState *);
 /* ...and after the device transmission */
 bool migration_in_postcopy_after_devices(MigrationState *);
+void migration_only_migratable_set(void);
+
 #endif
include/sysemu/sysemu.h +0 -1
index 9841a52..b213696 100644
@@ -15,7 +15,6 @@
 /* vl.c */
 
 extern const char *bios_name;
-extern int only_migratable;
 extern const char *qemu_name;
 extern QemuUUID qemu_uuid;
 extern bool qemu_uuid_set;
migration/migration.c +7 -1
index 221b22c..67f9e68 100644
@@ -115,6 +115,11 @@ MigrationState *migrate_get_current(void)
     return current_migration;
 }
 
+void migration_only_migratable_set(void)
+{
+    migrate_get_current()->only_migratable = true;
+}
+
 MigrationIncomingState *migration_incoming_get_current(void)
 {
     static bool once;
@@ -986,7 +991,7 @@ static GSList *migration_blockers;
 
 int migrate_add_blocker(Error *reason, Error **errp)
 {
-    if (only_migratable) {
+    if (migrate_get_current()->only_migratable) {
         error_propagate(errp, error_copy(reason));
         error_prepend(errp, "disallowing migration blocker "
                           "(--only_migratable) for: ");
@@ -1979,6 +1984,7 @@ void migrate_fd_connect(MigrationState *s)
 static Property migration_properties[] = {
     DEFINE_PROP_BOOL("store-global-state", MigrationState,
                      store_global_state, true),
+    DEFINE_PROP_BOOL("only-migratable", MigrationState, only_migratable, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
migration/migration.h +3 -0
index 4b898e9..34377dd 100644
@@ -139,6 +139,9 @@ struct MigrationState
      * during migration.
      */
     bool store_global_state;
+
+    /* Whether the VM is only allowing for migratable devices */
+    bool only_migratable;
 };
 
 void migrate_set_state(int *state, int old_state, int new_state);
migration/savevm.c +1 -1
index 6bfd489..917ab05 100644
@@ -2314,7 +2314,7 @@ void vmstate_register_ram_global(MemoryRegion *mr)
 bool vmstate_check_only_migratable(const VMStateDescription *vmsd)
 {
     /* check needed if --only-migratable is specified */
-    if (!only_migratable) {
+    if (!migrate_get_current()->only_migratable) {
         return true;
     }
 
vl.c +7 -2
index 9b04ba7..57ff065 100644
@@ -188,7 +188,6 @@ bool boot_strict;
 uint8_t *boot_splash_filedata;
 size_t boot_splash_filedata_size;
 uint8_t qemu_extra_params_fw[2];
-int only_migratable; /* turn it off unless user states otherwise */
 
 int icount_align_option;
 
@@ -3953,7 +3952,13 @@ int main(int argc, char **argv, char **envp)
                 incoming = optarg;
                 break;
             case QEMU_OPTION_only_migratable:
-                only_migratable = 1;
+                /*
+                 * TODO: we can remove this option one day, and we
+                 * should all use:
+                 *
+                 * "-global migration.only-migratable=true"
+                 */
+                migration_only_migratable_set();
                 break;
             case QEMU_OPTION_nodefaults:
                 has_defaults = 0;
Signature · 1 line
2.7.4
author
#19 lore raw

PATCH v5 7/10 migration: move skip_configuration out

In reply to Peter Xu

It was in SaveState but now moved to MigrationState altogether, reverted its meaning, then renamed to "send_configuration". Again, using HW_COMPAT_2_3 for old PC/SPAPR machines, and accel_register_prop() for xen_init().

Removing savevm_skip_configuration().

---
 hw/i386/pc_piix.c        |  1 -
 hw/ppc/spapr.c           |  1 -
 hw/xen/xen-common.c      |  6 +++++-
 include/hw/compat.h      |  4 ++++
 include/migration/misc.h |  1 -
 migration/migration.c    |  2 ++
 migration/migration.h    |  3 +++
 migration/savevm.c       | 15 ++++-----------
 8 files changed, 18 insertions(+), 15 deletions(-)
hw/i386/pc_piix.c +0 -1
index 3b51297..488fc0a 100644
@@ -318,7 +318,6 @@ static void pc_compat_2_3(MachineState *machine)
     if (kvm_enabled()) {
         pcms->smm = ON_OFF_AUTO_OFF;
     }
-    savevm_skip_configuration();
 }
 
 static void pc_compat_2_2(MachineState *machine)
hw/ppc/spapr.c +0 -1
index edbdbfd..29fac1b 100644
@@ -3580,7 +3580,6 @@ static void spapr_machine_2_3_instance_options(MachineState *machine)
 {
     spapr_machine_2_4_instance_options(machine);
     savevm_skip_section_footers();
-    savevm_skip_configuration();
 }
 
 static void spapr_machine_2_3_class_options(MachineClass *mc)
hw/xen/xen-common.c +5 -1
index 9163a0a..6e52fb0 100644
@@ -139,7 +139,6 @@ static int xen_init(MachineState *ms)
     }
     qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
 
-    savevm_skip_configuration();
     savevm_skip_section_footers();
 
     return 0;
@@ -151,6 +150,11 @@ GlobalProperty xen_compat_props[] = {
         .property = "store-global-state",
         .value = "off",
     },
+    {
+        .driver = "migration",
+        .property = "send-configuration",
+        .value = "off",
+    },
     { .driver = NULL, .property = NULL, .value = NULL },
 };
 
include/hw/compat.h +4 -0
index a506a74..1a3fd94 100644
@@ -183,6 +183,10 @@
         .value    = "off",\
     },{\
         .driver   = "migration",\
+        .property = "send-configuration",\
+        .value    = "off",\
+    },{\
+        .driver   = "migration",\
         .property = "store-global-state",\
         .value    = "off",\
     },
include/migration/misc.h +0 -1
index 6ac3307..f30db4d 100644
@@ -42,7 +42,6 @@ int64_t self_announce_delay(int round)
 
 void dump_vmstate_json_to_file(FILE *out_fp);
 void savevm_skip_section_footers(void);
-void savevm_skip_configuration(void);
 
 /* migration/migration.c */
 void migration_object_init(void);
migration/migration.c +2 -0
index 67f9e68..414e14d 100644
@@ -1985,6 +1985,8 @@ static Property migration_properties[] = {
     DEFINE_PROP_BOOL("store-global-state", MigrationState,
                      store_global_state, true),
     DEFINE_PROP_BOOL("only-migratable", MigrationState, only_migratable, false),
+    DEFINE_PROP_BOOL("send-configuration", MigrationState,
+                     send_configuration, true),
     DEFINE_PROP_END_OF_LIST(),
 };
 
migration/migration.h +3 -0
index 34377dd..4d4ea0d 100644
@@ -142,6 +142,9 @@ struct MigrationState
 
     /* Whether the VM is only allowing for migratable devices */
     bool only_migratable;
+
+    /* Whether we send QEMU_VM_CONFIGURATION during migration */
+    bool send_configuration;
 };
 
 void migrate_set_state(int *state, int old_state, int new_state);
migration/savevm.c +4 -11
index 917ab05..f1e144d 100644
@@ -287,7 +287,6 @@ typedef struct SaveStateEntry {
 typedef struct SaveState {
     QTAILQ_HEAD(, SaveStateEntry) handlers;
     int global_section_id;
-    bool skip_configuration;
     uint32_t len;
     const char *name;
     uint32_t target_page_bits;
@@ -296,15 +295,8 @@ typedef struct SaveState {
 static SaveState savevm_state = {
     .handlers = QTAILQ_HEAD_INITIALIZER(savevm_state.handlers),
     .global_section_id = 0,
-    .skip_configuration = false,
 };
 
-void savevm_skip_configuration(void)
-{
-    savevm_state.skip_configuration = true;
-}
-
-
 static void configuration_pre_save(void *opaque)
 {
     SaveState *state = opaque;
@@ -970,11 +962,11 @@ void qemu_savevm_state_header(QEMUFile *f)
     qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
     qemu_put_be32(f, QEMU_VM_FILE_VERSION);
 
-    if (!savevm_state.skip_configuration || enforce_config_section()) {
+    if (migrate_get_current()->send_configuration ||
+        enforce_config_section()) {
         qemu_put_byte(f, QEMU_VM_CONFIGURATION);
         vmstate_save_state(f, &vmstate_configuration, &savevm_state, 0);
     }
-
 }
 
 void qemu_savevm_state_begin(QEMUFile *f)
@@ -1995,7 +1987,8 @@ int qemu_loadvm_state(QEMUFile *f)
         return -ENOTSUP;
     }
 
-    if (!savevm_state.skip_configuration || enforce_config_section()) {
+    if (migrate_get_current()->send_configuration ||
+        enforce_config_section()) {
         if (qemu_get_byte(f) != QEMU_VM_CONFIGURATION) {
             error_report("Configuration section missing");
             return -EINVAL;
Signature · 1 line
2.7.4
author
#20 lore raw

PATCH v5 8/10 migration: move skip_section_footers

In reply to Peter Xu

Move it into MigrationState, revert its meaning and renaming it to send_section_footer, with a property bound to it. Same trick is played like previous patches.

Removing savevm_skip_section_footers().

---
 hw/i386/pc_piix.c        |  1 -
 hw/ppc/spapr.c           |  1 -
 hw/xen/xen-common.c      |  8 +++++---
 include/hw/compat.h      |  4 ++++
 include/migration/misc.h |  1 -
 migration/migration.c    |  2 ++
 migration/migration.h    |  2 ++
 migration/savevm.c       | 11 ++---------
 8 files changed, 15 insertions(+), 15 deletions(-)
hw/i386/pc_piix.c +0 -1
index 488fc0a..22dbef6 100644
@@ -314,7 +314,6 @@ static void pc_init1(MachineState *machine,
 static void pc_compat_2_3(MachineState *machine)
 {
     PCMachineState *pcms = PC_MACHINE(machine);
-    savevm_skip_section_footers();
     if (kvm_enabled()) {
         pcms->smm = ON_OFF_AUTO_OFF;
     }
hw/ppc/spapr.c +0 -1
index 29fac1b..7c40fdf 100644
@@ -3579,7 +3579,6 @@ DEFINE_SPAPR_MACHINE(2_4, "2.4", false);
 static void spapr_machine_2_3_instance_options(MachineState *machine)
 {
     spapr_machine_2_4_instance_options(machine);
-    savevm_skip_section_footers();
 }
 
 static void spapr_machine_2_3_class_options(MachineClass *mc)
hw/xen/xen-common.c +5 -3
index 6e52fb0..04512f4 100644
@@ -138,9 +138,6 @@ static int xen_init(MachineState *ms)
         return -1;
     }
     qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
-
-    savevm_skip_section_footers();
-
     return 0;
 }
 
@@ -155,6 +152,11 @@ GlobalProperty xen_compat_props[] = {
         .property = "send-configuration",
         .value = "off",
     },
+    {
+        .driver = "migration",
+        .property = "send-section-footer",
+        .value = "off",
+    },
     { .driver = NULL, .property = NULL, .value = NULL },
 };
 
include/hw/compat.h +4 -0
index 1a3fd94..08f3600 100644
@@ -187,6 +187,10 @@
         .value    = "off",\
     },{\
         .driver   = "migration",\
+        .property = "send-section-footer",\
+        .value    = "off",\
+    },{\
+        .driver   = "migration",\
         .property = "store-global-state",\
         .value    = "off",\
     },
include/migration/misc.h +0 -1
index f30db4d..854c28d 100644
@@ -41,7 +41,6 @@ int64_t self_announce_delay(int round)
 /* migration/savevm.c */
 
 void dump_vmstate_json_to_file(FILE *out_fp);
-void savevm_skip_section_footers(void);
 
 /* migration/migration.c */
 void migration_object_init(void);
migration/migration.c +2 -0
index 414e14d..96c6412 100644
@@ -1987,6 +1987,8 @@ static Property migration_properties[] = {
     DEFINE_PROP_BOOL("only-migratable", MigrationState, only_migratable, false),
     DEFINE_PROP_BOOL("send-configuration", MigrationState,
                      send_configuration, true),
+    DEFINE_PROP_BOOL("send-section-footer", MigrationState,
+                     send_section_footer, true),
     DEFINE_PROP_END_OF_LIST(),
 };
 
migration/migration.h +2 -0
index 4d4ea0d..994b017 100644
@@ -145,6 +145,8 @@ struct MigrationState
 
     /* Whether we send QEMU_VM_CONFIGURATION during migration */
     bool send_configuration;
+    /* Whether we send section footer during migration */
+    bool send_section_footer;
 };
 
 void migrate_set_state(int *state, int old_state, int new_state);
migration/savevm.c +2 -9
index f1e144d..28fa1d5 100644
@@ -62,8 +62,6 @@
 
 const unsigned int postcopy_ram_discard_version = 0;
 
-static bool skip_section_footers;
-
 /* Subcommands for QEMU_VM_COMMAND */
 enum qemu_vm_cmd {
     MIG_CMD_INVALID = 0,   /* Must be 0 */
@@ -761,11 +759,6 @@ static void vmstate_save(QEMUFile *f, SaveStateEntry *se, QJSON *vmdesc)
     vmstate_save_state(f, se->vmsd, se->opaque, vmdesc);
 }
 
-void savevm_skip_section_footers(void)
-{
-    skip_section_footers = true;
-}
-
 /*
  * Write the header for device section (QEMU_VM_SECTION START/END/PART/FULL)
  */
@@ -793,7 +786,7 @@ static void save_section_header(QEMUFile *f, SaveStateEntry *se,
  */
 static void save_section_footer(QEMUFile *f, SaveStateEntry *se)
 {
-    if (!skip_section_footers) {
+    if (migrate_get_current()->send_section_footer) {
         qemu_put_byte(f, QEMU_VM_SECTION_FOOTER);
         qemu_put_be32(f, se->section_id);
     }
@@ -1802,7 +1795,7 @@ static bool check_section_footer(QEMUFile *f, SaveStateEntry *se)
     uint8_t read_mark;
     uint32_t read_section_id;
 
-    if (skip_section_footers) {
+    if (!migrate_get_current()->send_section_footer) {
         /* No footer to check */
         return true;
     }
Signature · 1 line
2.7.4
author
#21 lore raw

PATCH v5 9/10 migration: merge enforce_config_section somewhat

In reply to Peter Xu

These two parameters:

- MachineState::enforce_config_section
- MigrationState::send_configuration

are playing similar role here. This patch merges the first one into second, then we'll have a single place to reference whether we need to send the configuration section.

I didn't remove the MachineState.enforce_config_section field since when applying that machine property (in machine_set_property()) we haven't yet initialized global properties and migration object. Then, it's still not easy to pass that boolean to MigrationState at such an early time.

A natural benefit for current patch is that now we kept the meaning of "enforce-config-section" since it'll still have the highest priority (that's what "enforce" mean I guess).

---
 migration/migration.c | 12 ++++++++++++
 migration/savevm.c    | 12 ++----------
 2 files changed, 14 insertions(+), 10 deletions(-)
migration/migration.c +12 -0
index 96c6412..e7e6cf3 100644
@@ -42,6 +42,7 @@
 #include "exec/target_page.h"
 #include "io/channel-buffer.h"
 #include "migration/colo.h"
+#include "hw/boards.h"
 
 #define MAX_THROTTLE  (32 << 20)      /* Migration transfer speed throttling */
 
@@ -102,9 +103,20 @@ static MigrationState *current_migration;
 
 void migration_object_init(void)
 {
+    MachineState *ms = MACHINE(qdev_get_machine());
+
     /* This can only be called once. */
     assert(!current_migration);
     current_migration = MIGRATION_OBJ(object_new(TYPE_MIGRATION));
+
+    /*
+     * We cannot really do this in migration_instance_init() since at
+     * that time global properties are not yet applied, then this
+     * value will be definitely replaced by something else.
+     */
+    if (ms->enforce_config_section) {
+        current_migration->send_configuration = true;
+    }
 }
 
 /* For outgoing */
migration/savevm.c +2 -10
index 28fa1d5..6b1a9a5 100644
@@ -943,20 +943,13 @@ bool qemu_savevm_state_blocked(Error **errp)
     return false;
 }
 
-static bool enforce_config_section(void)
-{
-    MachineState *machine = MACHINE(qdev_get_machine());
-    return machine->enforce_config_section;
-}
-
 void qemu_savevm_state_header(QEMUFile *f)
 {
     trace_savevm_state_header();
     qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
     qemu_put_be32(f, QEMU_VM_FILE_VERSION);
 
-    if (migrate_get_current()->send_configuration ||
-        enforce_config_section()) {
+    if (migrate_get_current()->send_configuration) {
         qemu_put_byte(f, QEMU_VM_CONFIGURATION);
         vmstate_save_state(f, &vmstate_configuration, &savevm_state, 0);
     }
@@ -1980,8 +1973,7 @@ int qemu_loadvm_state(QEMUFile *f)
         return -ENOTSUP;
     }
 
-    if (migrate_get_current()->send_configuration ||
-        enforce_config_section()) {
+    if (migrate_get_current()->send_configuration) {
         if (qemu_get_byte(f) != QEMU_VM_CONFIGURATION) {
             error_report("Configuration section missing");
             return -EINVAL;
Signature · 1 line
2.7.4
author
#22 lore raw

PATCH v5 10/10 migration: hmp: dump globals

In reply to Peter Xu

Now we have some globals that can be configured for migration. Dump them in HMP info migration for better debugging.

(we can also use this to monitor whether COMPAT fields are applied correctly on compatible machines)

---
 hmp.c                    |  3 +++
 include/migration/misc.h |  1 +
 migration/migration.c    | 11 +++++++++++
 3 files changed, 15 insertions(+)
hmp.c +3 -0
index 8c72c58..4c41cac 100644
@@ -43,6 +43,7 @@
 #include "exec/ramlist.h"
 #include "hw/intc/intc.h"
 #include "migration/snapshot.h"
+#include "migration/misc.h"
 
 #ifdef CONFIG_SPICE
 #include <spice/enums.h>
@@ -164,6 +165,8 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
     info = qmp_query_migrate(NULL);
     caps = qmp_query_migrate_capabilities(NULL);
 
+    migration_global_dump(mon);
+
     /* do not display parameters during setup */
     if (info->has_status && caps) {
         monitor_printf(mon, "capabilities: ");
include/migration/misc.h +1 -0
index 854c28d..2255121 100644
@@ -54,5 +54,6 @@ bool migration_has_failed(MigrationState *);
 /* ...and after the device transmission */
 bool migration_in_postcopy_after_devices(MigrationState *);
 void migration_only_migratable_set(void);
+void migration_global_dump(Monitor *mon);
 
 #endif
migration/migration.c +11 -0
index e7e6cf3..b1b0825 100644
@@ -43,6 +43,7 @@
 #include "io/channel-buffer.h"
 #include "migration/colo.h"
 #include "hw/boards.h"
+#include "monitor/monitor.h"
 
 #define MAX_THROTTLE  (32 << 20)      /* Migration transfer speed throttling */
 
@@ -1993,6 +1994,16 @@ void migrate_fd_connect(MigrationState *s)
     s->migration_thread_running = true;
 }
 
+void migration_global_dump(Monitor *mon)
+{
+    MigrationState *ms = migrate_get_current();
+
+    monitor_printf(mon, "globals: store-global-state=%d, only_migratable=%d, "
+                   "send-configuration=%d, send-section-footer=%d\n",
+                   ms->store_global_state, ms->only_migratable,
+                   ms->send_configuration, ms->send_section_footer);
+}
+
 static Property migration_properties[] = {
     DEFINE_PROP_BOOL("store-global-state", MigrationState,
                      store_global_state, true),
Signature · 1 line
2.7.4
#2 lore raw

Re: [Qemu-devel] [PATCH v5 01/10] machine: export register_compat_prop()

In reply to Peter Xu
Quoted 44 lines · Peter Xu

We have HW_COMPAT_*, however that's only bound to machines, not other things (like accelerators). Behind it, it was register_compat_prop() that played the trick. Let's export the function for further use outside HW_COMPAT_* magic.

Meanwhile, move it to qdev-properties.c where seems more proper (since it'll be used not only in machine codes).

---
 hw/core/machine.c            | 13 -------------
 hw/core/qdev-properties.c    | 13 +++++++++++++
 include/hw/qdev-properties.h |  3 +++
 3 files changed, 16 insertions(+), 13 deletions(-)
hw/core/machine.c +0 -13
index 2e7e977..ecb5552 100644
@@ -770,19 +770,6 @@ static void machine_class_finalize(ObjectClass *klass, void *data)
     g_free(mc->name);
 }
 
-static void register_compat_prop(const char *driver,
-                                 const char *property,
-                                 const char *value)
-{
-    GlobalProperty *p = g_new0(GlobalProperty, 1);
-    /* Machine compat_props must never cause errors: */
-    p->errp = &error_abort;
-    p->driver = driver;
-    p->property = property;
-    p->value = value;
-    qdev_prop_register_global(p);
-}
-
 static void machine_register_compat_for_subclass(ObjectClass *oc, void *opaque)
 {
     GlobalProperty *p = opaque;
hw/core/qdev-properties.c +0 -0
index 9f1a497..6ff1ac3 100644

hw/core/qdev-properties.c void qdev_prop_register_global(GlobalProperty *prop) · line 1055

Quoted 9 lines
hw/core/qdev-properties.c +6 -0
@@ -1047,6 +1047,19 @@ void qdev_prop_register_global(GlobalProperty *prop)
     global_props = g_list_append(global_props, prop);
 }
 
+void register_compat_prop(const char *driver,
+                          const char *property,
+                          const char *value)
+{
+    GlobalProperty *p = g_new0(GlobalProperty, 1);
+    /* Machine compat_props must never cause errors: */

Now this won't be used only for machine compat_props, so this comment needs to be deleted or updated (see suggestion below).

Quoted 15 lines
hw/core/qdev-properties.c +7 -0
+    p->errp = &error_abort;
+    p->driver = driver;
+    p->property = property;
+    p->value = value;
+    qdev_prop_register_global(p);
+}
+
 void qdev_prop_register_global_list(GlobalProperty *props)
 {
     int i;
include/hw/qdev-properties.h +0 -0
index d206fc9..1722ca4 100644

include/hw/qdev-properties.h void qdev_prop_set_globals(DeviceState *dev); · line 203

Quoted 3 lines
include/hw/qdev-properties.h +0 -0
@@ -201,6 +201,9 @@ void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value);
 

As this function is very easy to be misused, I suggest including the following documentation:

/**
* register_compat_prop:
*
* Register internal (not user-provided) global property, changing the
* default value of a given property in a device type. This can be used
* for enabling machine-type compatibility or for enabling
* accelerator-specific defaults in devices.
*
* The property values set using this function must be always valid and
* never report setter errors, as they property have
* GlobalProperty::errp set to &error_abort.
*
* User-provided global properties should override internal global
* properties, so callers of this function should ensure that it is
* called before user-provided global properties are registered. *
* @driver: Device type to be affected
* @property: Property whose default value is going to be changed
* @value: New default value for the property
*/

Quoted 10 lines
include/hw/qdev-properties.h +3 -0
+void register_compat_prop(const char *driver, const char *property,
+                          const char *value);
+
 /**
  * qdev_property_add_static:
  * @dev: Device to add the property to.
Signature · 1 line
2.7.4
Signature · 1 line
Eduardo
#5 lore raw

Re: [Qemu-devel] [PATCH v5 02/10] accel: introduce AccelClass.global_props

In reply to Peter Xu
Quoted 41 lines · Peter Xu

Introduce this new field for the accelerator classes so that each specific accelerator in the future can register its own global properties to be used further by the system. It works just like how the old machine compatible properties do, but only tailored for accelerators.

Introduce register_compat_props_array() for it. Export it so that it may be used in other codes as well in the future.

---
 accel/accel.c                |  6 ++++++
 hw/core/qdev-properties.c    |  7 +++++++
 include/hw/qdev-properties.h |  1 +
 include/sysemu/accel.h       | 10 ++++++++++
 vl.c                         |  1 +
 5 files changed, 25 insertions(+)
accel/accel.c +6 -0
index 7c079a5..fa85844 100644
@@ -120,6 +120,12 @@ void configure_accelerator(MachineState *ms)
     }
 }
 
+void accel_register_compat_props(AccelState *accel)
+{
+    AccelClass *class = ACCEL_GET_CLASS(accel);
+    register_compat_props_array(class->global_props);
+}
+
 static void register_accel_types(void)
 {
     type_register_static(&accel_type);
hw/core/qdev-properties.c +0 -0
index 6ff1ac3..19fa335 100644

hw/core/qdev-properties.c void register_compat_prop(const char *driver, · line 1063

Quoted 4 lines
hw/core/qdev-properties.c +1 -0
@@ -1060,6 +1060,13 @@ void register_compat_prop(const char *driver,
     qdev_prop_register_global(p);
 }
 
+void register_compat_props_array(GlobalProperty *prop)

Note for a later: we need to stop reusing struct GlobalProperty here, because the 'user_provided', 'used', and 'errp' fields are ignored by register_compat_prop(), but people may believe the are not.

I suggest defining:

  struct GlobalPropertyValue {
      const char *driver, *property, *value;
  };

and use it instead of GlobalProperty for MachineClass::compat_props, AccelClass::global_props, and register_compat_prop().

Quoted 14 lines
hw/core/qdev-properties.c +6 -0
+{
+    for (; prop && prop->driver; prop++) {
+        register_compat_prop(prop->driver, prop->property, prop->value);
+    }
+}
+
 void qdev_prop_register_global_list(GlobalProperty *props)
 {
     int i;
include/hw/qdev-properties.h +0 -0
index 1722ca4..2bac6a0 100644

include/hw/qdev-properties.h void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, · line 205

Quoted 3 lines
include/hw/qdev-properties.h +0 -0
@@ -203,6 +203,7 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
 
 void register_compat_prop(const char *driver, const char *property,
                           const char *value);

I suggest documenting here that this function will call register_compat_prop(), so it will register internal (not user-provided) global properties.

Quoted 17 lines
include/hw/qdev-properties.h +1 -0
+void register_compat_props_array(GlobalProperty *prop);
 
 /**
  * qdev_property_add_static:
include/sysemu/accel.h +1 -0
index 15944c1..effcd7f 100644
@@ -24,6 +24,7 @@
 #define HW_ACCEL_H
 
 #include "qom/object.h"
+#include "hw/qdev-properties.h"
 
 typedef struct AccelState {
     /*< private >*/

include/sysemu/accel.h typedef struct AccelClass { · line 48

Quoted 8 lines
include/sysemu/accel.h +5 -0
@@ -40,6 +41,13 @@ typedef struct AccelClass {
     int (*available)(void);
     int (*init_machine)(MachineState *ms);
     bool *allowed;
+    /*
+     * Array of global properties that would be applied when specific
+     * accelerator is chosen. It works just like
+     * MachineClass.compat_props but it's for accelerators not
+     * machines.

I suggest adding this:

"Accelerator-provided global properties may be overridden by machine-type compat_props or user-provided global properties."

Quoted 29 lines
include/sysemu/accel.h +4 -0
+     */
+    GlobalProperty *global_props;
 } AccelClass;
 
 #define TYPE_ACCEL "accel"
@@ -57,5 +65,7 @@ typedef struct AccelClass {
 extern int tcg_tb_size;
 
 void configure_accelerator(MachineState *ms);
+/* Register accelerator specific global properties */
+void accel_register_compat_props(AccelState *accel);
 
 #endif
vl.c +1 -0
index 59fea15..4452d7a 100644
@@ -4571,6 +4571,7 @@ int main(int argc, char **argv, char **envp)
             exit (i == 1 ? 1 : 0);
     }
 
+    accel_register_compat_props(current_machine->accelerator);
     machine_register_compat_props(current_machine);
 
     qemu_opts_foreach(qemu_find_opts("global"),
Signature · 1 line
2.7.4
Signature · 1 line
Eduardo
#9 lore raw

Re: [Qemu-devel] [PATCH v5 03/10] vl: clean up global property registerations

In reply to Peter Xu
Quoted 15 lines · Peter Xu

It's not that clear on how the global properties are registered to global_props (and also its priority relationship). Let's provide a single function to be called in main() for that, with comment to explain it a bit.

---
 vl.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)
vl.c +0 -0
index 4452d7a..cdd2ec8 100644

vl.c static int qemu_read_default_config_file(void) · line 2975

Quoted 7 lines
vl.c +4 -0
@@ -2969,6 +2969,25 @@ static int qemu_read_default_config_file(void)
     return 0;
 }
 
+static void user_register_compat_props(void)
+{
+    qemu_opts_foreach(qemu_find_opts("global"),
+                      global_init_func, NULL, NULL);

I suggest using "compat props" only when referring to global properties registered for internal use (because they help us ensure command-line compatibility). User-provided global properties are just "global properties", not "compat props".

Quoted 39 lines
vl.c +20 -5
+}
+
+/*
+ * Note: we should see that these compat properties are actually
+ * having a priority: accel < machine < user. This means e.g. when
+ * user specifies something in "-global", it'll always be used with
+ * highest priority.
+ */
+static void register_global_properties(MachineState *ms)
+{
+    accel_register_compat_props(ms->accelerator);
+    machine_register_compat_props(ms);
+    user_register_compat_props();
+}
+
 int main(int argc, char **argv, char **envp)
 {
     int i;
@@ -4571,11 +4590,11 @@ int main(int argc, char **argv, char **envp)
             exit (i == 1 ? 1 : 0);
     }
 
-    accel_register_compat_props(current_machine->accelerator);
-    machine_register_compat_props(current_machine);
-
-    qemu_opts_foreach(qemu_find_opts("global"),
-                      global_init_func, NULL, NULL);
+    /*
+     * Register all the global properties, including accel properties,
+     * machine properties, and user-specified ones.
+     */
+    register_global_properties(current_machine);
 
     /* This checkpoint is required by replay to separate prior clock
        reading from the other reads, because timer polling functions query
Signature · 1 line
2.7.4
Signature · 1 line
Eduardo
#12 lore raw

Re: [Qemu-devel] [PATCH v5 04/10] migration: let MigrationState be a qdev

In reply to Peter Xu
Quoted 24 lines · Peter Xu

Let the old man "MigrationState" join the object family. Direct benefit is that we can start to use all the property features derived from current QDev, like: HW_COMPAT_* bits, command line setup for migration parameters (so will never need to set them up each time using HMP/QMP, this is really, really attractive for test writters), etc.

I see no reason to disallow this happen yet. So let's start from this one, to see whether it would be anything good.

Now we init the MigrationState struct statically in main() to make sure it's initialized after global properties are applied, since we'll use them during creation of the object.

No functional change at all.

---
 include/migration/misc.h |  1 +
 migration/migration.c    | 78 ++++++++++++++++++++++++++++++++++--------------
 migration/migration.h    | 19 ++++++++++++
 vl.c                     |  6 ++++
 4 files changed, 81 insertions(+), 23 deletions(-)

[...]

Quoted 5 lines
vl.c +0 -0
index cdd2ec8..9b04ba7 100644

vl.c int main(int argc, char **argv, char **envp) · line 4604

Quoted 9 lines
vl.c +6 -0
@@ -4596,6 +4596,12 @@ int main(int argc, char **argv, char **envp)
      */
     register_global_properties(current_machine);
 
+    /*
+     * Migration object can only be created after global properties
+     * are applied correctly.
+     */
+    migration_object_init();
+

Do we really need this? Can't be we just do:

    if (!current_migration) {
        current_migration = MIGRATION_OBJ(object_new(TYPE_MIGRATION));
    }

inside migration_get_current()?

Quoted 7 lines
vl.c +0 -0
     /* This checkpoint is required by replay to separate prior clock
        reading from the other reads, because timer polling functions query
        clock values from the log. */
Signature · 1 line
2.7.4
Signature · 1 line
Eduardo
#16 lore raw

Re: [Qemu-devel] [PATCH v5 05/10] migration: move global_state.optional out

In reply to Peter Xu
Quoted 19 lines · Peter Xu

Put it into MigrationState then we can use the properties to specify whether to enable storing global state.

Removing global_state_set_optional() since now we can use HW_COMPAT_2_3 for x86/power, and AccelClass.global_props for Xen.

---
 hw/i386/pc_piix.c                |  1 -
 hw/ppc/spapr.c                   |  1 -
 hw/xen/xen-common.c              | 11 ++++++++++-
 include/hw/compat.h              |  4 ++++
 include/migration/global_state.h |  1 -
 migration/global_state.c         |  9 ++-------
 migration/migration.c            |  7 +++++++
 migration/migration.h            |  6 ++++++
 8 files changed, 29 insertions(+), 11 deletions(-)

[...]

Quoted 6 lines
hw/xen/xen-common.c +0 -0
index d3fa705..9163a0a 100644
@@ -139,19 +139,28 @@ static int xen_init(MachineState *ms)
     }

hw/xen/xen-common.c static int xen_init(MachineState *ms) · line 148

Quoted 10 lines
hw/xen/xen-common.c +1 -1
     qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
 
-    global_state_set_optional();
     savevm_skip_configuration();
     savevm_skip_section_footers();
 
     return 0;
 }
 
+GlobalProperty xen_compat_props[] = {

This can be static.

hw/xen/xen-common.c static int xen_init(MachineState *ms) · line 154

Quoted 6 lines
hw/xen/xen-common.c +6 -0
+    {
+        .driver = "migration",
+        .property = "store-global-state",
+        .value = "off",
+    },
+    { .driver = NULL, .property = NULL, .value = NULL },

Normally this is written as:

       { /* end of list */ },

hw/xen/xen-common.c static int xen_init(MachineState *ms) · line 156

Quoted 2 lines
hw/xen/xen-common.c +2 -0
+};
+

[...]

I didn't review the rest yet, but it seems to be good.

Signature · 1 line
Eduardo
author
#3 lore raw

Re: [Qemu-devel] [PATCH v5 01/10] machine: export register_compat_prop()

In reply to Eduardo Habkost
Quoted 48 lines · Eduardo Habkost
Quoted 47 lines · Peter Xu

We have HW_COMPAT_*, however that's only bound to machines, not other things (like accelerators). Behind it, it was register_compat_prop() that played the trick. Let's export the function for further use outside HW_COMPAT_* magic.

Meanwhile, move it to qdev-properties.c where seems more proper (since it'll be used not only in machine codes).

---
 hw/core/machine.c            | 13 -------------
 hw/core/qdev-properties.c    | 13 +++++++++++++
 include/hw/qdev-properties.h |  3 +++
 3 files changed, 16 insertions(+), 13 deletions(-)
hw/core/machine.c +0 -13
index 2e7e977..ecb5552 100644
@@ -770,19 +770,6 @@ static void machine_class_finalize(ObjectClass *klass, void *data)
     g_free(mc->name);
 }
 
-static void register_compat_prop(const char *driver,
-                                 const char *property,
-                                 const char *value)
-{
-    GlobalProperty *p = g_new0(GlobalProperty, 1);
-    /* Machine compat_props must never cause errors: */
-    p->errp = &error_abort;
-    p->driver = driver;
-    p->property = property;
-    p->value = value;
-    qdev_prop_register_global(p);
-}
-
 static void machine_register_compat_for_subclass(ObjectClass *oc, void *opaque)
 {
     GlobalProperty *p = opaque;
hw/core/qdev-properties.c +0 -0
index 9f1a497..6ff1ac3 100644
@@ -1047,6 +1047,19 @@ void qdev_prop_register_global(GlobalProperty *prop)
     global_props = g_list_append(global_props, prop);
 }
 
Quoted 9 lines

hw/core/qdev-properties.c void qdev_prop_register_global(GlobalProperty *prop) · line 1055

Quoted 6 lines
hw/core/qdev-properties.c +6 -0
+void register_compat_prop(const char *driver,
+                          const char *property,
+                          const char *value)
+{
+    GlobalProperty *p = g_new0(GlobalProperty, 1);
+    /* Machine compat_props must never cause errors: */

Now this won't be used only for machine compat_props, so this comment needs to be deleted or updated (see suggestion below).

Yes. Fixing.

Quoted 36 lines
Quoted 17 lines
hw/core/qdev-properties.c +7 -0
+    p->errp = &error_abort;
+    p->driver = driver;
+    p->property = property;
+    p->value = value;
+    qdev_prop_register_global(p);
+}
+
 void qdev_prop_register_global_list(GlobalProperty *props)
 {
     int i;
include/hw/qdev-properties.h +0 -0
index d206fc9..1722ca4 100644

include/hw/qdev-properties.h void qdev_prop_set_globals(DeviceState *dev); · line 203

Quoted 3 lines
include/hw/qdev-properties.h +0 -0
@@ -201,6 +201,9 @@ void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value);
 

As this function is very easy to be misused, I suggest including the following documentation:

/**
* register_compat_prop:
*
* Register internal (not user-provided) global property, changing the
* default value of a given property in a device type. This can be used
* for enabling machine-type compatibility or for enabling
* accelerator-specific defaults in devices.
*
* The property values set using this function must be always valid and
* never report setter errors, as they property have
* GlobalProperty::errp set to &error_abort.
*

Quoted 8 lines

* User-provided global properties should override internal global
* properties, so callers of this function should ensure that it is
* called before user-provided global properties are registered. *
* @driver: Device type to be affected
* @property: Property whose default value is going to be changed
* @value: New default value for the property
*/

Sure. Will take it directly. Thanks!

Quoted 14 lines
Quoted 11 lines
include/hw/qdev-properties.h +3 -0
+void register_compat_prop(const char *driver, const char *property,
+                          const char *value);
+
 /**
  * qdev_property_add_static:
  * @dev: Device to add the property to.
Signature · 1 line
2.7.4
Signature · 1 line
Eduardo
Signature · 1 line
Peter Xu
author
#6 lore raw

Re: [Qemu-devel] [PATCH v5 02/10] accel: introduce AccelClass.global_props

In reply to Eduardo Habkost
Quoted 51 lines · Eduardo Habkost
Quoted 41 lines · Peter Xu

Introduce this new field for the accelerator classes so that each specific accelerator in the future can register its own global properties to be used further by the system. It works just like how the old machine compatible properties do, but only tailored for accelerators.

Introduce register_compat_props_array() for it. Export it so that it may be used in other codes as well in the future.

---
 accel/accel.c                |  6 ++++++
 hw/core/qdev-properties.c    |  7 +++++++
 include/hw/qdev-properties.h |  1 +
 include/sysemu/accel.h       | 10 ++++++++++
 vl.c                         |  1 +
 5 files changed, 25 insertions(+)
accel/accel.c +6 -0
index 7c079a5..fa85844 100644
@@ -120,6 +120,12 @@ void configure_accelerator(MachineState *ms)
     }
 }
 
+void accel_register_compat_props(AccelState *accel)
+{
+    AccelClass *class = ACCEL_GET_CLASS(accel);
+    register_compat_props_array(class->global_props);
+}
+
 static void register_accel_types(void)
 {
     type_register_static(&accel_type);
hw/core/qdev-properties.c +0 -0
index 6ff1ac3..19fa335 100644

hw/core/qdev-properties.c void register_compat_prop(const char *driver, · line 1063

Quoted 4 lines
hw/core/qdev-properties.c +1 -0
@@ -1060,6 +1060,13 @@ void register_compat_prop(const char *driver,
     qdev_prop_register_global(p);
 }
 
+void register_compat_props_array(GlobalProperty *prop)

Note for a later: we need to stop reusing struct GlobalProperty here, because the 'user_provided', 'used', and 'errp' fields are ignored by register_compat_prop(), but people may believe the are not.

Quoted 8 lines

I suggest defining:

  struct GlobalPropertyValue {
      const char *driver, *property, *value;
  };

and use it instead of GlobalProperty for MachineClass::compat_props, AccelClass::global_props, and register_compat_prop().

Yeah maybe another definition would be nicer.

Do you mind I skip this change in this series? After all it can be done on top, and can be separated from current work.

Quoted 16 lines
Quoted 16 lines
hw/core/qdev-properties.c +6 -0
+{
+    for (; prop && prop->driver; prop++) {
+        register_compat_prop(prop->driver, prop->property, prop->value);
+    }
+}
+
 void qdev_prop_register_global_list(GlobalProperty *props)
 {
     int i;
include/hw/qdev-properties.h +0 -0
index 1722ca4..2bac6a0 100644
@@ -203,6 +203,7 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
 
Quoted 6 lines

include/hw/qdev-properties.h void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, · line 205

Quoted 2 lines
include/hw/qdev-properties.h +0 -0
 void register_compat_prop(const char *driver, const char *property,
                           const char *value);

I suggest documenting here that this function will call register_compat_prop(), so it will register internal (not user-provided) global properties.

Will do.

Quoted 29 lines
Quoted 18 lines
include/hw/qdev-properties.h +1 -0
+void register_compat_props_array(GlobalProperty *prop);
 
 /**
  * qdev_property_add_static:
include/sysemu/accel.h +1 -0
index 15944c1..effcd7f 100644
@@ -24,6 +24,7 @@
 #define HW_ACCEL_H
 
 #include "qom/object.h"
+#include "hw/qdev-properties.h"
 
 typedef struct AccelState {
     /*< private >*/

include/sysemu/accel.h typedef struct AccelClass { · line 48

Quoted 8 lines
include/sysemu/accel.h +5 -0
@@ -40,6 +41,13 @@ typedef struct AccelClass {
     int (*available)(void);
     int (*init_machine)(MachineState *ms);
     bool *allowed;
+    /*
+     * Array of global properties that would be applied when specific
+     * accelerator is chosen. It works just like
+     * MachineClass.compat_props but it's for accelerators not
+     * machines.

I suggest adding this:

Quoted 2 lines

"Accelerator-provided global properties may be overridden by machine-type compat_props or user-provided global properties."

Will do.

Thanks,

Signature · 1 line
Peter Xu
author
#10 lore raw

Re: [Qemu-devel] [PATCH v5 03/10] vl: clean up global property registerations

In reply to Eduardo Habkost
Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · Peter Xu

It's not that clear on how the global properties are registered to global_props (and also its priority relationship). Let's provide a single function to be called in main() for that, with comment to explain it a bit.

---
 vl.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)
vl.c +0 -0
index 4452d7a..cdd2ec8 100644
@@ -2969,6 +2969,25 @@ static int qemu_read_default_config_file(void)
     return 0;
 }
 
Quoted 9 lines

vl.c static int qemu_read_default_config_file(void) · line 2975

Quoted 4 lines
vl.c +4 -0
+static void user_register_compat_props(void)
+{
+    qemu_opts_foreach(qemu_find_opts("global"),
+                      global_init_func, NULL, NULL);

I suggest using "compat props" only when referring to global properties registered for internal use (because they help us ensure command-line compatibility). User-provided global properties are just "global properties", not "compat props".

Agree. Fixing up. Thanks,

Signature · 1 line
Peter Xu
author
#13 lore raw

Re: [Qemu-devel] [PATCH v5 04/10] migration: let MigrationState be a qdev

In reply to Eduardo Habkost
Quoted 43 lines · Eduardo Habkost
Quoted 24 lines · Peter Xu

Let the old man "MigrationState" join the object family. Direct benefit is that we can start to use all the property features derived from current QDev, like: HW_COMPAT_* bits, command line setup for migration parameters (so will never need to set them up each time using HMP/QMP, this is really, really attractive for test writters), etc.

I see no reason to disallow this happen yet. So let's start from this one, to see whether it would be anything good.

Now we init the MigrationState struct statically in main() to make sure it's initialized after global properties are applied, since we'll use them during creation of the object.

No functional change at all.

---
 include/migration/misc.h |  1 +
 migration/migration.c    | 78 ++++++++++++++++++++++++++++++++++--------------
 migration/migration.h    | 19 ++++++++++++
 vl.c                     |  6 ++++
 4 files changed, 81 insertions(+), 23 deletions(-)

[...]

Quoted 5 lines
vl.c +0 -0
index cdd2ec8..9b04ba7 100644

vl.c int main(int argc, char **argv, char **envp) · line 4604

Quoted 9 lines
vl.c +6 -0
@@ -4596,6 +4596,12 @@ int main(int argc, char **argv, char **envp)
      */
     register_global_properties(current_machine);
 
+    /*
+     * Migration object can only be created after global properties
+     * are applied correctly.
+     */
+    migration_object_init();
+

Do we really need this? Can't be we just do:

Quoted 5 lines
    if (!current_migration) {
        current_migration = MIGRATION_OBJ(object_new(TYPE_MIGRATION));
    }

inside migration_get_current()?

I did this change on purpose (after AccelClass.global_props is introduced). The comment above tried to explain it but looks like it's still not clear enough... The reason is that currently the creation of migration object is depending on the global properties, so we need to create the object after register_global_properties(), while the old migrate_get_current() cannot really be sure of this ordering: it just creates the object on the first call of the function, but the first call can be even before register_global_properties(). If so, we'll have a problem (e.g. Xen compat properties will be missing).

Now this restriction is strictly followed if we create the migrate object here. If anyone calls migrate_get_current() before register_global_properties(), there will be an assert, and that should be treated as a programming error.

Thanks,

Signature · 1 line
Peter Xu
author
#17 lore raw

Re: [Qemu-devel] [PATCH v5 05/10] migration: move global_state.optional out

In reply to Eduardo Habkost
Quoted 33 lines · Eduardo Habkost
Quoted 19 lines · Peter Xu

Put it into MigrationState then we can use the properties to specify whether to enable storing global state.

Removing global_state_set_optional() since now we can use HW_COMPAT_2_3 for x86/power, and AccelClass.global_props for Xen.

---
 hw/i386/pc_piix.c                |  1 -
 hw/ppc/spapr.c                   |  1 -
 hw/xen/xen-common.c              | 11 ++++++++++-
 include/hw/compat.h              |  4 ++++
 include/migration/global_state.h |  1 -
 migration/global_state.c         |  9 ++-------
 migration/migration.c            |  7 +++++++
 migration/migration.h            |  6 ++++++
 8 files changed, 29 insertions(+), 11 deletions(-)

[...]

Quoted 12 lines
hw/xen/xen-common.c +0 -1
index d3fa705..9163a0a 100644
@@ -139,19 +139,28 @@ static int xen_init(MachineState *ms)
     }
     qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
 
-    global_state_set_optional();
     savevm_skip_configuration();
     savevm_skip_section_footers();
 
Quoted 6 lines

hw/xen/xen-common.c static int xen_init(MachineState *ms) · line 148

Quoted 4 lines
hw/xen/xen-common.c +1 -0
     return 0;
 }
 
+GlobalProperty xen_compat_props[] = {

This can be static.

Yep.

Quoted 11 lines

hw/xen/xen-common.c static int xen_init(MachineState *ms) · line 154

Quoted 7 lines
hw/xen/xen-common.c +6 -0
+    {
+        .driver = "migration",
+        .property = "store-global-state",
+        .value = "off",
+    },
+    { .driver = NULL, .property = NULL, .value = NULL },

Normally this is written as:

       { /* end of list */ },

Let me switch.

Quoted 6 lines

hw/xen/xen-common.c static int xen_init(MachineState *ms) · line 156

Quoted 3 lines
hw/xen/xen-common.c +2 -0
+};
+

[...]

I didn't review the rest yet, but it seems to be good.

Thanks!

Signature · 1 line
Peter Xu
#7 lore raw

Re: [Qemu-devel] [PATCH v5 02/10] accel: introduce AccelClass.global_props

In reply to Peter Xu
Quoted 58 lines · Peter Xu
Quoted 57 lines · Eduardo Habkost
Quoted 41 lines · Peter Xu

Introduce this new field for the accelerator classes so that each specific accelerator in the future can register its own global properties to be used further by the system. It works just like how the old machine compatible properties do, but only tailored for accelerators.

Introduce register_compat_props_array() for it. Export it so that it may be used in other codes as well in the future.

---
 accel/accel.c                |  6 ++++++
 hw/core/qdev-properties.c    |  7 +++++++
 include/hw/qdev-properties.h |  1 +
 include/sysemu/accel.h       | 10 ++++++++++
 vl.c                         |  1 +
 5 files changed, 25 insertions(+)
accel/accel.c +6 -0
index 7c079a5..fa85844 100644
@@ -120,6 +120,12 @@ void configure_accelerator(MachineState *ms)
     }
 }
 
+void accel_register_compat_props(AccelState *accel)
+{
+    AccelClass *class = ACCEL_GET_CLASS(accel);
+    register_compat_props_array(class->global_props);
+}
+
 static void register_accel_types(void)
 {
     type_register_static(&accel_type);
hw/core/qdev-properties.c +0 -0
index 6ff1ac3..19fa335 100644

hw/core/qdev-properties.c void register_compat_prop(const char *driver, · line 1063

Quoted 4 lines
hw/core/qdev-properties.c +1 -0
@@ -1060,6 +1060,13 @@ void register_compat_prop(const char *driver,
     qdev_prop_register_global(p);
 }
 
+void register_compat_props_array(GlobalProperty *prop)

Note for a later: we need to stop reusing struct GlobalProperty here, because the 'user_provided', 'used', and 'errp' fields are ignored by register_compat_prop(), but people may believe the are not.

I suggest defining:

  struct GlobalPropertyValue {
      const char *driver, *property, *value;
  };
Quoted 8 lines
Quoted 2 lines

and use it instead of GlobalProperty for MachineClass::compat_props, AccelClass::global_props, and register_compat_prop().

Yeah maybe another definition would be nicer.

Do you mind I skip this change in this series? After all it can be done on top, and can be separated from current work.

No problem. This was just a suggestion for later.

Signature · 1 line
Eduardo
#14 lore raw

Re: [Qemu-devel] [PATCH v5 04/10] migration: let MigrationState be a qdev

In reply to Peter Xu
Quoted 60 lines · Peter Xu
Quoted 43 lines · Eduardo Habkost
Quoted 24 lines · Peter Xu

Let the old man "MigrationState" join the object family. Direct benefit is that we can start to use all the property features derived from current QDev, like: HW_COMPAT_* bits, command line setup for migration parameters (so will never need to set them up each time using HMP/QMP, this is really, really attractive for test writters), etc.

I see no reason to disallow this happen yet. So let's start from this one, to see whether it would be anything good.

Now we init the MigrationState struct statically in main() to make sure it's initialized after global properties are applied, since we'll use them during creation of the object.

No functional change at all.

---
 include/migration/misc.h |  1 +
 migration/migration.c    | 78 ++++++++++++++++++++++++++++++++++--------------
 migration/migration.h    | 19 ++++++++++++
 vl.c                     |  6 ++++
 4 files changed, 81 insertions(+), 23 deletions(-)

[...]

Quoted 5 lines
vl.c +0 -0
index cdd2ec8..9b04ba7 100644

vl.c int main(int argc, char **argv, char **envp) · line 4604

Quoted 9 lines
vl.c +6 -0
@@ -4596,6 +4596,12 @@ int main(int argc, char **argv, char **envp)
      */
     register_global_properties(current_machine);
 
+    /*
+     * Migration object can only be created after global properties
+     * are applied correctly.
+     */
+    migration_object_init();
+

Do we really need this? Can't be we just do:

Quoted 5 lines
    if (!current_migration) {
        current_migration = MIGRATION_OBJ(object_new(TYPE_MIGRATION));
    }

inside migration_get_current()?

I did this change on purpose (after AccelClass.global_props is introduced). The comment above tried to explain it but looks like it's still not clear enough... The reason is that currently the creation of migration object is depending on the global properties, so we need to create the object after register_global_properties(), while the old migrate_get_current() cannot really be sure of this ordering: it just creates the object on the first call of the function, but the first call can be even before register_global_properties(). If so, we'll have a problem (e.g. Xen compat properties will be missing).

Quoted 4 lines

Now this restriction is strictly followed if we create the migrate object here. If anyone calls migrate_get_current() before register_global_properties(), there will be an assert, and that should be treated as a programming error.

Makes sense to me. Thanks!

Signature · 1 line
Eduardo