1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

API: prevent query of --live and --config at once

Drivers were inconsistent when presented both --live and --config
at once.  For example, within qemu, getting memory parameters
favored live, getting blkio tuning favored config, and getting
scheduler parameters errored out.  Also, some, but not all,
attempts to mix flags on query were filtered at the virsh level.
We shouldn't have to duplicate efforts in every client app, nor
in every driver.  So, it is simpler to just enforce that the two
flags cannot both be used at once on query operations, which has
precedent in libvirt.c, and which matches the documentation of
virDomainModificationImpact.

* src/libvirt.c (virDomainGetMemoryParameters)
(virDomainGetBlkioParameters)
(virDomainGetSchedulerParametersFlags, virDomainGetVcpuPinInfo):
Borrow sanity checking from virDomainGetVcpusFlags.
This commit is contained in:
Eric Blake 2011-11-14 17:11:18 -07:00
parent 80eaa56561
commit 4199f3de2e

View File

@ -3742,6 +3742,13 @@ virDomainGetMemoryParameters(virDomainPtr domain,
if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn, if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
VIR_DRV_FEATURE_TYPED_PARAM_STRING)) VIR_DRV_FEATURE_TYPED_PARAM_STRING))
flags |= VIR_TYPED_PARAM_STRING_OKAY; flags |= VIR_TYPED_PARAM_STRING_OKAY;
/* At most one of these two flags should be set. */
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
conn = domain->conn; conn = domain->conn;
if (conn->driver->domainGetMemoryParameters) { if (conn->driver->domainGetMemoryParameters) {
@ -3867,6 +3874,13 @@ virDomainGetBlkioParameters(virDomainPtr domain,
if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn, if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
VIR_DRV_FEATURE_TYPED_PARAM_STRING)) VIR_DRV_FEATURE_TYPED_PARAM_STRING))
flags |= VIR_TYPED_PARAM_STRING_OKAY; flags |= VIR_TYPED_PARAM_STRING_OKAY;
/* At most one of these two flags should be set. */
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
conn = domain->conn; conn = domain->conn;
if (conn->driver->domainGetBlkioParameters) { if (conn->driver->domainGetBlkioParameters) {
@ -6573,6 +6587,13 @@ virDomainGetSchedulerParametersFlags(virDomainPtr domain,
if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn, if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
VIR_DRV_FEATURE_TYPED_PARAM_STRING)) VIR_DRV_FEATURE_TYPED_PARAM_STRING))
flags |= VIR_TYPED_PARAM_STRING_OKAY; flags |= VIR_TYPED_PARAM_STRING_OKAY;
/* At most one of these two flags should be set. */
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
conn = domain->conn; conn = domain->conn;
if (conn->driver->domainGetSchedulerParametersFlags) { if (conn->driver->domainGetSchedulerParametersFlags) {
@ -8056,7 +8077,8 @@ virDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
} }
/* At most one of these two flags should be set. */ /* At most one of these two flags should be set. */
if ((flags & VIR_DOMAIN_AFFECT_LIVE) && (flags & VIR_DOMAIN_AFFECT_CONFIG)) { if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error; goto error;
} }
@ -8153,7 +8175,7 @@ error:
* underlying virtualization system (Xen...). * underlying virtualization system (Xen...).
* If maplen < size, missing bytes are set to zero. * If maplen < size, missing bytes are set to zero.
* If maplen > size, failure code is returned. * If maplen > size, failure code is returned.
* @flags: bitwise-OR of virDomainModificationImpac * @flags: bitwise-OR of virDomainModificationImpact
* *
* Dynamically change the real CPUs which can be allocated to a virtual CPU. * Dynamically change the real CPUs which can be allocated to a virtual CPU.
* This function may require privileged access to the hypervisor. * This function may require privileged access to the hypervisor.
@ -8244,8 +8266,8 @@ error:
* -1 in case of failure. * -1 in case of failure.
*/ */
int int
virDomainGetVcpuPinInfo (virDomainPtr domain, int ncpumaps, virDomainGetVcpuPinInfo(virDomainPtr domain, int ncpumaps,
unsigned char *cpumaps, int maplen, unsigned int flags) unsigned char *cpumaps, int maplen, unsigned int flags)
{ {
virConnectPtr conn; virConnectPtr conn;
@ -8266,6 +8288,12 @@ virDomainGetVcpuPinInfo (virDomainPtr domain, int ncpumaps,
goto error; goto error;
} }
/* At most one of these two flags should be set. */
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
conn = domain->conn; conn = domain->conn;
if (conn->driver->domainGetVcpuPinInfo) { if (conn->driver->domainGetVcpuPinInfo) {