c401cc
From c1f1c134797e9ee7f68038e11e58171d255d37c3 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <c1f1c134797e9ee7f68038e11e58171d255d37c3.1391001809.git.jdenemar@redhat.com>
c401cc
From: Osier Yang <jyang@redhat.com>
c401cc
Date: Mon, 27 Jan 2014 20:39:31 +0800
c401cc
Subject: [PATCH] storage: Fix autostart of pool with "fc_host" type adapter
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=726797
c401cc
c401cc
The "checkPool" is a bit different for pool with "fc_host"
c401cc
type source adapter, since the vHBA it's based on might be
c401cc
not created yet (it's created by "startPool", which is
c401cc
involked after "checkPool" in storageDriverAutostart). So it
c401cc
should not fail, otherwise the "autostart" of the pool will
c401cc
fail either.
c401cc
c401cc
The problem is easy to reproduce:
c401cc
    * Enable "autostart" for the pool
c401cc
    * Restart libvirtd service
c401cc
    * Check the pool's state
c401cc
(cherry picked from commit 2340f0196f6339f95274f73699d54e0b5e07c362)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/storage/storage_backend_scsi.c | 15 +++++++++++++--
c401cc
 1 file changed, 13 insertions(+), 2 deletions(-)
c401cc
c401cc
diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
c401cc
index 7437488..26baf4a 100644
c401cc
--- a/src/storage/storage_backend_scsi.c
c401cc
+++ b/src/storage/storage_backend_scsi.c
c401cc
@@ -704,8 +704,19 @@ virStorageBackendSCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
c401cc
 
c401cc
     *isActive = false;
c401cc
 
c401cc
-    if (!(name = getAdapterName(pool->def->source.adapter)))
c401cc
-        return -1;
c401cc
+    if (!(name = getAdapterName(pool->def->source.adapter))) {
c401cc
+        /* It's normal for the pool with "fc_host" type source
c401cc
+         * adapter fails to get the adapter name, since the vHBA
c401cc
+         * the adapter based on might be not created yet.
c401cc
+         */
c401cc
+        if (pool->def->source.adapter.type ==
c401cc
+            VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) {
c401cc
+            virResetLastError();
c401cc
+            return 0;
c401cc
+        } else {
c401cc
+            return -1;
c401cc
+        }
c401cc
+    }
c401cc
 
c401cc
     if (getHostNumber(name, &host) < 0)
c401cc
         goto cleanup;
c401cc
-- 
c401cc
1.8.5.3
c401cc