aboutsummaryrefslogtreecommitdiff
path: root/qga/commands-win32.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-01-28 22:43:18 +0000
committerPeter Maydell <peter.maydell@linaro.org>2021-01-28 22:43:18 +0000
commit7e7eb9f852a46b51a71ae9d82590b2e4d28827ee (patch)
treed63017ecda357d29659abe087aa6a09d808b06b5 /qga/commands-win32.c
parent0bcd12fb1513bad44f05f2d3a8eef2a99b3077b6 (diff)
parent95b3a8c8a82a34ca874ac0d4a9bbbdb38034acf3 (diff)
downloadqemu-7e7eb9f852a46b51a71ae9d82590b2e4d28827ee.zip
qemu-7e7eb9f852a46b51a71ae9d82590b2e4d28827ee.tar.gz
qemu-7e7eb9f852a46b51a71ae9d82590b2e4d28827ee.tar.bz2
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-01-28' into staging
QAPI patches patches for 2021-01-28 # gpg: Signature made Thu 28 Jan 2021 07:10:21 GMT # gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653 # gpg: issuer "armbru@redhat.com" # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full] # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full] # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2021-01-28: qapi: More complex uses of QAPI_LIST_APPEND qapi: Use QAPI_LIST_APPEND in trivial cases qapi: Introduce QAPI_LIST_APPEND qapi: A couple more QAPI_LIST_PREPEND() stragglers net: Clarify early exit condition Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'qga/commands-win32.c')
-rw-r--r--qga/commands-win32.c99
1 files changed, 33 insertions, 66 deletions
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 684639b..a00e6cb 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1624,11 +1624,11 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
{
IP_ADAPTER_ADDRESSES *adptr_addrs, *addr;
IP_ADAPTER_UNICAST_ADDRESS *ip_addr = NULL;
- GuestNetworkInterfaceList *head = NULL, *cur_item = NULL;
- GuestIpAddressList *head_addr, *cur_addr;
- GuestNetworkInterfaceList *info;
+ GuestNetworkInterfaceList *head = NULL, **tail = &head;
+ GuestIpAddressList *head_addr, **tail_addr;
+ GuestNetworkInterface *info;
GuestNetworkInterfaceStat *interface_stat = NULL;
- GuestIpAddressList *address_item = NULL;
+ GuestIpAddress *address_item = NULL;
unsigned char *mac_addr;
char *addr_str;
WORD wsa_version;
@@ -1651,30 +1651,24 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
for (addr = adptr_addrs; addr; addr = addr->Next) {
info = g_malloc0(sizeof(*info));
- if (cur_item == NULL) {
- head = cur_item = info;
- } else {
- cur_item->next = info;
- cur_item = info;
- }
+ QAPI_LIST_APPEND(tail, info);
- info->value = g_malloc0(sizeof(*info->value));
- info->value->name = guest_wctomb_dup(addr->FriendlyName);
+ info->name = guest_wctomb_dup(addr->FriendlyName);
if (addr->PhysicalAddressLength != 0) {
mac_addr = addr->PhysicalAddress;
- info->value->hardware_address =
+ info->hardware_address =
g_strdup_printf("%02x:%02x:%02x:%02x:%02x:%02x",
(int) mac_addr[0], (int) mac_addr[1],
(int) mac_addr[2], (int) mac_addr[3],
(int) mac_addr[4], (int) mac_addr[5]);
- info->value->has_hardware_address = true;
+ info->has_hardware_address = true;
}
head_addr = NULL;
- cur_addr = NULL;
+ tail_addr = &head_addr;
for (ip_addr = addr->FirstUnicastAddress;
ip_addr;
ip_addr = ip_addr->Next) {
@@ -1685,37 +1679,29 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
address_item = g_malloc0(sizeof(*address_item));
- if (!cur_addr) {
- head_addr = cur_addr = address_item;
- } else {
- cur_addr->next = address_item;
- cur_addr = address_item;
- }
+ QAPI_LIST_APPEND(tail_addr, address_item);
- address_item->value = g_malloc0(sizeof(*address_item->value));
- address_item->value->ip_address = addr_str;
- address_item->value->prefix = guest_ip_prefix(ip_addr);
+ address_item->ip_address = addr_str;
+ address_item->prefix = guest_ip_prefix(ip_addr);
if (ip_addr->Address.lpSockaddr->sa_family == AF_INET) {
- address_item->value->ip_address_type =
- GUEST_IP_ADDRESS_TYPE_IPV4;
+ address_item->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV4;
} else if (ip_addr->Address.lpSockaddr->sa_family == AF_INET6) {
- address_item->value->ip_address_type =
- GUEST_IP_ADDRESS_TYPE_IPV6;
+ address_item->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV6;
}
}
if (head_addr) {
- info->value->has_ip_addresses = true;
- info->value->ip_addresses = head_addr;
+ info->has_ip_addresses = true;
+ info->ip_addresses = head_addr;
}
- if (!info->value->has_statistics) {
+ if (!info->has_statistics) {
interface_stat = g_malloc0(sizeof(*interface_stat));
if (guest_get_network_stats(addr->AdapterName,
interface_stat) == -1) {
- info->value->has_statistics = false;
+ info->has_statistics = false;
g_free(interface_stat);
} else {
- info->value->statistics = interface_stat;
- info->value->has_statistics = true;
+ info->statistics = interface_stat;
+ info->has_statistics = true;
}
}
}
@@ -1833,7 +1819,7 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
{
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION pslpi, ptr;
DWORD length;
- GuestLogicalProcessorList *head, **link;
+ GuestLogicalProcessorList *head, **tail;
Error *local_err = NULL;
int64_t current;
@@ -1841,7 +1827,7 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
length = 0;
current = 0;
head = NULL;
- link = &head;
+ tail = &head;
if ((GetLogicalProcessorInformation(pslpi, &length) == FALSE) &&
(GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
@@ -1864,18 +1850,13 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
while (cpu_bits > 0) {
if (!!(cpu_bits & 1)) {
GuestLogicalProcessor *vcpu;
- GuestLogicalProcessorList *entry;
vcpu = g_malloc0(sizeof *vcpu);
vcpu->logical_id = current++;
vcpu->online = true;
vcpu->has_can_offline = true;
- entry = g_malloc0(sizeof *entry);
- entry->value = vcpu;
-
- *link = entry;
- link = &entry->next;
+ QAPI_LIST_APPEND(tail, vcpu);
}
cpu_bits >>= 1;
}
@@ -2087,12 +2068,11 @@ GuestUserList *qmp_guest_get_users(Error **errp)
#define QGA_NANOSECONDS 10000000
GHashTable *cache = NULL;
- GuestUserList *head = NULL, *cur_item = NULL;
+ GuestUserList *head = NULL, **tail = &head;
DWORD buffer_size = 0, count = 0, i = 0;
GA_WTSINFOA *info = NULL;
WTS_SESSION_INFOA *entries = NULL;
- GuestUserList *item = NULL;
GuestUser *user = NULL;
gpointer value = NULL;
INT64 login = 0;
@@ -2128,23 +2108,17 @@ GuestUserList *qmp_guest_get_users(Error **errp)
user->login_time = login_time;
}
} else {
- item = g_new0(GuestUserList, 1);
- item->value = g_new0(GuestUser, 1);
+ user = g_new0(GuestUser, 1);
- item->value->user = g_strdup(info->UserName);
- item->value->domain = g_strdup(info->Domain);
- item->value->has_domain = true;
+ user->user = g_strdup(info->UserName);
+ user->domain = g_strdup(info->Domain);
+ user->has_domain = true;
- item->value->login_time = login_time;
+ user->login_time = login_time;
- g_hash_table_add(cache, item->value->user);
+ g_hash_table_add(cache, user->user);
- if (!cur_item) {
- head = cur_item = item;
- } else {
- cur_item->next = item;
- cur_item = item;
- }
+ QAPI_LIST_APPEND(tail, user);
}
}
WTSFreeMemory(info);
@@ -2429,7 +2403,7 @@ static GStrv ga_get_hardware_ids(DEVINST devInstance)
GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)
{
- GuestDeviceInfoList *head = NULL, *cur_item = NULL, *item = NULL;
+ GuestDeviceInfoList *head = NULL, **tail = &head;
HDEVINFO dev_info = INVALID_HANDLE_VALUE;
SP_DEVINFO_DATA dev_info_data;
int i, j;
@@ -2527,14 +2501,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)
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) {
- head = cur_item = item;
- } else {
- cur_item->next = item;
- cur_item = item;
- }
+ QAPI_LIST_APPEND(tail, g_steal_pointer(&device));
}
if (dev_info != INVALID_HANDLE_VALUE) {