virCaps: get rid of macPrefix field

Use the virDomainXMLConf structure to hold this data and tweak the code
to avoid semantic change.

Without configuration the KVM mac prefix is used by default. I chose it
as it's in the privately administered segment so it should be usable for
any purposes.
This commit is contained in:
Peter Krempa 2013-03-15 15:44:12 +01:00
parent 8960d65674
commit 46becc18ba
22 changed files with 59 additions and 63 deletions

View File

@ -921,17 +921,3 @@ virCapabilitiesFormatXML(virCapsPtr caps)
return virBufferContentAndReset(&xml); return virBufferContentAndReset(&xml);
} }
extern void
virCapabilitiesSetMacPrefix(virCapsPtr caps,
const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN])
{
memcpy(caps->macPrefix, prefix, sizeof(caps->macPrefix));
}
extern void
virCapabilitiesGenerateMac(virCapsPtr caps,
virMacAddrPtr mac)
{
virMacAddrGenerate(caps->macPrefix, mac);
}

View File

@ -162,7 +162,6 @@ struct _virCaps {
virCapsGuestPtr *guests; virCapsGuestPtr *guests;
/* Move to virDomainXMLOption later */ /* Move to virDomainXMLOption later */
unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch); int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch);
}; };
@ -175,14 +174,6 @@ virCapabilitiesNew(virArch hostarch,
extern void extern void
virCapabilitiesFreeNUMAInfo(virCapsPtr caps); virCapabilitiesFreeNUMAInfo(virCapsPtr caps);
extern void
virCapabilitiesSetMacPrefix(virCapsPtr caps,
const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN]);
extern void
virCapabilitiesGenerateMac(virCapsPtr caps,
virMacAddrPtr mac);
extern int extern int
virCapabilitiesAddHostFeature(virCapsPtr caps, virCapabilitiesAddHostFeature(virCapsPtr caps,
const char *name); const char *name);

View File

