On Fri, Aug 07, 2009 at 04:08:13PM +0200, Pritesh Kothari wrote:
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(a)Sun.com>
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 */
ACK
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|