conf: Add virCPUDefAddFeatureIfMissing

This new function adds a feature to a CPU definition only if it is not
present there yet.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
This commit is contained in:
Jiri Denemark 2020-11-19 18:44:48 +01:00
parent f5782579aa
commit d7756a67bb
3 changed files with 20 additions and 0 deletions

View File

@ -861,6 +861,7 @@ virCPUDefFormatBuf(virBufferPtr buf,
typedef enum { typedef enum {
VIR_CPU_ADD_FEATURE_MODE_EXCLUSIVE, /* Fail if feature exists */ VIR_CPU_ADD_FEATURE_MODE_EXCLUSIVE, /* Fail if feature exists */
VIR_CPU_ADD_FEATURE_MODE_UPDATE, /* Add feature or update policy */ VIR_CPU_ADD_FEATURE_MODE_UPDATE, /* Add feature or update policy */
VIR_CPU_ADD_FEATURE_MODE_NEW, /* Add feature if it does not exist */
} virCPUDefAddFeatureMode; } virCPUDefAddFeatureMode;
static int static int
@ -876,6 +877,9 @@ virCPUDefAddFeatureInternal(virCPUDefPtr def,
if ((feat = virCPUDefFindFeature(def, name))) { if ((feat = virCPUDefFindFeature(def, name))) {
switch (mode) { switch (mode) {
case VIR_CPU_ADD_FEATURE_MODE_NEW:
return 0;
case VIR_CPU_ADD_FEATURE_MODE_UPDATE: case VIR_CPU_ADD_FEATURE_MODE_UPDATE:
feat->policy = policy; feat->policy = policy;
return 0; return 0;
@ -920,6 +924,16 @@ virCPUDefAddFeature(virCPUDefPtr def,
} }
int
virCPUDefAddFeatureIfMissing(virCPUDefPtr def,
const char *name,
int policy)
{
return virCPUDefAddFeatureInternal(def, name, policy,
VIR_CPU_ADD_FEATURE_MODE_NEW);
}
virCPUFeatureDefPtr virCPUFeatureDefPtr
virCPUDefFindFeature(virCPUDefPtr def, virCPUDefFindFeature(virCPUDefPtr def,
const char *name) const char *name)

View File

@ -229,6 +229,11 @@ virCPUDefUpdateFeature(virCPUDefPtr cpu,
const char *name, const char *name,
int policy); int policy);
int
virCPUDefAddFeatureIfMissing(virCPUDefPtr def,
const char *name,
int policy);
virCPUFeatureDefPtr virCPUFeatureDefPtr
virCPUDefFindFeature(virCPUDefPtr def, virCPUDefFindFeature(virCPUDefPtr def,
const char *name); const char *name);

View File

@ -96,6 +96,7 @@ virDomainCheckpointTypeToString;
virCPUCacheModeTypeFromString; virCPUCacheModeTypeFromString;
virCPUCacheModeTypeToString; virCPUCacheModeTypeToString;
virCPUDefAddFeature; virCPUDefAddFeature;
virCPUDefAddFeatureIfMissing;
virCPUDefCheckFeatures; virCPUDefCheckFeatures;
virCPUDefCopy; virCPUDefCopy;
virCPUDefCopyModel; virCPUDefCopyModel;