[Libvirt] [PATCH v3] Fix bug #611823 prohibit pools with duplicate storage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Make sure the unique storage pool defined and create from different
directory to avoid inconsistent version of volume pool created. 

Signed-off-by: Lei Li <lilei@xxxxxxxxxxxxxxxxxx>
---
 src/conf/storage_conf.c  |   25 +++++++++++++++++++++++++
 src/conf/storage_conf.h  |    2 ++
 src/libvirt_private.syms |    1 +
 3 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 995f9a6..1d9fe25 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1317,6 +1317,21 @@ virStoragePoolObjFindByName(virStoragePoolObjListPtr pools,
     return NULL;
 }
 
+virStoragePoolObjPtr
+virStoragePoolObjFindByPath(virStoragePoolObjListPtr pools,
+                            const char *path) {
+    unsigned int i;
+
+    for (i = 0 ; i < pools->count ; i++) {
+        virStoragePoolObjLock(pools->objs[i]);
+        if (STREQ(pools->objs[i]->def->target.path, path))
+            return pools->objs[i];
+        virStoragePoolObjUnlock(pools->objs[i]);
+    }
+
+    return NULL;
+}
+
 void
 virStoragePoolObjClearVols(virStoragePoolObjPtr pool)
 {
@@ -1700,6 +1715,16 @@ int virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
         }
     }
 
+    /* Check the pool list if defined target path already exist */
+    pool = virStoragePoolObjFindByPath(pools, def->target.path);
+    if (pool) {
+        virStorageReportError(VIR_ERR_OPERATION_FAILED,
+                              _("target path '%s' is already in use"),
+                              pool->def->target.path);
+        dupPool = -1;
+        goto cleanup;
+    }
+ 
     ret = dupPool;
 cleanup:
     if (pool)
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 271441a..9239977 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -335,6 +335,8 @@ virStoragePoolObjPtr virStoragePoolObjFindByUUID(virStoragePoolObjListPtr pools,
                                                  const unsigned char *uuid);
 virStoragePoolObjPtr virStoragePoolObjFindByName(virStoragePoolObjListPtr pools,
                                                  const char *name);
+virStoragePoolObjPtr virStoragePoolObjFindByPath(virStoragePoolObjListPtr pools,
+                                                 const char *path);
 
 virStorageVolDefPtr virStorageVolDefFindByKey(virStoragePoolObjPtr pool,
                                               const char *key);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 830222b..19f5f92 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -937,6 +937,7 @@ virStoragePoolObjClearVols;
 virStoragePoolObjDeleteDef;
 virStoragePoolObjFindByName;
 virStoragePoolObjFindByUUID;
+virStoragePoolObjFindByPath;
 virStoragePoolObjIsDuplicate;
 virStoragePoolObjListFree;
 virStoragePoolObjLock;
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]