conf: Add helpers to insert/remove/find RNG devices in domain def

The helpers will be useful when implementing hotplug and coldplug of
random number generator devices.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Luyao Huang 2015-01-17 13:09:32 +08:00 committed by Peter Krempa
parent ad3e99e21b
commit 37b620059b
3 changed files with 79 additions and 0 deletions

View File

@ -12177,6 +12177,76 @@ virDomainChrRemove(virDomainDefPtr vmdef,
return ret; return ret;
} }
int
virDomainRNGInsert(virDomainDefPtr def,
virDomainRNGDefPtr rng,
bool inplace)
{
if (inplace)
return VIR_APPEND_ELEMENT_INPLACE(def->rngs, def->nrngs, rng);
else
return VIR_APPEND_ELEMENT(def->rngs, def->nrngs, rng);
}
ssize_t
virDomainRNGFind(virDomainDefPtr def,
virDomainRNGDefPtr rng)
{
size_t i;
for (i = 0; i < def->nrngs; i++) {
virDomainRNGDefPtr tmp = def->rngs[i];
if (rng->model != tmp->model || rng->backend != tmp->backend)
continue;
if (rng->rate != tmp->rate || rng->period != tmp->period)
continue;
switch ((virDomainRNGBackend) rng->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
if (STRNEQ_NULLABLE(rng->source.file, tmp->source.file))
continue;
break;
case VIR_DOMAIN_RNG_BACKEND_EGD:
if (!virDomainChrSourceDefIsEqual(rng->source.chardev,
tmp->source.chardev))
continue;
break;
case VIR_DOMAIN_RNG_BACKEND_LAST:
break;
}
if (rng->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
!virDomainDeviceInfoAddressIsEqual(&rng->info, &tmp->info))
continue;
break;
}
if (i < def->nrngs)
return i;
return -1;
}
virDomainRNGDefPtr
virDomainRNGRemove(virDomainDefPtr def,
size_t idx)
{
virDomainRNGDefPtr ret = def->rngs[idx];
VIR_DELETE_ELEMENT(def->rngs, idx, def->nrngs);
return ret;
}
char * char *
virDomainDefGetDefaultEmulator(virDomainDefPtr def, virDomainDefGetDefaultEmulator(virDomainDefPtr def,
virCapsPtr caps) virCapsPtr caps)

View File

@ -2665,6 +2665,12 @@ virDomainChrDefPtr
virDomainChrRemove(virDomainDefPtr vmdef, virDomainChrRemove(virDomainDefPtr vmdef,
virDomainChrDefPtr chr); virDomainChrDefPtr chr);
int virDomainRNGInsert(virDomainDefPtr def,
virDomainRNGDefPtr rng,
bool inplace);
ssize_t virDomainRNGFind(virDomainDefPtr def, virDomainRNGDefPtr rng);
virDomainRNGDefPtr virDomainRNGRemove(virDomainDefPtr def, size_t idx);
int virDomainSaveXML(const char *configDir, int virDomainSaveXML(const char *configDir,
virDomainDefPtr def, virDomainDefPtr def,
const char *xml); const char *xml);

View File

@ -380,7 +380,10 @@ virDomainPMSuspendedReasonTypeToString;
virDomainRedirdevBusTypeFromString; virDomainRedirdevBusTypeFromString;
virDomainRedirdevBusTypeToString; virDomainRedirdevBusTypeToString;
virDomainRNGBackendTypeToString; virDomainRNGBackendTypeToString;
virDomainRNGFind;
virDomainRNGInsert;
virDomainRNGModelTypeToString; virDomainRNGModelTypeToString;
virDomainRNGRemove;
virDomainRunningReasonTypeFromString; virDomainRunningReasonTypeFromString;
virDomainRunningReasonTypeToString; virDomainRunningReasonTypeToString;
virDomainSaveConfig; virDomainSaveConfig;