
On Tue, Dec 02, 2008 at 11:38:36AM +0000, Daniel P. Berrange wrote:
On Mon, Dec 01, 2008 at 12:23:12PM +0100, Gerd v. Egidy wrote:
Hi Daniel,
This patch alone not, but this patch + the one in my first mail (see https://www.redhat.com/archives/libvir-list/2008-November/msg00457.html) together make it work for me. The first patch fixes the autostart order, the second one adds the necessary conn structure.
Oh yes, I totally missed the patch in your first mail. The first patch is definitely correct and I'll apply that shortly.
I just added some documentation (same as in virInitialize) to make sure this bug does not get introduced again. New version attached.
While your second patch is also functionally OK, I'm not entirely happy with creating a connection object deep inside the QEMU driver code.
Yeah, that was exactly my thought too.
So I'm going to think about whether there's a better way todo that bit.
I looked through the rest of the qemu-initialization and it looks like this is the only point where the conn-object is needed. So a solution would be to directly access the network driver functions. But on the other hand these functions seem all to imply that there is a valid conn available. So we would have to change that, at least for the lookup-by-name case.
I've committed this patch now. I'll send a suggestion for the second patch shortly...
Ok, I think your suggested patch is the best we can manage at this point in time. Here's an update which also handle it for UML driver, and adds a check for NULL on connection open. Daniel Index: src/qemu_driver.c =================================================================== RCS file: /data/cvs/libvirt/src/qemu_driver.c,v retrieving revision 1.162 diff -u -p -r1.162 qemu_driver.c --- src/qemu_driver.c 28 Nov 2008 12:03:20 -0000 1.162 +++ src/qemu_driver.c 2 Dec 2008 11:52:28 -0000 @@ -138,12 +138,26 @@ static struct qemud_driver *qemu_driver static void qemudAutostartConfigs(struct qemud_driver *driver) { unsigned int i; + /* XXX: Figure out a better way todo this. The domain + * startup code needs a connection handle in order + * to lookup the bridge associated with a virtual + * network + */ + virConnectPtr conn = virConnectOpen(getuid() ? + "qemu:///session" : + "qemu:///system"); + + if (!conn) { + qemudLog(QEMUD_ERR, "%s", + _("Cannot autostart domains, failed to open connection")); + return; + } for (i = 0 ; i < driver->domains.count ; i++) { virDomainObjPtr vm = driver->domains.objs[i]; if (vm->autostart && !virDomainIsActive(vm)) { - int ret = qemudStartVMDaemon(NULL, driver, vm, NULL); + int ret = qemudStartVMDaemon(conn, driver, vm, NULL); if (ret < 0) { virErrorPtr err = virGetLastError(); qemudLog(QEMUD_ERR, _("Failed to autostart VM '%s': %s\n"), @@ -155,6 +169,8 @@ qemudAutostartConfigs(struct qemud_drive } } } + + virConnectClose(conn); } /** Index: src/uml_driver.c =================================================================== RCS file: /data/cvs/libvirt/src/uml_driver.c,v retrieving revision 1.6 diff -u -p -r1.6 uml_driver.c --- src/uml_driver.c 2 Dec 2008 11:23:27 -0000 1.6 +++ src/uml_driver.c 2 Dec 2008 11:52:28 -0000 @@ -117,16 +117,32 @@ static struct uml_driver *uml_driver = N static void umlAutostartConfigs(struct uml_driver *driver) { unsigned int i; + /* XXX: Figure out a better way todo this. The domain + * startup code needs a connection handle in order + * to lookup the bridge associated with a virtual + * network + */ + virConnectPtr conn = virConnectOpen(getuid() ? + "uml:///session" : + "uml:///system"); + + if (!conn) { + umlLog(UML_ERR, "%s", + _("Cannot autostart domains, failed to open connection")); + return; + } for (i = 0 ; i < driver->domains.count ; i++) { if (driver->domains.objs[i]->autostart && !virDomainIsActive(driver->domains.objs[i]) && - umlStartVMDaemon(NULL, driver, driver->domains.objs[i]) < 0) { + umlStartVMDaemon(conn, driver, driver->domains.objs[i]) < 0) { virErrorPtr err = virGetLastError(); umlLog(UML_ERR, _("Failed to autostart VM '%s': %s\n"), driver->domains.objs[i]->def->name, err->message); } } + + virConnectClose(conn); } -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|