aboutsummaryrefslogtreecommitdiff
path: root/qga/commands-win32.c
diff options
context:
space:
mode:
authorGal Hammer <ghammer@redhat.com>2015-11-02 16:49:48 +0200
committerMichael Roth <mdroth@linux.vnet.ibm.com>2016-02-25 09:48:51 -0600
commita7a173624e66785c6364e9f2f3ae0e7bea44bcb4 (patch)
tree6084b97b5fb54ffb8bb92a62d9b703c1f1702cef /qga/commands-win32.c
parent01fdadde8070d5355a2b36b80d07f1f412dc0491 (diff)
downloadqemu-a7a173624e66785c6364e9f2f3ae0e7bea44bcb4.zip
qemu-a7a173624e66785c6364e9f2f3ae0e7bea44bcb4.tar.gz
qemu-a7a173624e66785c6364e9f2f3ae0e7bea44bcb4.tar.bz2
qga: implement the guest-get-vcpus for windows
Signed-off-by: Gal Hammer <ghammer@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> * report rather than assert when VCPU count == 0 * fix up subject: s/set-vcpus/get-vcpus/ Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qga/commands-win32.c')
-rw-r--r--qga/commands-win32.c68
1 files changed, 66 insertions, 2 deletions
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 2799f5f..5ef460f 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1223,7 +1223,71 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
{
- error_setg(errp, QERR_UNSUPPORTED);
+ PSYSTEM_LOGICAL_PROCESSOR_INFORMATION pslpi, ptr;
+ DWORD length;
+ GuestLogicalProcessorList *head, **link;
+ Error *local_err = NULL;
+ int64_t current;
+
+ ptr = pslpi = NULL;
+ length = 0;
+ current = 0;
+ head = NULL;
+ link = &head;
+
+ if ((GetLogicalProcessorInformation(pslpi, &length) == FALSE) &&
+ (GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
+ (length > sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION))) {
+ ptr = pslpi = g_malloc0(length);
+ if (GetLogicalProcessorInformation(pslpi, &length) == FALSE) {
+ error_setg(&local_err, "Failed to get processor information: %d",
+ (int)GetLastError());
+ }
+ } else {
+ error_setg(&local_err,
+ "Failed to get processor information buffer length: %d",
+ (int)GetLastError());
+ }
+
+ while ((local_err == NULL) && (length > 0)) {
+ if (pslpi->Relationship == RelationProcessorCore) {
+ ULONG_PTR cpu_bits = pslpi->ProcessorMask;
+
+ 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 = false;
+
+ entry = g_malloc0(sizeof *entry);
+ entry->value = vcpu;
+
+ *link = entry;
+ link = &entry->next;
+ }
+ cpu_bits >>= 1;
+ }
+ }
+ length -= sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
+ pslpi++; /* next entry */
+ }
+
+ g_free(ptr);
+
+ if (local_err == NULL) {
+ if (head != NULL) {
+ return head;
+ }
+ /* there's no guest with zero VCPUs */
+ error_setg(&local_err, "Guest reported zero VCPUs");
+ }
+
+ qapi_free_GuestLogicalProcessorList(head);
+ error_propagate(errp, local_err);
return NULL;
}
@@ -1340,7 +1404,7 @@ GList *ga_command_blacklist_init(GList *blacklist)
{
const char *list_unsupported[] = {
"guest-suspend-hybrid",
- "guest-get-vcpus", "guest-set-vcpus",
+ "guest-set-vcpus",
"guest-get-memory-blocks", "guest-set-memory-blocks",
"guest-get-memory-block-size",
"guest-fsfreeze-freeze-list",