Set default emulator in domain_conf.*, rather than the driver.

Rather than numerous instances of:

emulator = vm->def->emulator;
if (!emulator)
    emulator = virDomainDefDefaultEmulator(conn, vm->def, driver->caps);
if (!emulator)
    return -1;

Set this value at XML parse time in the domain config, so we can depend on
it for all future emulator accesses. There were unchecked accesses in the
qemu driver that were tripping up on this if no emulator was specified in
the XML, see:

http://www.redhat.com/archives/libvir-list/2008-October/msg00602.html
This commit is contained in:
Cole Robinson 2009-06-16 15:42:46 +00:00
parent 3f63c44d12
commit 53603043c7
7 changed files with 44 additions and 51 deletions

View File

@ -1,3 +1,9 @@
Tue Jun 16 11:33:54 EDT 2009 Cole Robinson <crobinso@redhat.com>
* src/domain_conf.c src/domain_conf.h src/libvirt_private.syms
src/lxc_driver.c src/qemu_conf.c src/qemu_driver.c:
Set default emulator in domain_conf.*, rather than the driver.
Tue Jun 16 11:18:00 EDT 2009 Cole Robinson <crobinso@redhat.com> Tue Jun 16 11:18:00 EDT 2009 Cole Robinson <crobinso@redhat.com>
* src/capabilities.c src/capabilities.h src/libvirt_private.syms * src/capabilities.c src/capabilities.h src/libvirt_private.syms

View File

@ -2109,6 +2109,39 @@ int virDomainDiskQSort(const void *a, const void *b)
} }
#ifndef PROXY #ifndef PROXY
static char *virDomainDefDefaultEmulator(virConnectPtr conn,
virDomainDefPtr def,
virCapsPtr caps) {
const char *type;
const char *emulator;
char *retemu;
type = virDomainVirtTypeToString(def->virtType);
if (!type) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("unknown virt type"));
return NULL;
}
emulator = virCapabilitiesDefaultGuestEmulator(caps,
def->os.type,
def->os.arch,
type);
if (!emulator) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
_("no emulator for domain %s os type %s on architecture %s"),
type, def->os.type, def->os.arch);
return NULL;
}
retemu = strdup(emulator);
if (!retemu)
virReportOOMError(conn);
return retemu;
}
static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
xmlXPathContextPtr ctxt, int flags) xmlXPathContextPtr ctxt, int flags)
@ -2358,6 +2391,11 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
} }
def->emulator = virXPathString(conn, "string(./devices/emulator[1])", ctxt); def->emulator = virXPathString(conn, "string(./devices/emulator[1])", ctxt);
if (!def->emulator && virCapabilitiesIsEmulatorRequired(caps)) {
def->emulator = virDomainDefDefaultEmulator(conn, def, caps);
if (!def->emulator)
goto error;
}
/* analysis of the disk devices */ /* analysis of the disk devices */
if ((n = virXPathNodeSet(conn, "./devices/disk", ctxt, &nodes)) < 0) { if ((n = virXPathNodeSet(conn, "./devices/disk", ctxt, &nodes)) < 0) {
@ -4230,34 +4268,6 @@ int virDiskNameToBusDeviceIndex(const virDomainDiskDefPtr disk,
return 0; return 0;
} }
const char *virDomainDefDefaultEmulator(virConnectPtr conn,
virDomainDefPtr def,
virCapsPtr caps) {
const char *type;
const char *emulator;
type = virDomainVirtTypeToString(def->virtType);
if (!type) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("unknown virt type"));
return NULL;
}
emulator = virCapabilitiesDefaultGuestEmulator(caps,
def->os.type,
def->os.arch,
type);
if (!emulator) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
_("no emulator for domain %s os type %s on architecture %s"),
type, def->os.type, def->os.arch);
return NULL;
}
return emulator;
}
virDomainFSDefPtr virDomainGetRootFilesystem(virDomainDefPtr def) virDomainFSDefPtr virDomainGetRootFilesystem(virDomainDefPtr def)
{ {
int i; int i;

View File

@ -665,10 +665,6 @@ int virDiskNameToBusDeviceIndex(virDomainDiskDefPtr disk,
int *busIdx, int *busIdx,
int *devIdx); int *devIdx);
const char *virDomainDefDefaultEmulator(virConnectPtr conn,
virDomainDefPtr def,
virCapsPtr caps);
virDomainFSDefPtr virDomainGetRootFilesystem(virDomainDefPtr def); virDomainFSDefPtr virDomainGetRootFilesystem(virDomainDefPtr def);
void virDomainObjLock(virDomainObjPtr obj); void virDomainObjLock(virDomainObjPtr obj);

View File

@ -65,7 +65,6 @@ virDomainCpuSetParse;
virDomainChrDefFree; virDomainChrDefFree;
virDomainChrTypeFromString; virDomainChrTypeFromString;
virDomainChrTypeToString; virDomainChrTypeToString;
virDomainDefDefaultEmulator;
virDomainDefFormat; virDomainDefFormat;
virDomainDefFree; virDomainDefFree;
virDomainDefParseFile; virDomainDefParseFile;

View File

@ -758,7 +758,6 @@ static int lxcControllerStart(virConnectPtr conn,
fd_set keepfd; fd_set keepfd;
char appPtyStr[30]; char appPtyStr[30];
const char *emulator; const char *emulator;
lxc_driver_t *driver = conn->privateData;
FD_ZERO(&keepfd); FD_ZERO(&keepfd);
@ -787,10 +786,6 @@ static int lxcControllerStart(virConnectPtr conn,
snprintf(appPtyStr, sizeof(appPtyStr), "%d", appPty); snprintf(appPtyStr, sizeof(appPtyStr), "%d", appPty);
emulator = vm->def->emulator; emulator = vm->def->emulator;
if (!emulator)
emulator = virDomainDefDefaultEmulator(conn, vm->def, driver->caps);
if (!emulator)
return -1;
ADD_ARG_LIT(emulator); ADD_ARG_LIT(emulator);
ADD_ARG_LIT("--name"); ADD_ARG_LIT("--name");

View File

@ -920,11 +920,6 @@ int qemudBuildCommandLine(virConnectPtr conn,
} }
emulator = def->emulator; emulator = def->emulator;
if (!emulator)
emulator = virDomainDefDefaultEmulator(conn, def, driver->caps);
if (!emulator)
return -1;
/* Need to explicitly disable KQEMU if /* Need to explicitly disable KQEMU if
* 1. Arch matches host arch * 1. Arch matches host arch

View File

@ -1377,10 +1377,6 @@ static int qemudStartVMDaemon(virConnectPtr conn,
goto cleanup; goto cleanup;
emulator = vm->def->emulator; emulator = vm->def->emulator;
if (!emulator)
emulator = virDomainDefDefaultEmulator(conn, vm->def, driver->caps);
if (!emulator)
goto cleanup;
/* Make sure the binary we are about to try exec'ing exists. /* Make sure the binary we are about to try exec'ing exists.
* Technically we could catch the exec() failure, but that's * Technically we could catch the exec() failure, but that's
@ -3425,10 +3421,6 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
def->graphics[i]->data.vnc.port = 5900; def->graphics[i]->data.vnc.port = 5900;
} }
emulator = def->emulator; emulator = def->emulator;
if (!emulator)
emulator = virDomainDefDefaultEmulator(conn, def, driver->caps);
if (!emulator)
goto cleanup;
/* Make sure the binary we are about to try exec'ing exists. /* Make sure the binary we are about to try exec'ing exists.
* Technically we could catch the exec() failure, but that's * Technically we could catch the exec() failure, but that's