]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Introduce virStoragePoolObjSourceMatchTypeDIR
authorJohn Ferlan <jferlan@redhat.com>
Wed, 5 Apr 2017 12:14:49 +0000 (08:14 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 13 Apr 2017 14:10:39 +0000 (10:10 -0400)
Refactor virStoragePoolObjSourceFindDuplicate into smaller units
separated by the "supported" pool source type. The DIR, GLUSTER,
and NETFS pools all can use "<source>... <dir='%s'/>... </source>".

Alter the logic slightly to return the matching pool or NULL rather
than setting matchpool = pool and break.  Easier to read that way.

src/conf/virstorageobj.c

index 6e585fa0d9d44b4819bd6f23b0bab2ad38a669d0..3bf888c98566178b26c02fe31969a4ff9f4bd91e 100644 (file)
@@ -853,6 +853,30 @@ virStoragePoolSourceISCSIMatch(virStoragePoolObjPtr matchpool,
 }
 
 
+static virStoragePoolObjPtr
+virStoragePoolObjSourceMatchTypeDIR(virStoragePoolObjPtr pool,
+                                    virStoragePoolDefPtr def)
+{
+    if (pool->def->type == VIR_STORAGE_POOL_DIR) {
+        if (STREQ(pool->def->target.path, def->target.path))
+            return pool;
+    } else if (pool->def->type == VIR_STORAGE_POOL_GLUSTER) {
+        if (STREQ(pool->def->source.name, def->source.name) &&
+            STREQ_NULLABLE(pool->def->source.dir, def->source.dir) &&
+            virStoragePoolSourceMatchSingleHost(&pool->def->source,
+                                                &def->source))
+            return pool;
+    } else if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
+        if (STREQ(pool->def->source.dir, def->source.dir) &&
+            virStoragePoolSourceMatchSingleHost(&pool->def->source,
+                                                &def->source))
+            return pool;
+    }
+
+    return NULL;
+}
+
+
 int
 virStoragePoolObjSourceFindDuplicate(virConnectPtr conn,
                                      virStoragePoolObjListPtr pools,
@@ -879,23 +903,9 @@ virStoragePoolObjSourceFindDuplicate(virConnectPtr conn,
 
         switch ((virStoragePoolType)pool->def->type) {
         case VIR_STORAGE_POOL_DIR:
-            if (STREQ(pool->def->target.path, def->target.path))
-                matchpool = pool;
-            break;
-
         case VIR_STORAGE_POOL_GLUSTER:
-            if (STREQ(pool->def->source.name, def->source.name) &&
-                STREQ_NULLABLE(pool->def->source.dir, def->source.dir) &&
-                virStoragePoolSourceMatchSingleHost(&pool->def->source,
-                                                    &def->source))
-                matchpool = pool;
-            break;
-
         case VIR_STORAGE_POOL_NETFS:
-            if (STREQ(pool->def->source.dir, def->source.dir) &&
-                virStoragePoolSourceMatchSingleHost(&pool->def->source,
-                                                    &def->source))
-                matchpool = pool;
+            matchpool = virStoragePoolObjSourceMatchTypeDIR(pool, def);
             break;
 
         case VIR_STORAGE_POOL_SCSI: