qga: Fix several guest-get-devices issues
cover qga: Fix several guest-get-devices issues
To be frank, I'm disappointed the code passed review in this state. There are excuses for each of the issues addressed in this series (PATCH 1 naming is hard, PATCH 2 recognizing non-local relations is hard, PATCH 3 mistakes on error paths are easy to miss, PATCH 4 can't expect all reviewers to know "no more simple unions, please"). Still, having so many of them escape notice is disappointing.
Please review.
Markus Armbruster (4):
qga: Rename guest-get-devices return member 'address' to 'id'
qga: Use common time encoding for guest-get-devices 'driver-date'
qga-win: Fix guest-get-devices error API violations
qga: Flatten simple union GuestDeviceId
qga/qapi-schema.json | 29 +++++++++++++++++++---------- qga/commands-win32.c | 39 ++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 29 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/4 qga: Rename guest-get-devices return member 'address' to 'id'
Member 'address' is union GuestDeviceAddress with a single branch GuestDeviceAddressPCI, containing PCI vendor ID and device ID. This is not a PCI address. Type GuestPCIAddress is. Messed up in recent commit 2e4211cee4 "qga: add command guest-get-devices for reporting VirtIO devices".
Rename type GuestDeviceAddressPCI to GuestDeviceIdPCI, type GuestDeviceAddress to GuestDeviceId, and member 'address' to 'id'.
Document the member properly while there.
--- qga/qapi-schema.json | 17 +++++++++-------- qga/commands-win32.c | 16 ++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-)
qga/qapi-schema.json +9 -8
@@ -1257,26 +1257,26 @@ 'returns': 'GuestOSInfo' } ## -# @GuestDeviceAddressPCI: +# @GuestDeviceIdPCI: # # @vendor-id: vendor ID # @device-id: device ID # # Since: 5.2 ## -{ 'struct': 'GuestDeviceAddressPCI', +{ 'struct': 'GuestDeviceIdPCI', 'data': { 'vendor-id': 'uint16', 'device-id': 'uint16' } } ## -# @GuestDeviceAddress: +# @GuestDeviceId: # -# Address of the device -# - @pci: address of PCI device, since: 5.2 +# Id of the device +# - @pci: PCI ID, since: 5.2 # # Since: 5.2 ## -{ 'union': 'GuestDeviceAddress', - 'data': { 'pci': 'GuestDeviceAddressPCI' } } +{ 'union': 'GuestDeviceId', + 'data': { 'pci': 'GuestDeviceIdPCI' } } ## # @GuestDeviceInfo:
@@ -1284,6 +1284,7 @@ # @driver-name: name of the associated driver # @driver-date: driver release date in format YYYY-MM-DD # @driver-version: driver version +# @id: device ID # # Since: 5.2 ##
@@ -1292,7 +1293,7 @@ 'driver-name': 'str', '*driver-date': 'str', '*driver-version': 'str', - '*address': 'GuestDeviceAddress' + '*id': 'GuestDeviceId' } } ##
qga/commands-win32.c +8 -8
@@ -2390,22 +2390,22 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) }for (j =0 ; hw_ids[j] !=NULL ; j++) {GMatchInfo *match_info; -GuestDeviceAddressPCI *address; +GuestDeviceIdPCI *id;if (!g_regex_match (device_pci_re, hw_ids[j],0 , &match_info)) {continue ; } skip = false; - address =g_new0 (GuestDeviceAddressPCI,1 ); + id =g_new0 (GuestDeviceIdPCI,1 ); vendor_id =g_match_info_fetch (match_info,1 ); device_id =g_match_info_fetch (match_info,2 ); - address->vendor_id =g_ascii_strtoull (vendor_id,NULL ,16 ); - address->device_id =g_ascii_strtoull (device_id,NULL ,16 ); + id->vendor_id =g_ascii_strtoull (vendor_id,NULL ,16 ); + id->device_id =g_ascii_strtoull (device_id,NULL ,16 ); - device->address =g_new0 (GuestDeviceAddress,1 ); - device->has_address = true; - device->address->type =GUEST_DEVICE_ADDRESS_KIND_PCI ; - device->address->u.pci.data = address; + device->id =g_new0 (GuestDeviceId,1 ); + device->has_id = true; + device->id->type =GUEST_DEVICE_ID_KIND_PCI ; + device->id->u.pci.data = id;g_match_info_free (match_info);break ;
Signature · 1 line
2.26.2
Re: [PATCH 1/4] qga: Rename guest-get-devices return member 'address' to 'id'
Quoted 5 lines · Markus Armbruster
Member 'address' is union GuestDeviceAddress with a single branch GuestDeviceAddressPCI, containing PCI vendor ID and device ID. This is not a PCI address. Type GuestPCIAddress is. Messed up in recent commit
2e4211cee4"qga: add command guest-get-devices for reporting VirtIO devices".
Out of curiosity, how did you notice?
Quoted 11 lines
Rename type GuestDeviceAddressPCI to GuestDeviceIdPCI, type GuestDeviceAddress to GuestDeviceId, and member 'address' to 'id'.
Document the member properly while there.
Signed-off-by Markus Armbruster <[email protected]>--- qga/qapi-schema.json | 17 +++++++++-------- qga/commands-win32.c | 16 ++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-)
Re: [PATCH 1/4] qga: Rename guest-get-devices return member 'address' to 'id'
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Markus Armbruster
Member 'address' is union GuestDeviceAddress with a single branch GuestDeviceAddressPCI, containing PCI vendor ID and device ID. This is not a PCI address. Type GuestPCIAddress is. Messed up in recent commit
2e4211cee4"qga: add command guest-get-devices for reporting VirtIO devices".Out of curiosity, how did you notice?
I searched for simple unions to remind myself of the size of that problem, and found a new one, i.e. a problem I can still avoid. I started to do PATCH 4, and noticed the other issues.
Quoted 1 line
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thanks!
Re: [PATCH 1/4] qga: Rename guest-get-devices return member 'address' to 'id'
In reply to Markus ArmbrusterQuoted 7 lines · Markus Armbruster
Member 'address' is union GuestDeviceAddress with a single branch GuestDeviceAddressPCI, containing PCI vendor ID and device ID. This is not a PCI address. Type GuestPCIAddress is. Messed up in recent commit
2e4211cee4"qga: add command guest-get-devices for reporting VirtIO devices".
Quoted 6 lines
Rename type GuestDeviceAddressPCI to GuestDeviceIdPCI, type GuestDeviceAddress to GuestDeviceId, and member 'address' to 'id'.
Document the member properly while there.
Signed-off-by Markus Armbruster <[email protected]>
Quoted 98 lines
--- qga/qapi-schema.json | 17 +++++++++-------- qga/commands-win32.c | 16 ++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-)qga/qapi-schema.json +9
-8@@ -1257,26 +1257,26 @@ 'returns': 'GuestOSInfo' } ## -# @GuestDeviceAddressPCI: +# @GuestDeviceIdPCI: # # @vendor-id: vendor ID # @device-id: device ID # # Since: 5.2 ## -{ 'struct': 'GuestDeviceAddressPCI', +{ 'struct': 'GuestDeviceIdPCI', 'data': { 'vendor-id': 'uint16', 'device-id': 'uint16' } } ## -# @GuestDeviceAddress: +# @GuestDeviceId: # -# Address of the device -# - @pci: address of PCI device, since: 5.2 +# Id of the device +# - @pci: PCI ID, since: 5.2 # # Since: 5.2 ## -{ 'union': 'GuestDeviceAddress', - 'data': { 'pci': 'GuestDeviceAddressPCI' } } +{ 'union': 'GuestDeviceId', + 'data': { 'pci': 'GuestDeviceIdPCI' } } ## # @GuestDeviceInfo:@@ -1284,6 +1284,7 @@ # @driver-name: name of the associated driver # @driver-date: driver release date in format YYYY-MM-DD # @driver-version: driver version +# @id: device ID # # Since: 5.2 ##@@ -1292,7 +1293,7 @@ 'driver-name': 'str', '*driver-date': 'str', '*driver-version': 'str', - '*address': 'GuestDeviceAddress' + '*id': 'GuestDeviceId' } } ##qga/commands-win32.c +8
-9@@ -2390,22 +2390,22 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) }for (j =0 ; hw_ids[j] !=NULL ; j++) {GMatchInfo *match_info; -GuestDeviceAddressPCI *address; +GuestDeviceIdPCI *id;if (!g_regex_match (device_pci_re, hw_ids[j],0 , &match_info)) {continue ; } skip = false; - address =g_new0 (GuestDeviceAddressPCI,1 ); + id =g_new0 (GuestDeviceIdPCI,1 ); vendor_id =g_match_info_fetch (match_info,1 ); device_id =g_match_info_fetch (match_info,2 ); - address->vendor_id =g_ascii_strtoull (vendor_id,NULL ,16 ); - address->device_id =g_ascii_strtoull (device_id,NULL ,16 ); + id->vendor_id =g_ascii_strtoull (vendor_id,NULL ,16 ); + id->device_id =g_ascii_strtoull (device_id,NULL ,16 ); - device->address =g_new0 (GuestDeviceAddress,1 ); - device->has_address = true; - device->address->type =GUEST_DEVICE_ADDRESS_KIND_PCI ; - device->address->u.pci.data = address; + device->id =g_new0 (GuestDeviceId,1 ); + device->has_id = true; + device->id->type =GUEST_DEVICE_ID_KIND_PCI ; + device->id->u.pci.data = id;g_match_info_free (match_info);break ; --2.26.2
PATCH 2/4 qga: Use common time encoding for guest-get-devices 'driver-date'
In reply to Markus Armbrusterguest-get-devices returns 'driver-date' as string in the format YYYY-MM-DD. Goes back to recent commit 2e4211cee4 "qga: add command guest-get-devices for reporting VirtIO devices".
We should avoid use of multiple encodings for the same kind of data. Especially string encodings. Change it to return nanoseconds since the epoch, like guest-get-time does.
--- qga/qapi-schema.json | 4 ++-- qga/commands-win32.c | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-)
qga/qapi-schema.json +2 -2
@@ -1282,7 +1282,7 @@ # @GuestDeviceInfo: # # @driver-name: name of the associated driver -# @driver-date: driver release date in format YYYY-MM-DD +# @driver-date: driver release date, in nanoseconds since the epoch # @driver-version: driver version # @id: device ID #
@@ -1291,7 +1291,7 @@ { 'struct': 'GuestDeviceInfo', 'data': { 'driver-name': 'str', - '*driver-date': 'str', + '*driver-date': 'int', '*driver-version': 'str', '*id': 'GuestDeviceId' } }
qga/commands-win32.c +11 -8
@@ -1641,6 +1641,12 @@ out:return head; } +static int64_t filetime_to_ns (const FILETIME *tf) +{ +return ((((int64_t )tf->dwHighDateTime <<32 ) | tf->dwLowDateTime) + -W32_FT_OFFSET ) *100 ; +} +int64_t qmp_guest_get_time (Error **errp) {SYSTEMTIME ts = {0 };
@@ -1657,8 +1663,7 @@ int64_t qmp_guest_get_time(Error **errp)return -1 ; } -return ((((int64_t )tf.dwHighDateTime <<32 ) | tf.dwLowDateTime) - -W32_FT_OFFSET ) *100 ; +return filetime_to_ns (&tf); }void qmp_guest_set_time (bool has_time,int64_t time_ns,Error **errp)
@@ -2363,7 +2368,6 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)slog ("enumerating devices" );for (i =0 ;SetupDiEnumDeviceInfo (dev_info, i, &dev_info_data); i++) {bool skip = true; -SYSTEMTIME utc_date; g_autofree LPWSTR name = NULL; g_autofree LPFILETIME date = NULL; g_autofree LPWSTR version = NULL;
@@ -2434,13 +2438,12 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)slog ("failed to get driver date" );continue ; } -FileTimeToSystemTime (date, &utc_date); - device->driver_date =g_strdup_printf ("%04d-%02d-%02d" , - utc_date.wYear, utc_date.wMonth, utc_date.wDay); + device->driver_date =filetime_to_ns (date); device->has_driver_date = true; -slog ("driver: %s\ndriver version: %s,%s\n" , device->driver_name, - device->driver_date, device->driver_version); +slog ("driver: %s\ndriver version: %" PRId64",%s\n" , + device->driver_name, device->driver_date, + device->driver_version); item =g_new0 (GuestDeviceInfoList,1 ); item->value =g_steal_pointer (&device);if (!cur_item) {
Signature · 1 line
2.26.2
Re: [PATCH 2/4] qga: Use common time encoding for guest-get-devices 'driver-date'
Hi
Quoted 10 lines · Markus Armbruster
guest-get-devices returns 'driver-date' as string in the format YYYY-MM-DD. Goes back to recent commit
2e4211cee4"qga: add command guest-get-devices for reporting VirtIO devices".We should avoid use of multiple encodings for the same kind of data. Especially string encodings. Change it to return nanoseconds since the epoch, like guest-get-time does.
Signed-off-by Markus Armbruster <[email protected]>
I think I assumed it was free form human-friendly string, but it has a strict YYYY-MM-DD format in the doc, so let's use the existing one instead.
Quoted 87 lines
--- qga/qapi-schema.json | 4 ++-- qga/commands-win32.c | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-)qga/qapi-schema.json +2
-2@@ -1282,7 +1282,7 @@ # @GuestDeviceInfo: # # @driver-name: name of the associated driver -# @driver-date: driver release date in format YYYY-MM-DD +# @driver-date: driver release date, in nanoseconds since the epoch # @driver-version: driver version # @id: device ID #@@ -1291,7 +1291,7 @@ { 'struct': 'GuestDeviceInfo', 'data': { 'driver-name': 'str', - '*driver-date': 'str', + '*driver-date': 'int', '*driver-version': 'str', '*id': 'GuestDeviceId' } }qga/commands-win32.c +7
-3@@ -1641,6 +1641,12 @@ out:return head; } +static int64_t filetime_to_ns (const FILETIME *tf) +{ +return ((((int64_t )tf->dwHighDateTime <<32 ) | tf->dwLowDateTime) + -W32_FT_OFFSET ) *100 ; +} +int64_t qmp_guest_get_time (Error **errp) {SYSTEMTIME ts = {0 };@@ -1657,8 +1663,7 @@ int64_t qmp_guest_get_time(Error **errp)return -1 ; } -return ((((int64_t )tf.dwHighDateTime <<32 ) | tf.dwLowDateTime) - -W32_FT_OFFSET ) *100 ; +return filetime_to_ns (&tf); }void qmp_guest_set_time (bool has_time,int64_t time_ns,Error **errp)@@ -2363,7 +2368,6 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)slog ("enumerating devices" );for (i =0 ;SetupDiEnumDeviceInfo (dev_info, i, &dev_info_data); i++) {bool skip = true; -SYSTEMTIME utc_date; g_autofree LPWSTR name = NULL; g_autofree LPFILETIME date = NULL;g_autofree LPWSTR version = NULL;qga/commands-win32.c +4
-5@@ -2434,13 +2438,12 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)slog ("failed to get driver date" );continue ; } -FileTimeToSystemTime (date, &utc_date); - device->driver_date =g_strdup_printf ("%04d-%02d-%02d" , - utc_date.wYear, utc_date.wMonth, utc_date.wDay); + device->driver_date =filetime_to_ns (date); device->has_driver_date = true; -slog ("driver: %s\ndriver version: %s,%s\n" , device->driver_name, - device->driver_date, device->driver_version); +slog ("driver: %s\ndriver version: %" PRId64",%s\n" , + device->driver_name, device->driver_date, + device->driver_version); item =g_new0 (GuestDeviceInfoList,1 ); item->value =g_steal_pointer (&device);if (!cur_item) {--
2.26.2
Signature · 1 line
Marc-André Lureau
PATCH 3/4 qga-win: Fix guest-get-devices error API violations
In reply to Markus ArmbrusterThe Error ** argument must be NULL, &error_abort, &error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second call.
qmp_guest_get_devices() is wrong that way: it calls error_setg() in a loop.
If no iteration fails, the function returns a value and sets no error. Okay.
If exactly one iteration fails, the function returns a value and sets an error. Wrong.
If multiple iterations fail, the function trips error_setv()'s assertion.
Fix it to return immediately on error.
Perhaps the failure to convert the driver version to UTF-8 should not be an error. We could simply not report the botched version string instead.
Drop a superfluous continue while there.
--- qga/commands-win32.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
qga/commands-win32.c +2 -3
@@ -2385,7 +2385,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) device->driver_name =g_utf16_to_utf8 (name,-1 ,NULL ,NULL ,NULL );if (device->driver_name ==NULL ) {error_setg (errp,"conversion to utf8 failed (driver name)" ); -continue ; +return NULL ; }slog ("querying device: %s" , device->driver_name); hw_ids =ga_get_hardware_ids (dev_info_data.DevInst);
@@ -2428,7 +2428,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) NULL, NULL);if (device->driver_version ==NULL ) {error_setg (errp,"conversion to utf8 failed (driver version)" ); -continue ; +return NULL ; } device->has_driver_version = true;
@@ -2452,7 +2452,6 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) cur_item->next = item; cur_item = item; } -continue ; }if (dev_info !=INVALID_HANDLE_VALUE ) {
Signature · 1 line
2.26.2
Re: [PATCH 3/4] qga-win: Fix guest-get-devices error API violations
Quoted 20 lines · Markus Armbruster
The Error ** argument must be NULL,
&error_abort,&error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second call.
qmp_guest_get_devices()is wrong that way: it callserror_setg()in a loop.If no iteration fails, the function returns a value and sets no error. Okay.
If exactly one iteration fails, the function returns a value and sets an error. Wrong.
If multiple iterations fail, the function trips error_setv()'s assertion.
Fix it to return immediately on error.
Quoted 8 lines
Perhaps the failure to convert the driver version to UTF-8 should not be an error. We could simply not report the botched version string instead.
Drop a superfluous continue while there.
Signed-off-by Markus Armbruster <[email protected]>
Quoted 43 lines
--- qga/commands-win32.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)qga/commands-win32.c +1
-1@@ -2385,7 +2385,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) device->driver_name =g_utf16_to_utf8 (name,-1 ,NULL ,NULL ,NULL );if (device->driver_name ==NULL ) {error_setg (errp,"conversion to utf8 failed (driver name)" ); -continue ; +return NULL ; }slog ("querying device: %s" , device->driver_name);hw_ids = ga_get_hardware_ids(dev_info_data.DevInst);qga/commands-win32.c +1
-1@@ -2428,7 +2428,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) NULL, NULL);if (device->driver_version ==NULL ) { error_setg(errp, "conversion to utf8 failed (driver version)"); - continue; + returnNULL ; }device->has_driver_version = true;qga/commands-win32.c +0
-1@@ -2452,7 +2452,6 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) cur_item->next = item; cur_item = item; } -continue ; }if (dev_info != INVALID_HANDLE_VALUE) {--
2.26.2
Signature · 1 line
Marc-André Lureau
Re: [PATCH 3/4] qga-win: Fix guest-get-devices error API violations
In reply to Markus ArmbrusterQuoted 24 lines · Markus Armbruster
The Error ** argument must be NULL,
&error_abort,&error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second call.
qmp_guest_get_devices()is wrong that way: it callserror_setg()in a loop.If no iteration fails, the function returns a value and sets no error. Okay.
If exactly one iteration fails, the function returns a value and sets an error. Wrong.
If multiple iterations fail, the function trips error_setv()'s assertion.
Fix it to return immediately on error.
Perhaps the failure to convert the driver version to UTF-8 should not be an error. We could simply not report the botched version string instead.
Quoted 6 lines
Drop a superfluous continue while there.
Signed-off-by Markus Armbruster <[email protected]>--- qga/commands-win32.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
PATCH 4/4 qga: Flatten simple union GuestDeviceId
In reply to Markus ArmbrusterSimple unions are simpler than flat unions in the schema, but more complicated in C and on the QMP wire: there's extra indirection in C and extra nesting on the wire, both pointless. They should be avoided in new code.
GuestDeviceId was recently added for guest-get-devices. Convert it to a flat union.
--- qga/qapi-schema.json | 8 ++++++++ qga/commands-win32.c | 9 ++++----- 2 files changed, 12 insertions(+), 5 deletions(-)
qga/qapi-schema.json +8 -0
@@ -1256,6 +1256,12 @@ { 'command': 'guest-get-osinfo', 'returns': 'GuestOSInfo' } +## +# @GuestDeviceType: +## +{ 'enum': 'GuestDeviceType', + 'data': [ 'pci' ] } + ## # @GuestDeviceIdPCI: #
@@ -1276,6 +1282,8 @@ # Since: 5.2 ## { 'union': 'GuestDeviceId', + 'base': { 'type': 'GuestDeviceType' }, + 'discriminator': 'type', 'data': { 'pci': 'GuestDeviceIdPCI' } } ##
qga/commands-win32.c +4 -5
@@ -2400,16 +2400,15 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) } skip = false; - id =g_new0 (GuestDeviceIdPCI,1 ); vendor_id =g_match_info_fetch (match_info,1 ); device_id =g_match_info_fetch (match_info,2 ); - id->vendor_id =g_ascii_strtoull (vendor_id,NULL ,16 ); - id->device_id =g_ascii_strtoull (device_id,NULL ,16 ); device->id =g_new0 (GuestDeviceId,1 ); device->has_id = true; - device->id->type =GUEST_DEVICE_ID_KIND_PCI ; - device->id->u.pci.data = id; + device->id->type =GUEST_DEVICE_TYPE_PCI ; + id = &device->id->u.pci; + id->vendor_id =g_ascii_strtoull (vendor_id,NULL ,16 ); + id->device_id =g_ascii_strtoull (device_id,NULL ,16 );g_match_info_free (match_info);break ;
Signature · 1 line
2.26.2
Re: [PATCH 4/4] qga: Flatten simple union GuestDeviceId
Quoted 5 lines · Markus Armbruster
Simple unions are simpler than flat unions in the schema, but more complicated in C and on the QMP wire: there's extra indirection in C and extra nesting on the wire, both pointless. They should be avoided in new code.
Quoted 8 lines
GuestDeviceId was recently added for guest-get-devices. Convert it to a flat union.
Signed-off-by Markus Armbruster <[email protected]>--- qga/qapi-schema.json | 8 ++++++++ qga/commands-win32.c | 9 ++++----- 2 files changed, 12 insertions(+), 5 deletions(-)
Re: [PATCH 4/4] qga: Flatten simple union GuestDeviceId
In reply to Markus ArmbrusterQuoted 10 lines · Markus Armbruster
Simple unions are simpler than flat unions in the schema, but more complicated in C and on the QMP wire: there's extra indirection in C and extra nesting on the wire, both pointless. They should be avoided in new code.
GuestDeviceId was recently added for guest-get-devices. Convert it to a flat union.
Signed-off-by Markus Armbruster <[email protected]>
---
Quoted 61 lines
qga/qapi-schema.json | 8 ++++++++ qga/commands-win32.c | 9 ++++----- 2 files changed, 12 insertions(+), 5 deletions(-)qga/qapi-schema.json +8
-0@@ -1256,6 +1256,12 @@ { 'command': 'guest-get-osinfo', 'returns': 'GuestOSInfo' } +## +# @GuestDeviceType: +## +{ 'enum': 'GuestDeviceType', + 'data': [ 'pci' ] } + ## # @GuestDeviceIdPCI: #@@ -1276,6 +1282,8 @@ # Since: 5.2 ## { 'union': 'GuestDeviceId', + 'base': { 'type': 'GuestDeviceType' }, + 'discriminator': 'type', 'data': { 'pci': 'GuestDeviceIdPCI' } } ##qga/commands-win32.c +4
-5@@ -2400,16 +2400,15 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) } skip = false; - id =g_new0 (GuestDeviceIdPCI,1 ); vendor_id =g_match_info_fetch (match_info,1 ); device_id =g_match_info_fetch (match_info,2 ); - id->vendor_id =g_ascii_strtoull (vendor_id,NULL ,16 ); - id->device_id =g_ascii_strtoull (device_id,NULL ,16 ); device->id =g_new0 (GuestDeviceId,1 ); device->has_id = true; - device->id->type =GUEST_DEVICE_ID_KIND_PCI ; - device->id->u.pci.data = id; + device->id->type =GUEST_DEVICE_TYPE_PCI ; + id = &device->id->u.pci; + id->vendor_id =g_ascii_strtoull (vendor_id,NULL ,16 ); + id->device_id =g_ascii_strtoull (device_id,NULL ,16 );g_match_info_free (match_info);break;--
2.26.2
Signature · 1 line
Marc-André Lureau
Mike,
This series addresses interface defects, and must go into 5.2. It's fully reviewed. Pull request in time for soft freeze would be ideal. If you can't make it, feel free to ask me. I'll continue to push for the series even if it misses the soft freeze.