From 77911d305dfe22f2c93e560ac71602efd73e8ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Sat, 1 Nov 2014 12:10:17 +0100 Subject: [PATCH] Match scsi_host pools by parent address first If both source adapters are specified by a parent address, just comparing the address is faster and catches even addresses that do not refer to valid adapters. --- src/conf/storage_conf.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 19c452bf94..0317b06edd 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -2094,6 +2094,28 @@ getSCSIHostNumber(virStoragePoolSourceAdapter adapter, VIR_FREE(name); return ret; } +static bool +matchSCSIAdapterParent(virStoragePoolObjPtr pool, + virStoragePoolDefPtr def) +{ + virDevicePCIAddressPtr pooladdr = + &pool->def->source.adapter.data.scsi_host.parentaddr; + virDevicePCIAddressPtr defaddr = + &def->source.adapter.data.scsi_host.parentaddr; + int pool_unique_id = + pool->def->source.adapter.data.scsi_host.unique_id; + int def_unique_id = + def->source.adapter.data.scsi_host.unique_id; + if (pooladdr->domain == defaddr->domain && + pooladdr->bus == defaddr->bus && + pooladdr->slot == defaddr->slot && + pooladdr->function == defaddr->function && + pool_unique_id == def_unique_id) { + return true; + } + return false; +} + int virStoragePoolSourceFindDuplicate(virStoragePoolObjListPtr pools, @@ -2143,6 +2165,13 @@ virStoragePoolSourceFindDuplicate(virStoragePoolObjListPtr pools, VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) { unsigned int pool_hostnum, def_hostnum; + if (pool->def->source.adapter.data.scsi_host.has_parent && + def->source.adapter.data.scsi_host.has_parent && + matchSCSIAdapterParent(pool, def)) { + matchpool = pool; + break; + } + if (getSCSIHostNumber(pool->def->source.adapter, &pool_hostnum) < 0 || getSCSIHostNumber(def->source.adapter, &def_hostnum) < 0)