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

Ján Tomko jtomko at redhat.com
Fri Dec 15 15:49:01 UTC 2017

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 at 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:
                           _("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).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20171215/139bbf68/attachment-0001.sig>

More information about the libvir-list mailing list