@ -791,6 +791,18 @@ virDomainXMLOptionNew(virDomainDefParserConfigPtr config,
if (xmlns) if (xmlns)
xmlopt->ns = *xmlns; xmlopt->ns = *xmlns;
/* Technically this forbids to use one of Xerox's MAC address prefixes in
* our hypervisor drivers. This shouldn't ever be a problem.
*
* Use the KVM prefix as default as it's in the privately administered
* range */
if (xmlopt->config.macPrefix[0] == 0 &&
xmlopt->config.macPrefix[1] == 0 &&
xmlopt->config.macPrefix[2] == 0) {
xmlopt->config.macPrefix[0] = 0x52;
xmlopt->config.macPrefix[1] = 0x54;
}
return xmlopt; return xmlopt;
} }
@ -5039,6 +5051,14 @@ cleanup:
} }
void
virDomainNetGenerateMAC(virDomainXMLOptionPtr xmlopt,
virMacAddrPtr mac)
{
virMacAddrGenerate(xmlopt->config.macPrefix, mac);
}
/* Parse a value located at XPATH within CTXT, and store the /* Parse a value located at XPATH within CTXT, and store the
* result into val. If REQUIRED, then the value must exist; * result into val. If REQUIRED, then the value must exist;
* otherwise, the value is optional. The value is in bytes. * otherwise, the value is optional. The value is in bytes.
@ -5407,7 +5427,7 @@ error:
* @return 0 on success, -1 on failure * @return 0 on success, -1 on failure
*/ */
static virDomainNetDefPtr static virDomainNetDefPtr
virDomainNetDefParseXML(virCapsPtr caps, virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
xmlNodePtr node, xmlNodePtr node,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
virBitmapPtr bootMap, virBitmapPtr bootMap,
@ -5592,7 +5612,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
goto error; goto error;
} }
} else { } else {
virCapabilitiesGenerateMac(caps, &def->mac); virDomainNetGenerateMAC(xmlopt, &def->mac);
} }
if (devaddr) { if (devaddr) {
@ -8515,7 +8535,7 @@ virDomainDeviceDefParse(const char *xmlStr,
goto error; goto error;
} else if (xmlStrEqual(node->name, BAD_CAST "interface")) { } else if (xmlStrEqual(node->name, BAD_CAST "interface")) {
dev->type = VIR_DOMAIN_DEVICE_NET; dev->type = VIR_DOMAIN_DEVICE_NET;
if (!(dev->data.net = virDomainNetDefParseXML(caps, node, ctxt, if (!(dev->data.net = virDomainNetDefParseXML(xmlopt, node, ctxt,
NULL, flags))) NULL, flags)))
goto error; goto error;
} else if (xmlStrEqual(node->name, BAD_CAST "input")) { } else if (xmlStrEqual(node->name, BAD_CAST "input")) {
@ -10492,7 +10512,7 @@ virDomainDefParseXML(xmlDocPtr xml,
if (n && VIR_ALLOC_N(def->nets, n) < 0) if (n && VIR_ALLOC_N(def->nets, n) < 0)
goto no_memory; goto no_memory;
for (i = 0 ; i < n ; i++) { for (i = 0 ; i < n ; i++) {
virDomainNetDefPtr net = virDomainNetDefParseXML(caps, virDomainNetDefPtr net = virDomainNetDefParseXML(xmlopt,
nodes[i], nodes[i],
ctxt, ctxt,
bootMap, bootMap,

View File

@ -1959,6 +1959,7 @@ struct _virDomainDefParserConfig {
/* data */ /* data */
bool hasWideScsiBus; bool hasWideScsiBus;
unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
}; };
typedef struct _virDomainXMLPrivateDataCallbacks virDomainXMLPrivateDataCallbacks; typedef struct _virDomainXMLPrivateDataCallbacks virDomainXMLPrivateDataCallbacks;
@ -1974,6 +1975,8 @@ virDomainXMLOptionPtr virDomainXMLOptionNew(virDomainDefParserConfigPtr config,
virDomainXMLPrivateDataCallbacksPtr priv, virDomainXMLPrivateDataCallbacksPtr priv,
virDomainXMLNamespacePtr xmlns); virDomainXMLNamespacePtr xmlns);
void virDomainNetGenerateMAC(virDomainXMLOptionPtr xmlopt, virMacAddrPtr mac);
virDomainXMLNamespacePtr virDomainXMLNamespacePtr
virDomainXMLOptionGetNamespace(virDomainXMLOptionPtr xmlopt) virDomainXMLOptionGetNamespace(virDomainXMLOptionPtr xmlopt)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);

View File

@ -598,7 +598,6 @@ esxCapsInit(esxPrivate *priv)
return NULL; return NULL;
} }
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x0c, 0x29 });
virCapabilitiesAddHostMigrateTransport(caps, "vpxmigr"); virCapabilitiesAddHostMigrateTransport(caps, "vpxmigr");
caps->defaultConsoleTargetType = esxDefaultConsoleType; caps->defaultConsoleTargetType = esxDefaultConsoleType;

View File

@ -20,10 +20,8 @@ virCapabilitiesDefaultGuestMachine;
virCapabilitiesFormatXML; virCapabilitiesFormatXML;
virCapabilitiesFreeMachines; virCapabilitiesFreeMachines;
virCapabilitiesFreeNUMAInfo; virCapabilitiesFreeNUMAInfo;
virCapabilitiesGenerateMac;
virCapabilitiesNew; virCapabilitiesNew;
virCapabilitiesSetHostCPU; virCapabilitiesSetHostCPU;
virCapabilitiesSetMacPrefix;
# conf/cpu_conf.h # conf/cpu_conf.h
@ -240,6 +238,7 @@ virDomainMemDumpTypeToString;
virDomainNetDefFree; virDomainNetDefFree;
virDomainNetFind; virDomainNetFind;
virDomainNetFindIdx; virDomainNetFindIdx;
virDomainNetGenerateMAC;
virDomainNetGetActualBandwidth; virDomainNetGetActualBandwidth;
virDomainNetGetActualBridgeName; virDomainNetGetActualBridgeName;
virDomainNetGetActualDirectDev; virDomainNetGetActualDirectDev;

View File

@ -85,8 +85,6 @@ libxlBuildCapabilities(virArch hostarch,
if ((caps = virCapabilitiesNew(hostarch, 1, 1)) == NULL) if ((caps = virCapabilitiesNew(hostarch, 1, 1)) == NULL)
goto no_memory; goto no_memory;
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x16, 0x3e });
if (host_pae && if (host_pae &&
virCapabilitiesAddHostFeature(caps, "pae") < 0) virCapabilitiesAddHostFeature(caps, "pae") < 0)
goto no_memory; goto no_memory;

