Since 'qemuBuildDeviceAddressProps' now also builds 'drive' addresses
the generator is way simpler and doesn't use any special fields.

Signed-off-by: Peter Krempa <pkre...@redhat.com>
---
 src/qemu/qemu_command.c | 56 ++++++++++++++++-------------------------
 src/qemu/qemu_command.h |  7 +++---
 src/qemu/qemu_hotplug.c |  6 ++---
 3 files changed, 28 insertions(+), 41 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index bdfc84ba2d..5bea3991a9 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5068,44 +5068,29 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDef *dev)
     return virBufferContentAndReset(&buf);
 }

-char *
-qemuBuildSCSIHostdevDevStr(const virDomainDef *def,
-                           virDomainHostdevDef *dev,
-                           const char *backendAlias)
+virJSONValue *
+qemuBuildSCSIHostdevDevProps(const virDomainDef *def,
+                             virDomainHostdevDef *dev,
+                             const char *backendAlias)
 {
-    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-    int model = -1;
-    const char *contAlias;
+    g_autoptr(virJSONValue) props = NULL;

-    model = qemuDomainFindSCSIControllerModel(def, dev->info);
-    if (model < 0)
+    if (virJSONValueObjectCreate(&props,
+                                 "s:driver", "scsi-generic",
+                                 NULL) < 0)
         return NULL;

-    virBufferAddLit(&buf, "scsi-generic");
-
-    if (!(contAlias = virDomainControllerAliasFind(def, 
VIR_DOMAIN_CONTROLLER_TYPE_SCSI,
-                                                   
dev->info->addr.drive.controller)))
+    if (qemuBuildDeviceAddressProps(props, def, dev->info) < 0)
         return NULL;

-    if (model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
-        virBufferAsprintf(&buf, ",bus=%s.%d,scsi-id=%d",
-                          contAlias,
-                          dev->info->addr.drive.bus,
-                          dev->info->addr.drive.unit);
-    } else {
-        virBufferAsprintf(&buf, ",bus=%s.0,channel=%d,scsi-id=%d,lun=%d",
-                          contAlias,
-                          dev->info->addr.drive.bus,
-                          dev->info->addr.drive.target,
-                          dev->info->addr.drive.unit);
-    }
-
-    virBufferAsprintf(&buf, ",drive=%s,id=%s", backendAlias, dev->info->alias);
-
-    if (dev->info->bootIndex)
-        virBufferAsprintf(&buf, ",bootindex=%u", dev->info->bootIndex);
+    if (virJSONValueObjectAdd(props,
+                              "s:drive", backendAlias,
+                              "s:id", dev->info->alias,
+                              "p:bootindex", dev->info->bootIndex,
+                              NULL) < 0)
+        return NULL;

-    return virBufferContentAndReset(&buf);
+    return g_steal_pointer(&props);
 }

 static int
@@ -5593,7 +5578,7 @@ qemuBuildHostdevSCSICommandLine(virCommand *cmd,
                                 virQEMUCaps *qemuCaps)
 {
     g_autoptr(qemuBlockStorageSourceAttachData) data = NULL;
-    g_autofree char *devstr = NULL;
+    g_autoptr(virJSONValue) devprops = NULL;
     const char *backendAlias = NULL;

     if (!(data = qemuBuildHostdevSCSIAttachPrepare(hostdev, &backendAlias, 
qemuCaps)))
@@ -5602,10 +5587,11 @@ qemuBuildHostdevSCSICommandLine(virCommand *cmd,
     if (qemuBuildBlockStorageSourceAttachDataCommandline(cmd, data, qemuCaps) 
< 0)
         return -1;

-    virCommandAddArg(cmd, "-device");
-    if (!(devstr = qemuBuildSCSIHostdevDevStr(def, hostdev, backendAlias)))
+    if (!(devprops = qemuBuildSCSIHostdevDevProps(def, hostdev, backendAlias)))
+        return -1;
+
+    if (qemuBuildDeviceCommandlineFromJSON(cmd, devprops, qemuCaps) < 0)
         return -1;
-    virCommandAddArg(cmd, devstr);

     return 0;
 }
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 8ad87f4277..5b1b727b84 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -182,9 +182,10 @@ qemuBuildUSBHostdevDevProps(const virDomainDef *def,
                             virDomainHostdevDef *dev,
                             virQEMUCaps *qemuCaps);

-char *qemuBuildSCSIHostdevDevStr(const virDomainDef *def,
-                                 virDomainHostdevDef *dev,
-                                 const char *backendAlias);
+virJSONValue *
+qemuBuildSCSIHostdevDevProps(const virDomainDef *def,
+                             virDomainHostdevDef *dev,
+                             const char *backendAlias);

 qemuBlockStorageSourceAttachData *
 qemuBuildHostdevSCSIAttachPrepare(virDomainHostdevDef *hostdev,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 67aed2c128..28cafd11d2 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2639,7 +2639,7 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriver *driver,
     virErrorPtr orig_err;
     g_autoptr(qemuBlockStorageSourceAttachData) data = NULL;
     const char *backendalias = NULL;
-    g_autofree char *devstr = NULL;
+    g_autoptr(virJSONValue) devprops = NULL;
     bool teardowncgroup = false;
     bool teardownlabel = false;
     bool teardowndevice = false;
@@ -2683,7 +2683,7 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriver *driver,
                                                    priv->qemuCaps)))
         goto cleanup;

-    if (!(devstr = qemuBuildSCSIHostdevDevStr(vm->def, hostdev, backendalias)))
+    if (!(devprops = qemuBuildSCSIHostdevDevProps(vm->def, hostdev, 
backendalias)))
         goto cleanup;

     VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1);
@@ -2693,7 +2693,7 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriver *driver,
     if (qemuBlockStorageSourceAttachApply(priv->mon, data) < 0)
         goto exit_monitor;

-    if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
+    if (qemuMonitorAddDeviceProps(priv->mon, &devprops) < 0)
         goto exit_monitor;

     if (qemuDomainObjExitMonitor(driver, vm) < 0)
-- 
2.31.1

Reply via email to