[libvirt] [PATCH] Support for getting/setting number of cpus in VirtualBox

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All,

I have just added support for getting/setting number of cpus in VirtualBox.
The patch for the same is include below.

Regards,
Pritesh
commit 3dcaf67d0bb4aa58c4e2224779bebcf2263068b8
Author: Pritesh Kothari <Pritesh.Kothari@xxxxxxx>
Date:   Fri Aug 7 15:49:16 2009 +0200

    libvirt: support for getting/setting number of cpus

diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index d3158ef..32bfb4d 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1527,6 +1527,82 @@ cleanup:
     return ret;
 }
 
+static int vboxDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) {
+    nsresult rc;
+    vboxGlobalData *data = dom->conn->privateData;
+    IMachine *machine    = NULL;
+    vboxIID  *iid        = NULL;
+    PRUint32  CPUCount   = nvcpus;
+    int       ret        = -1;
+
+#if VBOX_API_VERSION == 2002
+    if (VIR_ALLOC(iid) < 0) {
+        virReportOOMError(dom->conn);
+        goto cleanup;
+    }
+#endif
+
+    if(data->vboxObj) {
+
+        vboxIIDFromUUID(dom->uuid, iid);
+
+        rc = data->vboxObj->vtbl->OpenSession(data->vboxObj, data->vboxSession, iid);
+        if (NS_SUCCEEDED(rc)) {
+            data->vboxSession->vtbl->GetMachine(data->vboxSession, &machine);
+            if (machine) {
+                rc = machine->vtbl->SetCPUCount(machine, CPUCount);
+                if (NS_SUCCEEDED(rc)) {
+                    machine->vtbl->SaveSettings(machine);
+                    ret = 0;
+                } else {
+                    vboxError(dom->conn, VIR_ERR_INTERNAL_ERROR, "%s: %u, rc=%08x",
+                              "could not set the number of cpus of the domain to",
+                              CPUCount, (unsigned)rc);
+                }
+                machine->vtbl->nsisupports.Release((nsISupports *)machine);
+            } else {
+                vboxError(dom->conn, VIR_ERR_INVALID_DOMAIN,
+                          "no domain with matching id %d", dom->id);
+            }
+        } else {
+            vboxError(dom->conn, VIR_ERR_INVALID_DOMAIN,
+                      "can't open session to the domain with id %d", dom->id);
+        }
+        data->vboxSession->vtbl->Close(data->vboxSession);
+    }
+
+#if VBOX_API_VERSION == 2002
+cleanup:
+#endif
+    vboxIIDFree(iid);
+    return ret;
+}
+
+static int vboxDomainGetMaxVcpus(virDomainPtr dom) {
+    vboxGlobalData *data = dom->conn->privateData;
+    PRUint32 maxCPUCount = 0;
+    int ret = -1;
+
+    /* Currently every domain supports the same number of max cpus
+     * as that supported by vbox and thus take it directly from
+     * the systemproperties.
+     */
+    if(data->vboxObj) {
+        ISystemProperties *systemProperties = NULL;
+
+        data->vboxObj->vtbl->GetSystemProperties(data->vboxObj, &systemProperties);
+        if (systemProperties) {
+            systemProperties->vtbl->GetMaxGuestCPUCount(systemProperties, &maxCPUCount);
+            systemProperties->vtbl->nsisupports.Release((nsISupports *)systemProperties);
+        }
+    }
+
+    if (maxCPUCount > 0)
+        ret = maxCPUCount;
+
+    return ret;
+}
+
 static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
     nsresult rc;
     vboxGlobalData *data = dom->conn->privateData;
@@ -5579,10 +5655,10 @@ virDriver NAME(Driver) = {
     vboxDomainSave, /* domainSave */
     NULL, /* domainRestore */
     NULL, /* domainCoreDump */
-    NULL, /* domainSetVcpus */
+    vboxDomainSetVcpus, /* domainSetVcpus */
     NULL, /* domainPinVcpu */
     NULL, /* domainGetVcpus */
-    NULL, /* domainGetMaxVcpus */
+    vboxDomainGetMaxVcpus, /* domainGetMaxVcpus */
     NULL, /* domainGetSecurityLabel */
     NULL, /* nodeGetSecurityModel */
     vboxDomainDumpXML, /* domainDumpXML */
--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]