[PATCH 2/4] virStorageBackendISCSIDirectFindPoolSources: Use allocated virStoragePoolSourceList

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

 



Using an allocated version together with copying the
host/initiator/device portions into it allows us to switch to automatic
clearing rather than open-coding it.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/storage/storage_backend_iscsi_direct.c | 42 ++++++++++------------
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c
index e4a14c3fd6..263db835ae 100644
--- a/src/storage/storage_backend_iscsi_direct.c
+++ b/src/storage/storage_backend_iscsi_direct.c
@@ -495,23 +495,21 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec,
     char **targets = NULL;
     char *ret = NULL;
     size_t i;
-    virStoragePoolSourceList list = {
-        .type = VIR_STORAGE_POOL_ISCSI_DIRECT,
-        .nsources = 0,
-        .sources = NULL
-    };
+    g_autoptr(virStoragePoolSourceList) list = g_new0(virStoragePoolSourceList, 1);
     g_autofree char *portal = NULL;
     g_autoptr(virStoragePoolSource) source = NULL;

     virCheckFlags(0, NULL);

+    list->type = VIR_STORAGE_POOL_ISCSI_DIRECT;
+
     if (!srcSpec) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
                        _("hostname must be specified for iscsi sources"));
         return NULL;
     }

-    if (!(source = virStoragePoolDefParseSourceString(srcSpec, list.type)))
+    if (!(source = virStoragePoolDefParseSourceString(srcSpec, list->type)))
         return NULL;

     if (source->nhost != 1) {
@@ -532,30 +530,28 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec,
     if (virISCSIDirectScanTargets(source->initiator.iqn, portal, &ntargets, &targets) < 0)
         goto cleanup;

-    list.sources = g_new0(virStoragePoolSource, ntargets);
+    list->sources = g_new0(virStoragePoolSource, ntargets);

     for (i = 0; i < ntargets; i++) {
-        list.sources[i].devices = g_new0(virStoragePoolSourceDevice, 1);
-        list.sources[i].hosts = g_new0(virStoragePoolSourceHost, 1);
-        list.sources[i].nhost = 1;
-        list.sources[i].hosts[0] = source->hosts[0];
-        list.sources[i].initiator = source->initiator;
-        list.sources[i].ndevice = 1;
-        list.sources[i].devices[0].path = targets[i];
-        list.nsources++;
+        list->sources[i].hosts = g_new0(virStoragePoolSourceHost, 1);
+        list->sources[i].nhost = 1;
+        list->sources[i].hosts[0].name = g_strdup(source->hosts[0].name);
+        list->sources[i].hosts[0].port = source->hosts[0].port;
+
+        virStorageSourceInitiatorCopy(&list->sources[i].initiator,
+                                      &source->initiator);
+
+        list->sources[i].devices = g_new0(virStoragePoolSourceDevice, 1);
+        list->sources[i].ndevice = 1;
+        list->sources[i].devices[0].path = g_strdup(targets[i]);
+
+        list->nsources++;
     }

-    if (!(ret = virStoragePoolSourceListFormat(&list)))
+    if (!(ret = virStoragePoolSourceListFormat(list)))
         goto cleanup;

  cleanup:
-    if (list.sources) {
-        for (i = 0; i < ntargets; i++) {
-            VIR_FREE(list.sources[i].hosts);
-            VIR_FREE(list.sources[i].devices);
-        }
-        VIR_FREE(list.sources);
-    }
     for (i = 0; i < ntargets; i++)
         VIR_FREE(targets[i]);
     VIR_FREE(targets);
-- 
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