[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 3/6] conf: move rombar and bootIndex into virDomainDeviceInfo



To help consolidate the commonality between virDomainHostdevDef and
virDomainInterface into as few members as possible (and because I
think it makes sense), this patch moves the rombar and bootIndex
members into the "info" member that is common to both (and to all the
other structs that use them).

It's a bit problematic that this gives rombar and bootIndex to many
device types that don't use them, but this is already the case for the
master and mastertype members of virDomainDeviceInfo, and is properly
commented as such in the definition.

Note that this opens the door to supporting rombar for other devices
that are attached to the guest PCI bus - virtio-blk-pci,
virtio-net-pci, various other network adapters - which which have that
capability in qemu, but previously had no support in libvirt.
---
 src/conf/domain_conf.c  |   26 +++++++++++++-------------
 src/conf/domain_conf.h  |   24 ++++++++++++------------
 src/qemu/qemu_command.c |   16 ++++++++--------
 src/qemu/qemu_driver.c  |    4 ++--
 4 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 471b0a2..8a35e6e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3021,7 +3021,7 @@ virDomainDiskDefParseXML(virCapsPtr caps,
                        (xmlStrEqual(cur->name, BAD_CAST "serial"))) {
                 serial = (char *)xmlNodeGetContent(cur);
             } else if (xmlStrEqual(cur->name, BAD_CAST "boot")) {
-                if (virDomainDeviceBootParseXML(cur, &def->bootIndex,
+                if (virDomainDeviceBootParseXML(cur, &def->info.bootIndex,
                                                 bootMap))
                     goto error;
             }
@@ -3790,7 +3790,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
                 /* Legacy back-compat. Don't add any more attributes here */
                 devaddr = virXMLPropString(cur, "devaddr");
             } else if (xmlStrEqual(cur->name, BAD_CAST "boot")) {
-                if (virDomainDeviceBootParseXML(cur, &def->bootIndex,
+                if (virDomainDeviceBootParseXML(cur, &def->info.bootIndex,
                                                 bootMap))
                     goto error;
             } else if ((actual == NULL) &&
@@ -6229,7 +6229,7 @@ virDomainHostdevDefParseXML(const xmlNodePtr node,
             } else if (xmlStrEqual(cur->name, BAD_CAST "alias")) {
                 /* alias is parsed as part of virDomainDeviceInfoParseXML */
             } else if (xmlStrEqual(cur->name, BAD_CAST "boot")) {
-                if (virDomainDeviceBootParseXML(cur, &def->bootIndex,
+                if (virDomainDeviceBootParseXML(cur, &def->info.bootIndex,
                                                 bootMap))
                     goto error;
             } else if (xmlStrEqual(cur->name, BAD_CAST "rom")) {
@@ -6239,7 +6239,7 @@ virDomainHostdevDefParseXML(const xmlNodePtr node,
                                          "%s", _("missing rom bar attribute"));
                     goto error;
                 }
-                if ((def->rombar = virDomainPciRombarModeTypeFromString(rombar)) <= 0) {
+                if ((def->info.rombar = virDomainPciRombarModeTypeFromString(rombar)) <= 0) {
                     virDomainReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                          _("unknown rom bar value '%s'"), rombar);
                     VIR_FREE(rombar);
@@ -10088,8 +10088,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
         virBufferAddLit(buf, "      </iotune>\n");
     }
 
-    if (def->bootIndex)
-        virBufferAsprintf(buf, "      <boot order='%d'/>\n", def->bootIndex);
+    if (def->info.bootIndex)
+        virBufferAsprintf(buf, "      <boot order='%d'/>\n", def->info.bootIndex);
     if (def->readonly)
         virBufferAddLit(buf, "      <readonly/>\n");
     if (def->shared)
@@ -10453,8 +10453,8 @@ virDomainNetDefFormat(virBufferPtr buf,
             return -1;
         virBufferAdjustIndent(buf, -6);
     }
-    if (def->bootIndex)
-        virBufferAsprintf(buf, "      <boot order='%d'/>\n", def->bootIndex);
+    if (def->info.bootIndex)
+        virBufferAsprintf(buf, "      <boot order='%d'/>\n", def->info.bootIndex);
 
     if (def->tune.sndbuf_specified) {
         virBufferAddLit(buf,   "      <tune>\n");
@@ -11304,19 +11304,19 @@ virDomainHostdevDefFormat(virBufferPtr buf,
 
     virBufferAddLit(buf, "      </source>\n");
 
-    if (def->bootIndex)
-        virBufferAsprintf(buf, "      <boot order='%d'/>\n", def->bootIndex);
+    if (def->info.bootIndex)
+        virBufferAsprintf(buf, "      <boot order='%d'/>\n", def->info.bootIndex);
 
     if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
         return -1;
 
-    if (def->rombar) {
+    if (def->info.rombar) {
         const char *rombar
-            = virDomainPciRombarModeTypeToString(def->rombar);
+            = virDomainPciRombarModeTypeToString(def->info.rombar);
         if (!rombar) {
             virDomainReportError(VIR_ERR_INTERNAL_ERROR,
                                  _("unexpected rom bar value %d"),
-                                 def->rombar);
+                                 def->info.rombar);
             return -1;
         }
         virBufferAsprintf(buf, "      <rom bar='%s'/>\n", rombar);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index dd2abf8..8fab383 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -82,6 +82,14 @@ enum virDomainDeviceAddressPciMulti {
     VIR_DOMAIN_DEVICE_ADDRESS_PCI_MULTI_LAST
 };
 
+enum virDomainPciRombarMode {
+    VIR_DOMAIN_PCI_ROMBAR_DEFAULT = 0,
+    VIR_DOMAIN_PCI_ROMBAR_ON,
+    VIR_DOMAIN_PCI_ROMBAR_OFF,
+
+    VIR_DOMAIN_PCI_ROMBAR_LAST
+};
+
 typedef struct _virDomainDevicePCIAddress virDomainDevicePCIAddress;
 typedef virDomainDevicePCIAddress *virDomainDevicePCIAddressPtr;
 struct _virDomainDevicePCIAddress {
@@ -179,6 +187,10 @@ struct _virDomainDeviceInfo {
     union {
         virDomainDeviceUSBMaster usb;
     } master;
+    /* rombar is only used for pci hostdev devices, and bootIndex only
+     * for disk, network interface, and hostdev devices */
+    int rombar;         /* enum virDomainPciRombarMode */
+    int bootIndex;
 };
 
 enum virDomainSeclabelType {
@@ -409,7 +421,6 @@ struct _virDomainDiskDef {
     int cachemode;
     int error_policy;  /* enum virDomainDiskErrorPolicy */
     int rerror_policy; /* enum virDomainDiskErrorPolicy */
-    int bootIndex;
     int iomode;
     int ioeventfd;
     int event_idx;
@@ -655,7 +666,6 @@ struct _virDomainNetDef {
     } tune;
     char *script;
     char *ifname;
-    int bootIndex;
     virDomainDeviceInfo info;
     char *filter;
     virNWFilterHashTablePtr filterparams;
@@ -1094,14 +1104,6 @@ enum virDomainHostdevSubsysType {
     VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST
 };
 
-enum virDomainPciRombarMode {
-    VIR_DOMAIN_PCI_ROMBAR_DEFAULT = 0,
-    VIR_DOMAIN_PCI_ROMBAR_ON,
-    VIR_DOMAIN_PCI_ROMBAR_OFF,
-
-    VIR_DOMAIN_PCI_ROMBAR_LAST
-};
-
 typedef struct _virDomainHostdevDef virDomainHostdevDef;
 typedef virDomainHostdevDef *virDomainHostdevDefPtr;
 struct _virDomainHostdevDef {
@@ -1116,9 +1118,7 @@ struct _virDomainHostdevDef {
             int dummy;
         } caps;
     } source;
-    int bootIndex;
     virDomainDeviceInfo info; /* Guest address */
-    int rombar;               /* enum virDomainPciRombarMode */
     virDomainHostdevOrigStates origstates;
 };
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index aaccf62..fd170bf 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2849,19 +2849,19 @@ qemuBuildPCIHostdevDevStr(virDomainHostdevDefPtr dev, const char *configfd,
     virBufferAsprintf(&buf, ",id=%s", dev->info.alias);
     if (configfd && *configfd)
         virBufferAsprintf(&buf, ",configfd=%s", configfd);
-    if (dev->bootIndex)
-        virBufferAsprintf(&buf, ",bootindex=%d", dev->bootIndex);
+    if (dev->info.bootIndex)
+        virBufferAsprintf(&buf, ",bootindex=%d", dev->info.bootIndex);
     if (qemuBuildDeviceAddressStr(&buf, &dev->info, qemuCaps) < 0)
         goto error;
 
-    if (dev->rombar) {
+    if (dev->info.rombar) {
         if (!qemuCapsGet(qemuCaps, QEMU_CAPS_PCI_ROMBAR)) {
             qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                             "%s", _("rombar not supported in this QEMU binary"));
             goto error;
         }
 
-        switch (dev->rombar) {
+        switch (dev->info.rombar) {
         case VIR_DOMAIN_PCI_ROMBAR_OFF:
             virBufferAddLit(&buf, ",rombar=0");
             break;
@@ -4419,8 +4419,8 @@ qemuBuildCommandLine(virConnectPtr conn,
 
             if (!emitBootindex)
                 bootindex = 0;
-            else if (disk->bootIndex)
-                bootindex = disk->bootIndex;
+            else if (disk->info.bootIndex)
+                bootindex = disk->info.bootIndex;
 
             if (withDeviceArg) {
                 if (disk->bus == VIR_DOMAIN_DISK_BUS_FDC) {
@@ -4614,7 +4614,7 @@ qemuBuildCommandLine(virConnectPtr conn,
 
             bootNet = 0;
             if (!bootindex)
-                bootindex = net->bootIndex;
+                bootindex = net->info.bootIndex;
 
             /* VLANs are not used with -netdev, so don't record them */
             if (qemuCapsGet(qemuCaps, QEMU_CAPS_NETDEV) &&
@@ -5547,7 +5547,7 @@ qemuBuildCommandLine(virConnectPtr conn,
         virDomainHostdevDefPtr hostdev = def->hostdevs[i];
         char *devstr;
 
-        if (hostdev->bootIndex) {
+        if (hostdev->info.bootIndex) {
             if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
                 hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
                 qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c81289a..729c621 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4518,7 +4518,7 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
      */
     for (i = 0 ; i < def->nnets ; i++) {
         virDomainNetDefPtr net = def->nets[i];
-        int bootIndex = net->bootIndex;
+        int bootIndex = net->info.bootIndex;
         if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
             int actualType = virDomainNetGetActualType(net);
             const char *brname;
@@ -4576,7 +4576,7 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
             net->data.ethernet.dev = brname;
             net->data.ethernet.ipaddr = ipaddr;
         }
-        net->bootIndex = bootIndex;
+        net->info.bootIndex = bootIndex;
     }
     for (i = 0 ; i < def->ngraphics ; i++) {
         if (def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
-- 
1.7.7.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]