[libvirt] [PATCH] storage: Add unique UUID check for virStoragePoolObjAssignDef

John Ferlan posted 1 patch 6 years, 4 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20171214182220.24718-1-jferlan@redhat.com
src/conf/virstorageobj.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
[libvirt] [PATCH] storage: Add unique UUID check for virStoragePoolObjAssignDef
Posted by John Ferlan 6 years, 4 months ago
Commit id '4b2e0ed6e' converted to using hash tables for storing
storage pool objs by name and uuid; however, neglected to add a check
to virStoragePoolObjAssignDef that the pool by uuid wasn't defined.
This caused issues for the virt-manager test driver which ended up
using the same UUID for a newly named pool and started having failures
from adding a non unique UUID.

So instead of getting a "Duplicate key", let's add a more descriptive
error message indicating which pool object by name already exists
using the same UUID as the pool object that is attempting to be added.

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

 FWIW: The virt-manager test was also fixed to not use a duplicate UUID
       as of commit '4224b0926' in the virt-manager git repo.

 src/conf/virstorageobj.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 49fe24b28..e3acc817c 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -747,10 +747,18 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
         return obj;
     }
 
+    virUUIDFormat(def->uuid, uuidstr);
+    if ((obj = virStoragePoolObjFindByUUIDLocked(pools, def->uuid))) {
+        virObjectLock(obj);
+        virReportError(VIR_ERR_OPERATION_FAILED,
+                       _("storage pool '%s' already exists with uuid %s"),
+                       obj->def->name, uuidstr);
+        goto error;
+    }
+
     if (!(obj = virStoragePoolObjNew()))
         return NULL;
 
-    virUUIDFormat(def->uuid, uuidstr);
     if (virHashAddEntry(pools->objs, uuidstr, obj) < 0)
         goto error;
     virObjectRef(obj);
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] storage: Add unique UUID check for virStoragePoolObjAssignDef
Posted by Ján Tomko 6 years, 4 months ago
On Thu, Dec 14, 2017 at 01:22:20PM -0500, John Ferlan wrote:
>Commit id '4b2e0ed6e' converted to using hash tables for storing
>storage pool objs by name and uuid; however, neglected to add a check
>to virStoragePoolObjAssignDef that the pool by uuid wasn't defined.
>This caused issues for the virt-manager test driver which ended up
>using the same UUID for a newly named pool and started having failures
>from adding a non unique UUID.
>
>So instead of getting a "Duplicate key", let's add a more descriptive
>error message indicating which pool object by name already exists
>using the same UUID as the pool object that is attempting to be added.
>
>Signed-off-by: John Ferlan <jferlan@redhat.com>
>---
>
> FWIW: The virt-manager test was also fixed to not use a duplicate UUID
>       as of commit '4224b0926' in the virt-manager git repo.
>
> src/conf/virstorageobj.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
>diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
>index 49fe24b28..e3acc817c 100644
>--- a/src/conf/virstorageobj.c
>+++ b/src/conf/virstorageobj.c
>@@ -747,10 +747,18 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
>         return obj;
>     }
>
>+    virUUIDFormat(def->uuid, uuidstr);
>+    if ((obj = virStoragePoolObjFindByUUIDLocked(pools, def->uuid))) {
>+        virObjectLock(obj);
>+        virReportError(VIR_ERR_OPERATION_FAILED,
>+                       _("storage pool '%s' already exists with uuid %s"),
>+                       obj->def->name, uuidstr);

For storage driver, this duplicates the error from virStoragePoolObjIsDuplicate:
            virReportError(VIR_ERR_OPERATION_FAILED,
                           _("pool '%s' is already defined with uuid %s"),
                           obj->def->name, uuidstr);

Test driver should use that function instead of adding duplicate error
checks to 'functional' code. Also, it seems this would not cover the
opposite case - same name but different UUIDs (which is already covered
by virStoragePoolObjIsDuplicate).

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