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

Gerd von Egidy lists at egidy.de
Sun Nov 30 23:24:58 UTC 2008


I'm using libvirt 0.5.0 to manage my kvm domains. Everything works fine except 
autostarting vms which use a network device not directly bridged to hw. I 
have the following net defined (and set to autostart):

  <bridge stp='on' forwardDelay='0' />
  <ip address='' netmask=''>
      <range start='' end='' />

When a vm using this net is autostarted I get the following error:

libvir: error : invalid connection pointer in virNetworkLookupByName
libvir: QEMU error : internal error Network 'local' not found
Failed to autostart VM 'testlocalnet': internal error Network 'local' not 

I took a dive into the code and found two problems causing this:

1. initialization order: 

qemuStateDriver is registered (and thus initialized) before 
networkStateDriver. This means the network is not up yet when qemu does it's 

I could fix this with the attached patch.

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:
-> qemudBuildCommandLine()
-> qemudNetworkIfaceConnect()
-> virNetworkLookupByName()

virNetworkLookupByName bails out if called with invalid virConnectPtr. This 
means starting this vm fails.

Currently I'm not familiar enough with the libvirt structures to come up with 
an idea how to fix this. 

Could anybody with a deeper knowledge of the code take a look at this? Thank 
you very much.

Kind regards,


diff -r -u libvirt-0.5.0.orig/qemud/qemud.c libvirt-0.5.0/qemud/qemud.c
--- libvirt-0.5.0.orig/qemud/qemud.c	2008-11-21 13:47:32.000000000 +0100
+++ libvirt-0.5.0/qemud/qemud.c	2008-11-30 21:27:06.000000000 +0100
@@ -761,22 +761,13 @@
      * If they try to use a open a connection for a module that
      * is not loaded they'll get a suitable error at that point
-    virDriverLoadModule("qemu");
-    virDriverLoadModule("lxc");
-    virDriverLoadModule("uml");
+    virDriverLoadModule("qemu");
+    virDriverLoadModule("lxc");
+    virDriverLoadModule("uml");
-#ifdef WITH_QEMU
-    qemuRegister();
-#ifdef WITH_LXC
-    lxcRegister();
-#ifdef WITH_UML
-    umlRegister();
@@ -786,6 +777,15 @@
 #if defined(HAVE_HAL) || defined(HAVE_DEVKIT)
+#ifdef WITH_QEMU
+    qemuRegister();
+#ifdef WITH_LXC
+    lxcRegister();
+#ifdef WITH_UML
+    umlRegister();
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