vmgenid: allow VM Generation ID modification via QMP/HMP
PATCH 1/1 vmgenid: allow VM Generation ID modification via QMP/HMP
From: Or Idgar <[email protected]>
This patch allow changing the Virtual Machine Generation ID through QMP/HMP while the vm guest is running. As the definition block of VMGENID in ACPI includes the "Notify" method, we can use it to notify the guest about ID changes.
QMP command example:
{ "execute": "set-vm-generation-id",
"arguments": {
"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
}
}HMP command example:
set-vm-generation-id 324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87
This patch is based off an earlier version by Igor Mammedov ([email protected])
--- docs/specs/vmgenid.txt | 7 ++++--- hmp-commands.hx | 13 +++++++++++++ hmp.c | 10 ++++++++++ hmp.h | 1 + hw/acpi/vmgenid.c | 10 ++++++++++ qapi-schema.json | 11 +++++++++++ tests/vmgenid-test.c | 31 +++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 3 deletions(-)
docs/specs/vmgenid.txt +4 -3
@@ -240,6 +240,7 @@ The property may be queried via QMP/HMP: (QEMU) query-vm-generation-id {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}} -Setting of this parameter is intentionally left out from the QMP/HMP -interfaces. There are no known use cases for changing the GUID once QEMU is -running, and adding this capability would greatly increase the complexity. +Also, the property may be set via QMP/HMP: + + (QEMU) set-vm-generation-id guid=ee6726ce-73b4-4a8b-863c-708f26515847 + {"return": {}}
hmp-commands.hx +13 -0
@@ -1871,5 +1871,18 @@ ETEXI }, STEXI +@item set-vm-generation-id @var{uuid} +Set Virtual Machine Generation ID counter to @var{guid} +ETEXI + + { + .name = "set-vm-generation-id", + .args_type = "guid:s", + .params = "guid", + .help = "Set Virtual Machine Generation ID counter", + .cmd = hmp_set_vm_generation_id, + }, + +STEXI @end table ETEXI
hmp.c +10 -0
@@ -2901,6 +2901,16 @@ void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)qapi_free_GuidInfo (info); } +void hmp_set_vm_generation_id (Monitor *mon,const QDict *qdict) +{ +Error *errp =NULL ; +const char *guid =qdict_get_str (qdict,"guid" ); + +qmp_set_vm_generation_id (guid, &errp); +if (errp) +hmp_handle_error (mon, &errp); +} +void hmp_info_memory_size_summary (Monitor *mon,const QDict *qdict) {Error *err =NULL ;
hmp.h +1 -0
@@ -147,5 +147,6 @@ void hmp_info_ramblock(Monitor *mon, const QDict *qdict);void hmp_hotpluggable_cpus (Monitor *mon,const QDict *qdict);void hmp_info_vm_generation_id (Monitor *mon,const QDict *qdict);void hmp_info_memory_size_summary (Monitor *mon,const QDict *qdict); +void hmp_set_vm_generation_id (Monitor *mon,const QDict *qdict);#endif
hw/acpi/vmgenid.c +10 -0
@@ -129,6 +129,16 @@ void vmgenid_add_fw_cfg(VmGenIdState *vms, FWCfgState *s, GArray *guid) ARRAY_SIZE(vms->vmgenid_addr_le), false); } +void qmp_set_vm_generation_id (const char *guid,Error **errp) +{ +Object *obj =find_vmgenid_dev (); + +if (!obj) { +return ; + } +object_property_set_str (obj, guid,VMGENID_GUID , errp); +} +static void vmgenid_update_guest (VmGenIdState *vms) {Object *obj =object_resolve_path_type ("" ,TYPE_ACPI_DEVICE_IF ,NULL );
qapi-schema.json +11 -0
@@ -3193,6 +3193,17 @@ { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' } ## +# @set-vm-generation-id: +# +# Set Virtual Machine Generation ID +# +# @guid: new GUID to set as Virtual Machine Generation ID +# +# Since 2.12 +## +{ 'command': 'set-vm-generation-id', 'data': { 'guid': 'str' } } + +## # @watchdog-set-action: # # Set watchdog action
tests/vmgenid-test.c +31 -0
@@ -130,6 +130,24 @@ static void read_guid_from_monitor(QemuUUID *guid)QDECREF (rsp); } +static void set_guid_via_monitor (QemuUUID *guid) +{ +QDict *rsp, *rsp_ret; +char command[256 ]; +char *guid_str; + + guid_str =qemu_uuid_unparse_strdup (guid); +sprintf (command,"{ 'execute': 'set-vm-generation-id', 'arguments': \ +{ 'guid': '%s' } }" , + guid_str); +free (guid_str); + rsp =qmp (command); +if (qdict_haskey (rsp,"return" )) { + rsp_ret =qdict_get_qdict (rsp,"return" ); +g_assert (qdict_size (rsp_ret) ==0 ); + } +} +static char disk[] ="tests/vmgenid-test-disk-XXXXXX" ;#define GUID_CMD (guid) \
@@ -182,6 +200,17 @@ static void vmgenid_query_monitor_test(void)qtest_quit (global_qtest); } +static void vmgenid_set_monitor_test (void ) +{ +QemuUUID expected, measured; + + global_qtest =qtest_startf (GUID_CMD (VGID_GUID )); +qemu_uuid_generate (&expected); +set_guid_via_monitor (&expected); +read_guid_from_monitor (&measured); +g_assert (memcmp (measured.data, expected.data,sizeof (measured.data)) ==0 ); +} +int main (int argc,char **argv) {int ret;
@@ -199,6 +228,8 @@ int main(int argc, char **argv) vmgenid_set_guid_auto_test);qtest_add_func ("/vmgenid/vmgenid/query-monitor" , vmgenid_query_monitor_test); +qtest_add_func ("/vmgenid/vmgenid/set-guid-qmp" , + vmgenid_set_monitor_test); ret =g_test_run ();boot_sector_cleanup (disk);
Signature · 1 line
2.9.5
Quoted 9 lines · Or Idgar
From: Or Idgar <[email protected]>
This patch allow changing the Virtual Machine Generation ID through QMP/HMP while the vm guest is running. As the definition block of VMGENID in ACPI includes the "Notify" method, we can use it to notify the guest about ID changes.
Ditto what Eric says. What is your use case? Setting was intentionally
left out in order to keep things simple. There were other concerns (I believe about migration) that will need to be revisited, but only if this feature extension is really needed.
Quoted 204 lines
QMP command example:
{ "execute": "set-vm-generation-id", "arguments": { "guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" } }HMP command example:
set-vm-generation-id 324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87This patch is based off an earlier version by Igor Mammedov ([email protected])
Signed-off-by Or Idgar <[email protected]>Reviewed-by Gal Hammer <[email protected]>--- docs/specs/vmgenid.txt | 7 ++++--- hmp-commands.hx | 13 +++++++++++++ hmp.c | 10 ++++++++++ hmp.h | 1 + hw/acpi/vmgenid.c | 10 ++++++++++ qapi-schema.json | 11 +++++++++++ tests/vmgenid-test.c | 31 +++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 3 deletions(-)docs/specs/vmgenid.txt +0
-2@@ -240,6 +240,7 @@ The property may be queried via QMP/HMP: (QEMU) query-vm-generation-id {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}} -Setting of this parameter is intentionally left out from the QMP/HMP -interfaces. There are no known use cases for changing the GUID once QEMUis
docs/specs/vmgenid.txt +4
-1-running, and adding this capability would greatly increase the complexity. +Also, the property may be set via QMP/HMP: + + (QEMU) set-vm-generation-id guid=ee6726ce-73b4-4a8b-863c-708f26515847 + {"return": {}}hmp-commands.hx +13
-0@@ -1871,5 +1871,18 @@ ETEXI }, STEXI +@item set-vm-generation-id @var{uuid} +Set Virtual Machine Generation ID counter to @var{guid} +ETEXI + + { + .name = "set-vm-generation-id", + .args_type = "guid:s", + .params = "guid", + .help = "Set Virtual Machine Generation ID counter", + .cmd = hmp_set_vm_generation_id, + }, + +STEXI @end table ETEXIhmp.c +10
-0@@ -2901,6 +2901,16 @@ void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)qapi_free_GuidInfo (info ); } +void hmp_set_vm_generation_id (Monitor *mon,const QDict *qdict) +{ +Error *errp =NULL ; +const char *guid =qdict_get_str (qdict,"guid" ); + +qmp_set_vm_generation_id (guid, &errp); +if (errp) +hmp_handle_error (mon, &errp); +} +void hmp_info_memory_size_summary (Monitor *mon,const QDict *qdict) {Error *err = NULL;hmp.h +1
-0@@ -147,5 +147,6 @@ void hmp_info_ramblock(Monitor *mon, const QDict *qdict);void hmp_hotpluggable_cpus (Monitor *mon,const QDict *qdict);void hmp_info_vm_generation_id (Monitor *mon,const QDict *qdict);void hmp_info_memory_size_summary (Monitor *mon,const QDict *qdict); +void hmp_set_vm_generation_id (Monitor *mon,const QDict *qdict);#endif
hw/acpi/vmgenid.c +10
-0@@ -129,6 +129,16 @@ void vmgenid_add_fw_cfg(VmGenIdState *vms, FWCfgState *s, GArray *guid) ARRAY_SIZE(vms->vmgenid_addr_le), false); } +void qmp_set_vm_generation_id (const char *guid,Error **errp) +{ +Object *obj =find_vmgenid_dev (); + +if (!obj) { +return ; + } +object_property_set_str (obj, guid,VMGENID_GUID , errp); +} +static void vmgenid_update_guest (VmGenIdState *vms) {Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, NULL);qapi-schema.json +11
-0@@ -3193,6 +3193,17 @@ { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' } ## +# @set-vm-generation-id: +# +# Set Virtual Machine Generation ID +# +# @guid: new GUID to set as Virtual Machine Generation ID +# +# Since 2.12 +## +{ 'command': 'set-vm-generation-id', 'data': { 'guid': 'str' } } + +## # @watchdog-set-action: # # Set watchdog actiontests/vmgenid-test.c +29
-0@@ -130,6 +130,24 @@ static void read_guid_from_monitor(QemuUUID *guid)QDECREF (rsp); } +static void set_guid_via_monitor (QemuUUID *guid) +{ +QDict *rsp, *rsp_ret; +char command[256 ]; +char *guid_str; + + guid_str =qemu_uuid_unparse_strdup (guid); +sprintf (command,"{ 'execute': 'set-vm-generation-id', 'arguments': \ +{ 'guid': '%s' } }" , + guid_str); +free (guid_str); + rsp =qmp (command); +if (qdict_haskey (rsp,"return" )) { + rsp_ret =qdict_get_qdict (rsp,"return" ); +g_assert (qdict_size (rsp_ret) ==0 ); + } +} +static char disk[] ="tests/vmgenid-test-disk-XXXXXX" ;#define GUID_CMD (guid) \@@ -182,6 +200,17 @@ static void vmgenid_query_monitor_test(void)qtest_quit (global_qtest); } +static void vmgenid_set_monitor_test (void ) +{ +QemuUUID expected, measured; + + global_qtest =qtest_startf (GUID_CMD (VGID_GUID )); +qemu_uuid_generate (&expected); +set_guid_via_monitor (&expected); +read_guid_from_monitor (&measured); +g_assert (memcmp (measured.data, expected.data,sizeof (measured.data)) ==0 ); +} +int main (int argc,char **argv) {int ret;tests/vmgenid-test.c +2
-1@@ -199,6 +228,8 @@ int main(int argc, char **argv) vmgenid_set_guid_auto_test);qtest_add_func ("/vmgenid/vmgenid/query-monitor" , vmgenid_query_monitor_test); +qtest_add_func ("/vmgenid/vmgenid/set-guid-qmp" , + vmgenid_set_monitor_test); ret =g_test_run ();boot_sector_cleanup (disk); --2.9.5