[libvirt] KVM/qemu: problems with autostart of vms with non-bridged nets

Gerd von Egidy lists at egidy.de
Mon Dec 1 01:07:37 UTC 2008


Hi,

> 2. missing virConnectPtr during autostart of the vm:
>
> in src/qemu_driver.c:145, qemudAutostartConfigs() you can find this call:
> int ret = qemudStartVMDaemon(NULL, driver, vm, NULL);
>
> This means virConnectPtr conn is NULL within qemudStartVMDaemon().
> Following the calls:
> qemudStartVMDaemon()
> -> qemudBuildCommandLine()
> -> qemudNetworkIfaceConnect()
> -> virNetworkLookupByName()
>
> virNetworkLookupByName bails out if called with invalid virConnectPtr. This
> means starting this vm fails.

I came up with the attached patch to fix this for me, but
a) I'm not sure if it is a clean use of the api to call virConnectOpen() from 
   within a state-initializer function
b) This is just for qemu/kvm, I haven't looked at any other drivers

It would be nice if an experienced libvirt-developer could take a look at
this. Thank you very much.

Kind regards,

Gerd


diff -r -u libvirt-0.5.0.orig/src/qemu_driver.c libvirt-0.5.0/src/qemu_driver.c
--- libvirt-0.5.0.orig/src/qemu_driver.c	2008-11-21 13:47:32.000000000 +0100
+++ libvirt-0.5.0/src/qemu_driver.c	2008-12-01 01:49:16.000000000 +0100
@@ -138,11 +138,14 @@
 qemudAutostartConfigs(struct qemud_driver *driver) {
     unsigned int i;
 
+    /* we need a valid virConnectPtr for qemudStartVMDaemon to be able to connect to other drivers */
+    virConnectPtr conn=virConnectOpen(getuid() ? "qemu:///session" : "qemu:///system");
+
     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"),
@@ -154,6 +157,8 @@
             }
         }
     }
+
+    virConnectClose(conn);
 }
 
 /**
-- 
Address (better: trap) for people I really don't want to get mail from:
james at cactusamerica.com




More information about the libvir-list mailing list