On 03/01/2013 02:13 PM, Laine Stump wrote: > On 02/20/2013 12:06 PM, Peter Krempa wrote: >> This patch implements the callback that is used to fill the qemu default >> network card into the XML if none is provided in the definition. >> --- >> src/qemu/qemu_conf.c | 1 + >> src/qemu/qemu_domain.c | 23 +++++++++++++++++++++++ >> src/qemu/qemu_domain.h | 1 + >> 3 files changed, 25 insertions(+) >> >> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c >> index a2a05d4..cc6a738 100644 >> --- a/src/qemu/qemu_conf.c >> +++ b/src/qemu/qemu_conf.c >> @@ -556,6 +556,7 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) >> >> qemuDomainSetPrivateDataHooks(caps); >> qemuDomainSetNamespaceHooks(caps); >> + qemuDomainSetDefHooks(caps); >> >> if (virGetHostUUID(caps->host.host_uuid)) { >> virReportError(VIR_ERR_INTERNAL_ERROR, >> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c >> index 482f64a..7c8768b 100644 >> --- a/src/qemu/qemu_domain.c >> +++ b/src/qemu/qemu_domain.c >> @@ -633,6 +633,24 @@ qemuDomainDefNamespaceFormatXML(virBufferPtr buf, >> return 0; >> } >> >> + >> +static int >> +qemuDomainDeviceDefCallback(void *device) >> +{ >> + virDomainDeviceDefPtr dev = device; >> + >> + if (dev->type == VIR_DOMAIN_DEVICE_NET) { >> + if (!dev->data.net->model) { >> + if (!(dev->data.net->model = strdup("rtl8139"))) { >> + virReportOOMError(); >> + return -1; Also, if the net->type is hostdev, then model should not be set at all (although it is harmlessly ignored, it could be confusing). >> + } >> + } >> + } >> + return 0; >> +} > This is a good example of why the domain pointer and caps pointer are > needed in the callback. The default netdev model cuold very well change > depending on which hypervisor is used, the version/capabilities of the > hypervisor, and the machinetype. > >> + >> + >> static const char * >> qemuDomainDefNamespaceHref(void) >> { >> @@ -659,6 +677,11 @@ void qemuDomainSetNamespaceHooks(virCapsPtr caps) >> caps->ns.href = qemuDomainDefNamespaceHref; >> } >> >> +void qemuDomainSetDefHooks(virCapsPtr caps) >> +{ >> + caps->virDriverDeviceDefCallback = qemuDomainDeviceDefCallback; >> +} >> + >> static void >> qemuDomainObjSaveJob(virQEMUDriverPtr driver, virDomainObjPtr obj) >> { >> diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h >> index 905b099..210cffd 100644 >> --- a/src/qemu/qemu_domain.h >> +++ b/src/qemu/qemu_domain.h >> @@ -180,6 +180,7 @@ void qemuDomainEventQueue(virQEMUDriverPtr driver, >> >> void qemuDomainSetPrivateDataHooks(virCapsPtr caps); >> void qemuDomainSetNamespaceHooks(virCapsPtr caps); >> +void qemuDomainSetDefHooks(virCapsPtr caps); >> >> int qemuDomainObjBeginJob(virQEMUDriverPtr driver, >> virDomainObjPtr obj, > -- > libvir-list mailing list > libvir-list@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/libvir-list > -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list