[libvirt] [PATCH v2 1/8] storage: Refactor iSCSI Source matching

John Ferlan jferlan at redhat.com
Mon Apr 13 21:21:05 UTC 2015


Create a separate iSCSI Source matching subroutine. Makes the calling
code a bit cleaner as well as sets up for future patches which need to
do better source hosts[0].name processing/checking.

As part of the effort the logic will be inverted from a multi-level
if statement to a series of single level checks for better readability
and further separation

Signed-off-by: John Ferlan <jferlan at redhat.com>

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/conf/storage_conf.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 990a528..351eea8 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -2406,6 +2406,26 @@ matchSCSIAdapterParent(virStoragePoolObjPtr pool,
 }
 
 
+static bool
+virStoragePoolSourceISCSIMatch(virStoragePoolObjPtr matchpool,
+                               virStoragePoolDefPtr def)
+{
+    virStoragePoolSourcePtr poolsrc = &matchpool->def->source;
+    virStoragePoolSourcePtr defsrc = &def->source;
+
+    if (poolsrc->nhost != 1 && defsrc->nhost != 1)
+        return false;
+
+    if (STRNEQ(poolsrc->hosts[0].name, defsrc->hosts[0].name))
+        return false;
+
+    if (STRNEQ_NULLABLE(poolsrc->initiator.iqn, defsrc->initiator.iqn))
+        return false;
+
+    return true;
+}
+
+
 int
 virStoragePoolSourceFindDuplicate(virConnectPtr conn,
                                   virStoragePoolObjListPtr pools,
@@ -2505,17 +2525,8 @@ virStoragePoolSourceFindDuplicate(virConnectPtr conn,
         case VIR_STORAGE_POOL_ISCSI:
             matchpool = virStoragePoolSourceFindDuplicateDevices(pool, def);
             if (matchpool) {
-                if (matchpool->def->source.nhost == 1 && def->source.nhost == 1) {
-                    if (STREQ(matchpool->def->source.hosts[0].name, def->source.hosts[0].name)) {
-                        if ((matchpool->def->source.initiator.iqn) && (def->source.initiator.iqn)) {
-                            if (STREQ(matchpool->def->source.initiator.iqn, def->source.initiator.iqn))
-                                break;
-                            matchpool = NULL;
-                        }
-                        break;
-                    }
-                }
-                matchpool = NULL;
+                if (!virStoragePoolSourceISCSIMatch(matchpool, def))
+                    matchpool = NULL;
             }
             break;
         case VIR_STORAGE_POOL_FS:
-- 
2.1.0




More information about the libvir-list mailing list