9119d9
From 29bfee99a3d73b8b5abd210925fa34af4e4fb857 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <29bfee99a3d73b8b5abd210925fa34af4e4fb857@dist-git>
9119d9
From: John Ferlan <jferlan@redhat.com>
9119d9
Date: Wed, 12 Nov 2014 13:34:48 -0500
9119d9
Subject: [PATCH] storage: Don't use a stack copy of the adapter
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1160926
9119d9
9119d9
Passing a copy of the storage pool adapter to a function just changes the
9119d9
copy of the fields in the particular function and then when returning to
9119d9
the caller those changes are discarded.  While not yet biting us in the
9119d9
storage clean-up case, it did cause an issue for the fchost storage pool
9119d9
startup case, createVport.  The issue was at startup, if no parent is found
9119d9
in the XML, the code will search for the 'best available' parent and then
9119d9
store that in the in memory copy of the adapter.  Of course, in this case
9119d9
it was a copy, so when returning to the virStorageBackendSCSIStartPool that
9119d9
change was discarded (or lost) from the pool->def->source.adapter which
9119d9
meant at shutdown (deleteVport), the code assumed no adapter was passed
9119d9
and skipped the deletion, leaving the vHBA created by libvirt still defined
9119d9
requiring an additional stop of a nodedev-destroy to remove.
9119d9
9119d9
Adjusted the createVport to take virStoragePoolDefPtr instead of the
9119d9
adapter copy. Then use the virStoragePoolSourceAdapterPtr when processing.
9119d9
A future patch will need the 'def' anyway, so this just sets up for that.
9119d9
9119d9
(cherry picked from commit 5b226fcdc6ea3b9be73e31b6cff88f65d754cb0d)
9119d9
Signed-off-by: John Ferlan <jferlan@redhat.com>
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/conf/storage_conf.c            | 16 ++++++++--------
9119d9
 src/conf/storage_conf.h            |  1 +
9119d9
 src/storage/storage_backend_scsi.c | 32 ++++++++++++++++----------------
9119d9
 3 files changed, 25 insertions(+), 24 deletions(-)
9119d9
9119d9
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
9119d9
index 67b44b9..3ceb0b5 100644
9119d9
--- a/src/conf/storage_conf.c
9119d9
+++ b/src/conf/storage_conf.c
9119d9
@@ -342,15 +342,15 @@ virStorageVolDefFree(virStorageVolDefPtr def)
9119d9
 }
9119d9
 
9119d9
 static void
9119d9
-virStoragePoolSourceAdapterClear(virStoragePoolSourceAdapter adapter)
9119d9
+virStoragePoolSourceAdapterClear(virStoragePoolSourceAdapterPtr adapter)
9119d9
 {
9119d9
-    if (adapter.type == VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) {
9119d9
-        VIR_FREE(adapter.data.fchost.wwnn);
9119d9
-        VIR_FREE(adapter.data.fchost.wwpn);
9119d9
-        VIR_FREE(adapter.data.fchost.parent);
9119d9
-    } else if (adapter.type ==
9119d9
+    if (adapter->type == VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) {
9119d9
+        VIR_FREE(adapter->data.fchost.wwnn);
9119d9
+        VIR_FREE(adapter->data.fchost.wwpn);
9119d9
+        VIR_FREE(adapter->data.fchost.parent);
9119d9
+    } else if (adapter->type ==
9119d9
                VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) {
9119d9
-        VIR_FREE(adapter.data.scsi_host.name);
9119d9
+        VIR_FREE(adapter->data.scsi_host.name);
9119d9
     }
9119d9
 }
9119d9
 
9119d9
@@ -379,7 +379,7 @@ virStoragePoolSourceClear(virStoragePoolSourcePtr source)
9119d9
     VIR_FREE(source->devices);
9119d9
     VIR_FREE(source->dir);
9119d9
     VIR_FREE(source->name);
9119d9
-    virStoragePoolSourceAdapterClear(source->adapter);
9119d9
+    virStoragePoolSourceAdapterClear(&source->adapter);
9119d9
     VIR_FREE(source->initiator.iqn);
9119d9
     virStorageAuthDefFree(source->auth);
9119d9
     VIR_FREE(source->vendor);
9119d9
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
9119d9
index 1276ac2..a9b5bdb 100644
9119d9
--- a/src/conf/storage_conf.h
9119d9
+++ b/src/conf/storage_conf.h
9119d9
@@ -177,6 +177,7 @@ typedef enum {
9119d9
 VIR_ENUM_DECL(virStoragePoolSourceAdapter)
9119d9
 
9119d9
 typedef struct _virStoragePoolSourceAdapter virStoragePoolSourceAdapter;
9119d9
+typedef virStoragePoolSourceAdapter *virStoragePoolSourceAdapterPtr;
9119d9
 struct _virStoragePoolSourceAdapter {
9119d9
     int type; /* virStoragePoolSourceAdapterType */
9119d9
 
9119d9
diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
9119d9
index bfef219..a5bb85f 100644
9119d9
--- a/src/storage/storage_backend_scsi.c
9119d9
+++ b/src/storage/storage_backend_scsi.c
9119d9
@@ -644,24 +644,25 @@ checkVhbaSCSIHostParent(virConnectPtr conn,
9119d9
 
9119d9
 static int
9119d9
 createVport(virConnectPtr conn,
9119d9
-            virStoragePoolSourceAdapter adapter)
9119d9
+            virStoragePoolDefPtr def)
9119d9
 {
9119d9
+    virStoragePoolSourceAdapterPtr adapter = &def->source.adapter;
9119d9
     unsigned int parent_host;
9119d9
     char *name = NULL;
9119d9
 
9119d9
-    if (adapter.type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST)
9119d9
+    if (adapter->type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST)
9119d9
         return 0;
9119d9
 
9119d9
     /* If a parent was provided, then let's make sure it's vhost capable */
9119d9
-    if (adapter.data.fchost.parent) {
9119d9
-        if (virGetSCSIHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
9119d9
+    if (adapter->data.fchost.parent) {
9119d9
+        if (virGetSCSIHostNumber(adapter->data.fchost.parent, &parent_host) < 0)
9119d9
             return -1;
9119d9
 
9119d9
         if (!virIsCapableFCHost(NULL, parent_host)) {
9119d9
             virReportError(VIR_ERR_XML_ERROR,
9119d9
                            _("parent '%s' specified for vHBA "
9119d9
                              "is not vport capable"),
9119d9
-                           adapter.data.fchost.parent);
9119d9
+                           adapter->data.fchost.parent);
9119d9
             return -1;
9119d9
         }
9119d9
     }
9119d9
@@ -670,35 +671,35 @@ createVport(virConnectPtr conn,
9119d9
      * using the wwnn/wwpn, then a nodedev is already created for
9119d9
      * this pool and we don't have to create the vHBA
9119d9
      */
9119d9
-    if ((name = virGetFCHostNameByWWN(NULL, adapter.data.fchost.wwnn,
9119d9
-                                      adapter.data.fchost.wwpn))) {
9119d9
+    if ((name = virGetFCHostNameByWWN(NULL, adapter->data.fchost.wwnn,
9119d9
+                                      adapter->data.fchost.wwpn))) {
9119d9
         int retval = 0;
9119d9
 
9119d9
         /* If a parent was provided, let's make sure the 'name' we've
9119d9
          * retrieved has the same parent
9119d9
          */
9119d9
-        if (adapter.data.fchost.parent &&
9119d9
-            !checkVhbaSCSIHostParent(conn, name, adapter.data.fchost.parent))
9119d9
+        if (adapter->data.fchost.parent &&
9119d9
+            !checkVhbaSCSIHostParent(conn, name, adapter->data.fchost.parent))
9119d9
             retval = -1;
9119d9
 
9119d9
         VIR_FREE(name);
9119d9
         return retval;
9119d9
     }
9119d9
 
9119d9
-    if (!adapter.data.fchost.parent) {
9119d9
-        if (!(adapter.data.fchost.parent = virFindFCHostCapableVport(NULL))) {
9119d9
+    if (!adapter->data.fchost.parent) {
9119d9
+        if (!(adapter->data.fchost.parent = virFindFCHostCapableVport(NULL))) {
9119d9
             virReportError(VIR_ERR_XML_ERROR, "%s",
9119d9
                            _("'parent' for vHBA not specified, and "
9119d9
                              "cannot find one on this host"));
9119d9
             return -1;
9119d9
         }
9119d9
 
9119d9
-        if (virGetSCSIHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
9119d9
+        if (virGetSCSIHostNumber(adapter->data.fchost.parent, &parent_host) < 0)
9119d9
             return -1;
9119d9
     }
9119d9
 
9119d9
-    if (virManageVport(parent_host, adapter.data.fchost.wwpn,
9119d9
-                       adapter.data.fchost.wwnn, VPORT_CREATE) < 0)
9119d9
+    if (virManageVport(parent_host, adapter->data.fchost.wwpn,
9119d9
+                       adapter->data.fchost.wwnn, VPORT_CREATE) < 0)
9119d9
         return -1;
9119d9
 
9119d9
     virFileWaitForDevices();
9119d9
@@ -816,8 +817,7 @@ static int
9119d9
 virStorageBackendSCSIStartPool(virConnectPtr conn,
9119d9
                                virStoragePoolObjPtr pool)
9119d9
 {
9119d9
-    virStoragePoolSourceAdapter adapter = pool->def->source.adapter;
9119d9
-    return createVport(conn, adapter);
9119d9
+    return createVport(conn, pool->def);
9119d9
 }
9119d9
 
9119d9
 static int
9119d9
-- 
9119d9
2.1.3
9119d9