mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
vbox: Rewrite vboxDomainSetVcpusFlags
This commit is contained in:
parent
97d8a17bf5
commit
da3b862aad
@ -2775,3 +2775,49 @@ int vboxDomainGetState(virDomainPtr dom, int *state,
|
|||||||
vboxIIDUnalloc(&domiid);
|
vboxIIDUnalloc(&domiid);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
VBOX_OBJECT_CHECK(dom->conn, int, -1);
|
||||||
|
IMachine *machine = NULL;
|
||||||
|
vboxIIDUnion iid;
|
||||||
|
PRUint32 CPUCount = nvcpus;
|
||||||
|
nsresult rc;
|
||||||
|
|
||||||
|
if (flags != VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG, _("unsupported flags: (0x%x)"), flags);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (openSessionForMachine(data, dom->uuid, &iid, &machine, true) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
rc = gVBoxAPI.UISession.Open(data, &iid, machine);
|
||||||
|
if (NS_SUCCEEDED(rc)) {
|
||||||
|
gVBoxAPI.UISession.GetMachine(data->vboxSession, &machine);
|
||||||
|
if (machine) {
|
||||||
|
rc = gVBoxAPI.UIMachine.SetCPUCount(machine, CPUCount);
|
||||||
|
if (NS_SUCCEEDED(rc)) {
|
||||||
|
gVBoxAPI.UIMachine.SaveSettings(machine);
|
||||||
|
ret = 0;
|
||||||
|
} else {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("could not set the number of cpus of the domain "
|
||||||
|
"to: %u, rc=%08x"),
|
||||||
|
CPUCount, (unsigned)rc);
|
||||||
|
}
|
||||||
|
VBOX_RELEASE(machine);
|
||||||
|
} else {
|
||||||
|
virReportError(VIR_ERR_NO_DOMAIN,
|
||||||
|
_("no domain with matching id %d"), dom->id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
virReportError(VIR_ERR_NO_DOMAIN,
|
||||||
|
_("can't open session to the domain with id %d"), dom->id);
|
||||||
|
}
|
||||||
|
gVBoxAPI.UISession.Close(data->vboxSession);
|
||||||
|
|
||||||
|
vboxIIDUnalloc(&iid);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -955,61 +955,6 @@ static virDomainState _vboxConvertState(PRUint32 state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|
||||||
unsigned int flags)
|
|
||||||
{
|
|
||||||
VBOX_OBJECT_CHECK(dom->conn, int, -1);
|
|
||||||
IMachine *machine = NULL;
|
|
||||||
vboxIID iid = VBOX_IID_INITIALIZER;
|
|
||||||
PRUint32 CPUCount = nvcpus;
|
|
||||||
nsresult rc;
|
|
||||||
|
|
||||||
if (flags != VIR_DOMAIN_AFFECT_LIVE) {
|
|
||||||
virReportError(VIR_ERR_INVALID_ARG, _("unsupported flags: (0x%x)"), flags);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
vboxIIDFromUUID(&iid, dom->uuid);
|
|
||||||
#if VBOX_API_VERSION >= 4000000
|
|
||||||
/* Get machine for the call to VBOX_SESSION_OPEN */
|
|
||||||
rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
|
|
||||||
if (NS_FAILED(rc)) {
|
|
||||||
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
||||||
_("no domain with matching uuid"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rc = VBOX_SESSION_OPEN(iid.value, machine);
|
|
||||||
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 {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("could not set the number of cpus of the domain "
|
|
||||||
"to: %u, rc=%08x"),
|
|
||||||
CPUCount, (unsigned)rc);
|
|
||||||
}
|
|
||||||
VBOX_RELEASE(machine);
|
|
||||||
} else {
|
|
||||||
virReportError(VIR_ERR_NO_DOMAIN,
|
|
||||||
_("no domain with matching id %d"), dom->id);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
virReportError(VIR_ERR_NO_DOMAIN,
|
|
||||||
_("can't open session to the domain with id %d"), dom->id);
|
|
||||||
}
|
|
||||||
VBOX_SESSION_CLOSE();
|
|
||||||
|
|
||||||
vboxIIDUnalloc(&iid);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vboxDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
|
vboxDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
|
||||||
{
|
{
|
||||||
|
@ -438,6 +438,9 @@ int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory);
|
|||||||
int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info);
|
int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info);
|
||||||
int vboxDomainGetState(virDomainPtr dom, int *state,
|
int vboxDomainGetState(virDomainPtr dom, int *state,
|
||||||
int *reason, unsigned int flags);
|
int *reason, unsigned int flags);
|
||||||
|
int vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
||||||
|
unsigned int flags);
|
||||||
|
|
||||||
|
|
||||||
/* Version specified functions for installing uniformed API */
|
/* Version specified functions for installing uniformed API */
|
||||||
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user