]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix virDomainDeviceInfoIsSet() to check all struct fields
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 15 May 2012 15:16:49 +0000 (16:16 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 15 May 2012 16:07:34 +0000 (17:07 +0100)
The virDomainDeviceInfoIsSet API was only checking if an
address or alias was set in the struct. Thus if only a
rom bar setting / filename, boot index, or USB master
value was set, they could be accidentally dropped when
formatting XML

src/conf/domain_conf.c
src/conf/domain_conf.h

index 54ac1db9b88acc4f3b51e8e85b4642593f17cc6d..e43d76ddb77ce0f8f3d91908f3193f52481830fc 100644 (file)
@@ -1904,14 +1904,21 @@ int virDomainDevicePCIAddressIsValid(virDomainDevicePCIAddressPtr addr)
 }
 
 
-static int
+static bool
 virDomainDeviceInfoIsSet(virDomainDeviceInfoPtr info, unsigned int flags)
 {
     if (info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
-        return 1;
+        return true;
     if (info->alias && !(flags & VIR_DOMAIN_XML_INACTIVE))
-        return 1;
-    return 0;
+        return true;
+    if (info->mastertype != VIR_DOMAIN_CONTROLLER_MASTER_NONE)
+        return true;
+    if ((info->rombar != VIR_DOMAIN_PCI_ROMBAR_DEFAULT) ||
+        info->romfile)
+        return true;
+    if (info->bootIndex)
+        return true;
+    return false;
 }
 
 void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info)
index 6648a174f15dfad895e91934cab907e69051f518..1597212fcb3112f113656e3038eb2605d87dd57d 100644 (file)
@@ -253,6 +253,10 @@ struct _virDomainDeviceUSBMaster {
 typedef struct _virDomainDeviceInfo virDomainDeviceInfo;
 typedef virDomainDeviceInfo *virDomainDeviceInfoPtr;
 struct _virDomainDeviceInfo {
+    /* If adding to this struct, ensure that
+     * virDomainDeviceInfoIsSet() is updated
+     * to consider the new fields
+     */
     char *alias;
     int type;
     union {