mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
conf: Introduce virDomainObjGetOneDefState
Return whether the live or persistent definition was returned. Sometimes it's necessary to base the decisions on this.
This commit is contained in:
parent
2e164b451e
commit
4cc65b4967
@ -3117,6 +3117,52 @@ virDomainObjGetDefs(virDomainObjPtr vm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virDomainObjGetOneDefState:
|
||||||
|
*
|
||||||
|
* @vm: Domain object
|
||||||
|
* @flags: for virDomainModificationImpact
|
||||||
|
* @live: set to true if live config was returned (may be omitted)
|
||||||
|
*
|
||||||
|
* Helper function to resolve @flags and return the correct domain pointer
|
||||||
|
* object. This function returns one of @vm->def or @vm->persistentDef
|
||||||
|
* according to @flags. @live is set to true if the live vm config will be
|
||||||
|
* returned. This helper should be used only in APIs that guarantee
|
||||||
|
* that @flags contains exactly one of VIR_DOMAIN_AFFECT_LIVE or
|
||||||
|
* VIR_DOMAIN_AFFECT_CONFIG and not both.
|
||||||
|
*
|
||||||
|
* Returns the correct definition pointer or NULL on error.
|
||||||
|
*/
|
||||||
|
virDomainDefPtr
|
||||||
|
virDomainObjGetOneDefState(virDomainObjPtr vm,
|
||||||
|
unsigned int flags,
|
||||||
|
bool *live)
|
||||||
|
{
|
||||||
|
if (flags & VIR_DOMAIN_AFFECT_LIVE && flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||||
|
virReportInvalidArg(ctl, "%s",
|
||||||
|
_("Flags 'VIR_DOMAIN_AFFECT_LIVE' and "
|
||||||
|
"'VIR_DOMAIN_AFFECT_CONFIG' are mutually "
|
||||||
|
"exclusive"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (live) {
|
||||||
|
if (flags & VIR_DOMAIN_AFFECT_LIVE)
|
||||||
|
*live = true;
|
||||||
|
else
|
||||||
|
*live = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virDomainObjIsActive(vm) && flags & VIR_DOMAIN_AFFECT_CONFIG)
|
||||||
|
return vm->newDef;
|
||||||
|
else
|
||||||
|
return vm->def;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virDomainObjGetOneDef:
|
* virDomainObjGetOneDef:
|
||||||
*
|
*
|
||||||
@ -3135,21 +3181,7 @@ virDomainDefPtr
|
|||||||
virDomainObjGetOneDef(virDomainObjPtr vm,
|
virDomainObjGetOneDef(virDomainObjPtr vm,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE && flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
return virDomainObjGetOneDefState(vm, flags, NULL);
|
||||||
virReportInvalidArg(ctl, "%s",
|
|
||||||
_("Flags 'VIR_DOMAIN_AFFECT_LIVE' and "
|
|
||||||
"'VIR_DOMAIN_AFFECT_CONFIG' are mutually "
|
|
||||||
"exclusive"));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (virDomainObjIsActive(vm) && flags & VIR_DOMAIN_AFFECT_CONFIG)
|
|
||||||
return vm->newDef;
|
|
||||||
else
|
|
||||||
return vm->def;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2592,6 +2592,9 @@ int virDomainObjGetDefs(virDomainObjPtr vm,
|
|||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
virDomainDefPtr *liveDef,
|
virDomainDefPtr *liveDef,
|
||||||
virDomainDefPtr *persDef);
|
virDomainDefPtr *persDef);
|
||||||
|
virDomainDefPtr virDomainObjGetOneDefState(virDomainObjPtr vm,
|
||||||
|
unsigned int flags,
|
||||||
|
bool *state);
|
||||||
virDomainDefPtr virDomainObjGetOneDef(virDomainObjPtr vm, unsigned int flags);
|
virDomainDefPtr virDomainObjGetOneDef(virDomainObjPtr vm, unsigned int flags);
|
||||||
|
|
||||||
virDomainDefPtr virDomainDefCopy(virDomainDefPtr src,
|
virDomainDefPtr virDomainDefCopy(virDomainDefPtr src,
|
||||||
|
@ -417,6 +417,7 @@ virDomainObjFormat;
|
|||||||
virDomainObjGetDefs;
|
virDomainObjGetDefs;
|
||||||
virDomainObjGetMetadata;
|
virDomainObjGetMetadata;
|
||||||
virDomainObjGetOneDef;
|
virDomainObjGetOneDef;
|
||||||
|
virDomainObjGetOneDefState;
|
||||||
virDomainObjGetPersistentDef;
|
virDomainObjGetPersistentDef;
|
||||||
virDomainObjGetShortName;
|
virDomainObjGetShortName;
|
||||||
virDomainObjGetState;
|
virDomainObjGetState;
|
||||||
|
Loading…
Reference in New Issue
Block a user