提交 33d90baf 编写于 作者: E Eric Blake 提交者: Matthias Bolte

API: consolidate common unreleased enums

This commit is safe precisely because there has been no release
for any of the enum values being deleted (they were added post-0.9.1).

After the 0.9.2 release, we can then take advantage of
virDomainModificationImpact in more places.

* include/libvirt/libvirt.h.in (virDomainModificationImpact): New
enum.
(virDomainSchedParameterFlags, virMemoryParamFlags): Delete, since
these were never released, and the new enum works fine here.
* src/libvirt.c	(virDomainGetMemoryParameters)
(virDomainSetMemoryParameters)
(virDomainGetSchedulerParametersFlags)
(virDomainSetSchedulerParametersFlags): Update documentation.
* src/qemu/qemu_driver.c (qemuDomainSetMemoryParameters)
(qemuDomainGetMemoryParameters, qemuSetSchedulerParametersFlags)
(qemuSetSchedulerParameters, qemuGetSchedulerParametersFlags)
(qemuGetSchedulerParameters): Adjust clients.
* tools/virsh.c (cmdSchedinfo, cmdMemtune): Likewise.
Based on ideas by Daniel Veillard and Hu Tao.
上级 aeed51f7
......@@ -141,6 +141,23 @@ typedef enum {
VIR_DOMAIN_CRASHED_UNKNOWN = 0, /* crashed for unknown reason */
} virDomainCrashedReason;
/**
* virDomainModificationImpact:
*
* Several APIs take flags to determine whether a change to the domain
* affects just the running instance, just the persistent definition,
* or both. The use of VIR_DOMAIN_AFFECT_CURRENT will resolve to
* either VIR_DOMAIN_AFFECT_LIVE or VIR_DOMAIN_AFFECT_CONFIG according
* to current domain state. VIR_DOMAIN_AFFECT_LIVE requires a running
* domain, and VIR_DOMAIN_AFFECT_CONFIG requires a persistent domain
* (whether or not it is running).
*/
typedef enum {
VIR_DOMAIN_AFFECT_CURRENT = 0, /* Affect current domain state. */
VIR_DOMAIN_AFFECT_LIVE = 1 << 0, /* Affect running domain state. */
VIR_DOMAIN_AFFECT_CONFIG = 1 << 1, /* Affect persistent domain state. */
} virDomainModificationImpact;
/**
* virDomainInfoPtr:
*
......@@ -338,12 +355,6 @@ typedef virTypedParameter *virTypedParameterPtr;
/* Management of scheduler parameters */
typedef enum {
VIR_DOMAIN_SCHEDPARAM_CURRENT = 0, /* affect current domain state */
VIR_DOMAIN_SCHEDPARAM_LIVE = (1 << 0), /* Affect active domain */
VIR_DOMAIN_SCHEDPARAM_CONFIG = (1 << 1), /* Affect next boot */
} virDomainSchedParameterFlags;
/*
* Fetch scheduler parameters, caller allocates 'params' field of size 'nparams'
*/
......@@ -799,13 +810,6 @@ int virDomainGetBlkioParameters(virDomainPtr domain,
/* Manage memory parameters. */
/* flags for setting memory parameters */
typedef enum {
VIR_DOMAIN_MEMORY_PARAM_CURRENT = 0, /* affect current domain state */
VIR_DOMAIN_MEMORY_PARAM_LIVE = (1 << 0), /* affect active domain */
VIR_DOMAIN_MEMORY_PARAM_CONFIG = (1 << 1) /* affect next boot */
} virMemoryParamFlags;
/**
* VIR_DOMAIN_MEMORY_PARAM_UNLIMITED:
*
......
......@@ -2994,7 +2994,7 @@ error:
* @params: pointer to memory parameter objects
* @nparams: number of memory parameter (this value can be the same or
* less than the number of parameters supported)
* @flags: currently unused, for future extension
* @flags: bitwise-OR of virDomainModificationImpact
*
* Change all or a subset of the memory tunables.
* This function requires privileged access to the hypervisor.
......@@ -3049,7 +3049,7 @@ error:
* @params: pointer to memory parameter object
* (return value, allocated by the caller)
* @nparams: pointer to number of memory parameters
* @flags: currently unused, for future extension
* @flags: one of virDomainModificationImpact
*
* Get all memory parameters, the @params array will be filled with the values
* equal to the number of parameters suggested by @nparams
......@@ -5480,13 +5480,13 @@ error:
* @nparams: pointer to number of scheduler parameter
* (this value should be same than the returned value
* nparams of virDomainGetSchedulerType)
* @flags: virDomainSchedParameterFlags
* @flags: one of virDomainModificationImpact
*
* Get the scheduler parameters, the @params array will be filled with the
* values.
*
* The value of @flags can be exactly VIR_DOMAIN_SCHEDPARAM_CURRENT,
* VIR_DOMAIN_SCHEDPARAM_LIVE, or VIR_DOMAIN_SCHEDPARAM_CONFIG.
* The value of @flags can be exactly VIR_DOMAIN_AFFECT_CURRENT,
* VIR_DOMAIN_AFFECT_LIVE, or VIR_DOMAIN_AFFECT_CONFIG.
*
* Returns -1 in case of error, 0 in case of success.
*/
......@@ -5596,12 +5596,12 @@ error:
* @nparams: number of scheduler parameter objects
* (this value can be the same or less than the returned value
* nparams of virDomainGetSchedulerType)
* @flags: virDomainSchedParameterFlags
* @flags: bitwise-OR of virDomainModificationImpact
*
* Change a subset or all scheduler parameters. The value of @flags
* should be either VIR_DOMAIN_SCHEDPARAM_CURRENT, or a bitwise-or of
* values from VIR_DOMAIN_SCHEDPARAM_LIVE and
* VIR_DOMAIN_SCHEDPARAM_CURRENT, although hypervisors vary in which
* should be either VIR_DOMAIN_AFFECT_CURRENT, or a bitwise-or of
* values from VIR_DOMAIN_AFFECT_LIVE and
* VIR_DOMAIN_AFFECT_CURRENT, although hypervisors vary in which
* flags are supported.
*
* Returns -1 in case of error, 0 in case of success.
......
......@@ -4921,8 +4921,8 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
int ret = -1;
bool isActive;
virCheckFlags(VIR_DOMAIN_MEMORY_PARAM_LIVE |
VIR_DOMAIN_MEMORY_PARAM_CONFIG, -1);
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
qemuDriverLock(driver);
......@@ -4936,14 +4936,14 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
isActive = virDomainObjIsActive(vm);
if (flags == VIR_DOMAIN_MEMORY_PARAM_CURRENT) {
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
if (isActive)
flags = VIR_DOMAIN_MEMORY_PARAM_LIVE;
flags = VIR_DOMAIN_AFFECT_LIVE;
else
flags = VIR_DOMAIN_MEMORY_PARAM_CONFIG;
flags = VIR_DOMAIN_AFFECT_CONFIG;
}
if (flags & VIR_DOMAIN_MEMORY_PARAM_LIVE) {
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if (!isActive) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
......@@ -4963,7 +4963,7 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
}
}
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
if (!vm->persistent) {
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot change persistent config of a transient domain"));
......@@ -4986,7 +4986,7 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
continue;
}
if (flags & VIR_DOMAIN_MEMORY_PARAM_LIVE) {
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
rc = virCgroupSetMemoryHardLimit(group, params[i].value.ul);
if (rc != 0) {
virReportSystemError(-rc, "%s",
......@@ -4995,7 +4995,7 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
}
}
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
persistentDef->mem.hard_limit = params[i].value.ul;
}
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT)) {
......@@ -5007,7 +5007,7 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
continue;
}
if (flags & VIR_DOMAIN_MEMORY_PARAM_LIVE) {
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
rc = virCgroupSetMemorySoftLimit(group, params[i].value.ul);
if (rc != 0) {
virReportSystemError(-rc, "%s",
......@@ -5016,7 +5016,7 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
}
}
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
persistentDef->mem.soft_limit = params[i].value.ul;
}
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT)) {
......@@ -5028,7 +5028,7 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
continue;
}
if (flags & VIR_DOMAIN_MEMORY_PARAM_LIVE) {
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
rc = virCgroupSetMemSwapHardLimit(group, params[i].value.ul);
if (rc != 0) {
virReportSystemError(-rc, "%s",
......@@ -5036,7 +5036,7 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
ret = -1;
}
}
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
persistentDef->mem.swap_hard_limit = params[i].value.ul;
}
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_MIN_GUARANTEE)) {
......@@ -5050,7 +5050,7 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
}
}
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
ret = virDomainSaveConfig(driver->configDir, persistentDef);
}
......@@ -5077,8 +5077,8 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
int rc;
bool isActive;
virCheckFlags(VIR_DOMAIN_MEMORY_PARAM_LIVE |
VIR_DOMAIN_MEMORY_PARAM_CONFIG, -1);
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
qemuDriverLock(driver);
......@@ -5092,14 +5092,14 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
isActive = virDomainObjIsActive(vm);
if (flags == VIR_DOMAIN_MEMORY_PARAM_CURRENT) {
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
if (isActive)
flags = VIR_DOMAIN_MEMORY_PARAM_LIVE;
flags = VIR_DOMAIN_AFFECT_LIVE;
else
flags = VIR_DOMAIN_MEMORY_PARAM_CONFIG;
flags = VIR_DOMAIN_AFFECT_CONFIG;
}
if (flags & VIR_DOMAIN_MEMORY_PARAM_LIVE) {
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if (!isActive) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
......@@ -5119,7 +5119,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
}
}
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
if (!vm->persistent) {
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot change persistent config of a transient domain"));
......@@ -5142,12 +5142,12 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
goto cleanup;
}
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
for (i = 0; i < *nparams; i++) {
virMemoryParameterPtr param = &params[i];
val = 0;
param->value.ul = 0;
param->type = VIR_DOMAIN_MEMORY_PARAM_ULLONG;
param->type = VIR_TYPED_PARAM_ULLONG;
switch (i) {
case 0: /* fill memory hard limit here */
......@@ -5269,8 +5269,8 @@ static int qemuSetSchedulerParametersFlags(virDomainPtr dom,
int ret = -1;
bool isActive;
virCheckFlags(VIR_DOMAIN_SCHEDPARAM_LIVE |
VIR_DOMAIN_SCHEDPARAM_CONFIG, -1);
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
qemuDriverLock(driver);
......@@ -5284,20 +5284,20 @@ static int qemuSetSchedulerParametersFlags(virDomainPtr dom,
isActive = virDomainObjIsActive(vm);
if (flags == VIR_DOMAIN_SCHEDPARAM_CURRENT) {
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
if (isActive)
flags = VIR_DOMAIN_SCHEDPARAM_LIVE;
flags = VIR_DOMAIN_AFFECT_LIVE;
else
flags = VIR_DOMAIN_SCHEDPARAM_CONFIG;
flags = VIR_DOMAIN_AFFECT_CONFIG;
}
if ((flags & VIR_DOMAIN_SCHEDPARAM_CONFIG) && !vm->persistent) {
if ((flags & VIR_DOMAIN_AFFECT_CONFIG) && !vm->persistent) {
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot change persistent config of a transient domain"));
goto cleanup;
}
if (flags & VIR_DOMAIN_SCHEDPARAM_LIVE) {
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if (!isActive) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
......@@ -5328,7 +5328,7 @@ static int qemuSetSchedulerParametersFlags(virDomainPtr dom,
goto cleanup;
}
if (flags & VIR_DOMAIN_SCHEDPARAM_LIVE) {
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
rc = virCgroupSetCpuShares(group, params[i].value.ul);
if (rc != 0) {
virReportSystemError(-rc, "%s",
......@@ -5339,7 +5339,7 @@ static int qemuSetSchedulerParametersFlags(virDomainPtr dom,
vm->def->cputune.shares = params[i].value.ul;
}
if (flags & VIR_DOMAIN_SCHEDPARAM_CONFIG) {
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
persistentDef = virDomainObjGetPersistentDef(driver->caps, vm);
if (!persistentDef) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
......@@ -5378,7 +5378,7 @@ static int qemuSetSchedulerParameters(virDomainPtr dom,
return qemuSetSchedulerParametersFlags(dom,
params,
nparams,
VIR_DOMAIN_SCHEDPARAM_LIVE);
VIR_DOMAIN_AFFECT_LIVE);
}
static int
......@@ -5395,11 +5395,11 @@ qemuGetSchedulerParametersFlags(virDomainPtr dom,
int rc;
bool isActive;
virCheckFlags(VIR_DOMAIN_SCHEDPARAM_LIVE |
VIR_DOMAIN_SCHEDPARAM_CONFIG, -1);
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
if ((flags & (VIR_DOMAIN_SCHEDPARAM_LIVE | VIR_DOMAIN_SCHEDPARAM_CONFIG)) ==
(VIR_DOMAIN_SCHEDPARAM_LIVE | VIR_DOMAIN_SCHEDPARAM_CONFIG)) {
if ((flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG)) ==
(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG)) {
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
_("cannot query live and config together"));
goto cleanup;
......@@ -5422,14 +5422,14 @@ qemuGetSchedulerParametersFlags(virDomainPtr dom,
isActive = virDomainObjIsActive(vm);
if (flags == VIR_DOMAIN_SCHEDPARAM_CURRENT) {
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
if (isActive)
flags = VIR_DOMAIN_SCHEDPARAM_LIVE;
flags = VIR_DOMAIN_AFFECT_LIVE;
else
flags = VIR_DOMAIN_SCHEDPARAM_CONFIG;
flags = VIR_DOMAIN_AFFECT_CONFIG;
}
if (flags & VIR_DOMAIN_SCHEDPARAM_CONFIG) {
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
if (!vm->persistent) {
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot query persistent config of a transient domain"));
......@@ -5502,7 +5502,7 @@ qemuGetSchedulerParameters(virDomainPtr dom,
int *nparams)
{
return qemuGetSchedulerParametersFlags(dom, params, nparams,
VIR_DOMAIN_SCHEDPARAM_CURRENT);
VIR_DOMAIN_AFFECT_CURRENT);
}
/* This uses the 'info blockstats' monitor command which was
......
......@@ -1732,12 +1732,12 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
vshError(ctl, "%s", _("--current must be specified exclusively"));
return false;
}
flags = VIR_DOMAIN_SCHEDPARAM_CURRENT;
flags = VIR_DOMAIN_AFFECT_CURRENT;
} else {
if (config)
flags |= VIR_DOMAIN_SCHEDPARAM_CONFIG;
flags |= VIR_DOMAIN_AFFECT_CONFIG;
if (live)
flags |= VIR_DOMAIN_SCHEDPARAM_LIVE;
flags |= VIR_DOMAIN_AFFECT_LIVE;
}
if (!vshConnectionUsability(ctl, ctl->conn))
......@@ -3505,12 +3505,12 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
vshError(ctl, "%s", _("--current must be specified exclusively"));
return false;
}
flags = VIR_DOMAIN_MEMORY_PARAM_CURRENT;
flags = VIR_DOMAIN_AFFECT_CURRENT;
} else {
if (config)
flags |= VIR_DOMAIN_MEMORY_PARAM_CONFIG;
flags |= VIR_DOMAIN_AFFECT_CONFIG;
if (live)
flags |= VIR_DOMAIN_MEMORY_PARAM_LIVE;
flags |= VIR_DOMAIN_AFFECT_LIVE;
}
if (!vshConnectionUsability(ctl, ctl->conn))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册