]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
storage: Refactor iSCSI Source matching
authorJohn Ferlan <jferlan@redhat.com>
Mon, 30 Mar 2015 23:59:26 +0000 (19:59 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 15 Apr 2015 10:40:01 +0000 (06:40 -0400)
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@redhat.com>
src/conf/storage_conf.c

index 990a528f23ad14c52e670e660eba3770a7ca5296..351eea88959b207753b2fcb31563ea1b6141bfd8 100644 (file)
@@ -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: