mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 13:57:43 +03:00
Provide a helper method virDomainLiveConfigHelperMethod
This chunk of code below repeated in several functions, factor it into a helper method virDomainLiveConfigHelperMethod to eliminate duplicated code based on Eric and Adam's suggestion. I have tested it for all the relevant APIs changed. Signed-off-by: Eric Blake <eblake@redhat.com> Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
This commit is contained in:
parent
b72c774b88
commit
ae52342754
@ -1669,6 +1669,58 @@ virDomainObjGetPersistentDef(virCapsPtr caps,
|
|||||||
return domain->def;
|
return domain->def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helper method for --current, --live, and --config options, and check
|
||||||
|
* whether domain is active or can get persistent domain configuration.
|
||||||
|
*
|
||||||
|
* Return 0 if success, also change the flags and get the persistent
|
||||||
|
* domain configuration if needed. Return -1 on error.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virDomainLiveConfigHelperMethod(virCapsPtr caps,
|
||||||
|
virDomainObjPtr dom,
|
||||||
|
unsigned int *flags,
|
||||||
|
virDomainDefPtr *persistentDef)
|
||||||
|
{
|
||||||
|
bool isActive;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
isActive = virDomainObjIsActive(dom);
|
||||||
|
|
||||||
|
if ((*flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG)) ==
|
||||||
|
VIR_DOMAIN_AFFECT_CURRENT) {
|
||||||
|
if (isActive)
|
||||||
|
*flags |= VIR_DOMAIN_AFFECT_LIVE;
|
||||||
|
else
|
||||||
|
*flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isActive && (*flags & VIR_DOMAIN_AFFECT_LIVE)) {
|
||||||
|
virDomainReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("domain is not running"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||||
|
if (!dom->persistent) {
|
||||||
|
virDomainReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("cannot change persistent config of a "
|
||||||
|
"transient domain"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (!(*persistentDef = virDomainObjGetPersistentDef(caps, dom))) {
|
||||||
|
virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("Get persistent config failed"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The caller must hold a lock on the driver owning 'doms',
|
* The caller must hold a lock on the driver owning 'doms',
|
||||||
* and must also have locked 'dom', to ensure no one else
|
* and must also have locked 'dom', to ensure no one else
|
||||||
|
@ -1737,6 +1737,13 @@ int virDomainObjSetDefTransient(virCapsPtr caps,
|
|||||||
virDomainDefPtr
|
virDomainDefPtr
|
||||||
virDomainObjGetPersistentDef(virCapsPtr caps,
|
virDomainObjGetPersistentDef(virCapsPtr caps,
|
||||||
virDomainObjPtr domain);
|
virDomainObjPtr domain);
|
||||||
|
|
||||||
|
int
|
||||||
|
virDomainLiveConfigHelperMethod(virCapsPtr caps,
|
||||||
|
virDomainObjPtr dom,
|
||||||
|
unsigned int *flags,
|
||||||
|
virDomainDefPtr *persistentDef);
|
||||||
|
|
||||||
virDomainDefPtr
|
virDomainDefPtr
|
||||||
virDomainObjCopyPersistentDef(virCapsPtr caps, virDomainObjPtr dom);
|
virDomainObjCopyPersistentDef(virCapsPtr caps, virDomainObjPtr dom);
|
||||||
|
|
||||||
|
@ -358,6 +358,7 @@ virDomainLifecycleCrashTypeFromString;
|
|||||||
virDomainLifecycleCrashTypeToString;
|
virDomainLifecycleCrashTypeToString;
|
||||||
virDomainLifecycleTypeFromString;
|
virDomainLifecycleTypeFromString;
|
||||||
virDomainLifecycleTypeToString;
|
virDomainLifecycleTypeToString;
|
||||||
|
virDomainLiveConfigHelperMethod;
|
||||||
virDomainLoadAllConfigs;
|
virDomainLoadAllConfigs;
|
||||||
virDomainMemballoonModelTypeFromString;
|
virDomainMemballoonModelTypeFromString;
|
||||||
virDomainMemballoonModelTypeToString;
|
virDomainMemballoonModelTypeToString;
|
||||||
|
@ -1810,7 +1810,6 @@ static int qemudDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
|||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
virDomainDefPtr persistentDef = NULL;
|
virDomainDefPtr persistentDef = NULL;
|
||||||
int ret = -1, r;
|
int ret = -1, r;
|
||||||
bool isActive;
|
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
VIR_DOMAIN_AFFECT_CONFIG |
|
VIR_DOMAIN_AFFECT_CONFIG |
|
||||||
@ -1830,36 +1829,9 @@ static int qemudDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
|||||||
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
isActive = virDomainObjIsActive(vm);
|
if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
|
||||||
|
&persistentDef) < 0)
|
||||||
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
|
|
||||||
if (isActive)
|
|
||||||
flags = VIR_DOMAIN_AFFECT_LIVE;
|
|
||||||
else
|
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
|
||||||
}
|
|
||||||
if (flags == VIR_DOMAIN_MEM_MAXIMUM) {
|
|
||||||
if (isActive)
|
|
||||||
flags = VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_MEM_MAXIMUM;
|
|
||||||
else
|
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG | VIR_DOMAIN_MEM_MAXIMUM;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isActive && (flags & VIR_DOMAIN_AFFECT_LIVE)) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
|
||||||
"%s", _("domain is not running"));
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
|
||||||
if (!vm->persistent) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("cannot change persistent config of a transient domain"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_MEM_MAXIMUM) {
|
if (flags & VIR_DOMAIN_MEM_MAXIMUM) {
|
||||||
/* resize the maximum memory */
|
/* resize the maximum memory */
|
||||||
@ -3281,7 +3253,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
const char * type;
|
const char * type;
|
||||||
int max;
|
int max;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
bool isActive;
|
|
||||||
bool maximum;
|
bool maximum;
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
@ -3309,16 +3280,12 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
isActive = virDomainObjIsActive(vm);
|
|
||||||
maximum = (flags & VIR_DOMAIN_VCPU_MAXIMUM) != 0;
|
maximum = (flags & VIR_DOMAIN_VCPU_MAXIMUM) != 0;
|
||||||
flags &= ~VIR_DOMAIN_VCPU_MAXIMUM;
|
flags &= ~VIR_DOMAIN_VCPU_MAXIMUM;
|
||||||
|
|
||||||
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
|
if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
|
||||||
if (isActive)
|
&persistentDef) < 0)
|
||||||
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
goto endjob;
|
||||||
else
|
|
||||||
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* MAXIMUM cannot be mixed with LIVE. */
|
/* MAXIMUM cannot be mixed with LIVE. */
|
||||||
if (maximum && (flags & VIR_DOMAIN_AFFECT_LIVE)) {
|
if (maximum && (flags & VIR_DOMAIN_AFFECT_LIVE)) {
|
||||||
@ -3327,18 +3294,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isActive && (flags & VIR_DOMAIN_AFFECT_LIVE)) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
|
||||||
"%s", _("domain is not running"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!vm->persistent && (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("cannot change persistent config of a transient domain"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(type = virDomainVirtTypeToString(vm->def->virtType))) {
|
if (!(type = virDomainVirtTypeToString(vm->def->virtType))) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unknown virt type in domain definition '%d'"),
|
_("unknown virt type in domain definition '%d'"),
|
||||||
@ -3363,9 +3318,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
|
||||||
goto endjob;
|
|
||||||
|
|
||||||
switch (flags) {
|
switch (flags) {
|
||||||
case VIR_DOMAIN_AFFECT_CONFIG:
|
case VIR_DOMAIN_AFFECT_CONFIG:
|
||||||
if (maximum) {
|
if (maximum) {
|
||||||
@ -3424,7 +3376,6 @@ qemudDomainPinVcpuFlags(virDomainPtr dom,
|
|||||||
int maxcpu, hostcpus;
|
int maxcpu, hostcpus;
|
||||||
virNodeInfo nodeinfo;
|
virNodeInfo nodeinfo;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
bool isActive;
|
|
||||||
qemuDomainObjPrivatePtr priv;
|
qemuDomainObjPrivatePtr priv;
|
||||||
bool canResetting = true;
|
bool canResetting = true;
|
||||||
int pcpu;
|
int pcpu;
|
||||||
@ -3444,20 +3395,9 @@ qemudDomainPinVcpuFlags(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
isActive = virDomainObjIsActive(vm);
|
if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
|
||||||
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
|
&persistentDef) < 0)
|
||||||
if (isActive)
|
|
||||||
flags = VIR_DOMAIN_AFFECT_LIVE;
|
|
||||||
else
|
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isActive && (flags & VIR_DOMAIN_AFFECT_LIVE)) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("a domain is inactive; can change only "
|
|
||||||
"persistent config"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
priv = vm->privateData;
|
priv = vm->privateData;
|
||||||
|
|
||||||
@ -3468,16 +3408,6 @@ qemudDomainPinVcpuFlags(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
|
||||||
if (!vm->persistent) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("cannot change persistent config of a transient domain"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nodeGetInfo(dom->conn, &nodeinfo) < 0)
|
if (nodeGetInfo(dom->conn, &nodeinfo) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
|
hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
|
||||||
@ -3577,7 +3507,6 @@ qemudDomainGetVcpuPinInfo(virDomainPtr dom,
|
|||||||
virNodeInfo nodeinfo;
|
virNodeInfo nodeinfo;
|
||||||
virDomainDefPtr targetDef = NULL;
|
virDomainDefPtr targetDef = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
bool isActive;
|
|
||||||
int maxcpu, hostcpus, vcpu, pcpu;
|
int maxcpu, hostcpus, vcpu, pcpu;
|
||||||
int n;
|
int n;
|
||||||
virDomainVcpuPinDefPtr *vcpupin_list;
|
virDomainVcpuPinDefPtr *vcpupin_list;
|
||||||
@ -3599,33 +3528,14 @@ qemudDomainGetVcpuPinInfo(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
isActive = virDomainObjIsActive(vm);
|
if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
|
||||||
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
|
&targetDef) < 0)
|
||||||
if (isActive)
|
goto cleanup;
|
||||||
flags = VIR_DOMAIN_AFFECT_LIVE;
|
|
||||||
else
|
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
if (!isActive) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
|
||||||
"%s", _("domain is not running"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
targetDef = vm->def;
|
targetDef = vm->def;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
|
||||||
if (!vm->persistent) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("cannot get persistent config of a transient domain"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (!(targetDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Coverity didn't realize that targetDef must be set if we got here. */
|
/* Coverity didn't realize that targetDef must be set if we got here. */
|
||||||
sa_assert(targetDef);
|
sa_assert(targetDef);
|
||||||
|
|
||||||
@ -3770,7 +3680,6 @@ qemudDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
|
|||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
virDomainDefPtr def;
|
virDomainDefPtr def;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
bool active;
|
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
VIR_DOMAIN_AFFECT_CONFIG |
|
VIR_DOMAIN_AFFECT_CONFIG |
|
||||||
@ -3788,34 +3697,11 @@ qemudDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
active = virDomainObjIsActive(vm);
|
if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags, &def) < 0)
|
||||||
|
goto cleanup;
|
||||||
if ((flags & (VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG)) == 0) {
|
|
||||||
if (active)
|
|
||||||
flags |= VIR_DOMAIN_VCPU_LIVE;
|
|
||||||
else
|
|
||||||
flags |= VIR_DOMAIN_VCPU_CONFIG;
|
|
||||||
}
|
|
||||||
if ((flags & VIR_DOMAIN_AFFECT_LIVE) && (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
|
|
||||||
qemuReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("invalid flag combination: (0x%x)"), flags);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
if (!active) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("domain not active"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
def = vm->def;
|
def = vm->def;
|
||||||
} else {
|
|
||||||
if (!vm->persistent) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("domain is transient"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
def = vm->newDef ? vm->newDef : vm->def;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus;
|
ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus;
|
||||||
@ -6024,7 +5910,6 @@ static int qemuDomainSetBlkioParameters(virDomainPtr dom,
|
|||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
virDomainDefPtr persistentDef = NULL;
|
virDomainDefPtr persistentDef = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
bool isActive;
|
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||||
@ -6038,22 +5923,11 @@ static int qemuDomainSetBlkioParameters(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
isActive = virDomainObjIsActive(vm);
|
if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
|
||||||
|
&persistentDef) < 0)
|
||||||
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
|
goto cleanup;
|
||||||
if (isActive)
|
|
||||||
flags = VIR_DOMAIN_AFFECT_LIVE;
|
|
||||||
else
|
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
if (!isActive) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
|
||||||
"%s", _("domain is not running"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) {
|
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) {
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, _("blkio cgroup isn't mounted"));
|
qemuReportError(VIR_ERR_OPERATION_INVALID, _("blkio cgroup isn't mounted"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -6066,16 +5940,6 @@ static int qemuDomainSetBlkioParameters(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
|
||||||
if (!vm->persistent) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("cannot change persistent config of a transient domain"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
for (i = 0; i < nparams; i++) {
|
for (i = 0; i < nparams; i++) {
|
||||||
@ -6230,7 +6094,6 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom,
|
|||||||
unsigned int val;
|
unsigned int val;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int rc;
|
int rc;
|
||||||
bool isActive;
|
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
VIR_DOMAIN_AFFECT_CONFIG |
|
VIR_DOMAIN_AFFECT_CONFIG |
|
||||||
@ -6257,22 +6120,11 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
isActive = virDomainObjIsActive(vm);
|
if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
|
||||||
|
&persistentDef) < 0)
|
||||||
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
|
goto cleanup;
|
||||||
if (isActive)
|
|
||||||
flags = VIR_DOMAIN_AFFECT_LIVE;
|
|
||||||
else
|
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
if (!isActive) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
|
||||||
"%s", _("domain is not running"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) {
|
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) {
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, _("blkio cgroup isn't mounted"));
|
qemuReportError(VIR_ERR_OPERATION_INVALID, _("blkio cgroup isn't mounted"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -6285,16 +6137,6 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
|
||||||
if (!vm->persistent) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("cannot change persistent config of a transient domain"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
for (i = 0; i < *nparams && i < QEMU_NB_BLKIO_PARAM; i++) {
|
for (i = 0; i < *nparams && i < QEMU_NB_BLKIO_PARAM; i++) {
|
||||||
virTypedParameterPtr param = ¶ms[i];
|
virTypedParameterPtr param = ¶ms[i];
|
||||||
@ -6450,7 +6292,6 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
|
|||||||
virCgroupPtr group = NULL;
|
virCgroupPtr group = NULL;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
bool isActive;
|
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||||
@ -6465,22 +6306,11 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
isActive = virDomainObjIsActive(vm);
|
if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
|
||||||
|
&persistentDef) < 0)
|
||||||
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
|
goto cleanup;
|
||||||
if (isActive)
|
|
||||||
flags = VIR_DOMAIN_AFFECT_LIVE;
|
|
||||||
else
|
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
if (!isActive) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
|
||||||
"%s", _("domain is not running"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY)) {
|
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY)) {
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
"%s", _("cgroup memory controller is not mounted"));
|
"%s", _("cgroup memory controller is not mounted"));
|
||||||
@ -6494,16 +6324,6 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
|
||||||
if (!vm->persistent) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("cannot change persistent config of a transient domain"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
for (i = 0; i < nparams; i++) {
|
for (i = 0; i < nparams; i++) {
|
||||||
virTypedParameterPtr param = ¶ms[i];
|
virTypedParameterPtr param = ¶ms[i];
|
||||||
@ -6608,7 +6428,6 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
|
|||||||
unsigned long long val;
|
unsigned long long val;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int rc;
|
int rc;
|
||||||
bool isActive;
|
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
VIR_DOMAIN_AFFECT_CONFIG |
|
VIR_DOMAIN_AFFECT_CONFIG |
|
||||||
@ -6627,22 +6446,11 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
isActive = virDomainObjIsActive(vm);
|
if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
|
||||||
|
&persistentDef) < 0)
|
||||||
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
|
goto cleanup;
|
||||||
if (isActive)
|
|
||||||
flags = VIR_DOMAIN_AFFECT_LIVE;
|
|
||||||
else
|
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
if (!isActive) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
|
||||||
"%s", _("domain is not running"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY)) {
|
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY)) {
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
"%s", _("cgroup memory controller is not mounted"));
|
"%s", _("cgroup memory controller is not mounted"));
|
||||||
@ -6656,16 +6464,6 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
|
||||||
if (!vm->persistent) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("cannot change persistent config of a transient domain"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((*nparams) == 0) {
|
if ((*nparams) == 0) {
|
||||||
/* Current number of memory parameters supported by cgroups */
|
/* Current number of memory parameters supported by cgroups */
|
||||||
*nparams = QEMU_NB_MEM_PARAM;
|
*nparams = QEMU_NB_MEM_PARAM;
|
||||||
@ -11136,7 +10934,6 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
|
|||||||
const char *device = NULL;
|
const char *device = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int i;
|
int i;
|
||||||
bool isActive;
|
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
@ -11161,33 +10958,9 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
|
|||||||
if (qemuDomainObjBeginJobWithDriver(driver, vm, QEMU_JOB_MODIFY) < 0)
|
if (qemuDomainObjBeginJobWithDriver(driver, vm, QEMU_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
isActive = virDomainObjIsActive(vm);
|
if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
|
||||||
|
&persistentDef) < 0)
|
||||||
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
|
|
||||||
if (isActive)
|
|
||||||
flags = VIR_DOMAIN_AFFECT_LIVE;
|
|
||||||
else
|
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isActive && (flags & VIR_DOMAIN_AFFECT_LIVE)) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("domain is not running"));
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
|
||||||
if (!vm->persistent) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("cannot change persistent config of a transient domain"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
|
||||||
goto endjob;
|
|
||||||
idx = virDomainDiskIndexByName(persistentDef, disk, true);
|
|
||||||
if (idx < 0)
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < nparams; i++) {
|
for (i = 0; i < nparams; i++) {
|
||||||
virTypedParameterPtr param = ¶ms[i];
|
virTypedParameterPtr param = ¶ms[i];
|
||||||
@ -11248,7 +11021,10 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||||
sa_assert(persistentDef && idx >= 0);
|
sa_assert(persistentDef);
|
||||||
|
idx = virDomainDiskIndexByName(persistentDef, disk, true);
|
||||||
|
if (idx < 0)
|
||||||
|
goto endjob;
|
||||||
persistentDef->disks[idx]->blkdeviotune = info;
|
persistentDef->disks[idx]->blkdeviotune = info;
|
||||||
ret = virDomainSaveConfig(driver->configDir, persistentDef);
|
ret = virDomainSaveConfig(driver->configDir, persistentDef);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -11286,7 +11062,6 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
|
|||||||
const char *device = NULL;
|
const char *device = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int i;
|
int i;
|
||||||
bool isActive;
|
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
VIR_DOMAIN_AFFECT_CONFIG |
|
VIR_DOMAIN_AFFECT_CONFIG |
|
||||||
@ -11320,20 +11095,9 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
|
|||||||
if (qemuDomainObjBeginJobWithDriver(driver, vm, QEMU_JOB_MODIFY) < 0)
|
if (qemuDomainObjBeginJobWithDriver(driver, vm, QEMU_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
isActive = virDomainObjIsActive(vm);
|
if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
|
||||||
|
&persistentDef) < 0)
|
||||||
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
|
|
||||||
if (isActive)
|
|
||||||
flags = VIR_DOMAIN_AFFECT_LIVE;
|
|
||||||
else
|
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isActive && (flags & VIR_DOMAIN_AFFECT_LIVE)) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("domain is not running"));
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
priv = vm->privateData;
|
priv = vm->privateData;
|
||||||
@ -11345,14 +11109,6 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||||
if (!vm->persistent) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("domain is transient"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
|
||||||
goto endjob;
|
|
||||||
|
|
||||||
int idx = virDomainDiskIndexByName(vm->def, disk, true);
|
int idx = virDomainDiskIndexByName(vm->def, disk, true);
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
@ -2103,7 +2103,6 @@ testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
|
|||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
virDomainDefPtr def;
|
virDomainDefPtr def;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
bool active;
|
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
VIR_DOMAIN_AFFECT_CONFIG |
|
VIR_DOMAIN_AFFECT_CONFIG |
|
||||||
@ -2121,37 +2120,11 @@ testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
active = virDomainObjIsActive(vm);
|
if (virDomainLiveConfigHelperMethod(privconn->caps, vm, &flags, &def) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if ((flags & (VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG)) == 0) {
|
if (flags & VIR_DOMAIN_AFFECT_LIVE)
|
||||||
if (active)
|
|
||||||
flags |= VIR_DOMAIN_VCPU_LIVE;
|
|
||||||
else
|
|
||||||
flags |= VIR_DOMAIN_VCPU_CONFIG;
|
|
||||||
}
|
|
||||||
if ((flags & VIR_DOMAIN_AFFECT_LIVE) && (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
|
|
||||||
testError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("invalid flag combination: (0x%x)"), flags);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
|
||||||
if (!active) {
|
|
||||||
testError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("domain not active"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
def = vm->def;
|
def = vm->def;
|
||||||
} else {
|
|
||||||
if (!vm->persistent) {
|
|
||||||
testError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("domain is transient"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
def = vm->newDef ? vm->newDef : vm->def;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus;
|
ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user