提交 37b62005 编写于 作者: L Luyao Huang 提交者: Peter Krempa

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: NLuyao Huang <lhuang@redhat.com>
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
上级 ad3e99e2
......@@ -12177,6 +12177,76 @@ virDomainChrRemove(virDomainDefPtr vmdef,
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 *
virDomainDefGetDefaultEmulator(virDomainDefPtr def,
virCapsPtr caps)
......
......@@ -2665,6 +2665,12 @@ virDomainChrDefPtr
virDomainChrRemove(virDomainDefPtr vmdef,
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,
virDomainDefPtr def,
const char *xml);
......
......@@ -380,7 +380,10 @@ virDomainPMSuspendedReasonTypeToString;
virDomainRedirdevBusTypeFromString;
virDomainRedirdevBusTypeToString;
virDomainRNGBackendTypeToString;
virDomainRNGFind;
virDomainRNGInsert;
virDomainRNGModelTypeToString;
virDomainRNGRemove;
virDomainRunningReasonTypeFromString;
virDomainRunningReasonTypeToString;
virDomainSaveConfig;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册