[PATCH 062/103] qemuBuildRNGCommandLine: Generate via JSON

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The 'virtio-rng' has the following property types according to QEMU:
  rng=<link<rng-backend>>
  max-bytes=<uint64>     -  (default: 9223372036854775807)
  period=<uint32>        -  (default: 65536)

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_command.c | 46 +++++++++++++++++++++++------------------
 src/qemu/qemu_command.h |  7 ++++---
 src/qemu/qemu_hotplug.c |  6 +++---
 3 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 95070e4a06..b321c964ab 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5800,32 +5800,36 @@ qemuBuildRNGBackendProps(virDomainRNGDef *rng,
 }


-char *
-qemuBuildRNGDevStr(const virDomainDef *def,
-                   virDomainRNGDef *dev,
-                   virQEMUCaps *qemuCaps)
+virJSONValue *
+qemuBuildRNGDevProps(const virDomainDef *def,
+                     virDomainRNGDef *dev,
+                     virQEMUCaps *qemuCaps)
 {
-    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    g_autoptr(virJSONValue) props = NULL;
+    unsigned int period = 0;

-    if (qemuBuildVirtioDevStr(&buf, qemuCaps, VIR_DOMAIN_DEVICE_RNG, dev) < 0) {
+    if (!(props = qemuBuildVirtioDevProps(VIR_DOMAIN_DEVICE_RNG, dev, qemuCaps)))
         return NULL;
-    }
-
-    virBufferAsprintf(&buf, ",rng=obj%s,id=%s",
-                      dev->info.alias, dev->info.alias);

     if (dev->rate > 0) {
-        virBufferAsprintf(&buf, ",max-bytes=%u", dev->rate);
-        if (dev->period)
-            virBufferAsprintf(&buf, ",period=%u", dev->period);
-        else
-            virBufferAddLit(&buf, ",period=1000");
+        period = dev->period;
+
+        if (period == 0)
+            period = 1000;
     }

-    if (qemuBuildDeviceAddressStr(&buf, def, &dev->info) < 0)
+    if (virJSONValueObjectAdd(props,
+                              "f:rng", g_strdup_printf("obj%s", dev->info.alias),
+                              "s:id", dev->info.alias,
+                              "p:max-bytes", dev->rate,
+                              "p:period", period,
+                              NULL) < 0)
         return NULL;

-    return virBufferContentAndReset(&buf);
+    if (qemuBuildDeviceAddressProps(props, def, &dev->info) < 0)
+        return NULL;
+
+    return g_steal_pointer(&props);
 }


@@ -5844,7 +5848,7 @@ qemuBuildRNGCommandLine(virLogManager *logManager,
         g_autoptr(virJSONValue) props = NULL;
         virDomainRNGDef *rng = def->rngs[i];
         g_autofree char *chardev = NULL;
-        g_autofree char *devstr = NULL;
+        g_autoptr(virJSONValue) devprops = NULL;

         if (!rng->info.alias) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -5871,9 +5875,11 @@ qemuBuildRNGCommandLine(virLogManager *logManager,
         if (qemuCommandAddExtDevice(cmd, &rng->info) < 0)
             return -1;

-        if (!(devstr = qemuBuildRNGDevStr(def, rng, qemuCaps)))
+        if (!(devprops = qemuBuildRNGDevProps(def, rng, qemuCaps)))
+            return -1;
+
+        if (qemuBuildDeviceCommandlineFromJSON(cmd, devprops, qemuCaps) < 0)
             return -1;
-        virCommandAddArgList(cmd, "-device", devstr, NULL);
     }

     return 0;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 3cf1671c79..709b75c252 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -169,9 +169,10 @@ char *qemuBuildPCIHostdevDevStr(const virDomainDef *def,
                                 virDomainHostdevDef *dev,
                                 virQEMUCaps *qemuCaps);

-char *qemuBuildRNGDevStr(const virDomainDef *def,
-                         virDomainRNGDef *dev,
-                         virQEMUCaps *qemuCaps);
+virJSONValue *
+qemuBuildRNGDevProps(const virDomainDef *def,
+                     virDomainRNGDef *dev,
+                     virQEMUCaps *qemuCaps);
 int qemuBuildRNGBackendProps(virDomainRNGDef *rng,
                              virJSONValue **props);

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 3ee0ccd088..4230f6f70e 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2309,7 +2309,7 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver,
     qemuDomainObjPrivate *priv = vm->privateData;
     virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_RNG, { .rng = rng } };
     virErrorPtr orig_err;
-    g_autofree char *devstr = NULL;
+    g_autoptr(virJSONValue) devprops = NULL;
     g_autofree char *charAlias = NULL;
     g_autofree char *objAlias = NULL;
     g_autofree char *tlsAlias = NULL;
@@ -2338,7 +2338,7 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver,
     teardowncgroup = true;

     /* build required metadata */
-    if (!(devstr = qemuBuildRNGDevStr(vm->def, rng, priv->qemuCaps)))
+    if (!(devprops = qemuBuildRNGDevProps(vm->def, rng, priv->qemuCaps)))
         goto cleanup;

     if (qemuBuildRNGBackendProps(rng, &props) < 0)
@@ -2369,7 +2369,7 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver,
     if (qemuDomainAttachExtensionDevice(priv->mon, &rng->info) < 0)
         goto exit_monitor;

-    if (qemuMonitorAddDevice(priv->mon, devstr) < 0) {
+    if (qemuMonitorAddDeviceProps(priv->mon, &devprops) < 0) {
         ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &rng->info));
         goto exit_monitor;
     }
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux