[PATCH] 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      |   36 ++++++++++++++++++++++++++++++++++++
 src/conf/storage_conf.h      |    5 +++++
 src/libvirt_private.syms     |    2 ++
 src/storage/storage_driver.c |    6 ++++++
 4 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 995f9a6..eb3595c 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)
 {
@@ -1707,6 +1722,27 @@ cleanup:
     return ret;
 }

+int virStoragePoolTargetDuplicate(virStoragePoolObjListPtr pools,
+                                  virStoragePoolDefPtr def)
+{
+    int ret = 1;
+    virStoragePoolObjPtr pool = NULL;
+
+    /* 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);
+        ret = -1;
+        goto cleanup;
+    }
+
+cleanup:
+    if (pool)
+        virStoragePoolObjUnlock(pool);
+    return ret;
+}

 void virStoragePoolObjLock(virStoragePoolObjPtr obj)
 {
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 271441a..44a2cc8 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);
@@ -388,6 +390,9 @@ int virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
                                  virStoragePoolDefPtr def,
                                  unsigned int check_active);

+int virStoragePoolTargetDuplicate(virStoragePoolObjListPtr pools,
+                                  virStoragePoolDefPtr def);
+
 void virStoragePoolObjLock(virStoragePoolObjPtr obj);
 void virStoragePoolObjUnlock(virStoragePoolObjPtr obj);

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 830222b..37afaf2 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -937,7 +937,9 @@ virStoragePoolObjClearVols;
 virStoragePoolObjDeleteDef;
 virStoragePoolObjFindByName;
 virStoragePoolObjFindByUUID;
+virStoragePoolObjFindByPath;
 virStoragePoolObjIsDuplicate;
+virStoragePoolTargetDuplicate;
 virStoragePoolObjListFree;
 virStoragePoolObjLock;
 virStoragePoolObjRemove;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 9c353e3..b757911 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -536,6 +536,9 @@ storagePoolCreate(virConnectPtr conn,
     if (virStoragePoolObjIsDuplicate(&driver->pools, def, 1)<  0)
         goto cleanup;

+    if (virStoragePoolTargetDuplicate(&driver->pools, def)<  0)
+        goto cleanup;
+
     if ((backend = virStorageBackendForType(def->type)) == NULL)
         goto cleanup;

@@ -589,6 +592,9 @@ storagePoolDefine(virConnectPtr conn,
     if (virStoragePoolObjIsDuplicate(&driver->pools, def, 0)<  0)
         goto cleanup;

+    if (virStoragePoolTargetDuplicate(&driver->pools, def)<  0)
+        goto cleanup;
+
     if (virStorageBackendForType(def->type) == NULL)
         goto cleanup;

--
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]