From 159f4d0b30ca9916a1b541a9ebcf560ffeca5330 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Tue, 24 Jan 2012 12:53:59 -0500 Subject: [PATCH] conf: put all guest-related HostdevDef data in one object To help consolidate the commonality between virDomainHostdevDef and virDomainNetDef 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 bf0e76f489..e3ac926fcc 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3022,7 +3022,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; } @@ -3791,7 +3791,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) && @@ -6230,7 +6230,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")) { @@ -6240,7 +6240,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); @@ -10089,8 +10089,8 @@ virDomainDiskDefFormat(virBufferPtr buf, virBufferAddLit(buf, " \n"); } - if (def->bootIndex) - virBufferAsprintf(buf, " \n", def->bootIndex); + if (def->info.bootIndex) + virBufferAsprintf(buf, " \n", def->info.bootIndex); if (def->readonly) virBufferAddLit(buf, " \n"); if (def->shared) @@ -10454,8 +10454,8 @@ virDomainNetDefFormat(virBufferPtr buf, return -1; virBufferAdjustIndent(buf, -6); } - if (def->bootIndex) - virBufferAsprintf(buf, " \n", def->bootIndex); + if (def->info.bootIndex) + virBufferAsprintf(buf, " \n", def->info.bootIndex); if (def->tune.sndbuf_specified) { virBufferAddLit(buf, " \n"); @@ -11305,19 +11305,19 @@ virDomainHostdevDefFormat(virBufferPtr buf, virBufferAddLit(buf, " \n"); - if (def->bootIndex) - virBufferAsprintf(buf, " \n", def->bootIndex); + if (def->info.bootIndex) + virBufferAsprintf(buf, " \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, " \n", rombar); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 1d2fb81fb8..6419618b76 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 { @@ -159,6 +167,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 { @@ -389,7 +401,6 @@ struct _virDomainDiskDef { int cachemode; int error_policy; /* enum virDomainDiskErrorPolicy */ int rerror_policy; /* enum virDomainDiskErrorPolicy */ - int bootIndex; int iomode; int ioeventfd; int event_idx; @@ -635,7 +646,6 @@ struct _virDomainNetDef { } tune; char *script; char *ifname; - int bootIndex; virDomainDeviceInfo info; char *filter; virNWFilterHashTablePtr filterparams; @@ -1074,14 +1084,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 { @@ -1108,9 +1110,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 9bfbada913..543c57ab22 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; @@ -4448,8 +4448,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) { @@ -4643,7 +4643,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) && @@ -5576,7 +5576,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 196fd23a07..1b147a9a35 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 &&