]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: use virBuffer in qemuBuildSCSIiSCSIHostdevDrvStr
authorAnya Harter <aharter@redhat.com>
Wed, 20 Jun 2018 13:16:59 +0000 (09:16 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 26 Jun 2018 15:04:38 +0000 (11:04 -0400)
Instead of source to enable use of virBuffer functions in
string construction.

Signed-off-by: Anya Harter <aharter@redhat.com>
src/qemu/qemu_command.c

index a357d2199cb0bb29d59b8b42685c93ac40c2db8c..1aa7c7adc34618238d459e6c601bbc8007325278 100644 (file)
@@ -4643,7 +4643,8 @@ static char *
 qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
                                 virQEMUCapsPtr qemuCaps)
 {
-    char *source = NULL;
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
     char *netsource = NULL;
     virJSONValuePtr srcprops = NULL;
     virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
@@ -4656,21 +4657,25 @@ qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
             goto cleanup;
         if (!(netsource = virQEMUBuildDriveCommandlineFromJSON(srcprops)))
             goto cleanup;
-        if (virAsprintf(&source, "%s,if=none,format=raw", netsource) < 0)
-            goto cleanup;
+        virBufferAsprintf(&buf, "%s,if=none,format=raw", netsource);
     } else {
         /* Rather than pull what we think we want - use the network disk code */
         if (!(netsource = qemuBuildNetworkDriveStr(iscsisrc->src, srcPriv ?
                                                    srcPriv->secinfo : NULL)))
             goto cleanup;
-        if (virAsprintf(&source, "file=%s,if=none,format=raw", netsource) < 0)
-            goto cleanup;
+        virBufferAsprintf(&buf, "file=%s,if=none,format=raw", netsource);
     }
 
+    if (virBufferCheckError(&buf) < 0)
+        goto cleanup;
+
+    return virBufferContentAndReset(&buf);
+
  cleanup:
     VIR_FREE(netsource);
     virJSONValueFree(srcprops);
-    return source;
+    virBufferFreeAndReset(&buf);
+    return NULL;
 }
 
 char *