mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
SetVcpus and DomainGetMaxVcpus for QEmu
* src/qemu_conf.c src/qemu_conf.h src/qemu_driver.c: another patch from Cole Robinson adding SetVcpus and DomainGetMaxVcpus for QEmu Daniel
This commit is contained in:
parent
0feb4c9552
commit
da6316f20e
@ -1,3 +1,8 @@
|
|||||||
|
Wed May 7 18:12:11 CEST 2008 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
|
* src/qemu_conf.c src/qemu_conf.h src/qemu_driver.c: another patch
|
||||||
|
from Cole Robinson adding SetVcpus and DomainGetMaxVcpus for QEmu
|
||||||
|
|
||||||
Wed May 7 16:42:59 CEST 2008 Daniel Veillard <veillard@redhat.com>
|
Wed May 7 16:42:59 CEST 2008 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* tests/qemuxml2argvdata/qemuxml2argv-sound.args
|
* tests/qemuxml2argvdata/qemuxml2argv-sound.args
|
||||||
|
@ -554,6 +554,21 @@ int qemudExtractVersion(virConnectPtr conn,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Converts def->virtType to applicable string type
|
||||||
|
* @param type integer virt type
|
||||||
|
* @return string type on success, NULL on fail
|
||||||
|
*/
|
||||||
|
const char * qemudVirtTypeToString(int type) {
|
||||||
|
switch (type) {
|
||||||
|
case QEMUD_VIRT_QEMU:
|
||||||
|
return "qemu";
|
||||||
|
case QEMUD_VIRT_KQEMU:
|
||||||
|
return "kqemu";
|
||||||
|
case QEMUD_VIRT_KVM:
|
||||||
|
return "kvm";
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse the XML definition for a disk
|
/* Parse the XML definition for a disk
|
||||||
* @param disk pre-allocated & zero'd disk record
|
* @param disk pre-allocated & zero'd disk record
|
||||||
@ -1751,9 +1766,12 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
|
|||||||
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/emulator[1])", ctxt);
|
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/emulator[1])", ctxt);
|
||||||
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
|
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
|
||||||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
||||||
const char *type = (def->virtType == QEMUD_VIRT_QEMU ? "qemu" :
|
const char *type = qemudVirtTypeToString(def->virtType);
|
||||||
def->virtType == QEMUD_VIRT_KQEMU ? "kqemu":
|
if (!type) {
|
||||||
"kvm");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("unknown virt type"));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
const char *emulator = virCapabilitiesDefaultGuestEmulator(driver->caps,
|
const char *emulator = virCapabilitiesDefaultGuestEmulator(driver->caps,
|
||||||
def->os.type,
|
def->os.type,
|
||||||
def->os.arch,
|
def->os.arch,
|
||||||
@ -3607,18 +3625,7 @@ char *qemudGenerateXML(virConnectPtr conn,
|
|||||||
const char *type = NULL;
|
const char *type = NULL;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
switch (def->virtType) {
|
if (!(type = qemudVirtTypeToString(def->virtType))) {
|
||||||
case QEMUD_VIRT_QEMU:
|
|
||||||
type = "qemu";
|
|
||||||
break;
|
|
||||||
case QEMUD_VIRT_KQEMU:
|
|
||||||
type = "kqemu";
|
|
||||||
break;
|
|
||||||
case QEMUD_VIRT_KVM:
|
|
||||||
type = "kvm";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!type) {
|
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unexpected domain type %d"), def->virtType);
|
_("unexpected domain type %d"), def->virtType);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -503,6 +503,7 @@ char * qemudGenerateNetworkXML (virConnectPtr conn,
|
|||||||
struct qemud_network *network,
|
struct qemud_network *network,
|
||||||
struct qemud_network_def *def);
|
struct qemud_network_def *def);
|
||||||
|
|
||||||
|
const char *qemudVirtTypeToString (int type);
|
||||||
|
|
||||||
#endif /* WITH_QEMU */
|
#endif /* WITH_QEMU */
|
||||||
|
|
||||||
|
@ -113,6 +113,8 @@ static int qemudShutdownNetworkDaemon(virConnectPtr conn,
|
|||||||
struct qemud_driver *driver,
|
struct qemud_driver *driver,
|
||||||
struct qemud_network *network);
|
struct qemud_network *network);
|
||||||
|
|
||||||
|
static int qemudDomainGetMaxVcpus(virDomainPtr dom);
|
||||||
|
|
||||||
static struct qemud_driver *qemu_driver = NULL;
|
static struct qemud_driver *qemu_driver = NULL;
|
||||||
|
|
||||||
|
|
||||||
@ -1563,21 +1565,23 @@ static const char *qemudGetType(virConnectPtr conn ATTRIBUTE_UNUSED) {
|
|||||||
return "QEMU";
|
return "QEMU";
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudGetMaxVCPUs(virConnectPtr conn ATTRIBUTE_UNUSED,
|
static int qemudGetMaxVCPUs(virConnectPtr conn, const char *type) {
|
||||||
const char *type) {
|
|
||||||
if (!type)
|
if (!type)
|
||||||
return 16;
|
return 16;
|
||||||
|
|
||||||
if (!strcmp(type, "qemu"))
|
if (STRCASEEQ(type, "qemu"))
|
||||||
return 16;
|
return 16;
|
||||||
|
|
||||||
/* XXX future KVM will support SMP. Need to probe
|
/* XXX future KVM will support SMP. Need to probe
|
||||||
kernel to figure out KVM module version i guess */
|
kernel to figure out KVM module version i guess */
|
||||||
if (!strcmp(type, "kvm"))
|
if (STRCASEEQ(type, "kvm"))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (!strcmp(type, "kqemu"))
|
if (STRCASEEQ(type, "kqemu"))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INVALID_ARG,
|
||||||
|
_("unknown type '%s'"), type);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2161,6 +2165,67 @@ static int qemudDomainSave(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int qemudDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) {
|
||||||
|
const struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
|
||||||
|
struct qemud_vm *vm = qemudFindVMByUUID(driver, dom->uuid);
|
||||||
|
int max;
|
||||||
|
|
||||||
|
if (!vm) {
|
||||||
|
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
|
||||||
|
_("no domain with matching uuid '%s'"), dom->uuid);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qemudIsActiveVM(vm)) {
|
||||||
|
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("cannot change vcpu count of an active domain"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((max = qemudDomainGetMaxVcpus(dom)) < 0) {
|
||||||
|
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("could not determine max vcpus for the domain"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nvcpus > max) {
|
||||||
|
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
|
||||||
|
_("requested vcpus is greater than max allowable"
|
||||||
|
" vcpus for the domain: %d > %d"), nvcpus, max);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
vm->def->vcpus = nvcpus;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int qemudDomainGetMaxVcpus(virDomainPtr dom) {
|
||||||
|
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
|
||||||
|
struct qemud_vm *vm = qemudFindVMByUUID(driver, dom->uuid);
|
||||||
|
const char *type;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!vm) {
|
||||||
|
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
|
||||||
|
_("no domain with matching uuid '%s'"), dom->uuid);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(type = qemudVirtTypeToString(vm->def->virtType))) {
|
||||||
|
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("unknown virt type in domain definition '%d'"),
|
||||||
|
vm->def->virtType);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ret = qemudGetMaxVCPUs(dom->conn, type)) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int qemudDomainRestore(virConnectPtr conn,
|
static int qemudDomainRestore(virConnectPtr conn,
|
||||||
const char *path) {
|
const char *path) {
|
||||||
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
|
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
|
||||||
@ -3081,10 +3146,10 @@ static virDriver qemuDriver = {
|
|||||||
qemudDomainSave, /* domainSave */
|
qemudDomainSave, /* domainSave */
|
||||||
qemudDomainRestore, /* domainRestore */
|
qemudDomainRestore, /* domainRestore */
|
||||||
NULL, /* domainCoreDump */
|
NULL, /* domainCoreDump */
|
||||||
NULL, /* domainSetVcpus */
|
qemudDomainSetVcpus, /* domainSetVcpus */
|
||||||
NULL, /* domainPinVcpu */
|
NULL, /* domainPinVcpu */
|
||||||
NULL, /* domainGetVcpus */
|
NULL, /* domainGetVcpus */
|
||||||
NULL, /* domainGetMaxVcpus */
|
qemudDomainGetMaxVcpus, /* domainGetMaxVcpus */
|
||||||
qemudDomainDumpXML, /* domainDumpXML */
|
qemudDomainDumpXML, /* domainDumpXML */
|
||||||
qemudListDefinedDomains, /* listDomains */
|
qemudListDefinedDomains, /* listDomains */
|
||||||
qemudNumDefinedDomains, /* numOfDomains */
|
qemudNumDefinedDomains, /* numOfDomains */
|
||||||
|
Loading…
Reference in New Issue
Block a user