aboutsummaryrefslogtreecommitdiff
path: root/qga
diff options
context:
space:
mode:
Diffstat (limited to 'qga')
-rw-r--r--qga/commands-posix.c50
-rw-r--r--qga/commands-win32.c99
2 files changed, 48 insertions, 101 deletions
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index edf785b2da..8dd94a3314 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -2474,18 +2474,17 @@ static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu,
GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
{
int64_t current;
- GuestLogicalProcessorList *head, **link;
+ GuestLogicalProcessorList *head, **tail;
long sc_max;
Error *local_err = NULL;
current = 0;
head = NULL;
- link = &head;
+ tail = &head;
sc_max = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
while (local_err == NULL && current < sc_max) {
GuestLogicalProcessor *vcpu;
- GuestLogicalProcessorList *entry;
int64_t id = current++;
char *path = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/",
id);
@@ -2495,10 +2494,7 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
vcpu->logical_id = id;
vcpu->has_can_offline = true; /* lolspeak ftw */
transfer_vcpu(vcpu, true, path, &local_err);
- entry = g_malloc0(sizeof *entry);
- entry->value = vcpu;
- *link = entry;
- link = &entry->next;
+ QAPI_LIST_APPEND(tail, vcpu);
}
g_free(path);
}
@@ -2831,13 +2827,13 @@ out1:
GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp)
{
- GuestMemoryBlockList *head, **link;
+ GuestMemoryBlockList *head, **tail;
Error *local_err = NULL;
struct dirent *de;
DIR *dp;
head = NULL;
- link = &head;
+ tail = &head;
dp = opendir("/sys/devices/system/memory/");
if (!dp) {
@@ -2859,7 +2855,6 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp)
*/
while ((de = readdir(dp)) != NULL) {
GuestMemoryBlock *mem_blk;
- GuestMemoryBlockList *entry;
if ((strncmp(de->d_name, "memory", 6) != 0) ||
!(de->d_type & DT_DIR)) {
@@ -2875,11 +2870,7 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp)
break;
}
- entry = g_malloc0(sizeof *entry);
- entry->value = mem_blk;
-
- *link = entry;
- link = &entry->next;
+ QAPI_LIST_APPEND(tail, mem_blk);
}
closedir(dp);
@@ -2899,15 +2890,14 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp)
GuestMemoryBlockResponseList *
qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks, Error **errp)
{
- GuestMemoryBlockResponseList *head, **link;
+ GuestMemoryBlockResponseList *head, **tail;
Error *local_err = NULL;
head = NULL;
- link = &head;
+ tail = &head;
while (mem_blks != NULL) {
GuestMemoryBlockResponse *result;
- GuestMemoryBlockResponseList *entry;
GuestMemoryBlock *current_mem_blk = mem_blks->value;
result = g_malloc0(sizeof(*result));
@@ -2916,11 +2906,8 @@ qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks, Error **errp)
if (local_err) { /* should never happen */
goto err;
}
- entry = g_malloc0(sizeof *entry);
- entry->value = result;
- *link = entry;
- link = &entry->next;
+ QAPI_LIST_APPEND(tail, result);
mem_blks = mem_blks->next;
}
@@ -3151,11 +3138,10 @@ static double ga_get_login_time(struct utmpx *user_info)
GuestUserList *qmp_guest_get_users(Error **errp)
{
GHashTable *cache = NULL;
- GuestUserList *head = NULL, *cur_item = NULL;
+ GuestUserList *head = NULL, **tail = &head;
struct utmpx *user_info = NULL;
gpointer value = NULL;
GuestUser *user = NULL;
- GuestUserList *item = NULL;
double login_time = 0;
cache = g_hash_table_new(g_str_hash, g_str_equal);
@@ -3178,19 +3164,13 @@ GuestUserList *qmp_guest_get_users(Error **errp)
continue;
}
- item = g_new0(GuestUserList, 1);
- item->value = g_new0(GuestUser, 1);
- item->value->user = g_strdup(user_info->ut_user);
- item->value->login_time = ga_get_login_time(user_info);
+ user = g_new0(GuestUser, 1);
+ user->user = g_strdup(user_info->ut_user);
+ user->login_time = ga_get_login_time(user_info);
- g_hash_table_insert(cache, item->value->user, item->value);
+ g_hash_table_insert(cache, user->user, user);
- if (!cur_item) {
- head = cur_item = item;
- } else {
- cur_item->next = item;
- cur_item = item;
- }
+ QAPI_LIST_APPEND(tail, user);
}
endutxent();
g_hash_table_destroy(cache);
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 684639bd13..a00e6cb165 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) {