migration: Move check_migratable() into qdev.c
PATCH v2 1/1 migration: Move check_migratable() into qdev.c
The function is only used once, and nothing else in migration knows about objects. Create the function vmstate_device_is_migratable() in savem.c that really do the bit that is related with migration.
---
- move only_migrateble use back to savevm.c to fix linux-user compilation.
hw/core/qdev.c | 20 ++++++++++++++++---- include/migration/migration.h | 6 ------ include/migration/vmstate.h | 2 ++ include/sysemu/sysemu.h | 2 +- migration/migration.c | 15 --------------- migration/savevm.c | 10 ++++++++++ stubs/vmstate.c | 5 ++--- 7 files changed, 31 insertions(+), 29 deletions(-)
hw/core/qdev.c +16 -4
@@ -37,7 +37,7 @@#include "hw/boards.h" #include "hw/sysbus.h" #include "qapi-event.h" -#include "migration/migration.h" +#include "migration/vmstate.h" bool qdev_hotplug = false;static bool qdev_hot_added = false;
@@ -861,6 +861,20 @@ static bool device_get_realized(Object *obj, Error **errp)return dev->realized; } +static bool check_only_migratable (Object *obj,Error **err) +{ +DeviceClass *dc =DEVICE_GET_CLASS (obj); + +if (!vmstate_check_only_migratable (dc->vmsd)) { +error_setg (err,"Device %s is not migratable, but " +"--only-migratable was specified" , +object_get_typename (obj)); +return false; + } + +return true; +} +static void device_set_realized (Object *obj,bool value,Error **errp) {DeviceState *dev =DEVICE (obj);
@@ -870,7 +884,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp)Error *local_err =NULL ;bool unattached_parent = false;static int unattached_count; -int ret;if (dev->hotplugged && !dc->hotpluggable) {error_setg (errp,QERR_DEVICE_NO_HOTPLUG ,object_get_typename (obj));
@@ -878,8 +891,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp) }if (value && !dev->realized) { - ret =check_migratable (obj, &local_err); -if (ret <0 ) { +if (!check_only_migratable (obj, &local_err)) { goto fail; }
include/migration/migration.h +0 -6
@@ -22,7 +22,6 @@#include "qapi-types.h" #include "exec/cpu-common.h" #include "qemu/coroutine_int.h" -#include "qom/object.h" #define QEMU_VM_FILE_MAGIC 0x5145564d#define QEMU_VM_FILE_VERSION_COMPAT 0x00000002
@@ -39,9 +38,6 @@#define QEMU_VM_COMMAND 0x08#define QEMU_VM_SECTION_FOOTER 0x7e -/* for vl.c */ -extern int only_migratable; -/* Messages sent on the return path from destination to source */ enum mig_rp_message_type {MIG_RP_MSG_INVALID =0 ,/* Must be 0 */
@@ -268,8 +264,6 @@ int ram_discard_range(const char *block_name, uint64_t start, size_t length);int ram_postcopy_incoming_init (MigrationIncomingState *mis);void ram_postcopy_migrated_memory_release (MigrationState *ms); -int check_migratable (Object *obj,Error **err); -bool migrate_release_ram (void );bool migrate_postcopy_ram (void );bool migrate_zero_blocks (void );
include/migration/vmstate.h +2 -0
@@ -1066,4 +1066,6 @@ int64_t self_announce_delay(int round)void dump_vmstate_json_to_file (FILE *out_fp); +bool vmstate_check_only_migratable (const VMStateDescription *vmsd); +#endif
include/sysemu/sysemu.h +1 -1
@@ -15,7 +15,7 @@/* 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 +0 -15
@@ -1162,21 +1162,6 @@ void migrate_del_blocker(Error *reason) migration_blockers =g_slist_remove (migration_blockers, reason); } -int check_migratable (Object *obj,Error **err) -{ -DeviceClass *dc =DEVICE_GET_CLASS (obj); -if (only_migratable && dc->vmsd) { -if (dc->vmsd->unmigratable) { -error_setg (err,"Device %s is not migratable, but " -"--only-migratable was specified" , -object_get_typename (obj)); -return -1 ; - } - } - -return 0 ; -} -void qmp_migrate_incoming (const char *uri,Error **errp) {Error *local_err =NULL ;
migration/savevm.c +10 -0
@@ -2310,3 +2310,13 @@ void vmstate_register_ram_global(MemoryRegion *mr) {vmstate_register_ram (mr,NULL ); } + +bool vmstate_check_only_migratable (const VMStateDescription *vmsd) +{ +/* check needed if --only-migratable is specified */ +if (!only_migratable) { +return true; + } + +return !(vmsd && vmsd->unmigratable); +}
stubs/vmstate.c +2 -3
@@ -1,7 +1,6 @@#include "qemu/osdep.h" #include "qemu-common.h" #include "migration/vmstate.h" -#include "migration/migration.h" const VMStateDescription vmstate_dummy = {};
@@ -21,7 +20,7 @@ void vmstate_unregister(DeviceState *dev, { } -int check_migratable (Object *obj,Error **err) +bool vmstate_check_only_migratable (const VMStateDescription *vmsd) { -return 0 ; +return true; }
Signature · 1 line
2.9.3
Quoted 3 lines · Juan Quintela
The function is only used once, and nothing else in migration knows about objects. Create the function
vmstate_device_is_migratable()insavem.cthat really do the bit that is related with migration.
(may need to touch up the commit message as well, since we don't have
vmstate_device_is_migratable() now)
Quoted 2 lines
Signed-off-by Juan Quintela <[email protected]>
For the build error for linux-user on previous v1, not sure defining one only_migratable in stubs/vmstate.c can work. Anyway, I think current patch is okay as well (considering that our goal is to cleanup the header "#include"s). So, best with the commit message touched up:
Thanks,
Quoted 190 lines
---
- move
only_migratebleuse back tosavevm.cto fix linux-user compilation.hw/core/qdev.c | 20 ++++++++++++++++---- include/migration/migration.h | 6 ------ include/migration/vmstate.h | 2 ++ include/sysemu/sysemu.h | 2 +- migration/migration.c | 15 --------------- migration/savevm.c | 10 ++++++++++ stubs/vmstate.c | 5 ++--- 7 files changed, 31 insertions(+), 29 deletions(-)hw/core/qdev.c +16
-4@@ -37,7 +37,7 @@#include "hw/boards.h" #include "hw/sysbus.h" #include "qapi-event.h" -#include "migration/migration.h" +#include "migration/vmstate.h" bool qdev_hotplug = false;static bool qdev_hot_added = false;@@ -861,6 +861,20 @@ static bool device_get_realized(Object *obj, Error **errp)return dev->realized; } +static bool check_only_migratable (Object *obj,Error **err) +{ +DeviceClass *dc =DEVICE_GET_CLASS (obj); + +if (!vmstate_check_only_migratable (dc->vmsd)) { +error_setg (err,"Device %s is not migratable, but " +"--only-migratable was specified" , +object_get_typename (obj)); +return false; + } + +return true; +} +static void device_set_realized (Object *obj,bool value,Error **errp) {DeviceState *dev =DEVICE (obj);@@ -870,7 +884,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp)Error *local_err =NULL ;bool unattached_parent = false;static int unattached_count; -int ret;if (dev->hotplugged && !dc->hotpluggable) {error_setg (errp,QERR_DEVICE_NO_HOTPLUG ,object_get_typename (obj));@@ -878,8 +891,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp) }if (value && !dev->realized) { - ret =check_migratable (obj, &local_err); -if (ret <0 ) { +if (!check_only_migratable (obj, &local_err)) { goto fail; }include/migration/migration.h +0
-6@@ -22,7 +22,6 @@#include "qapi-types.h" #include "exec/cpu-common.h" #include "qemu/coroutine_int.h" -#include "qom/object.h" #define QEMU_VM_FILE_MAGIC 0x5145564d#define QEMU_VM_FILE_VERSION_COMPAT 0x00000002@@ -39,9 +38,6 @@#define QEMU_VM_COMMAND 0x08#define QEMU_VM_SECTION_FOOTER 0x7e -/* for vl.c */ -extern int only_migratable; -/* Messages sent on the return path from destination to source */ enum mig_rp_message_type {MIG_RP_MSG_INVALID =0 ,/* Must be 0 */ @@ -268,8 +264,6 @@ int ram_discard_range(const char *block_name, uint64_t start, size_t length);int ram_postcopy_incoming_init (MigrationIncomingState *mis);void ram_postcopy_migrated_memory_release (MigrationState *ms); -int check_migratable (Object *obj,Error **err); -bool migrate_release_ram (void );bool migrate_postcopy_ram (void );bool migrate_zero_blocks (void );include/migration/vmstate.h +2
-0@@ -1066,4 +1066,6 @@ int64_t self_announce_delay(int round)void dump_vmstate_json_to_file (FILE *out_fp); +bool vmstate_check_only_migratable (const VMStateDescription *vmsd); +#endif include/sysemu/sysemu.h +1
-1@@ -15,7 +15,7 @@/* 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 +0
-15@@ -1162,21 +1162,6 @@ void migrate_del_blocker(Error *reason) migration_blockers =g_slist_remove (migration_blockers, reason); } -int check_migratable (Object *obj,Error **err) -{ -DeviceClass *dc =DEVICE_GET_CLASS (obj); -if (only_migratable && dc->vmsd) { -if (dc->vmsd->unmigratable) { -error_setg (err,"Device %s is not migratable, but " -"--only-migratable was specified" , -object_get_typename (obj)); -return -1 ; - } - } - -return 0 ; -} -void qmp_migrate_incoming (const char *uri,Error **errp) {Error *local_err =NULL ;migration/savevm.c +10
-0@@ -2310,3 +2310,13 @@ void vmstate_register_ram_global(MemoryRegion *mr) {vmstate_register_ram (mr,NULL ); } + +bool vmstate_check_only_migratable (const VMStateDescription *vmsd) +{ +/* check needed if --only-migratable is specified */ +if (!only_migratable) { +return true; + } + +return !(vmsd && vmsd->unmigratable); +}stubs/vmstate.c +2
-3@@ -1,7 +1,6 @@#include "qemu/osdep.h" #include "qemu-common.h" #include "migration/vmstate.h" -#include "migration/migration.h" const VMStateDescription vmstate_dummy = {};@@ -21,7 +20,7 @@ void vmstate_unregister(DeviceState *dev, { } -int check_migratable (Object *obj,Error **err) +bool vmstate_check_only_migratable (const VMStateDescription *vmsd) { -return 0 ; +return true; }Signature · 1 line
2.9.3
Signature · 1 line
Peter Xu