9119d9
From b8ef2c7dbcaedff7a5eb49ccd339ab15b0ffe407 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <b8ef2c7dbcaedff7a5eb49ccd339ab15b0ffe407@dist-git>
9119d9
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
9119d9
Date: Sat, 1 Nov 2014 17:55:32 -0400
9119d9
Subject: [PATCH] Match scsi_host pools by parent address first
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1146837
9119d9
9119d9
If both source adapters are specified by a parent address,
9119d9
just comparing the address is faster and catches even addresses
9119d9
that do not refer to valid adapters.
9119d9
9119d9
(cherry picked from commit 77911d305dfe22f2c93e560ac71602efd73e8ffa)
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 | 29 +++++++++++++++++++++++++++++
9119d9
 1 file changed, 29 insertions(+)
9119d9
9119d9
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
9119d9
index 7fa3dbf..d614b2d 100644
9119d9
--- a/src/conf/storage_conf.c
9119d9
+++ b/src/conf/storage_conf.c
9119d9
@@ -2093,6 +2093,28 @@ getSCSIHostNumber(virStoragePoolSourceAdapter adapter,
9119d9
     VIR_FREE(name);
9119d9
     return ret;
9119d9
 }
9119d9
+static bool
9119d9
+matchSCSIAdapterParent(virStoragePoolObjPtr pool,
9119d9
+                       virStoragePoolDefPtr def)
9119d9
+{
9119d9
+    virDevicePCIAddressPtr pooladdr =
9119d9
+        &pool->def->source.adapter.data.scsi_host.parentaddr;
9119d9
+    virDevicePCIAddressPtr defaddr =
9119d9
+        &def->source.adapter.data.scsi_host.parentaddr;
9119d9
+    int pool_unique_id =
9119d9
+        pool->def->source.adapter.data.scsi_host.unique_id;
9119d9
+    int def_unique_id =
9119d9
+        def->source.adapter.data.scsi_host.unique_id;
9119d9
+    if (pooladdr->domain == defaddr->domain &&
9119d9
+        pooladdr->bus == defaddr->bus &&
9119d9
+        pooladdr->slot == defaddr->slot &&
9119d9
+        pooladdr->function == defaddr->function &&
9119d9
+        pool_unique_id == def_unique_id) {
9119d9
+        return true;
9119d9
+    }
9119d9
+    return false;
9119d9
+}
9119d9
+
9119d9
 
9119d9
 int
9119d9
 virStoragePoolSourceFindDuplicate(virStoragePoolObjListPtr pools,
9119d9
@@ -2142,6 +2164,13 @@ virStoragePoolSourceFindDuplicate(virStoragePoolObjListPtr pools,
9119d9
                        VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) {
9119d9
                 unsigned int pool_hostnum, def_hostnum;
9119d9
 
9119d9
+                if (pool->def->source.adapter.data.scsi_host.has_parent &&
9119d9
+                    def->source.adapter.data.scsi_host.has_parent &&
9119d9
+                    matchSCSIAdapterParent(pool, def)) {
9119d9
+                    matchpool = pool;
9119d9
+                    break;
9119d9
+                }
9119d9
+
9119d9
                 if (getSCSIHostNumber(pool->def->source.adapter,
9119d9
                                       &pool_hostnum) < 0 ||
9119d9
                     getSCSIHostNumber(def->source.adapter, &def_hostnum) < 0)
9119d9
-- 
9119d9
2.1.3
9119d9