virCaps: get rid of emulatorRequired

This patch removes the emulatorRequired field and associated
infrastructure from the virCaps object. Instead the driver specific
callbacks are used as this field isn't enforced by all drivers.

This patch implements the appropriate callbacks in the qemu and lxc
driver and moves to check to that location.
This commit is contained in:
Peter Krempa 2013-03-11 12:12:08 +01:00
parent 9ea249e7d9
commit b5def001cc
12 changed files with 47 additions and 36 deletions

View File

@ -935,13 +935,3 @@ virCapabilitiesGenerateMac(virCapsPtr caps,
{ {
virMacAddrGenerate(caps->macPrefix, mac); virMacAddrGenerate(caps->macPrefix, mac);
} }
extern void
virCapabilitiesSetEmulatorRequired(virCapsPtr caps) {
caps->emulatorRequired = 1;
}
extern unsigned int
virCapabilitiesIsEmulatorRequired(virCapsPtr caps) {
return caps->emulatorRequired;
}

View File

@ -163,7 +163,6 @@ struct _virCaps {
/* Move to virDomainXMLOption later */ /* Move to virDomainXMLOption later */
unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN]; unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
unsigned int emulatorRequired : 1;
int defaultDiskDriverType; /* enum virStorageFileFormat */ int defaultDiskDriverType; /* enum virStorageFileFormat */
int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch); int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch);
bool hasWideScsiBus; bool hasWideScsiBus;
@ -186,12 +185,6 @@ extern void
virCapabilitiesGenerateMac(virCapsPtr caps, virCapabilitiesGenerateMac(virCapsPtr caps,
virMacAddrPtr mac); virMacAddrPtr mac);
extern void
virCapabilitiesSetEmulatorRequired(virCapsPtr caps);
extern unsigned int
virCapabilitiesIsEmulatorRequired(virCapsPtr caps);
extern int extern int
virCapabilitiesAddHostFeature(virCapsPtr caps, virCapabilitiesAddHostFeature(virCapsPtr caps,
const char *name); const char *name);

View File

