qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Gal Hammer <ghammer@redhat.com>,
	peter.maydell@linaro.org,
	Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PULL 3/9] qga: implement the guest-get-vcpus for windows
Date: Thu, 25 Feb 2016 11:11:55 -0600	[thread overview]
Message-ID: <1456420321-20924-4-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1456420321-20924-1-git-send-email-mdroth@linux.vnet.ibm.com>

From: Gal Hammer <ghammer@redhat.com>

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>
---
 qga/commands-win32.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file 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",
-- 
1.9.1

  parent reply	other threads:[~2016-02-25 17:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-25 17:11 [Qemu-devel] [PULL 0/9] qemu-ga patch queue for 2.6 Michael Roth
2016-02-25 17:11 ` [Qemu-devel] [PULL 1/9] qga: Support enum names in guest-file-seek Michael Roth
2016-02-25 17:11 ` [Qemu-devel] [PULL 2/9] qemu-ga: Fixed minor version switch issue Michael Roth
2016-02-25 17:11 ` Michael Roth [this message]
2016-02-25 17:11 ` [Qemu-devel] [PULL 4/9] qga: use more idiomatic qemu-style eol operators Michael Roth
2016-02-25 17:11 ` [Qemu-devel] [PULL 5/9] qga: use size_t for wcslen() return value Michael Roth
2016-02-25 17:11 ` [Qemu-devel] [PULL 6/9] qga: use wide-chars constants for wchar_t comparisons Michael Roth
2016-02-25 17:11 ` [Qemu-devel] [PULL 7/9] qga: fix off-by-one length check Michael Roth
2016-02-25 17:12 ` [Qemu-devel] [PULL 8/9] qga: check utf8-to-utf16 conversion Michael Roth
2016-02-25 17:12 ` [Qemu-devel] [PULL 9/9] qga: fix w32 breakage due to missing osdep.h includes Michael Roth
2016-02-25 18:18 ` [Qemu-devel] [PULL 0/9] qemu-ga patch queue for 2.6 Peter Maydell
2016-02-25 21:27   ` Michael Roth
2016-02-26  5:44     ` Stefan Weil
2016-02-26 11:39       ` Peter Maydell
2016-02-26 11:40         ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1456420321-20924-4-git-send-email-mdroth@linux.vnet.ibm.com \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=ghammer@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).