View File

@ -431,6 +431,10 @@ virDomainXMLPrivateDataCallbacks libxlDomainXMLPrivateDataCallbacks = {
.free = libxlDomainObjPrivateFree, .free = libxlDomainObjPrivateFree,
}; };
virDomainDefParserConfig libxlDomainDefParserConfig = {
.macPrefix = { 0x00, 0x16, 0x3e },
};
/* driver must be locked before calling */ /* driver must be locked before calling */
static void static void
libxlDomainEventQueue(libxlDriverPrivatePtr driver, virDomainEventPtr event) libxlDomainEventQueue(libxlDriverPrivatePtr driver, virDomainEventPtr event)
@ -1239,7 +1243,7 @@ libxlStartup(bool privileged,
goto error; goto error;
} }
if (!(libxl_driver->xmlopt = virDomainXMLOptionNew(NULL, if (!(libxl_driver->xmlopt = virDomainXMLOptionNew(&libxlDomainDefParserConfig,
&libxlDomainXMLPrivateDataCallbacks, &libxlDomainXMLPrivateDataCallbacks,
NULL))) NULL)))
goto error; goto error;

View File

@ -79,9 +79,6 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver)
goto error; goto error;
} }
/* XXX shouldn't 'borrow' KVM's prefix */
virCapabilitiesSetMacPrefix(caps, (unsigned char []){ 0x52, 0x54, 0x00 });
if ((guest = virCapabilitiesAddGuest(caps, if ((guest = virCapabilitiesAddGuest(caps,
"exe", "exe",
caps->host.arch, caps->host.arch,

View File

@ -187,8 +187,6 @@ virCapsPtr openvzCapsInit(void)
if (nodeCapsInitNUMA(caps) < 0) if (nodeCapsInitNUMA(caps) < 0)
goto no_memory; goto no_memory;
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x52, 0x54, 0x00 });
if ((guest = virCapabilitiesAddGuest(caps, if ((guest = virCapabilitiesAddGuest(caps,
"exe", "exe",
caps->host.arch, caps->host.arch,

View File

@ -832,7 +832,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
} }
virMacAddrFormat(&net->mac, macaddr); virMacAddrFormat(&net->mac, macaddr);
virCapabilitiesGenerateMac(driver->caps, &host_mac); virDomainNetGenerateMAC(driver->xmlopt, &host_mac);
virMacAddrFormat(&host_mac, host_macaddr); virMacAddrFormat(&host_mac, host_macaddr);
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE || if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||

View File

@ -129,9 +129,6 @@ parallelsBuildCapabilities(void)
if (nodeCapsInitNUMA(caps) < 0) if (nodeCapsInitNUMA(caps) < 0)
goto no_memory; goto no_memory;
virCapabilitiesSetMacPrefix(caps, (unsigned char[]) {
0x42, 0x1C, 0x00});
if ((guest = virCapabilitiesAddGuest(caps, "hvm", if ((guest = virCapabilitiesAddGuest(caps, "hvm",
VIR_ARCH_X86_64, VIR_ARCH_X86_64,
"parallels", "parallels",
@ -911,6 +908,12 @@ parallelsLoadDomains(parallelsConnPtr privconn, const char *domain_name)
return ret; return ret;
} }
virDomainDefParserConfig parallelsDomainDefParserConfig = {
.macPrefix = {0x42, 0x1C, 0x00},
};
static int static int
parallelsOpenDefault(virConnectPtr conn) parallelsOpenDefault(virConnectPtr conn)
{ {
@ -929,7 +932,8 @@ parallelsOpenDefault(virConnectPtr conn)
if (!(privconn->caps = parallelsBuildCapabilities())) if (!(privconn->caps = parallelsBuildCapabilities()))
goto error; goto error;
if (!(privconn->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL))) if (!(privconn->xmlopt = virDomainXMLOptionNew(&parallelsDomainDefParserConfig,
NULL, NULL)))
goto error; goto error;
if (!(privconn->domains = virDomainObjListNew())) if (!(privconn->domains = virDomainObjListNew()))

View File

@ -327,10 +327,6 @@ phypCapsInit(void)
("Failed to query host NUMA topology, disabling NUMA capabilities"); ("Failed to query host NUMA topology, disabling NUMA capabilities");
} }
/* XXX shouldn't 'borrow' KVM's prefix */
virCapabilitiesSetMacPrefix(caps, (unsigned char[]) {
0x52, 0x54, 0x00});
if ((guest = virCapabilitiesAddGuest(caps, if ((guest = virCapabilitiesAddGuest(caps,
"linux", "linux",
caps->host.arch, caps->host.arch,

View File

@ -876,9 +876,6 @@ virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache)
1, 1)) == NULL) 1, 1)) == NULL)
goto error; goto error;
/* Using KVM's mac prefix for QEMU too */
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x52, 0x54, 0x00 });
/* Some machines have problematic NUMA toplogy causing /* Some machines have problematic NUMA toplogy causing
* unexpected failures. We don't want to break the QEMU * unexpected failures. We don't want to break the QEMU
* driver in this scenario, so log errors & carry on * driver in this scenario, so log errors & carry on

View File

@ -8337,7 +8337,7 @@ qemuFindNICForVLAN(int nnics,
* match up against. Horribly complicated stuff * match up against. Horribly complicated stuff
*/ */
static virDomainNetDefPtr static virDomainNetDefPtr
qemuParseCommandLineNet(virCapsPtr qemuCaps, qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt,
const char *val, const char *val,
int nnics, int nnics,
const char **nics) const char **nics)
@ -8471,7 +8471,7 @@ qemuParseCommandLineNet(virCapsPtr qemuCaps,
} }
if (genmac) if (genmac)
virCapabilitiesGenerateMac(qemuCaps, &def->mac); virDomainNetGenerateMAC(xmlopt, &def->mac);
cleanup: cleanup:
for (i = 0 ; i < nkeywords ; i++) { for (i = 0 ; i < nkeywords ; i++) {
@ -9561,7 +9561,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
WANT_VALUE(); WANT_VALUE();
if (!STRPREFIX(val, "nic") && STRNEQ(val, "none")) { if (!STRPREFIX(val, "nic") && STRNEQ(val, "none")) {
virDomainNetDefPtr net; virDomainNetDefPtr net;
if (!(net = qemuParseCommandLineNet(qemuCaps, val, nnics, nics))) if (!(net = qemuParseCommandLineNet(xmlopt, val, nnics, nics)))
goto error; goto error;
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) { if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) {
virDomainNetDefFree(net); virDomainNetDefFree(net);

View File

@ -851,10 +851,16 @@ static int vboxDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED,
} }
static virDomainDefParserConfig vboxDomainDefParserConfig = {
.macPrefix = { 0x08, 0x00, 0x27 },
};
static virDomainXMLOptionPtr static virDomainXMLOptionPtr
vboxXMLConfInit(void) vboxXMLConfInit(void)
{ {
return virDomainXMLOptionNew(NULL, NULL, NULL); return virDomainXMLOptionNew(&vboxDomainDefParserConfig,
NULL, NULL);
} }
@ -870,8 +876,6 @@ static virCapsPtr vboxCapsInit(void)
if (nodeCapsInitNUMA(caps) < 0) if (nodeCapsInitNUMA(caps) < 0)
goto no_memory; goto no_memory;
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x08, 0x00, 0x27 });
if ((guest = virCapabilitiesAddGuest(caps, if ((guest = virCapabilitiesAddGuest(caps,
"hvm", "hvm",
caps->host.arch, caps->host.arch,

View File

@ -72,8 +72,6 @@ vmwareCapsInit(void)
if (nodeCapsInitNUMA(caps) < 0) if (nodeCapsInitNUMA(caps) < 0)
goto error; goto error;
virCapabilitiesSetMacPrefix(caps, (unsigned char[]) {0x52, 0x54, 0x00});
/* i686 guests are always supported */ /* i686 guests are always supported */
if ((guest = virCapabilitiesAddGuest(caps, if ((guest = virCapabilitiesAddGuest(caps,
"hvm", "hvm",

View File

@ -522,6 +522,7 @@ VIR_ENUM_IMPL(virVMXControllerModelSCSI, VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LAST,
virDomainDefParserConfig virVMXDomainDefParserConfig = { virDomainDefParserConfig virVMXDomainDefParserConfig = {
.hasWideScsiBus = true, .hasWideScsiBus = true,
.macPrefix = {0x00, 0x0c, 0x29},
}; };

View File

@ -265,6 +265,10 @@ xenUnifiedXendProbe(void)
#endif #endif
virDomainDefParserConfig xenDomainDefParserConfig = {
.macPrefix = { 0x00, 0x16, 0x3e },
};
static virDrvOpenStatus static virDrvOpenStatus
xenUnifiedOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags) xenUnifiedOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags)
@ -401,7 +405,8 @@ xenUnifiedOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags)
goto fail; goto fail;
} }
if (!(priv->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL))) if (!(priv->xmlopt = virDomainXMLOptionNew(&xenDomainDefParserConfig,
NULL, NULL)))
goto fail; goto fail;
#if WITH_XEN_INOTIFY #if WITH_XEN_INOTIFY

View File

@ -2303,8 +2303,6 @@ xenHypervisorBuildCapabilities(virConnectPtr conn, virArch hostarch,
if ((caps = virCapabilitiesNew(hostarch, 1, 1)) == NULL) if ((caps = virCapabilitiesNew(hostarch, 1, 1)) == NULL)
goto no_memory; goto no_memory;
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x16, 0x3e });
if (hvm_type && STRNEQ(hvm_type, "") && if (hvm_type && STRNEQ(hvm_type, "") &&
virCapabilitiesAddHostFeature(caps, hvm_type) < 0) virCapabilitiesAddHostFeature(caps, hvm_type) < 0)
goto no_memory; goto no_memory;

View File

@ -34,7 +34,6 @@ testCapsInit(void)
caps->defaultConsoleTargetType = testDefaultConsoleType; caps->defaultConsoleTargetType = testDefaultConsoleType;
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x0c, 0x29 });
virCapabilitiesAddHostMigrateTransport(caps, "esx"); virCapabilitiesAddHostMigrateTransport(caps, "esx");
/* i686 guest */ /* i686 guest */

View File

@ -34,7 +34,6 @@ testCapsInit(void)
caps->defaultConsoleTargetType = testDefaultConsoleType; caps->defaultConsoleTargetType = testDefaultConsoleType;
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x0c, 0x29 });
virCapabilitiesAddHostMigrateTransport(caps, "esx"); virCapabilitiesAddHostMigrateTransport(caps, "esx");