When parsing the domain xml, disks are supposed to be
rearranged in an alphabetic order based on bus type
and target. The reordering code had a flaw though, in
that it would always put the first disk it encountered
at the head of the list, and had no way of putting
new entries in front of it.
The attached patch reworks the code to compare the new
disk against the current disk entry (rather than the
next entry like the existing code). Seems to pass all
my tests.
Thanks,
Cole
commit ce3abbb62327672f756848efec7c95275fa797d6
Author: Cole (Work Acct) <crobinso(a)localhost.localdomain>
Date: Thu Aug 21 23:04:11 2008 -0400
Fix disk ordering when parsing domain xml.
diff --git a/src/domain_conf.c b/src/domain_conf.c
index ed6cc8b..3c61039 100644
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -1949,25 +1949,27 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
goto error;
/* Maintain list in sorted order according to target device name */
- if (def->disks == NULL) {
- disk->next = def->disks;
- def->disks = disk;
- } else {
- virDomainDiskDefPtr ptr = def->disks;
- while (ptr) {
- if (ptr->next && STREQ(disk->dst, ptr->next->dst)) {
- virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("duplicate disk target
'%s'"),
- disk->dst);
- goto error;
- }
- if (!ptr->next || virDomainDiskCompare(disk, ptr->next) < 0) {
- disk->next = ptr->next;
- ptr->next = disk;
- break;
- }
- ptr = ptr->next;
+ virDomainDiskDefPtr ptr = def->disks;
+ virDomainDiskDefPtr *prev = &(def->disks);
+ while (ptr) {
+ if (STREQ(disk->dst, ptr->dst)) {
+ virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ _("duplicate disk target '%s'"),
+ disk->dst);
+ goto error;
+ }
+ if (virDomainDiskCompare(disk, ptr) < 0) {
+ disk->next = ptr;
+ *prev = disk;
+ break;
}
+ prev = &(ptr->next);
+ ptr = ptr->next;
+ }
+
+ if (!ptr) {
+ disk->next = ptr;
+ *prev = disk;
}
}
VIR_FREE(nodes);