@ -9165,8 +9165,10 @@ virDomainLeaseRemove(virDomainDefPtr def,
} }
static char *virDomainDefDefaultEmulator(virDomainDefPtr def, char *
virCapsPtr caps) { virDomainDefGetDefaultEmulator(virDomainDefPtr def,
virCapsPtr caps)
{
const char *type; const char *type;
const char *emulator; const char *emulator;
char *retemu; char *retemu;
@ -9185,13 +9187,13 @@ static char *virDomainDefDefaultEmulator(virDomainDefPtr def,
if (!emulator) { if (!emulator) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("no emulator for domain %s os type %s on architecture %s"), _("no emulator for domain %s os type %s "
"on architecture %s"),
type, def->os.type, virArchToString(def->os.arch)); type, def->os.type, virArchToString(def->os.arch));
return NULL; return NULL;
} }
retemu = strdup(emulator); if (!(retemu = strdup(emulator)))
if (!retemu)
virReportOOMError(); virReportOOMError();
return retemu; return retemu;
@ -10385,11 +10387,6 @@ virDomainDefParseXML(xmlDocPtr xml,
} }
def->emulator = virXPathString("string(./devices/emulator[1])", ctxt); def->emulator = virXPathString("string(./devices/emulator[1])", ctxt);
if (!def->emulator && virCapabilitiesIsEmulatorRequired(caps)) {
def->emulator = virDomainDefDefaultEmulator(def, caps);
if (!def->emulator)
goto error;
}
/* analysis of the disk devices */ /* analysis of the disk devices */
if ((n = virXPathNodeSet("./devices/disk", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./devices/disk", ctxt, &nodes)) < 0)

View File

@ -2476,4 +2476,6 @@ int virDomainObjListExport(virDomainObjListPtr doms,
virDomainVcpuPinDefPtr virDomainLookupVcpuPin(virDomainDefPtr def, virDomainVcpuPinDefPtr virDomainLookupVcpuPin(virDomainDefPtr def,
int vcpuid); int vcpuid);
char *virDomainDefGetDefaultEmulator(virDomainDefPtr def, virCapsPtr caps);
#endif /* __DOMAIN_CONF_H */ #endif /* __DOMAIN_CONF_H */

View File

@ -21,9 +21,7 @@ virCapabilitiesFormatXML;
virCapabilitiesFreeMachines; virCapabilitiesFreeMachines;
virCapabilitiesFreeNUMAInfo; virCapabilitiesFreeNUMAInfo;
virCapabilitiesGenerateMac; virCapabilitiesGenerateMac;
virCapabilitiesIsEmulatorRequired;
virCapabilitiesNew; virCapabilitiesNew;
virCapabilitiesSetEmulatorRequired;
virCapabilitiesSetHostCPU; virCapabilitiesSetHostCPU;
virCapabilitiesSetMacPrefix; virCapabilitiesSetMacPrefix;
@ -118,6 +116,7 @@ virDomainDefFormat;
virDomainDefFormatInternal; virDomainDefFormatInternal;
virDomainDefFree; virDomainDefFree;
virDomainDefGenSecurityLabelDef; virDomainDefGenSecurityLabelDef;
virDomainDefGetDefaultEmulator;
virDomainDefGetSecurityLabelDef; virDomainDefGetSecurityLabelDef;
virDomainDefParseFile; virDomainDefParseFile;
virDomainDefParseNode; virDomainDefParseNode;

View File

@ -119,9 +119,6 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver)
goto error; goto error;
} }
/* LXC Requires an emulator in the XML */
virCapabilitiesSetEmulatorRequired(caps);
if (driver) { if (driver) {
/* Security driver data */ /* Security driver data */
const char *doi, *model; const char *doi, *model;
@ -159,11 +156,12 @@ error:
virDomainXMLOptionPtr virDomainXMLOptionPtr
lxcDomainXMLConfInit(void) lxcDomainXMLConfInit(void)
{ {
return virDomainXMLOptionNew(NULL, return virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig,
&virLXCDriverPrivateDataCallbacks, &virLXCDriverPrivateDataCallbacks,
NULL); NULL);
} }
int lxcLoadDriverConfig(virLXCDriverPtr driver) int lxcLoadDriverConfig(virLXCDriverPtr driver)
{ {
char *filename; char *filename;

View File

@ -79,3 +79,20 @@ virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks = {
.format = virLXCDomainObjPrivateXMLFormat, .format = virLXCDomainObjPrivateXMLFormat,
.parse = virLXCDomainObjPrivateXMLParse, .parse = virLXCDomainObjPrivateXMLParse,
}; };
static int
virLXCDomainDefPostParse(virDomainDefPtr def,
virCapsPtr caps,
void *opaque ATTRIBUTE_UNUSED)
{
/* check for emulator and create a default one if needed */
if (!def->emulator &&
!(def->emulator = virDomainDefGetDefaultEmulator(def, caps)))
return -1;
return 0;
}
virDomainDefParserConfig virLXCDriverDomainDefParserConfig = {
.domainPostParseCallback = virLXCDomainDefPostParse,
};

View File

@ -39,5 +39,6 @@ struct _virLXCDomainObjPrivate {
}; };
extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks; extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks;
extern virDomainDefParserConfig virLXCDriverDomainDefParserConfig;
#endif /* __LXC_DOMAIN_H__ */ #endif /* __LXC_DOMAIN_H__ */

View File

@ -909,9 +909,6 @@ virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache)
i) < 0) i) < 0)
goto error; goto error;
/* QEMU Requires an emulator in the XML */
virCapabilitiesSetEmulatorRequired(caps);
caps->defaultConsoleTargetType = virQEMUCapsDefaultConsoleType; caps->defaultConsoleTargetType = virQEMUCapsDefaultConsoleType;
return caps; return caps;

View File

@ -662,6 +662,20 @@ virDomainXMLNamespace virQEMUDriverDomainXMLNamespace = {
}; };
static int
qemuDomainDefPostParse(virDomainDefPtr def,
virCapsPtr caps,
void *opaque ATTRIBUTE_UNUSED)
{
/* check for emulator and create a default one if needed */
if (!def->emulator &&
!(def->emulator = virDomainDefGetDefaultEmulator(def, caps)))
return -1;
return 0;
}
static int static int
qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
virDomainDefPtr def ATTRIBUTE_UNUSED, virDomainDefPtr def ATTRIBUTE_UNUSED,
@ -703,6 +717,7 @@ no_memory:
virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = { virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = {
.devicesPostParseCallback = qemuDomainDeviceDefPostParse, .devicesPostParseCallback = qemuDomainDeviceDefPostParse,
.domainPostParseCallback = qemuDomainDefPostParse,
}; };

View File

@ -13,6 +13,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/root/container'/> <source dir='/root/container'/>
<target dir='/'/> <target dir='/'/>

View File

@ -15,6 +15,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/root/container'/> <source dir='/root/container'/>
<target dir='/'/> <target dir='/'/>