diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2021-01-28 22:43:18 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2021-01-28 22:43:18 +0000 |
commit | 7e7eb9f852a46b51a71ae9d82590b2e4d28827ee (patch) | |
tree | d63017ecda357d29659abe087aa6a09d808b06b5 /qga/commands-posix.c | |
parent | 0bcd12fb1513bad44f05f2d3a8eef2a99b3077b6 (diff) | |
parent | 95b3a8c8a82a34ca874ac0d4a9bbbdb38034acf3 (diff) | |
download | qemu-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-posix.c')
-rw-r--r-- | qga/commands-posix.c | 50 |
1 files changed, 15 insertions, 35 deletions
diff --git a/qga/commands-posix.c b/qga/commands-posix.c index edf785b..8dd94a3 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); |