]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: reject duplicate paths in device weights
authorEric Blake <eblake@redhat.com>
Tue, 29 Nov 2011 20:23:17 +0000 (13:23 -0700)
committerEric Blake <eblake@redhat.com>
Wed, 30 Nov 2011 19:15:22 +0000 (12:15 -0700)
The next patch will make it possible to have virDomainSetBlkioParameters
leave device weights unchanged if they are not mentioned in the incoming
string, but this only works if the list of block weights does not allow
duplicate paths.  Technically, a user can still confuse libvirt by
passing alternate spellings that resolve to the same device, but it
is not worth worrying about working around that kind of abuse.

* src/conf/domain_conf.c (virDomainDefParseXML): Require unique
paths.

src/conf/domain_conf.c

index 7ed2c35a1776d7260123acaa64ff41c23dc1e58f..d1f8a76db11d9f662a6374bfd1b96c6e4564413e 100644 (file)
@@ -6969,10 +6969,20 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
         goto no_memory;
 
     for (i = 0; i < n; i++) {
+        int j;
         if (virDomainBlkioDeviceWeightParseXML(nodes[i],
                                                &def->blkio.devices[i]) < 0)
             goto error;
         def->blkio.ndevices++;
+        for (j = 0; j < i; j++) {
+            if (STREQ(def->blkio.devices[j].path,
+                      def->blkio.devices[i].path)) {
+                virDomainReportError(VIR_ERR_XML_ERROR,
+                                     _("duplicate device weight path '%s'"),
+                                     def->blkio.devices[i].path);
+                goto error;
+            }
+        }
     }
     VIR_FREE(nodes);