From: Luyao Huang <lhuang(a)redhat.com>
The helpers will be useful when implementing hotplug and coldplug of
random number generator devices.
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 4 +++
src/libvirt_private.syms | 3 +++
3 files changed, 73 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 94289cf..526fb15 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12173,6 +12173,72 @@ virDomainChrRemove(virDomainDefPtr vmdef,
return ret;
}
+
+int
+virDomainRNGInsert(virDomainDefPtr def,
+ virDomainRNGDefPtr rng)
+{
+ 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)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index d073a99..af6f733 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2665,6 +2665,10 @@ virDomainChrDefPtr
virDomainChrRemove(virDomainDefPtr vmdef,
virDomainChrDefPtr chr);
+int virDomainRNGInsert(virDomainDefPtr def, virDomainRNGDefPtr rng);
+ssize_t virDomainRNGFind(virDomainDefPtr def, virDomainRNGDefPtr rng);
+virDomainRNGDefPtr virDomainRNGRemove(virDomainDefPtr def, size_t idx);
+
int virDomainSaveXML(const char *configDir,
virDomainDefPtr def,
const char *xml);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8407b7c..07f0fd5 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -380,7 +380,10 @@ virDomainPMSuspendedReasonTypeToString;
virDomainRedirdevBusTypeFromString;
virDomainRedirdevBusTypeToString;
virDomainRNGBackendTypeToString;
+virDomainRNGFind;
+virDomainRNGInsert;
virDomainRNGModelTypeToString;
+virDomainRNGRemove;
virDomainRunningReasonTypeFromString;
virDomainRunningReasonTypeToString;
virDomainSaveConfig;
--
2.2.2