]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: snapshot: Avoid autogenerating duplicate snapshot names
authorPeter Krempa <pkrempa@redhat.com>
Thu, 11 Feb 2016 08:57:45 +0000 (09:57 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 11 Feb 2016 14:33:10 +0000 (15:33 +0100)
The snapshot name generator truncates the original file name after a '.'
and replaces the suffix with the snapshot name. If two disks source
images differ only in the suffix portion, the generated name will be
duplicate.

Since this is a corner case just error out stating that a duplicate name
was generated. The user can work around this situation by providing
the file names explicitly.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1283085

src/conf/snapshot_conf.c

index f8a1aed19cfb24ccadfb1d60c444f465a01476d4..58646bd982d37c8f4b57100c94eb96b16ea220ce 100644 (file)
@@ -445,6 +445,7 @@ virDomainSnapshotDefAssignExternalNames(virDomainSnapshotDefPtr def)
     char *tmp;
     struct stat sb;
     size_t i;
+    size_t j;
 
     for (i = 0; i < def->ndisks; i++) {
         virDomainSnapshotDiskDefPtr disk = &def->disks[i];
@@ -491,6 +492,17 @@ virDomainSnapshotDefAssignExternalNames(virDomainSnapshotDefPtr def)
         }
 
         VIR_FREE(tmppath);
+
+        /* verify that we didn't generate a duplicate name */
+        for (j = 0; j < i; j++) {
+            if (STREQ_NULLABLE(disk->src->path, def->disks[j].src->path)) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("cannot generate external snapshot name for "
+                                 "disk '%s': collision with disk '%s'"),
+                               disk->name, def->disks[j].name);
+                return -1;
+            }
+        }
     }
 
     return 0;