mirror of https://gitee.com/openkylin/libvirt.git
conf: Introduce helper to help getting correct def for getter functions
virDomainObjGetOneDef will help to retrieve the correct definition pointer from @vm in cases where VIR_DOMAIN_AFFECT_LIVE and VIR_DOMAIN_AFFECT_CONFIG are mutually exclusive. The function simply returns the correct pointer. This similarly to virDomainObjGetDefs will greatly simplify the code.
This commit is contained in:
parent
63aaf69bbe
commit
47171cd1a6
|
@ -2948,6 +2948,42 @@ virDomainObjGetDefs(virDomainObjPtr vm,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virDomainObjGetOneDef:
|
||||||
|
*
|
||||||
|
* @vm: Domain object
|
||||||
|
* @flags: for virDomainModificationImpact
|
||||||
|
*
|
||||||
|
* 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. 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
|
||||||
|
virDomainObjGetOneDef(virDomainObjPtr vm,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
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 (virDomainObjIsActive(vm) && flags & VIR_DOMAIN_AFFECT_CONFIG)
|
||||||
|
return vm->newDef;
|
||||||
|
else
|
||||||
|
return vm->def;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
|
|
|
@ -2553,6 +2553,7 @@ int virDomainObjGetDefs(virDomainObjPtr vm,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
virDomainDefPtr *liveDef,
|
virDomainDefPtr *liveDef,
|
||||||
virDomainDefPtr *persDef);
|
virDomainDefPtr *persDef);
|
||||||
|
virDomainDefPtr virDomainObjGetOneDef(virDomainObjPtr vm, unsigned int flags);
|
||||||
|
|
||||||
int
|
int
|
||||||
virDomainLiveConfigHelperMethod(virCapsPtr caps,
|
virDomainLiveConfigHelperMethod(virCapsPtr caps,
|
||||||
|
|
|
@ -385,6 +385,7 @@ virDomainObjEndAPI;
|
||||||
virDomainObjFormat;
|
virDomainObjFormat;
|
||||||
virDomainObjGetDefs;
|
virDomainObjGetDefs;
|
||||||
virDomainObjGetMetadata;
|
virDomainObjGetMetadata;
|
||||||
|
virDomainObjGetOneDef;
|
||||||
virDomainObjGetPersistentDef;
|
virDomainObjGetPersistentDef;
|
||||||
virDomainObjGetState;
|
virDomainObjGetState;
|
||||||
virDomainObjListAdd;
|
virDomainObjListAdd;
|
||||||
|
|
Loading…
Reference in New Issue