[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libvir] PATCH 6/9: Split qemud_server struct in two



This is a very big patch, but actually there is no real functional change
in it at all. It is splitting the qemud_server struct into 2 pieces. The
qemud_server struct now only deals with client/server socket stuff. The
new  qemud_driver struct deals with QEMU vms and networks. The driver.c
and conf.c files are now 100% independant of the QEMU daemon, and so ready
for the final adaption to the libvirt driver API.

 conf.c     |  192 ++++++++---------
 conf.h     |   30 +-
 dispatch.c |  295 +++++++++++----------------
 driver.c   |  657 ++++++++++++++++++++++++++++++++++---------------------------
 driver.h   |  335 ++++++++++++++++++++++++++-----
 internal.h |  237 ----------------------
 qemud.c    |   50 ----
 7 files changed, 909 insertions(+), 887 deletions(-)


Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
diff -r af6d5f54a13a qemud/conf.c
--- a/qemud/conf.c	Sun Jun 17 22:11:10 2007 -0400
+++ b/qemud/conf.c	Sun Jun 17 22:11:17 2007 -0400
@@ -183,7 +183,7 @@ static const char *qemudDefaultBinaryFor
 }
 
 /* Find the fully qualified path to the binary for an architecture */
-static char *qemudLocateBinaryForArch(struct qemud_server *server,
+static char *qemudLocateBinaryForArch(struct qemud_driver *driver,
                                       int virtType, const char *arch) {
     const char *name;
     char *path;
@@ -303,14 +303,14 @@ static int qemudExtractVersionInfo(const
     }
 }
 
-int qemudExtractVersion(struct qemud_server *server) {
+int qemudExtractVersion(struct qemud_driver *driver) {
     char *binary = NULL;
     struct stat sb;
 
-    if (server->qemuVersion > 0)
+    if (driver->qemuVersion > 0)
         return 0;
 
-    if (!(binary = qemudLocateBinaryForArch(server, QEMUD_VIRT_QEMU, "i686")))
+    if (!(binary = qemudLocateBinaryForArch(driver, QEMUD_VIRT_QEMU, "i686")))
         return -1;
 
     if (stat(binary, &sb) < 0) {
@@ -321,7 +321,7 @@ int qemudExtractVersion(struct qemud_ser
         return -1;
     }
 
-    if (qemudExtractVersionInfo(binary, &server->qemuVersion, &server->qemuCmdFlags) < 0) {
+    if (qemudExtractVersionInfo(binary, &driver->qemuVersion, &driver->qemuCmdFlags) < 0) {
         free(binary);
         return -1;
     }
@@ -332,7 +332,7 @@ int qemudExtractVersion(struct qemud_ser
 
 
 /* Parse the XML definition for a disk */
-static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_server *server,
+static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_driver *driver,
                                                    xmlNodePtr node) {
     struct qemud_vm_disk_def *disk = calloc(1, sizeof(struct qemud_vm_disk_def));
     xmlNodePtr cur;
@@ -469,7 +469,7 @@ static void qemudRandomMAC(struct qemud_
 
 
 /* Parse the XML definition for a network interface */
-static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_server *server,
+static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driver,
                                                        xmlNodePtr node) {
     struct qemud_vm_net_def *net = calloc(1, sizeof(struct qemud_vm_net_def));
     xmlNodePtr cur;
@@ -723,7 +723,7 @@ static struct qemud_vm_net_def *qemudPar
  * Parses a libvirt XML definition of a guest, and populates the
  * the qemud_vm struct with matching data about the guests config
  */
-static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
+static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
                                           xmlDocPtr xml) {
     xmlNodePtr root = NULL;
     xmlChar *prop = NULL;
@@ -1006,7 +1006,7 @@ static struct qemud_vm_def *qemudParseXM
     obj = xmlXPathEval(BAD_CAST "string(/domain/devices/emulator[1])", ctxt);
     if ((obj == NULL) || (obj->type != XPATH_STRING) ||
         (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
-        char *tmp = qemudLocateBinaryForArch(server, def->virtType, def->os.arch);
+        char *tmp = qemudLocateBinaryForArch(driver, def->virtType, def->os.arch);
         if (!tmp) {
             goto error;
         }
@@ -1054,7 +1054,7 @@ static struct qemud_vm_def *qemudParseXM
         struct qemud_vm_disk_def *prev = NULL;
         for (i = 0; i < obj->nodesetval->nodeNr; i++) {
             struct qemud_vm_disk_def *disk;
-            if (!(disk = qemudParseDiskXML(server, obj->nodesetval->nodeTab[i]))) {
+            if (!(disk = qemudParseDiskXML(driver, obj->nodesetval->nodeTab[i]))) {
                 goto error;
             }
             def->ndisks++;
@@ -1077,7 +1077,7 @@ static struct qemud_vm_def *qemudParseXM
         struct qemud_vm_net_def *prev = NULL;
         for (i = 0; i < obj->nodesetval->nodeNr; i++) {
             struct qemud_vm_net_def *net;
-            if (!(net = qemudParseInterfaceXML(server, obj->nodesetval->nodeTab[i]))) {
+            if (!(net = qemudParseInterfaceXML(driver, obj->nodesetval->nodeTab[i]))) {
                 goto error;
             }
             def->nnets++;
@@ -1108,7 +1108,7 @@ static struct qemud_vm_def *qemudParseXM
 
 
 static char *
-qemudNetworkIfaceConnect(struct qemud_server *server,
+qemudNetworkIfaceConnect(struct qemud_driver *driver,
                          struct qemud_vm *vm,
                          struct qemud_vm_net_def *net,
                          int vlan)
@@ -1123,7 +1123,7 @@ qemudNetworkIfaceConnect(struct qemud_se
     int *tapfds;
 
     if (net->type == QEMUD_NET_NETWORK) {
-        if (!(network = qemudFindNetworkByName(server, net->dst.network.name))) {
+        if (!(network = qemudFindNetworkByName(driver, net->dst.network.name))) {
             qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "Network '%s' not found", net->dst.network.name);
             goto error;
@@ -1151,13 +1151,13 @@ qemudNetworkIfaceConnect(struct qemud_se
         goto error;
     }
 
-    if (!server->brctl && (err = brInit(&server->brctl))) {
+    if (!driver->brctl && (err = brInit(&driver->brctl))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "cannot initialize bridge support: %s", strerror(err));
         goto error;
     }
 
-    if ((err = brAddTap(server->brctl, brname,
+    if ((err = brAddTap(driver->brctl, brname,
                         ifname, BR_IFNAME_MAXLEN, &tapfd))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "Failed to add tap interface '%s' to bridge '%s' : %s",
@@ -1193,7 +1193,7 @@ qemudNetworkIfaceConnect(struct qemud_se
  * Constructs a argv suitable for launching qemu with config defined
  * for a given virtual machine.
  */
-int qemudBuildCommandLine(struct qemud_server *server,
+int qemudBuildCommandLine(struct qemud_driver *driver,
                           struct qemud_vm *vm,
                           char ***argv) {
     int len, n = -1, i;
@@ -1206,7 +1206,7 @@ int qemudBuildCommandLine(struct qemud_s
     struct utsname ut;
     int disableKQEMU = 0;
 
-    if (qemudExtractVersion(server) < 0)
+    if (qemudExtractVersion(driver) < 0)
         return -1;
 
     uname(&ut);
@@ -1223,7 +1223,7 @@ int qemudBuildCommandLine(struct qemud_s
      * 2. Guest is 'qemu'
      * 3. The qemu binary has the -no-kqemu flag
      */
-    if ((server->qemuCmdFlags & QEMUD_CMD_FLAG_KQEMU) &&
+    if ((driver->qemuCmdFlags & QEMUD_CMD_FLAG_KQEMU) &&
         !strcmp(ut.machine, vm->def->os.arch) &&
         vm->def->virtType == QEMUD_VIRT_QEMU)
         disableKQEMU = 1;
@@ -1248,7 +1248,7 @@ int qemudBuildCommandLine(struct qemud_s
         2 + /* cpus */
         2 + /* boot device */
         2 + /* monitor */
-        (server->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
+        (driver->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
          vm->def->noReboot ? 1 : 0) + /* no-reboot */
         (vm->def->features & QEMUD_FEATURE_ACPI ? 0 : 1) + /* acpi */
         (vm->def->os.kernel[0] ? 2 : 0) + /* kernel */
@@ -1286,7 +1286,7 @@ int qemudBuildCommandLine(struct qemud_s
     if (!((*argv)[++n] = strdup("pty")))
         goto no_memory;
 
-    if (server->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
+    if (driver->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
         vm->def->noReboot) {
         if (!((*argv)[++n] = strdup("-no-reboot")))
             goto no_memory;
@@ -1387,7 +1387,7 @@ int qemudBuildCommandLine(struct qemud_s
             switch (net->type) {
             case QEMUD_NET_NETWORK:
             case QEMUD_NET_BRIDGE:
-                if (!((*argv)[++n] = qemudNetworkIfaceConnect(server, vm, net, vlan)))
+                if (!((*argv)[++n] = qemudNetworkIfaceConnect(driver, vm, net, vlan)))
                     goto error;
                 break;
 
@@ -1455,7 +1455,7 @@ int qemudBuildCommandLine(struct qemud_s
         char port[10];
         int ret;
         ret = snprintf(port, sizeof(port),
-                       ((server->qemuCmdFlags & QEMUD_CMD_FLAG_VNC_COLON) ?
+                       ((driver->qemuCmdFlags & QEMUD_CMD_FLAG_VNC_COLON) ?
                         ":%d" : "%d"),
                        vm->def->vncActivePort - 5900);
         if (ret < 0 || ret >= (int)sizeof(port))
@@ -1496,14 +1496,14 @@ int qemudBuildCommandLine(struct qemud_s
 
 
 /* Save a guest's config data into a persistent file */
-static int qemudSaveConfig(struct qemud_server *server,
+static int qemudSaveConfig(struct qemud_driver *driver,
                            struct qemud_vm *vm,
                            struct qemud_vm_def *def) {
     char *xml;
     int fd = -1, ret = -1;
     int towrite;
 
-    if (!(xml = qemudGenerateXML(server, vm, def, 0)))
+    if (!(xml = qemudGenerateXML(driver, vm, def, 0)))
         return -1;
 
     if ((fd = open(vm->configFile,
@@ -1542,7 +1542,7 @@ static int qemudSaveConfig(struct qemud_
 }
 
 struct qemud_vm_def *
-qemudParseVMDef(struct qemud_server *server,
+qemudParseVMDef(struct qemud_driver *driver,
                 const char *xmlStr,
                 const char *displayName) {
     xmlDocPtr xml;
@@ -1555,7 +1555,7 @@ qemudParseVMDef(struct qemud_server *ser
         return NULL;
     }
 
-    def = qemudParseXML(server, xml);
+    def = qemudParseXML(driver, xml);
 
     xmlFreeDoc(xml);
 
@@ -1563,12 +1563,12 @@ qemudParseVMDef(struct qemud_server *ser
 }
 
 struct qemud_vm *
-qemudAssignVMDef(struct qemud_server *server,
+qemudAssignVMDef(struct qemud_driver *driver,
                  struct qemud_vm_def *def)
 {
     struct qemud_vm *vm = NULL;
 
-    if ((vm = qemudFindVMByName(server, def->name))) {
+    if ((vm = qemudFindVMByName(driver, def->name))) {
         if (!qemudIsActiveVM(vm)) {
             qemudFreeVMDef(vm->def);
             vm->def = def;
@@ -1593,21 +1593,21 @@ qemudAssignVMDef(struct qemud_server *se
     vm->id = -1;
     vm->state = QEMUD_STATE_STOPPED;
     vm->def = def;
-    vm->next = server->vms;
-
-    server->vms = vm;
-    server->ninactivevms++;
+    vm->next = driver->vms;
+
+    driver->vms = vm;
+    driver->ninactivevms++;
 
     return vm;
 }
 
 void
-qemudRemoveInactiveVM(struct qemud_server *server,
+qemudRemoveInactiveVM(struct qemud_driver *driver,
                       struct qemud_vm *vm)
 {
     struct qemud_vm *prev = NULL, *curr;
 
-    curr = server->vms;
+    curr = driver->vms;
     while (curr != vm) {
         prev = curr;
         curr = curr->next;
@@ -1617,36 +1617,36 @@ qemudRemoveInactiveVM(struct qemud_serve
         if (prev)
             prev->next = curr->next;
         else
-            server->vms = curr->next;
-
-        server->ninactivevms--;
+            driver->vms = curr->next;
+
+        driver->ninactivevms--;
     }
 
     qemudFreeVM(vm);
 }
 
 int
-qemudSaveVMDef(struct qemud_server *server,
+qemudSaveVMDef(struct qemud_driver *driver,
                struct qemud_vm *vm,
                struct qemud_vm_def *def) {
     if (vm->configFile[0] == '\0') {
         int err;
 
-        if ((err = qemudEnsureDir(server->configDir))) {
+        if ((err = qemudEnsureDir(driver->configDir))) {
             qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "cannot create config directory %s: %s",
-                             server->configDir, strerror(err));
+                             driver->configDir, strerror(err));
             return -1;
         }
 
-        if (qemudMakeConfigPath(server->configDir, def->name, ".xml",
+        if (qemudMakeConfigPath(driver->configDir, def->name, ".xml",
                                 vm->configFile, PATH_MAX) < 0) {
             qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "cannot construct config file path");
             return -1;
         }
 
-        if (qemudMakeConfigPath(server->autostartDir, def->name, ".xml",
+        if (qemudMakeConfigPath(driver->autostartDir, def->name, ".xml",
                                 vm->autostartLink, PATH_MAX) < 0) {
             qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "cannot construct autostart link path");
@@ -1655,10 +1655,10 @@ qemudSaveVMDef(struct qemud_server *serv
         }
     }
 
-    return qemudSaveConfig(server, vm, def);
-}
-
-static int qemudSaveNetworkConfig(struct qemud_server *server,
+    return qemudSaveConfig(driver, vm, def);
+}
+
+static int qemudSaveNetworkConfig(struct qemud_driver *driver,
                                   struct qemud_network *network,
                                   struct qemud_network_def *def) {
     char *xml;
@@ -1666,14 +1666,14 @@ static int qemudSaveNetworkConfig(struct
     int towrite;
     int err;
 
-    if (!(xml = qemudGenerateNetworkXML(server, network, def))) {
+    if (!(xml = qemudGenerateNetworkXML(driver, network, def))) {
         return -1;
     }
 
-    if ((err = qemudEnsureDir(server->networkConfigDir))) {
+    if ((err = qemudEnsureDir(driver->networkConfigDir))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "cannot create config directory %s: %s",
-                         server->networkConfigDir, strerror(err));
+                         driver->networkConfigDir, strerror(err));
         goto cleanup;
     }
 
@@ -1727,7 +1727,7 @@ void qemudFreeNetwork(struct qemud_netwo
     free(network);
 }
 
-static int qemudParseBridgeXML(struct qemud_server *server ATTRIBUTE_UNUSED,
+static int qemudParseBridgeXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
                                struct qemud_network_def *def,
                                xmlNodePtr node) {
     xmlChar *name, *stp, *delay;
@@ -1759,7 +1759,7 @@ static int qemudParseBridgeXML(struct qe
     return 1;
 }
 
-static int qemudParseDhcpRangesXML(struct qemud_server *server,
+static int qemudParseDhcpRangesXML(struct qemud_driver *driver,
                                    struct qemud_network_def *def,
                                    xmlNodePtr node) {
 
@@ -1809,7 +1809,7 @@ static int qemudParseDhcpRangesXML(struc
     return 1;
 }
 
-static int qemudParseInetXML(struct qemud_server *server ATTRIBUTE_UNUSED,
+static int qemudParseInetXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
                              struct qemud_network_def *def,
                              xmlNodePtr node) {
     xmlChar *address, *netmask;
@@ -1850,7 +1850,7 @@ static int qemudParseInetXML(struct qemu
     while (cur != NULL) {
         if (cur->type == XML_ELEMENT_NODE &&
             xmlStrEqual(cur->name, BAD_CAST "dhcp") &&
-            !qemudParseDhcpRangesXML(server, def, cur))
+            !qemudParseDhcpRangesXML(driver, def, cur))
             return 0;
         cur = cur->next;
     }
@@ -1859,7 +1859,7 @@ static int qemudParseInetXML(struct qemu
 }
 
 
-static struct qemud_network_def *qemudParseNetworkXML(struct qemud_server *server,
+static struct qemud_network_def *qemudParseNetworkXML(struct qemud_driver *driver,
                                                       xmlDocPtr xml) {
     xmlNodePtr root = NULL;
     xmlXPathContextPtr ctxt = NULL;
@@ -1920,7 +1920,7 @@ static struct qemud_network_def *qemudPa
     obj = xmlXPathEval(BAD_CAST "/network/bridge[1]", ctxt);
     if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
         (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr > 0)) {
-        if (!qemudParseBridgeXML(server, def, obj->nodesetval->nodeTab[0])) {
+        if (!qemudParseBridgeXML(driver, def, obj->nodesetval->nodeTab[0])) {
             goto error;
         }
     }
@@ -1930,7 +1930,7 @@ static struct qemud_network_def *qemudPa
     obj = xmlXPathEval(BAD_CAST "/network/ip[1]", ctxt);
     if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
         (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr > 0)) {
-        if (!qemudParseInetXML(server, def, obj->nodesetval->nodeTab[0])) {
+        if (!qemudParseInetXML(driver, def, obj->nodesetval->nodeTab[0])) {
             goto error;
         }
     }
@@ -1987,7 +1987,7 @@ static struct qemud_network_def *qemudPa
 }
 
 struct qemud_network_def *
-qemudParseNetworkDef(struct qemud_server *server,
+qemudParseNetworkDef(struct qemud_driver *driver,
                      const char *xmlStr,
                      const char *displayName) {
     xmlDocPtr xml;
@@ -2000,7 +2000,7 @@ qemudParseNetworkDef(struct qemud_server
         return NULL;
     }
 
-    def = qemudParseNetworkXML(server, xml);
+    def = qemudParseNetworkXML(driver, xml);
 
     xmlFreeDoc(xml);
 
@@ -2008,11 +2008,11 @@ qemudParseNetworkDef(struct qemud_server
 }
 
 struct qemud_network *
-qemudAssignNetworkDef(struct qemud_server *server,
+qemudAssignNetworkDef(struct qemud_driver *driver,
                       struct qemud_network_def *def) {
     struct qemud_network *network;
 
-    if ((network = qemudFindNetworkByName(server, def->name))) {
+    if ((network = qemudFindNetworkByName(driver, def->name))) {
         if (!qemudIsActiveNetwork(network)) {
             qemudFreeNetworkDef(network->def);
             network->def = def;
@@ -2031,21 +2031,21 @@ qemudAssignNetworkDef(struct qemud_serve
     }
 
     network->def = def;
-    network->next = server->networks;
-
-    server->networks = network;
-    server->ninactivenetworks++;
+    network->next = driver->networks;
+
+    driver->networks = network;
+    driver->ninactivenetworks++;
 
     return network;
 }
 
 void
-qemudRemoveInactiveNetwork(struct qemud_server *server,
+qemudRemoveInactiveNetwork(struct qemud_driver *driver,
                            struct qemud_network *network)
 {
     struct qemud_network *prev = NULL, *curr;
 
-    curr = server->networks;
+    curr = driver->networks;
     while (curr != network) {
         prev = curr;
         curr = curr->next;
@@ -2055,37 +2055,37 @@ qemudRemoveInactiveNetwork(struct qemud_
         if (prev)
             prev->next = curr->next;
         else
-            server->networks = curr->next;
-
-        server->ninactivenetworks--;
+            driver->networks = curr->next;
+
+        driver->ninactivenetworks--;
     }
 
     qemudFreeNetwork(network);
 }
 
 int
-qemudSaveNetworkDef(struct qemud_server *server,
+qemudSaveNetworkDef(struct qemud_driver *driver,
                     struct qemud_network *network,
                     struct qemud_network_def *def) {
 
     if (network->configFile[0] == '\0') {
         int err;
 
-        if ((err = qemudEnsureDir(server->networkConfigDir))) {
+        if ((err = qemudEnsureDir(driver->networkConfigDir))) {
             qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "cannot create config directory %s: %s",
-                             server->networkConfigDir, strerror(err));
+                             driver->networkConfigDir, strerror(err));
             return -1;
         }
 
-        if (qemudMakeConfigPath(server->networkConfigDir, def->name, ".xml",
+        if (qemudMakeConfigPath(driver->networkConfigDir, def->name, ".xml",
                                 network->configFile, PATH_MAX) < 0) {
             qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "cannot construct config file path");
             return -1;
         }
 
-        if (qemudMakeConfigPath(server->networkAutostartDir, def->name, ".xml",
+        if (qemudMakeConfigPath(driver->networkAutostartDir, def->name, ".xml",
                                 network->autostartLink, PATH_MAX) < 0) {
             qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "cannot construct autostart link path");
@@ -2094,7 +2094,7 @@ qemudSaveNetworkDef(struct qemud_server 
         }
     }
 
-    return qemudSaveNetworkConfig(server, network, def);
+    return qemudSaveNetworkConfig(driver, network, def);
 }
 
 static int
@@ -2267,7 +2267,7 @@ checkLinkPointsTo(const char *checkLink,
 }
 
 static struct qemud_vm *
-qemudLoadConfig(struct qemud_server *server,
+qemudLoadConfig(struct qemud_driver *driver,
                 const char *file,
                 const char *path,
                 const char *xml,
@@ -2275,7 +2275,7 @@ qemudLoadConfig(struct qemud_server *ser
     struct qemud_vm_def *def;
     struct qemud_vm *vm;
 
-    if (!(def = qemudParseVMDef(server, xml, file))) {
+    if (!(def = qemudParseVMDef(driver, xml, file))) {
         virErrorPtr err = virGetLastError();
         qemudLog(QEMUD_WARN, "Error parsing QEMU guest config '%s' : %s",
                  path, err->message);
@@ -2289,7 +2289,7 @@ qemudLoadConfig(struct qemud_server *ser
         return NULL;
     }
 
-    if (!(vm = qemudAssignVMDef(server, def))) {
+    if (!(vm = qemudAssignVMDef(driver, def))) {
         qemudLog(QEMUD_WARN, "Failed to load QEMU guest config '%s': out of memory", path);
         qemudFreeVMDef(def);
         return NULL;
@@ -2307,7 +2307,7 @@ qemudLoadConfig(struct qemud_server *ser
 }
 
 static struct qemud_network *
-qemudLoadNetworkConfig(struct qemud_server *server,
+qemudLoadNetworkConfig(struct qemud_driver *driver,
                        const char *file,
                        const char *path,
                        const char *xml,
@@ -2315,7 +2315,7 @@ qemudLoadNetworkConfig(struct qemud_serv
     struct qemud_network_def *def;
     struct qemud_network *network;
 
-    if (!(def = qemudParseNetworkDef(server, xml, file))) {
+    if (!(def = qemudParseNetworkDef(driver, xml, file))) {
         virErrorPtr err = virGetLastError();
         qemudLog(QEMUD_WARN, "Error parsing network config '%s' : %s",
                  path, err->message);
@@ -2329,7 +2329,7 @@ qemudLoadNetworkConfig(struct qemud_serv
         return NULL;
     }
 
-    if (!(network = qemudAssignNetworkDef(server, def))) {
+    if (!(network = qemudAssignNetworkDef(driver, def))) {
         qemudLog(QEMUD_WARN, "Failed to load network config '%s': out of memory", path);
         qemudFreeNetworkDef(def);
         return NULL;
@@ -2347,7 +2347,7 @@ qemudLoadNetworkConfig(struct qemud_serv
 }
 
 static
-int qemudScanConfigDir(struct qemud_server *server,
+int qemudScanConfigDir(struct qemud_driver *driver,
                        const char *configDir,
                        const char *autostartDir,
                        int isGuest) {
@@ -2389,9 +2389,9 @@ int qemudScanConfigDir(struct qemud_serv
             continue;
 
         if (isGuest)
-            qemudLoadConfig(server, entry->d_name, path, xml, autostartLink);
+            qemudLoadConfig(driver, entry->d_name, path, xml, autostartLink);
         else
-            qemudLoadNetworkConfig(server, entry->d_name, path, xml, autostartLink);
+            qemudLoadNetworkConfig(driver, entry->d_name, path, xml, autostartLink);
     }
 
     closedir(dir);
@@ -2400,17 +2400,17 @@ int qemudScanConfigDir(struct qemud_serv
 }
 
 static
-void qemudAutostartConfigs(struct qemud_server *server) {
+void qemudAutostartConfigs(struct qemud_driver *driver) {
     struct qemud_network *network;
     struct qemud_vm *vm;
 
-    network = server->networks;
+    network = driver->networks;
     while (network != NULL) {
         struct qemud_network *next = network->next;
 
         if (network->autostart &&
             !qemudIsActiveNetwork(network) &&
-            qemudStartNetworkDaemon(server, network) < 0) {
+            qemudStartNetworkDaemon(driver, network) < 0) {
             virErrorPtr err = virGetLastError();
             qemudLog(QEMUD_ERR, "Failed to autostart network '%s': %s",
                      network->def->name, err->message);
@@ -2419,13 +2419,13 @@ void qemudAutostartConfigs(struct qemud_
         network = next;
     }
 
-    vm = server->vms;
+    vm = driver->vms;
     while (vm != NULL) {
         struct qemud_vm *next = vm->next;
 
         if (vm->autostart &&
             !qemudIsActiveVM(vm) &&
-            qemudStartVMDaemon(server, vm) < 0) {
+            qemudStartVMDaemon(driver, vm) < 0) {
             virErrorPtr err = virGetLastError();
             qemudLog(QEMUD_ERR, "Failed to autostart VM '%s': %s",
                      vm->def->name, err->message);
@@ -2436,20 +2436,20 @@ void qemudAutostartConfigs(struct qemud_
 }
 
 /* Scan for all guest and network config files */
-int qemudScanConfigs(struct qemud_server *server) {
-    if (qemudScanConfigDir(server, server->configDir, server->autostartDir, 1) < 0)
+int qemudScanConfigs(struct qemud_driver *driver) {
+    if (qemudScanConfigDir(driver, driver->configDir, driver->autostartDir, 1) < 0)
         return -1;
 
-    if (qemudScanConfigDir(server, server->networkConfigDir, server->networkAutostartDir, 0) < 0)
+    if (qemudScanConfigDir(driver, driver->networkConfigDir, driver->networkAutostartDir, 0) < 0)
         return -1;
 
-    qemudAutostartConfigs(server);
+    qemudAutostartConfigs(driver);
 
     return 0;
 }
 
 /* Generate an XML document describing the guest's configuration */
-char *qemudGenerateXML(struct qemud_server *server,
+char *qemudGenerateXML(struct qemud_driver *driver,
                        struct qemud_vm *vm,
                        struct qemud_vm_def *def,
                        int live) {
@@ -2727,7 +2727,7 @@ char *qemudGenerateXML(struct qemud_serv
 }
 
 
-char *qemudGenerateNetworkXML(struct qemud_server *server,
+char *qemudGenerateNetworkXML(struct qemud_driver *driver,
                               struct qemud_network *network,
                               struct qemud_network_def *def) {
     bufferPtr buf = 0;
@@ -2818,7 +2818,7 @@ char *qemudGenerateNetworkXML(struct qem
 }
 
 
-int qemudDeleteConfig(struct qemud_server *server,
+int qemudDeleteConfig(struct qemud_driver *driver,
                       const char *configFile,
                       const char *name) {
     if (!configFile[0]) {
diff -r af6d5f54a13a qemud/conf.h
--- a/qemud/conf.h	Sun Jun 17 22:11:10 2007 -0400
+++ b/qemud/conf.h	Sun Jun 17 22:11:17 2007 -0400
@@ -24,15 +24,15 @@
 #ifndef __QEMUD_CONF_H
 #define __QEMUD_CONF_H
 
-#include "internal.h"
+#include "driver.h"
 
-int         qemudExtractVersion         (struct qemud_server *server);
-int         qemudBuildCommandLine       (struct qemud_server *server,
+int         qemudExtractVersion         (struct qemud_driver *driver);
+int         qemudBuildCommandLine       (struct qemud_driver *driver,
                                          struct qemud_vm *vm,
                                          char ***argv);
 
-int         qemudScanConfigs            (struct qemud_server *server);
-int         qemudDeleteConfig           (struct qemud_server *server,
+int         qemudScanConfigs            (struct qemud_driver *driver);
+int         qemudDeleteConfig           (struct qemud_driver *driver,
                                          const char *configFile,
                                          const char *name);
 int         qemudEnsureDir              (const char *path);
@@ -41,19 +41,19 @@ void        qemudFreeVM                 
 void        qemudFreeVM                 (struct qemud_vm *vm);
 
 struct qemud_vm *
-            qemudAssignVMDef            (struct qemud_server *server,
+            qemudAssignVMDef            (struct qemud_driver *driver,
                                          struct qemud_vm_def *def);
-void        qemudRemoveInactiveVM       (struct qemud_server *server,
+void        qemudRemoveInactiveVM       (struct qemud_driver *driver,
                                          struct qemud_vm *vm);
 
 struct qemud_vm_def *
-            qemudParseVMDef             (struct qemud_server *server,
+            qemudParseVMDef             (struct qemud_driver *driver,
                                          const char *xmlStr,
                                          const char *displayName);
-int         qemudSaveVMDef              (struct qemud_server *server,
+int         qemudSaveVMDef              (struct qemud_driver *driver,
                                          struct qemud_vm *vm,
                                          struct qemud_vm_def *def);
-char *      qemudGenerateXML            (struct qemud_server *server,
+char *      qemudGenerateXML            (struct qemud_driver *driver,
                                          struct qemud_vm *vm,
                                          struct qemud_vm_def *def,
                                          int live);
@@ -62,19 +62,19 @@ void        qemudFreeNetwork            
 void        qemudFreeNetwork            (struct qemud_network *network);
 
 struct qemud_network *
-            qemudAssignNetworkDef       (struct qemud_server *server,
+            qemudAssignNetworkDef       (struct qemud_driver *driver,
                                          struct qemud_network_def *def);
-void        qemudRemoveInactiveNetwork  (struct qemud_server *server,
+void        qemudRemoveInactiveNetwork  (struct qemud_driver *driver,
                                          struct qemud_network *network);
 
 struct qemud_network_def *
-            qemudParseNetworkDef        (struct qemud_server *server,
+            qemudParseNetworkDef        (struct qemud_driver *driver,
                                          const char *xmlStr,
                                          const char *displayName);
-int         qemudSaveNetworkDef         (struct qemud_server *server,
+int         qemudSaveNetworkDef         (struct qemud_driver *driver,
                                          struct qemud_network *network,
                                          struct qemud_network_def *def);
-char *      qemudGenerateNetworkXML     (struct qemud_server *server,
+char *      qemudGenerateNetworkXML     (struct qemud_driver *driver,
                                          struct qemud_network *network,
                                          struct qemud_network_def *def);
 
diff -r af6d5f54a13a qemud/dispatch.c
--- a/qemud/dispatch.c	Sun Jun 17 22:11:10 2007 -0400
+++ b/qemud/dispatch.c	Sun Jun 17 22:11:17 2007 -0400
@@ -34,11 +34,10 @@
 #include "driver.h"
 #include "dispatch.h"
 #include "conf.h"
-
-
-static int qemudDispatchFailure(struct qemud_server *server ATTRIBUTE_UNUSED,
-                                struct qemud_client *client ATTRIBUTE_UNUSED,
-                                struct qemud_packet_server_data *out) {
+extern struct qemud_driver *qemu_driver;
+
+
+static int qemudDispatchFailure(struct qemud_packet_server_data *out) {
     virErrorPtr err = virGetLastError();
 
     out->type = QEMUD_SERVER_PKT_FAILURE;
@@ -51,11 +50,10 @@ static int qemudDispatchFailure(struct q
 }
 
 
-static int qemudDispatchGetVersion(struct qemud_server *server, struct qemud_client *client,
-                                   struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
-    int version = qemudGetVersion(server);
+static int qemudDispatchGetVersion(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
+    int version = qemudGetVersion(qemu_driver);
     if (version < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_GET_VERSION;
@@ -64,8 +62,7 @@ static int qemudDispatchGetVersion(struc
     return 0;
 }
 
-static int qemudDispatchGetNodeInfo(struct qemud_server *server, struct qemud_client *client,
-                                    struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
+static int qemudDispatchGetNodeInfo(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
     if (qemudGetNodeInfo(&out->qemud_packet_server_data_u.getNodeInfoReply.memory,
                          out->qemud_packet_server_data_u.getNodeInfoReply.model,
                          sizeof(out->qemud_packet_server_data_u.getNodeInfoReply.model),
@@ -75,7 +72,7 @@ static int qemudDispatchGetNodeInfo(stru
                          &out->qemud_packet_server_data_u.getNodeInfoReply.sockets,
                          &out->qemud_packet_server_data_u.getNodeInfoReply.cores,
                          &out->qemud_packet_server_data_u.getNodeInfoReply.threads) < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
         return 0;
     }
@@ -87,16 +84,14 @@ static int qemudDispatchGetNodeInfo(stru
 }
 
 static int
-qemudDispatchGetCapabilities (struct qemud_server *server,
-                              struct qemud_client *client,
-                              struct qemud_packet_client_data *in ATTRIBUTE_UNUSED,
+qemudDispatchGetCapabilities (struct qemud_packet_client_data *in ATTRIBUTE_UNUSED,
                               struct qemud_packet_server_data *out)
 {
-    char *xml = qemudGetCapabilities(server);
+    char *xml = qemudGetCapabilities(qemu_driver);
 
     if (strlen(xml) > QEMUD_MAX_XML_LEN) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
-        qemudDispatchFailure (server, client, out);
+        qemudDispatchFailure(out);
         free(xml);
         return 0;
     }
@@ -107,15 +102,14 @@ qemudDispatchGetCapabilities (struct qem
     return 0;
 }
 
-static int qemudDispatchListDomains(struct qemud_server *server, struct qemud_client *client,
-                                    struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
+static int qemudDispatchListDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
     int i, ndomains, domains[QEMUD_MAX_NUM_DOMAINS];
 
-    ndomains = qemudListDomains(server,
+    ndomains = qemudListDomains(qemu_driver,
                                 domains,
                                 QEMUD_MAX_NUM_DOMAINS);
     if (ndomains < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_LIST_DOMAINS;
@@ -127,11 +121,10 @@ static int qemudDispatchListDomains(stru
     return 0;
 }
 
-static int qemudDispatchNumDomains(struct qemud_server *server, struct qemud_client *client,
-                                   struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
-    int ndomains = qemudNumDomains(server);
+static int qemudDispatchNumDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
+    int ndomains = qemudNumDomains(qemu_driver);
     if (ndomains < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NUM_DOMAINS;
@@ -140,13 +133,12 @@ static int qemudDispatchNumDomains(struc
     return 0;
 }
 
-static int qemudDispatchDomainCreate(struct qemud_server *server, struct qemud_client *client,
-                                     struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+static int qemudDispatchDomainCreate(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
     in->qemud_packet_client_data_u.domainCreateRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
 
-    struct qemud_vm *vm = qemudDomainCreate(server, in->qemud_packet_client_data_u.domainCreateRequest.xml);
+    struct qemud_vm *vm = qemudDomainCreate(qemu_driver, in->qemud_packet_client_data_u.domainCreateRequest.xml);
     if (!vm) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_CREATE;
@@ -158,11 +150,10 @@ static int qemudDispatchDomainCreate(str
     return 0;
 }
 
-static int qemudDispatchDomainLookupByID(struct qemud_server *server, struct qemud_client *client,
-                                         struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
-    struct qemud_vm *vm = qemudFindVMByID(server, in->qemud_packet_client_data_u.domainLookupByIDRequest.id);
+static int qemudDispatchDomainLookupByID(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+    struct qemud_vm *vm = qemudFindVMByID(qemu_driver, in->qemud_packet_client_data_u.domainLookupByIDRequest.id);
     if (!vm) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_ID;
@@ -173,11 +164,10 @@ static int qemudDispatchDomainLookupByID
     return 0;
 }
 
-static int qemudDispatchDomainLookupByUUID(struct qemud_server *server, struct qemud_client *client,
-                                           struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
-    struct qemud_vm *vm = qemudFindVMByUUID(server, in->qemud_packet_client_data_u.domainLookupByUUIDRequest.uuid);
+static int qemudDispatchDomainLookupByUUID(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+    struct qemud_vm *vm = qemudFindVMByUUID(qemu_driver, in->qemud_packet_client_data_u.domainLookupByUUIDRequest.uuid);
     if (!vm) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_UUID;
@@ -188,13 +178,12 @@ static int qemudDispatchDomainLookupByUU
     return 0;
 }
 
-static int qemudDispatchDomainLookupByName(struct qemud_server *server, struct qemud_client *client,
-                                           struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+static int qemudDispatchDomainLookupByName(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
     /* Paranoia NULL termination */
     in->qemud_packet_client_data_u.domainLookupByNameRequest.name[QEMUD_MAX_NAME_LEN-1] = '\0';
-    struct qemud_vm *vm = qemudFindVMByName(server, in->qemud_packet_client_data_u.domainLookupByNameRequest.name);
+    struct qemud_vm *vm = qemudFindVMByName(qemu_driver, in->qemud_packet_client_data_u.domainLookupByNameRequest.name);
     if (!vm) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_NAME;
@@ -204,11 +193,10 @@ static int qemudDispatchDomainLookupByNa
     return 0;
 }
 
-static int qemudDispatchDomainSuspend(struct qemud_server *server, struct qemud_client *client,
-                                      struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
-    int ret = qemudDomainSuspend(server, in->qemud_packet_client_data_u.domainSuspendRequest.id);
-    if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+static int qemudDispatchDomainSuspend(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+    int ret = qemudDomainSuspend(qemu_driver, in->qemud_packet_client_data_u.domainSuspendRequest.id);
+    if (ret < 0) {
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_SUSPEND;
@@ -216,11 +204,10 @@ static int qemudDispatchDomainSuspend(st
     return 0;
 }
 
-static int qemudDispatchDomainResume(struct qemud_server *server, struct qemud_client *client,
-                                     struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
-    int ret = qemudDomainResume(server, in->qemud_packet_client_data_u.domainResumeRequest.id);
-    if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+static int qemudDispatchDomainResume(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+    int ret = qemudDomainResume(qemu_driver, in->qemud_packet_client_data_u.domainResumeRequest.id);
+    if (ret < 0) {
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_RESUME;
@@ -228,10 +215,9 @@ static int qemudDispatchDomainResume(str
     return 0;
 }
 
-static int qemudDispatchDomainDestroy(struct qemud_server *server, struct qemud_client *client,
-                                      struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
-    if (qemudDomainDestroy(server, in->qemud_packet_client_data_u.domainDestroyRequest.id) < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+static int qemudDispatchDomainDestroy(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+    if (qemudDomainDestroy(qemu_driver, in->qemud_packet_client_data_u.domainDestroyRequest.id) < 0) {
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_DESTROY;
@@ -239,22 +225,21 @@ static int qemudDispatchDomainDestroy(st
     return 0;
 }
 
-static int qemudDispatchDomainGetInfo(struct qemud_server *server, struct qemud_client *client,
-                                      struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+static int qemudDispatchDomainGetInfo(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
     int runstate;
     unsigned long long cpuTime;
     unsigned long memory;
     unsigned long maxmem;
     unsigned int nrVirtCpu;
 
-    int ret = qemudDomainGetInfo(server, in->qemud_packet_client_data_u.domainGetInfoRequest.uuid,
+    int ret = qemudDomainGetInfo(qemu_driver, in->qemud_packet_client_data_u.domainGetInfoRequest.uuid,
                                  &runstate,
                                  &cpuTime,
                                  &maxmem,
                                  &memory,
                                  &nrVirtCpu);
     if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_GET_INFO;
@@ -267,16 +252,15 @@ static int qemudDispatchDomainGetInfo(st
     return 0;
 }
 
-static int qemudDispatchDomainSave(struct qemud_server *server, struct qemud_client *client,
-                                   struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+static int qemudDispatchDomainSave(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
     /* Paranoia NULL termination */
     in->qemud_packet_client_data_u.domainSaveRequest.file[PATH_MAX-1] ='\0';
 
-    int ret = qemudDomainSave(server,
+    int ret = qemudDomainSave(qemu_driver,
                               in->qemud_packet_client_data_u.domainSaveRequest.id,
                               in->qemud_packet_client_data_u.domainSaveRequest.file);
     if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_SAVE;
@@ -284,16 +268,15 @@ static int qemudDispatchDomainSave(struc
     return 0;
 }
 
-static int qemudDispatchDomainRestore(struct qemud_server *server, struct qemud_client *client,
-                                      struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+static int qemudDispatchDomainRestore(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
     int id;
 
     /* Paranoia null termination */
     in->qemud_packet_client_data_u.domainRestoreRequest.file[PATH_MAX-1] ='\0';
 
-    id = qemudDomainRestore(server, in->qemud_packet_client_data_u.domainRestoreRequest.file);
+    id = qemudDomainRestore(qemu_driver, in->qemud_packet_client_data_u.domainRestoreRequest.file);
     if (id < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_RESTORE;
@@ -302,15 +285,14 @@ static int qemudDispatchDomainRestore(st
     return 0;
 }
 
-static int qemudDispatchDumpXML(struct qemud_server *server, struct qemud_client *client,
-                                struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+static int qemudDispatchDumpXML(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
     int ret;
-    ret = qemudDomainDumpXML(server,
+    ret = qemudDomainDumpXML(qemu_driver,
                              in->qemud_packet_client_data_u.domainDumpXMLRequest.uuid,
                              out->qemud_packet_server_data_u.domainDumpXMLReply.xml,
                              QEMUD_MAX_XML_LEN);
     if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DUMP_XML;
@@ -318,8 +300,7 @@ static int qemudDispatchDumpXML(struct q
     return 0;
 }
 
-static int qemudDispatchListDefinedDomains(struct qemud_server *server, struct qemud_client *client,
-                                           struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
+static int qemudDispatchListDefinedDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
     char **names;
     int i, ndomains;
 
@@ -330,12 +311,12 @@ static int qemudDispatchListDefinedDomai
         names[i] = &out->qemud_packet_server_data_u.listDefinedDomainsReply.domains[i*QEMUD_MAX_NAME_LEN];
     }
 
-    ndomains = qemudListDefinedDomains(server,
+    ndomains = qemudListDefinedDomains(qemu_driver,
                                        names,
                                        QEMUD_MAX_NUM_DOMAINS);
     free(names);
     if (ndomains < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_LIST_DEFINED_DOMAINS;
@@ -348,11 +329,10 @@ static int qemudDispatchListDefinedDomai
     return 0;
 }
 
-static int qemudDispatchNumDefinedDomains(struct qemud_server *server, struct qemud_client *client,
-                                          struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
-    int ndomains = qemudNumDefinedDomains(server);
+static int qemudDispatchNumDefinedDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
+    int ndomains = qemudNumDefinedDomains(qemu_driver);
     if (ndomains < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NUM_DEFINED_DOMAINS;
@@ -361,12 +341,11 @@ static int qemudDispatchNumDefinedDomain
     return 0;
 }
 
-static int qemudDispatchDomainStart(struct qemud_server *server, struct qemud_client *client,
-                                    struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+static int qemudDispatchDomainStart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
     struct qemud_vm *vm;
 
-    if (!(vm = qemudDomainStart(server, in->qemud_packet_client_data_u.domainStartRequest.uuid))) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+    if (!(vm = qemudDomainStart(qemu_driver, in->qemud_packet_client_data_u.domainStartRequest.uuid))) {
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_START;
@@ -375,13 +354,12 @@ static int qemudDispatchDomainStart(stru
     return 0;
 }
 
-static int qemudDispatchDomainDefine(struct qemud_server *server, struct qemud_client *client,
-                                     struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+static int qemudDispatchDomainDefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
     in->qemud_packet_client_data_u.domainDefineRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
 
-    struct qemud_vm *vm = qemudDomainDefine(server, in->qemud_packet_client_data_u.domainDefineRequest.xml);
+    struct qemud_vm *vm = qemudDomainDefine(qemu_driver, in->qemud_packet_client_data_u.domainDefineRequest.xml);
     if (!vm) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_DEFINE;
@@ -392,11 +370,10 @@ static int qemudDispatchDomainDefine(str
     return 0;
 }
 
-static int qemudDispatchDomainUndefine(struct qemud_server *server, struct qemud_client *client,
-                                       struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
-    int ret = qemudDomainUndefine(server, in->qemud_packet_client_data_u.domainUndefineRequest.uuid);
-    if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+static int qemudDispatchDomainUndefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+    int ret = qemudDomainUndefine(qemu_driver, in->qemud_packet_client_data_u.domainUndefineRequest.uuid);
+    if (ret < 0) {
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_UNDEFINE;
@@ -404,11 +381,10 @@ static int qemudDispatchDomainUndefine(s
     return 0;
 }
 
-static int qemudDispatchNumNetworks(struct qemud_server *server, struct qemud_client *client,
-                                    struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
-    int nnetworks = qemudNumNetworks(server);
+static int qemudDispatchNumNetworks(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
+    int nnetworks = qemudNumNetworks(qemu_driver);
     if (nnetworks < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NUM_NETWORKS;
@@ -417,8 +393,7 @@ static int qemudDispatchNumNetworks(stru
     return 0;
 }
 
-static int qemudDispatchListNetworks(struct qemud_server *server, struct qemud_client *client,
-                                     struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
+static int qemudDispatchListNetworks(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
     char **names;
     int i;
 
@@ -429,12 +404,12 @@ static int qemudDispatchListNetworks(str
         names[i] = &out->qemud_packet_server_data_u.listNetworksReply.networks[i*QEMUD_MAX_NAME_LEN];
     }
 
-    int nnetworks = qemudListNetworks(server,
+    int nnetworks = qemudListNetworks(qemu_driver,
                                       names,
                                       QEMUD_MAX_NUM_NETWORKS);
     free(names);
     if (nnetworks < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_LIST_NETWORKS;
@@ -443,11 +418,10 @@ static int qemudDispatchListNetworks(str
     return 0;
 }
 
-static int qemudDispatchNumDefinedNetworks(struct qemud_server *server, struct qemud_client *client,
-                                           struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
-    int nnetworks = qemudNumDefinedNetworks(server);
+static int qemudDispatchNumDefinedNetworks(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
+    int nnetworks = qemudNumDefinedNetworks(qemu_driver);
     if (nnetworks < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NUM_DEFINED_NETWORKS;
@@ -456,8 +430,7 @@ static int qemudDispatchNumDefinedNetwor
     return 0;
 }
 
-static int qemudDispatchListDefinedNetworks(struct qemud_server *server, struct qemud_client *client,
-                                            struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
+static int qemudDispatchListDefinedNetworks(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
     char **names;
     int i;
 
@@ -468,12 +441,12 @@ static int qemudDispatchListDefinedNetwo
         names[i] = &out->qemud_packet_server_data_u.listDefinedNetworksReply.networks[i*QEMUD_MAX_NAME_LEN];
     }
 
-    int nnetworks = qemudListDefinedNetworks(server,
+    int nnetworks = qemudListDefinedNetworks(qemu_driver,
                                              names,
                                              QEMUD_MAX_NUM_NETWORKS);
     free(names);
     if (nnetworks < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_LIST_DEFINED_NETWORKS;
@@ -482,13 +455,12 @@ static int qemudDispatchListDefinedNetwo
     return 0;
 }
 
-static int qemudDispatchNetworkLookupByName(struct qemud_server *server, struct qemud_client *client,
-                                            struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+static int qemudDispatchNetworkLookupByName(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
     /* Paranoia NULL termination */
     in->qemud_packet_client_data_u.networkLookupByNameRequest.name[QEMUD_MAX_NAME_LEN-1] = '\0';
-    struct qemud_network *network = qemudFindNetworkByName(server, in->qemud_packet_client_data_u.networkLookupByNameRequest.name);
+    struct qemud_network *network = qemudFindNetworkByName(qemu_driver, in->qemud_packet_client_data_u.networkLookupByNameRequest.name);
     if (!network) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NETWORK_LOOKUP_BY_NAME;
@@ -497,11 +469,10 @@ static int qemudDispatchNetworkLookupByN
     return 0;
 }
 
-static int qemudDispatchNetworkLookupByUUID(struct qemud_server *server, struct qemud_client *client,
-                                            struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
-    struct qemud_network *network = qemudFindNetworkByUUID(server, in->qemud_packet_client_data_u.networkLookupByUUIDRequest.uuid);
+static int qemudDispatchNetworkLookupByUUID(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+    struct qemud_network *network = qemudFindNetworkByUUID(qemu_driver, in->qemud_packet_client_data_u.networkLookupByUUIDRequest.uuid);
     if (!network) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NETWORK_LOOKUP_BY_UUID;
@@ -511,13 +482,12 @@ static int qemudDispatchNetworkLookupByU
     return 0;
 }
 
-static int qemudDispatchNetworkCreate(struct qemud_server *server, struct qemud_client *client,
-                                      struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+static int qemudDispatchNetworkCreate(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
     in->qemud_packet_client_data_u.networkCreateRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
 
-    struct qemud_network *network = qemudNetworkCreate(server, in->qemud_packet_client_data_u.networkCreateRequest.xml);
+    struct qemud_network *network = qemudNetworkCreate(qemu_driver, in->qemud_packet_client_data_u.networkCreateRequest.xml);
     if (!network) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NETWORK_CREATE;
@@ -528,13 +498,12 @@ static int qemudDispatchNetworkCreate(st
     return 0;
 }
 
-static int qemudDispatchNetworkDefine(struct qemud_server *server, struct qemud_client *client,
-                                      struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+static int qemudDispatchNetworkDefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
     in->qemud_packet_client_data_u.networkDefineRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
 
-    struct qemud_network *network = qemudNetworkDefine(server, in->qemud_packet_client_data_u.networkDefineRequest.xml);
+    struct qemud_network *network = qemudNetworkDefine(qemu_driver, in->qemud_packet_client_data_u.networkDefineRequest.xml);
     if (!network) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NETWORK_DEFINE;
@@ -545,11 +514,10 @@ static int qemudDispatchNetworkDefine(st
     return 0;
 }
 
-static int qemudDispatchNetworkUndefine(struct qemud_server *server, struct qemud_client *client,
-                                        struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
-    int ret = qemudNetworkUndefine(server, in->qemud_packet_client_data_u.networkUndefineRequest.uuid);
-    if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+static int qemudDispatchNetworkUndefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+    int ret = qemudNetworkUndefine(qemu_driver, in->qemud_packet_client_data_u.networkUndefineRequest.uuid);
+    if (ret < 0) {
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NETWORK_UNDEFINE;
@@ -557,12 +525,11 @@ static int qemudDispatchNetworkUndefine(
     return 0;
 }
 
-static int qemudDispatchNetworkStart(struct qemud_server *server, struct qemud_client *client,
-                                     struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+static int qemudDispatchNetworkStart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
     struct qemud_network *network;
 
-    if (!(network = qemudNetworkStart(server, in->qemud_packet_client_data_u.networkStartRequest.uuid))) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+    if (!(network = qemudNetworkStart(qemu_driver, in->qemud_packet_client_data_u.networkStartRequest.uuid))) {
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NETWORK_START;
@@ -570,10 +537,9 @@ static int qemudDispatchNetworkStart(str
     return 0;
 }
 
-static int qemudDispatchNetworkDestroy(struct qemud_server *server, struct qemud_client *client,
-                                      struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
-    if (qemudNetworkDestroy(server, in->qemud_packet_client_data_u.networkDestroyRequest.uuid) < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+static int qemudDispatchNetworkDestroy(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+    if (qemudNetworkDestroy(qemu_driver, in->qemud_packet_client_data_u.networkDestroyRequest.uuid) < 0) {
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NETWORK_DESTROY;
@@ -581,13 +547,12 @@ static int qemudDispatchNetworkDestroy(s
     return 0;
 }
 
-static int qemudDispatchNetworkDumpXML(struct qemud_server *server, struct qemud_client *client,
-                                      struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
-    int ret = qemudNetworkDumpXML(server,
+static int qemudDispatchNetworkDumpXML(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+    int ret = qemudNetworkDumpXML(qemu_driver,
                                   in->qemud_packet_client_data_u.networkDumpXMLRequest.uuid,
                                   out->qemud_packet_server_data_u.networkDumpXMLReply.xml, QEMUD_MAX_XML_LEN);
     if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NETWORK_DUMP_XML;
@@ -595,13 +560,12 @@ static int qemudDispatchNetworkDumpXML(s
     return 0;
 }
 
-static int qemudDispatchNetworkGetBridgeName(struct qemud_server *server, struct qemud_client *client,
-                                             struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
-    int ret = qemudNetworkGetBridgeName(server,
+static int qemudDispatchNetworkGetBridgeName(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
+    int ret = qemudNetworkGetBridgeName(qemu_driver,
                                         in->qemud_packet_client_data_u.networkDumpXMLRequest.uuid,
                                         out->qemud_packet_server_data_u.networkGetBridgeNameReply.ifname, QEMUD_MAX_IFNAME_LEN);
     if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NETWORK_GET_BRIDGE_NAME;
@@ -609,19 +573,18 @@ static int qemudDispatchNetworkGetBridge
     return 0;
 }
 
-static int qemudDispatchDomainGetAutostart(struct qemud_server *server, struct qemud_client *client,
-                                           struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
+static int qemudDispatchDomainGetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
 {
     int ret;
     int autostart;
 
     autostart = 0;
 
-    ret = qemudDomainGetAutostart(server,
+    ret = qemudDomainGetAutostart(qemu_driver,
                                   in->qemud_packet_client_data_u.domainGetAutostartRequest.uuid,
                                   &autostart);
     if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_GET_AUTOSTART;
@@ -630,16 +593,15 @@ static int qemudDispatchDomainGetAutosta
     return 0;
 }
 
-static int qemudDispatchDomainSetAutostart(struct qemud_server *server, struct qemud_client *client,
-                                           struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
+static int qemudDispatchDomainSetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
 {
     int ret;
 
-    ret = qemudDomainSetAutostart(server,
+    ret = qemudDomainSetAutostart(qemu_driver,
                                   in->qemud_packet_client_data_u.domainGetAutostartRequest.uuid,
                                   in->qemud_packet_client_data_u.domainSetAutostartRequest.autostart);
     if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_DOMAIN_SET_AUTOSTART;
@@ -647,19 +609,18 @@ static int qemudDispatchDomainSetAutosta
     return 0;
 }
 
-static int qemudDispatchNetworkGetAutostart(struct qemud_server *server, struct qemud_client *client,
-                                            struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
+static int qemudDispatchNetworkGetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
 {
     int ret;
     int autostart;
 
     autostart = 0;
 
-    ret = qemudNetworkGetAutostart(server,
+    ret = qemudNetworkGetAutostart(qemu_driver,
                                    in->qemud_packet_client_data_u.networkGetAutostartRequest.uuid,
                                    &autostart);
     if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NETWORK_GET_AUTOSTART;
@@ -668,16 +629,15 @@ static int qemudDispatchNetworkGetAutost
     return 0;
 }
 
-static int qemudDispatchNetworkSetAutostart(struct qemud_server *server, struct qemud_client *client,
-                                            struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
+static int qemudDispatchNetworkSetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
 {
     int ret;
 
-    ret = qemudNetworkSetAutostart(server,
+    ret = qemudNetworkSetAutostart(qemu_driver,
                                    in->qemud_packet_client_data_u.networkGetAutostartRequest.uuid,
                                    in->qemud_packet_client_data_u.networkSetAutostartRequest.autostart);
     if (ret < 0) {
-        if (qemudDispatchFailure(server, client, out) < 0)
+        if (qemudDispatchFailure(out) < 0)
             return -1;
     } else {
         out->type = QEMUD_SERVER_PKT_NETWORK_SET_AUTOSTART;
@@ -685,8 +645,7 @@ static int qemudDispatchNetworkSetAutost
     return 0;
 }
 
-typedef int (*clientFunc)(struct qemud_server *server, struct qemud_client *client,
-                          struct qemud_packet_client_data *in, struct qemud_packet_server_data *out);
+typedef int (*clientFunc)(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out);
 
 
 /* One per message type recorded in qemud_packet_type enum */
@@ -782,7 +741,9 @@ clientFunc funcsTransmitRO[QEMUD_CLIENT_
  * is recorded by the return message type - either it matches the
  * incoming type, or is QEMUD_PKT_FAILURE
  */
-int qemudDispatch(struct qemud_server *server, struct qemud_client *client,
+
+int qemudDispatch(struct qemud_server *server ATTRIBUTE_UNUSED,
+                  struct qemud_client *client,
                   qemud_packet_client_data *in, qemud_packet_server_data *out) {
     clientFunc *funcs;
     unsigned int type = in->type;
@@ -806,9 +767,9 @@ int qemudDispatch(struct qemud_server *s
     if (!funcs[type]) {
         qemudDebug("Illegal operation requested");
         qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_DENIED, NULL);
-        qemudDispatchFailure(server, client, out);
-    } else {
-        if ((funcs[type])(server, client, in, out) < 0) {
+        qemudDispatchFailure(out);
+    } else {
+        if ((funcs[type])(in, out) < 0) {
             qemudDebug("Dispatch failed");
             return -1;
         }
diff -r af6d5f54a13a qemud/driver.c
--- a/qemud/driver.c	Sun Jun 17 22:11:10 2007 -0400
+++ b/qemud/driver.c	Sun Jun 17 22:11:17 2007 -0400
@@ -23,6 +23,8 @@
 
 #include <config.h>
 
+#define _GNU_SOURCE /* for asprintf */
+
 #include <sys/types.h>
 #include <sys/poll.h>
 #include <dirent.h>
@@ -40,6 +42,8 @@
 #include <signal.h>
 #include <paths.h>
 #include <ctype.h>
+#include <pwd.h>
+#include <stdio.h>
 #include <sys/wait.h>
 
 #include <libvirt/virterror.h>
@@ -83,66 +87,151 @@ void qemudReportError(virConnectPtr conn
 
 static void qemudDispatchVMEvent(int fd, int events, void *opaque);
 
-int qemudStartup(struct qemud_server *server) {
-    return qemudScanConfigs(server);
-}
-
-void qemudReload(struct qemud_server *server) {
-    qemudScanConfigs(server);
-
-    if (server->iptables) {
+struct qemud_driver *qemu_driver = NULL;
+
+int qemudStartup(void) {
+    uid_t uid = geteuid();
+    struct passwd *pw;
+    char *base = NULL;
+
+    if (!(qemu_driver = calloc(1, sizeof(struct qemud_driver)))) {
+        return -1;
+    }
+
+    /* Don't have a dom0 so start from 1 */
+    qemu_driver->nextvmid = 1;
+
+    if (!uid) {
+        if (snprintf(qemu_driver->logDir, PATH_MAX, "%s/log/libvirt/qemu", LOCAL_STATE_DIR) >= PATH_MAX)
+            goto snprintf_error;
+
+        if ((base = strdup (SYSCONF_DIR "/libvirt/qemu")) == NULL)
+            goto out_of_memory;
+    } else {
+        if (!(pw = getpwuid(uid))) {
+            qemudLog(QEMUD_ERR, "Failed to find user record for uid '%d': %s",
+                     uid, strerror(errno));
+            goto out_of_memory;
+        }
+
+        if (snprintf(qemu_driver->logDir, PATH_MAX, "%s/.libvirt/qemu/log", pw->pw_dir) >= PATH_MAX)
+            goto snprintf_error;
+
+        if (asprintf (&base, "%s/.libvirt/qemu", pw->pw_dir) == -1) {
+            qemudLog (QEMUD_ERR, "out of memory in asprintf");
+            goto out_of_memory;
+        }
+    }
+
+    /* Configuration paths are either ~/.libvirt/qemu/... (session) or
+     * /etc/libvirt/qemu/... (system).
+     */
+    if (asprintf (&qemu_driver->configDir, "%s", base) == -1)
+        goto out_of_memory;
+
+    if (asprintf (&qemu_driver->autostartDir, "%s/autostart", base) == -1)
+        goto out_of_memory;
+
+    if (asprintf (&qemu_driver->networkConfigDir, "%s/networks", base) == -1)
+        goto out_of_memory;
+
+    if (asprintf (&qemu_driver->networkAutostartDir, "%s/networks/autostart",
+                  base) == -1)
+        goto out_of_memory;
+
+    if (qemudScanConfigs(qemu_driver) < 0)
+        qemudShutdown();
+
+    return 0;
+
+ snprintf_error:
+    qemudLog(QEMUD_ERR, "Resulting path to long for buffer in qemudInitPaths()");
+    return -1;
+
+ out_of_memory:
+    qemudLog (QEMUD_ERR, "qemudStartup: out of memory");
+    if (base) free (base);
+    free(qemu_driver);
+    qemu_driver = NULL;
+    return -1;
+}
+
+void qemudReload(void) {
+    qemudScanConfigs(qemu_driver);
+
+    if (qemu_driver->iptables) {
         qemudLog(QEMUD_INFO, "Reloading iptables rules");
-        iptablesReloadRules(server->iptables);
-    }
-}
-
-void qemudShutdown(struct qemud_server *server) {
+        iptablesReloadRules(qemu_driver->iptables);
+    }
+}
+
+void qemudShutdown() {
     struct qemud_vm *vm;
     struct qemud_network *network;
 
+    if (!qemu_driver)
+        return;
+
     /* shutdown active VMs */
-    vm = server->vms;
+    vm = qemu_driver->vms;
     while (vm) {
         struct qemud_vm *next = vm->next;
         if (qemudIsActiveVM(vm))
-            qemudShutdownVMDaemon(server, vm);
+            qemudShutdownVMDaemon(qemu_driver, vm);
         vm = next;
     }
     
     /* free inactive VMs */
-    vm = server->vms;
+    vm = qemu_driver->vms;
     while (vm) {
         struct qemud_vm *next = vm->next;
         qemudFreeVM(vm);
         vm = next;
     }
-    server->vms = NULL;
-    server->nactivevms = 0;
-    server->ninactivevms = 0;
+    qemu_driver->vms = NULL;
+    qemu_driver->nactivevms = 0;
+    qemu_driver->ninactivevms = 0;
 
     /* shutdown active networks */
-    network = server->networks;
+    network = qemu_driver->networks;
     while (network) {
         struct qemud_network *next = network->next;
         if (qemudIsActiveNetwork(network))
-            qemudShutdownNetworkDaemon(server, network);
+            qemudShutdownNetworkDaemon(qemu_driver, network);
         network = next;
     }
     
     /* free inactive networks */
-    network = server->networks;
+    network = qemu_driver->networks;
     while (network) {
         struct qemud_network *next = network->next;
         qemudFreeNetwork(network);
         network = next;
     }
-    server->networks = NULL;
-    server->nactivenetworks = 0;
-    server->ninactivenetworks = 0;
+    qemu_driver->networks = NULL;
+    qemu_driver->nactivenetworks = 0;
+    qemu_driver->ninactivenetworks = 0;
+
+    if (qemu_driver->configDir)
+        free(qemu_driver->configDir);
+    if (qemu_driver->autostartDir)
+        free(qemu_driver->autostartDir);
+    if (qemu_driver->networkConfigDir)
+        free(qemu_driver->networkConfigDir);
+    if (qemu_driver->networkAutostartDir)
+        free(qemu_driver->networkAutostartDir);
+
+    if (qemu_driver->brctl)
+        brShutdown(qemu_driver->brctl);
+    if (qemu_driver->iptables)
+        iptablesContextFree(qemu_driver->iptables);
+
+    free(qemu_driver);
+    qemu_driver = NULL;
 }
 
 static int
-qemudExec(struct qemud_server *server, char **argv,
+qemudExec(char **argv,
           int *retpid, int *outfd, int *errfd) {
     int pid, null;
     int pipeout[2] = {-1,-1};
@@ -226,13 +315,13 @@ qemudExec(struct qemud_server *server, c
 }
 
 /* Return -1 for error, 1 to continue reading and 0 for success */
-typedef int qemudHandlerMonitorOutput(struct qemud_server *server,
+typedef int qemudHandlerMonitorOutput(struct qemud_driver *driver,
                                       struct qemud_vm *vm,
                                       const char *output,
                                       int fd);
 
 static int
-qemudReadMonitorOutput(struct qemud_server *server,
+qemudReadMonitorOutput(struct qemud_driver *driver,
                        struct qemud_vm *vm,
                        int fd,
                        char *buf,
@@ -292,7 +381,7 @@ qemudReadMonitorOutput(struct qemud_serv
         } else {
             got += ret;
             buf[got] = '\0';
-            if ((ret = func(server, vm, buf, fd)) != 1)
+            if ((ret = func(driver, vm, buf, fd)) != 1)
                 return ret;
         }
     }
@@ -305,7 +394,7 @@ qemudReadMonitorOutput(struct qemud_serv
 }
 
 static int
-qemudCheckMonitorPrompt(struct qemud_server *server ATTRIBUTE_UNUSED,
+qemudCheckMonitorPrompt(struct qemud_driver *driver ATTRIBUTE_UNUSED,
                         struct qemud_vm *vm,
                         const char *output,
                         int fd)
@@ -318,7 +407,7 @@ qemudCheckMonitorPrompt(struct qemud_ser
     return 0;
 }
 
-static int qemudOpenMonitor(struct qemud_server *server, struct qemud_vm *vm, const char *monitor) {
+static int qemudOpenMonitor(struct qemud_driver *driver, struct qemud_vm *vm, const char *monitor) {
     int monfd;
     char buf[1024];
     int ret = -1;
@@ -339,7 +428,7 @@ static int qemudOpenMonitor(struct qemud
         goto error;
     }
 
-    ret = qemudReadMonitorOutput(server, vm, monfd,
+    ret = qemudReadMonitorOutput(driver, vm, monfd,
                                  buf, sizeof(buf),
                                  qemudCheckMonitorPrompt,
                                  "monitor");
@@ -379,7 +468,7 @@ static int qemudExtractMonitorPath(const
 }
 
 static int
-qemudOpenMonitorPath(struct qemud_server *server,
+qemudOpenMonitorPath(struct qemud_driver *driver,
                      struct qemud_vm *vm,
                      const char *output,
                      int fd ATTRIBUTE_UNUSED)
@@ -389,12 +478,12 @@ qemudOpenMonitorPath(struct qemud_server
     if (qemudExtractMonitorPath(output, monitor, sizeof(monitor)) < 0)
         return 1; /* keep reading */
 
-    return qemudOpenMonitor(server, vm, monitor);
-}
-
-static int qemudWaitForMonitor(struct qemud_server *server, struct qemud_vm *vm) {
+    return qemudOpenMonitor(driver, vm, monitor);
+}
+
+static int qemudWaitForMonitor(struct qemud_driver *driver, struct qemud_vm *vm) {
     char buf[1024]; /* Plenty of space to get startup greeting */
-    int ret = qemudReadMonitorOutput(server, vm, vm->stderr,
+    int ret = qemudReadMonitorOutput(driver, vm, vm->stderr,
                                      buf, sizeof(buf),
                                      qemudOpenMonitorPath,
                                      "console");
@@ -412,7 +501,7 @@ static int qemudWaitForMonitor(struct qe
     return ret;
 }
 
-static int qemudNextFreeVNCPort(struct qemud_server *server ATTRIBUTE_UNUSED) {
+static int qemudNextFreeVNCPort(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
     int i;
 
     for (i = 5900 ; i < 6000 ; i++) {
@@ -448,7 +537,7 @@ static int qemudNextFreeVNCPort(struct q
     return -1;
 }
 
-int qemudStartVMDaemon(struct qemud_server *server,
+int qemudStartVMDaemon(struct qemud_driver *driver,
                        struct qemud_vm *vm) {
     char **argv = NULL, **tmp;
     int i;
@@ -461,7 +550,7 @@ int qemudStartVMDaemon(struct qemud_serv
     }
 
     if (vm->def->vncPort < 0) {
-        int port = qemudNextFreeVNCPort(server);
+        int port = qemudNextFreeVNCPort(driver);
         if (port < 0) {
             qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "Unable to find an unused VNC port");
@@ -471,25 +560,25 @@ int qemudStartVMDaemon(struct qemud_serv
     } else
         vm->def->vncActivePort = vm->def->vncPort;
 
-    if ((strlen(server->logDir) + /* path */
+    if ((strlen(driver->logDir) + /* path */
          1 + /* Separator */
          strlen(vm->def->name) + /* basename */
          4 + /* suffix .log */
          1 /* NULL */) > PATH_MAX) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "config file path too long: %s/%s.log",
-                         server->logDir, vm->def->name);
-        return -1;
-    }
-    strcpy(logfile, server->logDir);
+                         driver->logDir, vm->def->name);
+        return -1;
+    }
+    strcpy(logfile, driver->logDir);
     strcat(logfile, "/");
     strcat(logfile, vm->def->name);
     strcat(logfile, ".log");
 
-    if (qemudEnsureDir(server->logDir) < 0) {
+    if (qemudEnsureDir(driver->logDir) < 0) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "cannot create log directory %s: %s",
-                         server->logDir, strerror(errno));
+                         driver->logDir, strerror(errno));
         return -1;
     }
 
@@ -501,7 +590,7 @@ int qemudStartVMDaemon(struct qemud_serv
         return -1;
     }
 
-    if (qemudBuildCommandLine(server, vm, &argv) < 0) {
+    if (qemudBuildCommandLine(driver, vm, &argv) < 0) {
         close(vm->logfile);
         vm->logfile = -1;
         return -1;
@@ -521,13 +610,12 @@ int qemudStartVMDaemon(struct qemud_serv
         qemudLog(QEMUD_WARN, "Unable to write argv to logfile %d: %s",
                  errno, strerror(errno));
 
-    if (qemudExec(server, argv, &vm->pid, &vm->stdout, &vm->stderr) == 0) {
-        vm->id = server->nextvmid++;
+    if (qemudExec(argv, &vm->pid, &vm->stdout, &vm->stderr) == 0) {
+        vm->id = driver->nextvmid++;
         vm->state = QEMUD_STATE_RUNNING;
 
-        server->ninactivevms--;
-        server->nactivevms++;
-        server->nvmfds += 2;
+        driver->ninactivevms--;
+        driver->nactivevms++;
     }
 
     for (i = 0 ; argv[i] ; i++)
@@ -547,29 +635,29 @@ int qemudStartVMDaemon(struct qemud_serv
     if (virEventAddHandle(vm->stdout,
                           POLLIN | POLLERR | POLLHUP,
                           qemudDispatchVMEvent,
-                          server) < 0) {
-        qemudShutdownVMDaemon(server, vm);
+                          driver) < 0) {
+        qemudShutdownVMDaemon(driver, vm);
         return -1;
     }
 
     if (virEventAddHandle(vm->stderr,
                           POLLIN | POLLERR | POLLHUP,
                           qemudDispatchVMEvent,
-                          server) < 0) {
-        qemudShutdownVMDaemon(server, vm);
-        return -1;
-    }
-
-
-    if (qemudWaitForMonitor(server, vm) < 0) {
-        qemudShutdownVMDaemon(server, vm);
-        return -1;
-    }
-
-    return 0;
-}
-
-static int qemudVMData(struct qemud_server *server ATTRIBUTE_UNUSED,
+                          driver) < 0) {
+        qemudShutdownVMDaemon(driver, vm);
+        return -1;
+    }
+
+
+    if (qemudWaitForMonitor(driver, vm) < 0) {
+        qemudShutdownVMDaemon(driver, vm);
+        return -1;
+    }
+
+    return 0;
+}
+
+static int qemudVMData(struct qemud_driver *driver ATTRIBUTE_UNUSED,
                        struct qemud_vm *vm, int fd) {
     char buf[4096];
     if (vm->pid < 0)
@@ -599,7 +687,7 @@ static int qemudVMData(struct qemud_serv
 }
 
 
-int qemudShutdownVMDaemon(struct qemud_server *server, struct qemud_vm *vm) {
+int qemudShutdownVMDaemon(struct qemud_driver *driver, struct qemud_vm *vm) {
     if (!qemudIsActiveVM(vm))
         return 0;
 
@@ -607,8 +695,8 @@ int qemudShutdownVMDaemon(struct qemud_s
 
     kill(vm->pid, SIGTERM);
 
-    qemudVMData(server, vm, vm->stdout);
-    qemudVMData(server, vm, vm->stderr);
+    qemudVMData(driver, vm, vm->stdout);
+    qemudVMData(driver, vm, vm->stderr);
 
     virEventRemoveHandle(vm->stdout);
     virEventRemoveHandle(vm->stderr);
@@ -623,7 +711,6 @@ int qemudShutdownVMDaemon(struct qemud_s
     vm->stdout = -1;
     vm->stderr = -1;
     vm->monitor = -1;
-    server->nvmfds -= 2;
 
     if (waitpid(vm->pid, NULL, WNOHANG) != vm->pid) {
         kill(vm->pid, SIGKILL);
@@ -642,32 +729,31 @@ int qemudShutdownVMDaemon(struct qemud_s
         vm->newDef = NULL;
     }
 
-    server->nactivevms--;
-    server->ninactivevms++;
+    driver->nactivevms--;
+    driver->ninactivevms++;
 
     if (!vm->configFile[0])
-        qemudRemoveInactiveVM(server, vm);
-
-    return 0;
-}
-
-static int qemudDispatchVMLog(struct qemud_server *server, struct qemud_vm *vm, int fd) {
-    if (qemudVMData(server, vm, fd) < 0)
-        if (qemudShutdownVMDaemon(server, vm) < 0)
+        qemudRemoveInactiveVM(driver, vm);
+
+    return 0;
+}
+
+static int qemudDispatchVMLog(struct qemud_driver *driver, struct qemud_vm *vm, int fd) {
+    if (qemudVMData(driver, vm, fd) < 0)
+        if (qemudShutdownVMDaemon(driver, vm) < 0)
             return -1;
     return 0;
 }
 
-static int qemudDispatchVMFailure(struct qemud_server *server, struct qemud_vm *vm,
+static int qemudDispatchVMFailure(struct qemud_driver *driver, struct qemud_vm *vm,
                                   int fd ATTRIBUTE_UNUSED) {
-    if (qemudShutdownVMDaemon(server, vm) < 0)
+    if (qemudShutdownVMDaemon(driver, vm) < 0)
         return -1;
     return 0;
 }
 
 static int
-qemudBuildDnsmasqArgv(struct qemud_server *server,
-                      struct qemud_network *network,
+qemudBuildDnsmasqArgv(struct qemud_network *network,
                       char ***argv) {
     int i, len;
     char buf[PATH_MAX];
@@ -702,7 +788,7 @@ qemudBuildDnsmasqArgv(struct qemud_serve
     APPEND_ARG(*argv, i++, "--keep-in-foreground");
     /*
      * Needed to ensure dnsmasq uses same algorithm for processing
-     * multiple nameserver entries in /etc/resolv.conf as GLibC.
+     * multiple namedriver entries in /etc/resolv.conf as GLibC.
      */
     APPEND_ARG(*argv, i++, "--strict-order");
     APPEND_ARG(*argv, i++, "--bind-interfaces");
@@ -764,8 +850,7 @@ qemudBuildDnsmasqArgv(struct qemud_serve
 
 
 static int
-dhcpStartDhcpDaemon(struct qemud_server *server,
-                    struct qemud_network *network)
+dhcpStartDhcpDaemon(struct qemud_network *network)
 {
     char **argv;
     int ret, i;
@@ -777,10 +862,10 @@ dhcpStartDhcpDaemon(struct qemud_server 
     }
 
     argv = NULL;
-    if (qemudBuildDnsmasqArgv(server, network, &argv) < 0)
-        return -1;
-
-    ret = qemudExec(server, argv, &network->dnsmasqPid, NULL, NULL);
+    if (qemudBuildDnsmasqArgv(network, &argv) < 0)
+        return -1;
+
+    ret = qemudExec(argv, &network->dnsmasqPid, NULL, NULL);
 
     for (i = 0; argv[i]; i++)
         free(argv[i]);
@@ -790,25 +875,25 @@ dhcpStartDhcpDaemon(struct qemud_server 
 }
 
 static int
-qemudAddIptablesRules(struct qemud_server *server,
+qemudAddIptablesRules(struct qemud_driver *driver,
                       struct qemud_network *network) {
     int err;
 
-    if (!server->iptables && !(server->iptables = iptablesContextNew())) {
+    if (!driver->iptables && !(driver->iptables = iptablesContextNew())) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "iptables support");
         return 1;
     }
 
 
     /* allow DHCP requests through to dnsmasq */
-    if ((err = iptablesAddTcpInput(server->iptables, network->bridge, 67))) {
+    if ((err = iptablesAddTcpInput(driver->iptables, network->bridge, 67))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "failed to add iptables rule to allow DHCP requests from '%s' : %s\n",
                          network->bridge, strerror(err));
         goto err1;
     }
 
-    if ((err = iptablesAddUdpInput(server->iptables, network->bridge, 67))) {
+    if ((err = iptablesAddUdpInput(driver->iptables, network->bridge, 67))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "failed to add iptables rule to allow DHCP requests from '%s' : %s\n",
                          network->bridge, strerror(err));
@@ -816,14 +901,14 @@ qemudAddIptablesRules(struct qemud_serve
     }
 
     /* allow DNS requests through to dnsmasq */
-    if ((err = iptablesAddTcpInput(server->iptables, network->bridge, 53))) {
+    if ((err = iptablesAddTcpInput(driver->iptables, network->bridge, 53))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "failed to add iptables rule to allow DNS requests from '%s' : %s\n",
                          network->bridge, strerror(err));
         goto err3;
     }
 
-    if ((err = iptablesAddUdpInput(server->iptables, network->bridge, 53))) {
+    if ((err = iptablesAddUdpInput(driver->iptables, network->bridge, 53))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "failed to add iptables rule to allow DNS requests from '%s' : %s\n",
                          network->bridge, strerror(err));
@@ -833,14 +918,14 @@ qemudAddIptablesRules(struct qemud_serve
 
     /* Catch all rules to block forwarding to/from bridges */
 
-    if ((err = iptablesAddForwardRejectOut(server->iptables, network->bridge))) {
+    if ((err = iptablesAddForwardRejectOut(driver->iptables, network->bridge))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "failed to add iptables rule to block outbound traffic from '%s' : %s\n",
                          network->bridge, strerror(err));
         goto err5;
     }
 
-    if ((err = iptablesAddForwardRejectIn(server->iptables, network->bridge))) {
+    if ((err = iptablesAddForwardRejectIn(driver->iptables, network->bridge))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "failed to add iptables rule to block inbound traffic to '%s' : %s\n",
                          network->bridge, strerror(err));
@@ -848,7 +933,7 @@ qemudAddIptablesRules(struct qemud_serve
     }
 
     /* Allow traffic between guests on the same bridge */
-    if ((err = iptablesAddForwardAllowCross(server->iptables, network->bridge))) {
+    if ((err = iptablesAddForwardAllowCross(driver->iptables, network->bridge))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "failed to add iptables rule to allow cross bridge traffic on '%s' : %s\n",
                          network->bridge, strerror(err));
@@ -861,7 +946,7 @@ qemudAddIptablesRules(struct qemud_serve
         return 1;
 
     /* allow forwarding packets from the bridge interface */
-    if ((err = iptablesAddForwardAllowOut(server->iptables,
+    if ((err = iptablesAddForwardAllowOut(driver->iptables,
                                           network->def->network,
                                           network->bridge,
                                           network->def->forwardDev))) {
@@ -872,7 +957,7 @@ qemudAddIptablesRules(struct qemud_serve
     }
 
     /* allow forwarding packets to the bridge interface if they are part of an existing connection */
-    if ((err = iptablesAddForwardAllowIn(server->iptables,
+    if ((err = iptablesAddForwardAllowIn(driver->iptables,
                                          network->def->network,
                                          network->bridge,
                                          network->def->forwardDev))) {
@@ -883,7 +968,7 @@ qemudAddIptablesRules(struct qemud_serve
     }
 
     /* enable masquerading */
-    if ((err = iptablesAddForwardMasquerade(server->iptables,
+    if ((err = iptablesAddForwardMasquerade(driver->iptables,
                                             network->def->network,
                                             network->def->forwardDev))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -895,59 +980,59 @@ qemudAddIptablesRules(struct qemud_serve
     return 1;
 
  err10:
-    iptablesRemoveForwardAllowIn(server->iptables,
+    iptablesRemoveForwardAllowIn(driver->iptables,
                                  network->def->network,
                                  network->bridge,
                                  network->def->forwardDev);
  err9:
-    iptablesRemoveForwardAllowOut(server->iptables,
+    iptablesRemoveForwardAllowOut(driver->iptables,
                                   network->def->network,
                                   network->bridge,
                                   network->def->forwardDev);
  err8:
-    iptablesRemoveForwardAllowCross(server->iptables,
+    iptablesRemoveForwardAllowCross(driver->iptables,
                                     network->bridge);
  err7:
-    iptablesRemoveForwardRejectIn(server->iptables,
+    iptablesRemoveForwardRejectIn(driver->iptables,
                                   network->bridge);
  err6:
-    iptablesRemoveForwardRejectOut(server->iptables,
+    iptablesRemoveForwardRejectOut(driver->iptables,
                                    network->bridge);
  err5:
-    iptablesRemoveUdpInput(server->iptables, network->bridge, 53);
+    iptablesRemoveUdpInput(driver->iptables, network->bridge, 53);
  err4:
-    iptablesRemoveTcpInput(server->iptables, network->bridge, 53);
+    iptablesRemoveTcpInput(driver->iptables, network->bridge, 53);
  err3:
-    iptablesRemoveUdpInput(server->iptables, network->bridge, 67);
+    iptablesRemoveUdpInput(driver->iptables, network->bridge, 67);
  err2:
-    iptablesRemoveTcpInput(server->iptables, network->bridge, 67);
+    iptablesRemoveTcpInput(driver->iptables, network->bridge, 67);
  err1:
     return 0;
 }
 
 static void
-qemudRemoveIptablesRules(struct qemud_server *server,
+qemudRemoveIptablesRules(struct qemud_driver *driver,
                          struct qemud_network *network) {
     if (network->def->forward) {
-        iptablesRemoveForwardMasquerade(server->iptables,
+        iptablesRemoveForwardMasquerade(driver->iptables,
                                      network->def->network,
                                      network->def->forwardDev);
-        iptablesRemoveForwardAllowIn(server->iptables,
+        iptablesRemoveForwardAllowIn(driver->iptables,
                                    network->def->network,
                                    network->bridge,
                                    network->def->forwardDev);
-        iptablesRemoveForwardAllowOut(server->iptables,
+        iptablesRemoveForwardAllowOut(driver->iptables,
                                       network->def->network,
                                       network->bridge,
                                       network->def->forwardDev);
     }
-    iptablesRemoveForwardAllowCross(server->iptables, network->bridge);
-    iptablesRemoveForwardRejectIn(server->iptables, network->bridge);
-    iptablesRemoveForwardRejectOut(server->iptables, network->bridge);
-    iptablesRemoveUdpInput(server->iptables, network->bridge, 53);
-    iptablesRemoveTcpInput(server->iptables, network->bridge, 53);
-    iptablesRemoveUdpInput(server->iptables, network->bridge, 67);
-    iptablesRemoveTcpInput(server->iptables, network->bridge, 67);
+    iptablesRemoveForwardAllowCross(driver->iptables, network->bridge);
+    iptablesRemoveForwardRejectIn(driver->iptables, network->bridge);
+    iptablesRemoveForwardRejectOut(driver->iptables, network->bridge);
+    iptablesRemoveUdpInput(driver->iptables, network->bridge, 53);
+    iptablesRemoveTcpInput(driver->iptables, network->bridge, 53);
+    iptablesRemoveUdpInput(driver->iptables, network->bridge, 67);
+    iptablesRemoveTcpInput(driver->iptables, network->bridge, 67);
 }
 
 static int
@@ -970,7 +1055,7 @@ qemudEnableIpForwarding(void)
 #undef PROC_IP_FORWARD
 }
 
-int qemudStartNetworkDaemon(struct qemud_server *server,
+int qemudStartNetworkDaemon(struct qemud_driver *driver,
                             struct qemud_network *network) {
     const char *name;
     int err;
@@ -981,7 +1066,7 @@ int qemudStartNetworkDaemon(struct qemud
         return -1;
     }
 
-    if (!server->brctl && (err = brInit(&server->brctl))) {
+    if (!driver->brctl && (err = brInit(&driver->brctl))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "cannot initialize bridge support: %s", strerror(err));
         return -1;
@@ -994,14 +1079,14 @@ int qemudStartNetworkDaemon(struct qemud
         name = network->def->bridge;
     }
 
-    if ((err = brAddBridge(server->brctl, name, network->bridge, sizeof(network->bridge)))) {
+    if ((err = brAddBridge(driver->brctl, name, network->bridge, sizeof(network->bridge)))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "cannot create bridge '%s' : %s", name, strerror(err));
         return -1;
     }
 
     if (network->def->ipAddress[0] &&
-        (err = brSetInetAddress(server->brctl, network->bridge, network->def->ipAddress))) {
+        (err = brSetInetAddress(driver->brctl, network->bridge, network->def->ipAddress))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "cannot set IP address on bridge '%s' to '%s' : %s\n",
                          network->bridge, network->def->ipAddress, strerror(err));
@@ -1009,7 +1094,7 @@ int qemudStartNetworkDaemon(struct qemud
     }
 
     if (network->def->netmask[0] &&
-        (err = brSetInetNetmask(server->brctl, network->bridge, network->def->netmask))) {
+        (err = brSetInetNetmask(driver->brctl, network->bridge, network->def->netmask))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "cannot set netmask on bridge '%s' to '%s' : %s\n",
                          network->bridge, network->def->netmask, strerror(err));
@@ -1017,14 +1102,14 @@ int qemudStartNetworkDaemon(struct qemud
     }
 
     if (network->def->ipAddress[0] &&
-        (err = brSetInterfaceUp(server->brctl, network->bridge, 1))) {
+        (err = brSetInterfaceUp(driver->brctl, network->bridge, 1))) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "failed to bring the bridge '%s' up : %s\n",
                          network->bridge, strerror(err));
         goto err_delbr;
     }
 
-    if (!qemudAddIptablesRules(server, network))
+    if (!qemudAddIptablesRules(driver, network))
         goto err_delbr1;
 
     if (network->def->forward &&
@@ -1035,28 +1120,28 @@ int qemudStartNetworkDaemon(struct qemud
     }
 
     if (network->def->ranges &&
-        dhcpStartDhcpDaemon(server, network) < 0)
+        dhcpStartDhcpDaemon(network) < 0)
         goto err_delbr2;
 
     network->active = 1;
 
-    server->ninactivenetworks--;
-    server->nactivenetworks++;
+    driver->ninactivenetworks--;
+    driver->nactivenetworks++;
 
     return 0;
 
  err_delbr2:
-    qemudRemoveIptablesRules(server, network);
+    qemudRemoveIptablesRules(driver, network);
 
  err_delbr1:
     if (network->def->ipAddress[0] &&
-        (err = brSetInterfaceUp(server->brctl, network->bridge, 0))) {
+        (err = brSetInterfaceUp(driver->brctl, network->bridge, 0))) {
         qemudLog(QEMUD_WARN, "Failed to bring down bridge '%s' : %s",
                  network->bridge, strerror(err));
     }
 
  err_delbr:
-    if ((err = brDeleteBridge(server->brctl, network->bridge))) {
+    if ((err = brDeleteBridge(driver->brctl, network->bridge))) {
         qemudLog(QEMUD_WARN, "Failed to delete bridge '%s' : %s\n",
                  network->bridge, strerror(err));
     }
@@ -1065,7 +1150,7 @@ int qemudStartNetworkDaemon(struct qemud
 }
 
 
-int qemudShutdownNetworkDaemon(struct qemud_server *server,
+int qemudShutdownNetworkDaemon(struct qemud_driver *driver,
                                struct qemud_network *network) {
     int err;
 
@@ -1077,15 +1162,15 @@ int qemudShutdownNetworkDaemon(struct qe
     if (network->dnsmasqPid > 0)
         kill(network->dnsmasqPid, SIGTERM);
 
-    qemudRemoveIptablesRules(server, network);
+    qemudRemoveIptablesRules(driver, network);
 
     if (network->def->ipAddress[0] &&
-        (err = brSetInterfaceUp(server->brctl, network->bridge, 0))) {
+        (err = brSetInterfaceUp(driver->brctl, network->bridge, 0))) {
         qemudLog(QEMUD_WARN, "Failed to bring down bridge '%s' : %s\n",
                  network->bridge, strerror(err));
     }
 
-    if ((err = brDeleteBridge(server->brctl, network->bridge))) {
+    if ((err = brDeleteBridge(driver->brctl, network->bridge))) {
         qemudLog(QEMUD_WARN, "Failed to delete bridge '%s' : %s\n",
                  network->bridge, strerror(err));
     }
@@ -1107,19 +1192,19 @@ int qemudShutdownNetworkDaemon(struct qe
         network->newDef = NULL;
     }
 
-    server->nactivenetworks--;
-    server->ninactivenetworks++;
+    driver->nactivenetworks--;
+    driver->ninactivenetworks++;
 
     if (!network->configFile[0])
-        qemudRemoveInactiveNetwork(server, network);
+        qemudRemoveInactiveNetwork(driver, network);
 
     return 0;
 }
 
 
 static void qemudDispatchVMEvent(int fd, int events, void *opaque) {
-    struct qemud_server *server = (struct qemud_server *)opaque;
-    struct qemud_vm *vm = server->vms;
+    struct qemud_driver *driver = (struct qemud_driver *)opaque;
+    struct qemud_vm *vm = driver->vms;
 
     while (vm) {
         if (qemudIsActiveVM(vm) &&
@@ -1134,12 +1219,12 @@ static void qemudDispatchVMEvent(int fd,
         return;
 
     if (events == POLLIN)
-        qemudDispatchVMLog(server, vm, fd);
+        qemudDispatchVMLog(driver, vm, fd);
     else
-        qemudDispatchVMFailure(server, vm, fd);
-}
-
-int qemudMonitorCommand(struct qemud_server *server ATTRIBUTE_UNUSED,
+        qemudDispatchVMFailure(driver, vm, fd);
+}
+
+int qemudMonitorCommand(struct qemud_driver *driver ATTRIBUTE_UNUSED,
                         struct qemud_vm *vm,
                         const char *cmd,
                         char **reply) {
@@ -1301,7 +1386,7 @@ int qemudGetNodeInfo(unsigned int *memor
     return 0;
 }
 
-char *qemudGetCapabilities(struct qemud_server *server) {
+char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
     struct utsname utsname;
     int i, j, r;
     int have_kqemu = 0;
@@ -1488,8 +1573,8 @@ static int qemudGetProcessInfo(unsigned 
     return 0;
 }
 
-struct qemud_vm *qemudFindVMByID(const struct qemud_server *server, int id) {
-    struct qemud_vm *vm = server->vms;
+struct qemud_vm *qemudFindVMByID(const struct qemud_driver *driver, int id) {
+    struct qemud_vm *vm = driver->vms;
 
     while (vm) {
         if (qemudIsActiveVM(vm) && vm->id == id)
@@ -1500,9 +1585,9 @@ struct qemud_vm *qemudFindVMByID(const s
     return NULL;
 }
 
-struct qemud_vm *qemudFindVMByUUID(const struct qemud_server *server,
+struct qemud_vm *qemudFindVMByUUID(const struct qemud_driver *driver,
                                    const unsigned char *uuid) {
-    struct qemud_vm *vm = server->vms;
+    struct qemud_vm *vm = driver->vms;
 
     while (vm) {
         if (!memcmp(vm->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
@@ -1513,9 +1598,9 @@ struct qemud_vm *qemudFindVMByUUID(const
     return NULL;
 }
 
-struct qemud_vm *qemudFindVMByName(const struct qemud_server *server,
+struct qemud_vm *qemudFindVMByName(const struct qemud_driver *driver,
                                    const char *name) {
-    struct qemud_vm *vm = server->vms;
+    struct qemud_vm *vm = driver->vms;
 
     while (vm) {
         if (!strcmp(vm->def->name, name))
@@ -1526,15 +1611,15 @@ struct qemud_vm *qemudFindVMByName(const
     return NULL;
 }
 
-int qemudGetVersion(struct qemud_server *server) {
-    if (qemudExtractVersion(server) < 0)
-        return -1;
-
-    return server->qemuVersion;
-}
-
-int qemudListDomains(struct qemud_server *server, int *ids, int nids) {
-    struct qemud_vm *vm = server->vms;
+int qemudGetVersion(struct qemud_driver *driver) {
+    if (qemudExtractVersion(driver) < 0)
+        return -1;
+
+    return driver->qemuVersion;
+}
+
+int qemudListDomains(struct qemud_driver *driver, int *ids, int nids) {
+    struct qemud_vm *vm = driver->vms;
     int got = 0;
     while (vm && got < nids) {
         if (qemudIsActiveVM(vm)) {
@@ -1545,24 +1630,24 @@ int qemudListDomains(struct qemud_server
     }
     return got;
 }
-int qemudNumDomains(struct qemud_server *server) {
-    return server->nactivevms;
-}
-struct qemud_vm *qemudDomainCreate(struct qemud_server *server, const char *xml) {
+int qemudNumDomains(struct qemud_driver *driver) {
+    return driver->nactivevms;
+}
+struct qemud_vm *qemudDomainCreate(struct qemud_driver *driver, const char *xml) {
 
     struct qemud_vm_def *def;
     struct qemud_vm *vm;
 
-    if (!(def = qemudParseVMDef(server, xml, NULL)))
+    if (!(def = qemudParseVMDef(driver, xml, NULL)))
         return NULL;
 
-    if (!(vm = qemudAssignVMDef(server, def))) {
+    if (!(vm = qemudAssignVMDef(driver, def))) {
         qemudFreeVMDef(def);
         return NULL;
     }
 
-    if (qemudStartVMDaemon(server, vm) < 0) {
-        qemudRemoveInactiveVM(server, vm);
+    if (qemudStartVMDaemon(driver, vm) < 0) {
+        qemudRemoveInactiveVM(driver, vm);
         return NULL;
     }
 
@@ -1570,9 +1655,9 @@ struct qemud_vm *qemudDomainCreate(struc
 }
 
 
-int qemudDomainSuspend(struct qemud_server *server, int id) {
+int qemudDomainSuspend(struct qemud_driver *driver, int id) {
     char *info;
-    struct qemud_vm *vm = qemudFindVMByID(server, id);
+    struct qemud_vm *vm = qemudFindVMByID(driver, id);
     if (!vm) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
         return -1;
@@ -1584,7 +1669,7 @@ int qemudDomainSuspend(struct qemud_serv
     if (vm->state == QEMUD_STATE_PAUSED)
         return 0;
 
-    if (qemudMonitorCommand(server, vm, "stop\n", &info) < 0) {
+    if (qemudMonitorCommand(driver, vm, "stop\n", &info) < 0) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "suspend operation failed");
         return -1;
     }
@@ -1595,9 +1680,9 @@ int qemudDomainSuspend(struct qemud_serv
 }
 
 
-int qemudDomainResume(struct qemud_server *server, int id) {
+int qemudDomainResume(struct qemud_driver *driver, int id) {
     char *info;
-    struct qemud_vm *vm = qemudFindVMByID(server, id);
+    struct qemud_vm *vm = qemudFindVMByID(driver, id);
     if (!vm) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
         return -1;
@@ -1608,7 +1693,7 @@ int qemudDomainResume(struct qemud_serve
     }
     if (vm->state == QEMUD_STATE_RUNNING)
         return 0;
-    if (qemudMonitorCommand(server, vm, "cont\n", &info) < 0) {
+    if (qemudMonitorCommand(driver, vm, "cont\n", &info) < 0) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "resume operation failed");
         return -1;
     }
@@ -1619,8 +1704,8 @@ int qemudDomainResume(struct qemud_serve
 }
 
 
-int qemudDomainDestroy(struct qemud_server *server, int id) {
-    struct qemud_vm *vm = qemudFindVMByID(server, id);
+int qemudDomainDestroy(struct qemud_driver *driver, int id) {
+    struct qemud_vm *vm = qemudFindVMByID(driver, id);
 
     if (!vm) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN,
@@ -1628,17 +1713,17 @@ int qemudDomainDestroy(struct qemud_serv
         return -1;
     }
 
-    return qemudShutdownVMDaemon(server, vm);
-}
-
-
-int qemudDomainGetInfo(struct qemud_server *server, const unsigned char *uuid,
+    return qemudShutdownVMDaemon(driver, vm);
+}
+
+
+int qemudDomainGetInfo(struct qemud_driver *driver, const unsigned char *uuid,
                        int *runstate,
                        unsigned long long *cputime,
                        unsigned long *maxmem,
                        unsigned long *memory,
                        unsigned int *nrVirtCpu) {
-    struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
+    struct qemud_vm *vm = qemudFindVMByUUID(driver, uuid);
     if (!vm) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
         return -1;
@@ -1662,9 +1747,9 @@ int qemudDomainGetInfo(struct qemud_serv
 }
 
 
-int qemudDomainSave(struct qemud_server *server, int id,
+int qemudDomainSave(struct qemud_driver *driver, int id,
                     const char *path ATTRIBUTE_UNUSED) {
-    struct qemud_vm *vm = qemudFindVMByID(server, id);
+    struct qemud_vm *vm = qemudFindVMByID(driver, id);
     if (!vm) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
         return -1;
@@ -1678,22 +1763,22 @@ int qemudDomainSave(struct qemud_server 
 }
 
 
-int qemudDomainRestore(struct qemud_server *server,
+int qemudDomainRestore(struct qemud_driver *driver ATTRIBUTE_UNUSED,
                        const char *path ATTRIBUTE_UNUSED) {
     qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "restore is not supported");
     return -1;
 }
 
 
-int qemudDomainDumpXML(struct qemud_server *server, const unsigned char *uuid, char *xml, int xmllen) {
-    struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
+int qemudDomainDumpXML(struct qemud_driver *driver, const unsigned char *uuid, char *xml, int xmllen) {
+    struct qemud_vm *vm = qemudFindVMByUUID(driver, uuid);
     char *vmxml;
     if (!vm) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
         return -1;
     }
 
-    vmxml = qemudGenerateXML(server, vm, vm->def, 1);
+    vmxml = qemudGenerateXML(driver, vm, vm->def, 1);
     if (!vmxml)
         return -1;
 
@@ -1706,8 +1791,8 @@ int qemudDomainDumpXML(struct qemud_serv
 }
 
 
-int qemudListDefinedDomains(struct qemud_server *server, char *const*names, int nnames) {
-    struct qemud_vm *vm = server->vms;
+int qemudListDefinedDomains(struct qemud_driver *driver, char *const*names, int nnames) {
+    struct qemud_vm *vm = driver->vms;
     int got = 0;
     while (vm && got < nnames) {
         if (!qemudIsActiveVM(vm)) {
@@ -1721,13 +1806,13 @@ int qemudListDefinedDomains(struct qemud
 }
 
 
-int qemudNumDefinedDomains(struct qemud_server *server) {
-    return server->ninactivevms;
-}
-
-
-struct qemud_vm *qemudDomainStart(struct qemud_server *server, const unsigned char *uuid) {
-    struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
+int qemudNumDefinedDomains(struct qemud_driver *driver) {
+    return driver->ninactivevms;
+}
+
+
+struct qemud_vm *qemudDomainStart(struct qemud_driver *driver, const unsigned char *uuid) {
+    struct qemud_vm *vm = qemudFindVMByUUID(driver, uuid);
 
     if (!vm) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN,
@@ -1735,32 +1820,32 @@ struct qemud_vm *qemudDomainStart(struct
         return NULL;
     }
 
-    return qemudStartVMDaemon(server, vm) < 0 ? NULL : vm;
-}
-
-
-struct qemud_vm *qemudDomainDefine(struct qemud_server *server, const char *xml) {
+    return qemudStartVMDaemon(driver, vm) < 0 ? NULL : vm;
+}
+
+
+struct qemud_vm *qemudDomainDefine(struct qemud_driver *driver, const char *xml) {
     struct qemud_vm_def *def;
     struct qemud_vm *vm;
 
-    if (!(def = qemudParseVMDef(server, xml, NULL)))
+    if (!(def = qemudParseVMDef(driver, xml, NULL)))
         return NULL;
 
-    if (!(vm = qemudAssignVMDef(server, def))) {
+    if (!(vm = qemudAssignVMDef(driver, def))) {
         qemudFreeVMDef(def);
         return NULL;
     }
 
-    if (qemudSaveVMDef(server, vm, def) < 0) {
-        qemudRemoveInactiveVM(server, vm);
+    if (qemudSaveVMDef(driver, vm, def) < 0) {
+        qemudRemoveInactiveVM(driver, vm);
         return NULL;
     }
 
     return vm;
 }
 
-int qemudDomainUndefine(struct qemud_server *server, const unsigned char *uuid) {
-    struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
+int qemudDomainUndefine(struct qemud_driver *driver, const unsigned char *uuid) {
+    struct qemud_vm *vm = qemudFindVMByUUID(driver, uuid);
 
     if (!vm) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
@@ -1772,7 +1857,7 @@ int qemudDomainUndefine(struct qemud_ser
         return -1;
     }
 
-    if (qemudDeleteConfig(server, vm->configFile, vm->def->name) < 0)
+    if (qemudDeleteConfig(driver, vm->configFile, vm->def->name) < 0)
         return -1;
 
     if (unlink(vm->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR)
@@ -1782,15 +1867,15 @@ int qemudDomainUndefine(struct qemud_ser
     vm->configFile[0] = '\0';
     vm->autostartLink[0] = '\0';
 
-    qemudRemoveInactiveVM(server, vm);
-
-    return 0;
-}
-
-int qemudDomainGetAutostart(struct qemud_server *server,
+    qemudRemoveInactiveVM(driver, vm);
+
+    return 0;
+}
+
+int qemudDomainGetAutostart(struct qemud_driver *driver,
                              const unsigned char *uuid,
                              int *autostart) {
-    struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
+    struct qemud_vm *vm = qemudFindVMByUUID(driver, uuid);
 
     if (!vm) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
@@ -1802,10 +1887,10 @@ int qemudDomainGetAutostart(struct qemud
     return 0;
 }
 
-int qemudDomainSetAutostart(struct qemud_server *server,
+int qemudDomainSetAutostart(struct qemud_driver *driver,
                              const unsigned char *uuid,
                              int autostart) {
-    struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
+    struct qemud_vm *vm = qemudFindVMByUUID(driver, uuid);
 
     if (!vm) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
@@ -1820,10 +1905,10 @@ int qemudDomainSetAutostart(struct qemud
     if (autostart) {
         int err;
 
-        if ((err = qemudEnsureDir(server->autostartDir))) {
+        if ((err = qemudEnsureDir(driver->autostartDir))) {
             qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "cannot create autostart directory %s: %s",
-                             server->autostartDir, strerror(err));
+                             driver->autostartDir, strerror(err));
             return -1;
         }
 
@@ -1847,9 +1932,9 @@ int qemudDomainSetAutostart(struct qemud
     return 0;
 }
 
-struct qemud_network *qemudFindNetworkByUUID(const struct qemud_server *server,
+struct qemud_network *qemudFindNetworkByUUID(const struct qemud_driver *driver,
                                              const unsigned char *uuid) {
-    struct qemud_network *network = server->networks;
+    struct qemud_network *network = driver->networks;
 
     while (network) {
         if (!memcmp(network->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
@@ -1860,9 +1945,9 @@ struct qemud_network *qemudFindNetworkBy
     return NULL;
 }
 
-struct qemud_network *qemudFindNetworkByName(const struct qemud_server *server,
+struct qemud_network *qemudFindNetworkByName(const struct qemud_driver *driver,
                                              const char *name) {
-    struct qemud_network *network = server->networks;
+    struct qemud_network *network = driver->networks;
 
     while (network) {
         if (!strcmp(network->def->name, name))
@@ -1873,12 +1958,12 @@ struct qemud_network *qemudFindNetworkBy
     return NULL;
 }
 
-int qemudNumNetworks(struct qemud_server *server) {
-    return server->nactivenetworks;
-}
-
-int qemudListNetworks(struct qemud_server *server, char *const*names, int nnames) {
-    struct qemud_network *network = server->networks;
+int qemudNumNetworks(struct qemud_driver *driver) {
+    return driver->nactivenetworks;
+}
+
+int qemudListNetworks(struct qemud_driver *driver, char *const*names, int nnames) {
+    struct qemud_network *network = driver->networks;
     int got = 0;
     while (network && got < nnames) {
         if (qemudIsActiveNetwork(network)) {
@@ -1891,12 +1976,12 @@ int qemudListNetworks(struct qemud_serve
     return got;
 }
 
-int qemudNumDefinedNetworks(struct qemud_server *server) {
-    return server->ninactivenetworks;
-}
-
-int qemudListDefinedNetworks(struct qemud_server *server, char *const*names, int nnames) {
-    struct qemud_network *network = server->networks;
+int qemudNumDefinedNetworks(struct qemud_driver *driver) {
+    return driver->ninactivenetworks;
+}
+
+int qemudListDefinedNetworks(struct qemud_driver *driver, char *const*names, int nnames) {
+    struct qemud_network *network = driver->networks;
     int got = 0;
     while (network && got < nnames) {
         if (!qemudIsActiveNetwork(network)) {
@@ -1909,55 +1994,55 @@ int qemudListDefinedNetworks(struct qemu
     return got;
 }
 
-struct qemud_network *qemudNetworkCreate(struct qemud_server *server, const char *xml) {
+struct qemud_network *qemudNetworkCreate(struct qemud_driver *driver, const char *xml) {
     struct qemud_network_def *def;
     struct qemud_network *network;
 
-    if (!(def = qemudParseNetworkDef(server, xml, NULL)))
+    if (!(def = qemudParseNetworkDef(driver, xml, NULL)))
         return NULL;
 
-    if (!(network = qemudAssignNetworkDef(server, def))) {
+    if (!(network = qemudAssignNetworkDef(driver, def))) {
         qemudFreeNetworkDef(def);
         return NULL;
     }
 
-    if (qemudStartNetworkDaemon(server, network) < 0) {
-        qemudRemoveInactiveNetwork(server, network);
+    if (qemudStartNetworkDaemon(driver, network) < 0) {
+        qemudRemoveInactiveNetwork(driver, network);
         return NULL;
     }
 
     return network;
 }
 
-struct qemud_network *qemudNetworkDefine(struct qemud_server *server, const char *xml) {
+struct qemud_network *qemudNetworkDefine(struct qemud_driver *driver, const char *xml) {
     struct qemud_network_def *def;
     struct qemud_network *network;
 
-    if (!(def = qemudParseNetworkDef(server, xml, NULL)))
+    if (!(def = qemudParseNetworkDef(driver, xml, NULL)))
         return NULL;
 
-    if (!(network = qemudAssignNetworkDef(server, def))) {
+    if (!(network = qemudAssignNetworkDef(driver, def))) {
         qemudFreeNetworkDef(def);
         return NULL;
     }
 
-    if (qemudSaveNetworkDef(server, network, def) < 0) {
-        qemudRemoveInactiveNetwork(server, network);
+    if (qemudSaveNetworkDef(driver, network, def) < 0) {
+        qemudRemoveInactiveNetwork(driver, network);
         return NULL;
     }
 
     return network;
 }
 
-int qemudNetworkUndefine(struct qemud_server *server, const unsigned char *uuid) {
-    struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
+int qemudNetworkUndefine(struct qemud_driver *driver, const unsigned char *uuid) {
+    struct qemud_network *network = qemudFindNetworkByUUID(driver, uuid);
 
     if (!network) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no network with matching uuid");
         return -1;
     }
 
-    if (qemudDeleteConfig(server, network->configFile, network->def->name) < 0)
+    if (qemudDeleteConfig(driver, network->configFile, network->def->name) < 0)
         return -1;
 
     if (unlink(network->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR)
@@ -1967,13 +2052,13 @@ int qemudNetworkUndefine(struct qemud_se
     network->configFile[0] = '\0';
     network->autostartLink[0] = '\0';
 
-    qemudRemoveInactiveNetwork(server, network);
-
-    return 0;
-}
-
-struct qemud_network *qemudNetworkStart(struct qemud_server *server, const unsigned char *uuid) {
-    struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
+    qemudRemoveInactiveNetwork(driver, network);
+
+    return 0;
+}
+
+struct qemud_network *qemudNetworkStart(struct qemud_driver *driver, const unsigned char *uuid) {
+    struct qemud_network *network = qemudFindNetworkByUUID(driver, uuid);
 
     if (!network) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK,
@@ -1981,11 +2066,11 @@ struct qemud_network *qemudNetworkStart(
         return NULL;
     }
 
-    return qemudStartNetworkDaemon(server, network) < 0 ? NULL : network;
-}
-
-int qemudNetworkDestroy(struct qemud_server *server, const unsigned char *uuid) {
-    struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
+    return qemudStartNetworkDaemon(driver, network) < 0 ? NULL : network;
+}
+
+int qemudNetworkDestroy(struct qemud_driver *driver, const unsigned char *uuid) {
+    struct qemud_network *network = qemudFindNetworkByUUID(driver, uuid);
 
     if (!network) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK,
@@ -1993,18 +2078,18 @@ int qemudNetworkDestroy(struct qemud_ser
         return -1;
     }
 
-    return qemudShutdownNetworkDaemon(server, network);
-}
-
-int qemudNetworkDumpXML(struct qemud_server *server, const unsigned char *uuid, char *xml, int xmllen) {
-    struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
+    return qemudShutdownNetworkDaemon(driver, network);
+}
+
+int qemudNetworkDumpXML(struct qemud_driver *driver, const unsigned char *uuid, char *xml, int xmllen) {
+    struct qemud_network *network = qemudFindNetworkByUUID(driver, uuid);
     char *networkxml;
     if (!network) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK, "no network with matching uuid");
         return -1;
     }
 
-    networkxml = qemudGenerateNetworkXML(server, network, network->def);
+    networkxml = qemudGenerateNetworkXML(driver, network, network->def);
     if (!networkxml)
         return -1;
 
@@ -2016,8 +2101,8 @@ int qemudNetworkDumpXML(struct qemud_ser
     return 0;
 }
 
-int qemudNetworkGetBridgeName(struct qemud_server *server, const unsigned char *uuid, char *ifname, int ifnamelen) {
-    struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
+int qemudNetworkGetBridgeName(struct qemud_driver *driver, const unsigned char *uuid, char *ifname, int ifnamelen) {
+    struct qemud_network *network = qemudFindNetworkByUUID(driver, uuid);
 
     if (!network) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK, "no network with matching id");
@@ -2030,10 +2115,10 @@ int qemudNetworkGetBridgeName(struct qem
     return 0;
 }
 
-int qemudNetworkGetAutostart(struct qemud_server *server,
+int qemudNetworkGetAutostart(struct qemud_driver *driver,
                              const unsigned char *uuid,
                              int *autostart) {
-    struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
+    struct qemud_network *network = qemudFindNetworkByUUID(driver, uuid);
 
     if (!network) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK, "no network with matching uuid");
@@ -2045,10 +2130,10 @@ int qemudNetworkGetAutostart(struct qemu
     return 0;
 }
 
-int qemudNetworkSetAutostart(struct qemud_server *server,
+int qemudNetworkSetAutostart(struct qemud_driver *driver,
                              const unsigned char *uuid,
                              int autostart) {
-    struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
+    struct qemud_network *network = qemudFindNetworkByUUID(driver, uuid);
 
     if (!network) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK, "no network with matching uuid");
@@ -2063,10 +2148,10 @@ int qemudNetworkSetAutostart(struct qemu
     if (autostart) {
         int err;
 
-        if ((err = qemudEnsureDir(server->networkAutostartDir))) {
+        if ((err = qemudEnsureDir(driver->networkAutostartDir))) {
             qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "cannot create autostart directory %s: %s",
-                             server->networkAutostartDir, strerror(err));
+                             driver->networkAutostartDir, strerror(err));
             return -1;
         }
 
diff -r af6d5f54a13a qemud/driver.h
--- a/qemud/driver.h	Sun Jun 17 22:11:10 2007 -0400
+++ b/qemud/driver.h	Sun Jun 17 22:11:17 2007 -0400
@@ -27,21 +27,266 @@
 
 #include "internal.h"
 
-int qemudStartVMDaemon(struct qemud_server *server,
+/* Different types of QEMU acceleration possible */
+enum qemud_vm_virt_type {
+    QEMUD_VIRT_QEMU,
+    QEMUD_VIRT_KQEMU,
+    QEMUD_VIRT_KVM,
+};
+
+
+/* Two types of disk backends */
+enum qemud_vm_disk_type {
+    QEMUD_DISK_BLOCK,
+    QEMUD_DISK_FILE
+};
+
+/* Three types of disk frontend */
+enum qemud_vm_disk_device {
+    QEMUD_DISK_DISK,
+    QEMUD_DISK_CDROM,
+    QEMUD_DISK_FLOPPY,
+};
+
+/* Stores the virtual disk configuration */
+struct qemud_vm_disk_def {
+    int type;
+    int device;
+    char src[PATH_MAX];
+    char dst[NAME_MAX];
+    int readonly;
+
+    struct qemud_vm_disk_def *next;
+};
+
+#define QEMUD_MAC_ADDRESS_LEN 6
+#define QEMUD_OS_TYPE_MAX_LEN 10
+#define QEMUD_OS_ARCH_MAX_LEN 10
+#define QEMUD_OS_MACHINE_MAX_LEN 10
+
+/* 5 different types of networking config */
+enum qemud_vm_net_type {
+    QEMUD_NET_USER,
+    QEMUD_NET_ETHERNET,
+    QEMUD_NET_SERVER,
+    QEMUD_NET_CLIENT,
+    QEMUD_NET_MCAST,
+    QEMUD_NET_NETWORK,
+    QEMUD_NET_BRIDGE,
+};
+
+/* Stores the virtual network interface configuration */
+struct qemud_vm_net_def {
+    int type;
+    unsigned char mac[QEMUD_MAC_ADDRESS_LEN];
+    union {
+        struct {
+            char ifname[BR_IFNAME_MAXLEN];
+            char script[PATH_MAX];
+        } ethernet;
+        struct {
+            char address[BR_INET_ADDR_MAXLEN];
+            int port;
+        } socket; /* any of NET_CLIENT or NET_SERVER or NET_MCAST */
+        struct {
+            char name[QEMUD_MAX_NAME_LEN];
+            char ifname[BR_IFNAME_MAXLEN];
+        } network;
+        struct {
+            char brname[BR_IFNAME_MAXLEN];
+            char ifname[BR_IFNAME_MAXLEN];
+        } bridge;
+    } dst;
+
+    struct qemud_vm_net_def *next;
+};
+
+#define QEMUD_MAX_BOOT_DEVS 4
+
+/* 3 possible boot devices */
+enum qemud_vm_boot_order {
+    QEMUD_BOOT_FLOPPY,
+    QEMUD_BOOT_CDROM,
+    QEMUD_BOOT_DISK,
+    QEMUD_BOOT_NET,
+};
+/* 3 possible graphics console modes */
+enum qemud_vm_grapics_type {
+    QEMUD_GRAPHICS_NONE,
+    QEMUD_GRAPHICS_SDL,
+    QEMUD_GRAPHICS_VNC,
+};
+
+/* Internal flags to keep track of qemu command line capabilities */
+enum qemud_cmd_flags {
+    QEMUD_CMD_FLAG_KQEMU = 1,
+    QEMUD_CMD_FLAG_VNC_COLON = 2,
+    QEMUD_CMD_FLAG_NO_REBOOT = 4,
+};
+
+
+enum qemud_vm_features {
+    QEMUD_FEATURE_ACPI = 1,
+};
+
+/* Operating system configuration data & machine / arch */
+struct qemud_vm_os_def {
+    char type[QEMUD_OS_TYPE_MAX_LEN];
+    char arch[QEMUD_OS_ARCH_MAX_LEN];
+    char machine[QEMUD_OS_MACHINE_MAX_LEN];
+    int nBootDevs;
+    int bootDevs[QEMUD_MAX_BOOT_DEVS];
+    char kernel[PATH_MAX];
+    char initrd[PATH_MAX];
+    char cmdline[PATH_MAX];
+    char binary[PATH_MAX];
+};
+
+/* Guest VM main configuration */
+struct qemud_vm_def {
+    int virtType;
+    unsigned char uuid[QEMUD_UUID_RAW_LEN];
+    char name[QEMUD_MAX_NAME_LEN];
+
+    int memory;
+    int maxmem;
+    int vcpus;
+
+    int noReboot;
+
+    struct qemud_vm_os_def os;
+
+    int features;
+    int graphicsType;
+    int vncPort;
+    int vncActivePort;
+
+    int ndisks;
+    struct qemud_vm_disk_def *disks;
+
+    int nnets;
+    struct qemud_vm_net_def *nets;
+};
+
+/* Guest VM runtime state */
+struct qemud_vm {
+    int stdout;
+    int stderr;
+    int monitor;
+    int logfile;
+    int pid;
+    int id;
+    int state;
+
+    int *tapfds;
+    int ntapfds;
+
+    char configFile[PATH_MAX];
+    char autostartLink[PATH_MAX];
+
+    struct qemud_vm_def *def; /* The current definition */
+    struct qemud_vm_def *newDef; /* New definition to activate at shutdown */
+
+    unsigned int autostart : 1;
+
+    struct qemud_vm *next;
+};
+
+/* Store start and end addresses of a dhcp range */
+struct qemud_dhcp_range_def {
+    char start[BR_INET_ADDR_MAXLEN];
+    char end[BR_INET_ADDR_MAXLEN];
+
+    struct qemud_dhcp_range_def *next;
+};
+
+/* Virtual Network main configuration */
+struct qemud_network_def {
+    unsigned char uuid[QEMUD_UUID_RAW_LEN];
+    char name[QEMUD_MAX_NAME_LEN];
+
+    char bridge[BR_IFNAME_MAXLEN];
+    int disableSTP;
+    int forwardDelay;
+
+    int forward;
+    char forwardDev[BR_IFNAME_MAXLEN];
+
+    char ipAddress[BR_INET_ADDR_MAXLEN];
+    char netmask[BR_INET_ADDR_MAXLEN];
+    char network[BR_INET_ADDR_MAXLEN+BR_INET_ADDR_MAXLEN+1];
+
+    int nranges;
+    struct qemud_dhcp_range_def *ranges;
+};
+
+/* Virtual Network runtime state */
+struct qemud_network {
+    char configFile[PATH_MAX];
+    char autostartLink[PATH_MAX];
+
+    struct qemud_network_def *def; /* The current definition */
+    struct qemud_network_def *newDef; /* New definition to activate at shutdown */
+
+    char bridge[BR_IFNAME_MAXLEN];
+    int dnsmasqPid;
+
+    unsigned int active : 1;
+    unsigned int autostart : 1;
+
+    struct qemud_network *next;
+};
+
+
+/* Main driver state */
+struct qemud_driver {
+    int qemuVersion;
+    int qemuCmdFlags; /* values from enum qemud_cmd_flags */
+    int nactivevms;
+    int ninactivevms;
+    struct qemud_vm *vms;
+    int nextvmid;
+    int nactivenetworks;
+    int ninactivenetworks;
+    struct qemud_network *networks;
+    brControl *brctl;
+    iptablesContext *iptables;
+    char *configDir;
+    char *autostartDir;
+    char *networkConfigDir;
+    char *networkAutostartDir;
+    char logDir[PATH_MAX];
+};
+
+
+static inline int
+qemudIsActiveVM(struct qemud_vm *vm)
+{
+    return vm->id != -1;
+}
+
+static inline int
+qemudIsActiveNetwork(struct qemud_network *network)
+{
+    return network->active;
+}
+
+
+int qemudStartVMDaemon(struct qemud_driver *driver,
                        struct qemud_vm *vm);
 
-int qemudShutdownVMDaemon(struct qemud_server *server,
+int qemudShutdownVMDaemon(struct qemud_driver *driver,
                           struct qemud_vm *vm);
 
-int qemudStartNetworkDaemon(struct qemud_server *server,
+int qemudStartNetworkDaemon(struct qemud_driver *driver,
                             struct qemud_network *network);
 
-int qemudShutdownNetworkDaemon(struct qemud_server *server,
+int qemudShutdownNetworkDaemon(struct qemud_driver *driver,
                                struct qemud_network *network);
 
-int qemudStartup(struct qemud_server *server);
-void qemudReload(struct qemud_server *server);
-void qemudShutdown(struct qemud_server *server);
+int qemudStartup(void);
+void qemudReload(void);
+void qemudShutdown(void);
 
 void qemudReportError(virConnectPtr conn,
                       virDomainPtr dom,
@@ -55,100 +300,100 @@ int qemudGetNodeInfo(unsigned int *memor
                      unsigned int *nodes, unsigned int *sockets,
                      unsigned int *cores, unsigned int *threads);
 
-char *qemudGetCapabilities(struct qemud_server *server);
-int qemudMonitorCommand(struct qemud_server *server,
+char *qemudGetCapabilities(struct qemud_driver *driver);
+int qemudMonitorCommand(struct qemud_driver *driver,
                         struct qemud_vm *vm,
                         const char *cmd,
                         char **reply);
 
-struct qemud_vm *qemudFindVMByID(const struct qemud_server *server,
+struct qemud_vm *qemudFindVMByID(const struct qemud_driver *driver,
                                  int id);
-struct qemud_vm *qemudFindVMByUUID(const struct qemud_server *server,
+struct qemud_vm *qemudFindVMByUUID(const struct qemud_driver *driver,
                                    const unsigned char *uuid);
-struct qemud_vm *qemudFindVMByName(const struct qemud_server *server,
+struct qemud_vm *qemudFindVMByName(const struct qemud_driver *driver,
                                    const char *name);
 
-int qemudGetVersion(struct qemud_server *server);
-int qemudListDomains(struct qemud_server *server,
+int qemudGetVersion(struct qemud_driver *driver);
+int qemudListDomains(struct qemud_driver *driver,
                      int *ids,
                      int nids);
-int qemudNumDomains(struct qemud_server *server);
-struct qemud_vm *qemudDomainCreate(struct qemud_server *server,
+int qemudNumDomains(struct qemud_driver *driver);
+struct qemud_vm *qemudDomainCreate(struct qemud_driver *driver,
                                    const char *xml);
-int qemudDomainSuspend(struct qemud_server *server,
+int qemudDomainSuspend(struct qemud_driver *driver,
                        int id);
-int qemudDomainResume(struct qemud_server *server,
+int qemudDomainResume(struct qemud_driver *driver,
                       int id);
-int qemudDomainDestroy(struct qemud_server *server,
+int qemudDomainDestroy(struct qemud_driver *driver,
                        int id);
-int qemudDomainGetInfo(struct qemud_server *server,
+int qemudDomainGetInfo(struct qemud_driver *driver,
                        const unsigned char *uuid,
                        int *runstate,
                        unsigned long long *cputime,
                        unsigned long *maxmem,
                        unsigned long *memory,
                        unsigned int *nrVirtCpu);
-int qemudDomainSave(struct qemud_server *server,
+int qemudDomainSave(struct qemud_driver *driver,
                     int id,
                     const char *path);
-int qemudDomainRestore(struct qemud_server *server,
+int qemudDomainRestore(struct qemud_driver *driver,
                        const char *path);
-int qemudDomainDumpXML(struct qemud_server *server,
+int qemudDomainDumpXML(struct qemud_driver *driver,
                        const unsigned char *uuid,
                        char *xml,
                        int xmllen);
-int qemudListDefinedDomains(struct qemud_server *server,
+int qemudListDefinedDomains(struct qemud_driver *driver,
                             char *const*names,
                             int nnames);
-int qemudNumDefinedDomains(struct qemud_server *server);
-struct qemud_vm *qemudDomainStart(struct qemud_server *server,
+int qemudNumDefinedDomains(struct qemud_driver *driver);
+struct qemud_vm *qemudDomainStart(struct qemud_driver *driver,
                                   const unsigned char *uuid);
-struct qemud_vm *qemudDomainDefine(struct qemud_server *server,
+struct qemud_vm *qemudDomainDefine(struct qemud_driver *driver,
                                    const char *xml);
-int qemudDomainUndefine(struct qemud_server *server,
+int qemudDomainUndefine(struct qemud_driver *driver,
                         const unsigned char *uuid);
-int qemudDomainGetAutostart(struct qemud_server *server,
+int qemudDomainGetAutostart(struct qemud_driver *driver,
                             const unsigned char *uuid,
                             int *autostart);
-int qemudDomainSetAutostart(struct qemud_server *server,
+int qemudDomainSetAutostart(struct qemud_driver *driver,
                             const unsigned char *uuid,
                             int autostart);
 
-struct qemud_network *qemudFindNetworkByUUID(const struct qemud_server *server,
+struct qemud_network *qemudFindNetworkByUUID(const struct qemud_driver *driver,
                                              const unsigned char *uuid);
-struct qemud_network *qemudFindNetworkByName(const struct qemud_server *server,
+struct qemud_network *qemudFindNetworkByName(const struct qemud_driver *driver,
                                              const char *name);
 
-int qemudNumNetworks(struct qemud_server *server);
-int qemudListNetworks(struct qemud_server *server,
+int qemudNumNetworks(struct qemud_driver *driver);
+int qemudListNetworks(struct qemud_driver *driver,
                       char *const*names,
                       int nnames);
-int qemudNumDefinedNetworks(struct qemud_server *server);
-int qemudListDefinedNetworks(struct qemud_server *server,
+int qemudNumDefinedNetworks(struct qemud_driver *driver);
+int qemudListDefinedNetworks(struct qemud_driver *driver,
                              char *const*names,
                              int nnames);
-struct qemud_network *qemudNetworkCreate(struct qemud_server *server,
+struct qemud_network *qemudNetworkCreate(struct qemud_driver *driver,
                                          const char *xml);
-struct qemud_network *qemudNetworkDefine(struct qemud_server *server,
+struct qemud_network *qemudNetworkDefine(struct qemud_driver *driver,
                                          const char *xml);
-struct qemud_network *qemudNetworkStart(struct qemud_server *server,
+struct qemud_network *qemudNetworkStart(struct qemud_driver *driver,
                                         const unsigned char *uuid);
-int qemudNetworkUndefine(struct qemud_server *server,
+int qemudNetworkUndefine(struct qemud_driver *driver,
                          const unsigned char *uuid);
-int qemudNetworkDestroy(struct qemud_server *server,
+int qemudNetworkDestroy(struct qemud_driver *driver,
                         const unsigned char *uuid);
-int qemudNetworkDumpXML(struct qemud_server *server,
+int qemudNetworkDumpXML(struct qemud_driver *driver,
                         const unsigned char *uuid,
                         char *xml,
                         int xmllen);
-int qemudNetworkGetBridgeName(struct qemud_server *server,
+int qemudNetworkGetBridgeName(struct qemud_driver *driver,
                               const unsigned char *uuid,
                               char *ifname,
                               int ifnamelen);
-int qemudNetworkGetAutostart(struct qemud_server *server,
+int qemudNetworkGetAutostart(struct qemud_driver *driver,
                              const unsigned char *uuid,
                              int *autostart);
-int qemudNetworkSetAutostart(struct qemud_server *server,
+int qemudNetworkSetAutostart(struct qemud_driver *driver,
                              const unsigned char *uuid,
                              int autostart);
 
diff -r af6d5f54a13a qemud/internal.h
--- a/qemud/internal.h	Sun Jun 17 22:11:10 2007 -0400
+++ b/qemud/internal.h	Sun Jun 17 22:11:17 2007 -0400
@@ -60,216 +60,6 @@ typedef enum {
     QEMUD_DEBUG
 #endif
 } qemudLogPriority;
-
-/* Different types of QEMU acceleration possible */
-enum qemud_vm_virt_type {
-    QEMUD_VIRT_QEMU,
-    QEMUD_VIRT_KQEMU,
-    QEMUD_VIRT_KVM,
-};
-
-
-/* Two types of disk backends */
-enum qemud_vm_disk_type {
-    QEMUD_DISK_BLOCK,
-    QEMUD_DISK_FILE
-};
-
-/* Three types of disk frontend */
-enum qemud_vm_disk_device {
-    QEMUD_DISK_DISK,
-    QEMUD_DISK_CDROM,
-    QEMUD_DISK_FLOPPY,
-};
-
-/* Stores the virtual disk configuration */
-struct qemud_vm_disk_def {
-    int type;
-    int device;
-    char src[PATH_MAX];
-    char dst[NAME_MAX];
-    int readonly;
-
-    struct qemud_vm_disk_def *next;
-};
-
-#define QEMUD_MAC_ADDRESS_LEN 6
-#define QEMUD_OS_TYPE_MAX_LEN 10
-#define QEMUD_OS_ARCH_MAX_LEN 10
-#define QEMUD_OS_MACHINE_MAX_LEN 10
-
-/* 5 different types of networking config */
-enum qemud_vm_net_type {
-    QEMUD_NET_USER,
-    QEMUD_NET_ETHERNET,
-    QEMUD_NET_SERVER,
-    QEMUD_NET_CLIENT,
-    QEMUD_NET_MCAST,
-    QEMUD_NET_NETWORK,
-    QEMUD_NET_BRIDGE,
-};
-
-/* Stores the virtual network interface configuration */
-struct qemud_vm_net_def {
-    int type;
-    unsigned char mac[QEMUD_MAC_ADDRESS_LEN];
-    union {
-        struct {
-            char ifname[BR_IFNAME_MAXLEN];
-            char script[PATH_MAX];
-        } ethernet;
-        struct {
-            char address[BR_INET_ADDR_MAXLEN];
-            int port;
-        } socket; /* any of NET_CLIENT or NET_SERVER or NET_MCAST */
-        struct {
-            char name[QEMUD_MAX_NAME_LEN];
-            char ifname[BR_IFNAME_MAXLEN];
-        } network;
-        struct {
-            char brname[BR_IFNAME_MAXLEN];
-            char ifname[BR_IFNAME_MAXLEN];
-        } bridge;
-    } dst;
-
-    struct qemud_vm_net_def *next;
-};
-
-#define QEMUD_MAX_BOOT_DEVS 4
-
-/* 3 possible boot devices */
-enum qemud_vm_boot_order {
-    QEMUD_BOOT_FLOPPY,
-    QEMUD_BOOT_CDROM,
-    QEMUD_BOOT_DISK,
-    QEMUD_BOOT_NET,
-};
-/* 3 possible graphics console modes */
-enum qemud_vm_grapics_type {
-    QEMUD_GRAPHICS_NONE,
-    QEMUD_GRAPHICS_SDL,
-    QEMUD_GRAPHICS_VNC,
-};
-
-/* Internal flags to keep track of qemu command line capabilities */
-enum qemud_cmd_flags {
-    QEMUD_CMD_FLAG_KQEMU = 1,
-    QEMUD_CMD_FLAG_VNC_COLON = 2,
-    QEMUD_CMD_FLAG_NO_REBOOT = 4,
-};
-
-
-enum qemud_vm_features {
-    QEMUD_FEATURE_ACPI = 1,
-};
-
-/* Operating system configuration data & machine / arch */
-struct qemud_vm_os_def {
-    char type[QEMUD_OS_TYPE_MAX_LEN];
-    char arch[QEMUD_OS_ARCH_MAX_LEN];
-    char machine[QEMUD_OS_MACHINE_MAX_LEN];
-    int nBootDevs;
-    int bootDevs[QEMUD_MAX_BOOT_DEVS];
-    char kernel[PATH_MAX];
-    char initrd[PATH_MAX];
-    char cmdline[PATH_MAX];
-    char binary[PATH_MAX];
-};
-
-/* Guest VM main configuration */
-struct qemud_vm_def {
-    int virtType;
-    unsigned char uuid[QEMUD_UUID_RAW_LEN];
-    char name[QEMUD_MAX_NAME_LEN];
-
-    int memory;
-    int maxmem;
-    int vcpus;
-
-    int noReboot;
-
-    struct qemud_vm_os_def os;
-
-    int features;
-    int graphicsType;
-    int vncPort;
-    int vncActivePort;
-
-    int ndisks;
-    struct qemud_vm_disk_def *disks;
-
-    int nnets;
-    struct qemud_vm_net_def *nets;
-};
-
-/* Guest VM runtime state */
-struct qemud_vm {
-    int stdout;
-    int stderr;
-    int monitor;
-    int logfile;
-    int pid;
-    int id;
-    int state;
-
-    int *tapfds;
-    int ntapfds;
-
-    char configFile[PATH_MAX];
-    char autostartLink[PATH_MAX];
-
-    struct qemud_vm_def *def; /* The current definition */
-    struct qemud_vm_def *newDef; /* New definition to activate at shutdown */
-
-    unsigned int autostart : 1;
-
-    struct qemud_vm *next;
-};
-
-/* Store start and end addresses of a dhcp range */
-struct qemud_dhcp_range_def {
-    char start[BR_INET_ADDR_MAXLEN];
-    char end[BR_INET_ADDR_MAXLEN];
-
-    struct qemud_dhcp_range_def *next;
-};
-
-/* Virtual Network main configuration */
-struct qemud_network_def {
-    unsigned char uuid[QEMUD_UUID_RAW_LEN];
-    char name[QEMUD_MAX_NAME_LEN];
-
-    char bridge[BR_IFNAME_MAXLEN];
-    int disableSTP;
-    int forwardDelay;
-
-    int forward;
-    char forwardDev[BR_IFNAME_MAXLEN];
-
-    char ipAddress[BR_INET_ADDR_MAXLEN];
-    char netmask[BR_INET_ADDR_MAXLEN];
-    char network[BR_INET_ADDR_MAXLEN+BR_INET_ADDR_MAXLEN+1];
-
-    int nranges;
-    struct qemud_dhcp_range_def *ranges;
-};
-
-/* Virtual Network runtime state */
-struct qemud_network {
-    char configFile[PATH_MAX];
-    char autostartLink[PATH_MAX];
-
-    struct qemud_network_def *def; /* The current definition */
-    struct qemud_network_def *newDef; /* New definition to activate at shutdown */
-
-    char bridge[BR_IFNAME_MAXLEN];
-    int dnsmasqPid;
-
-    unsigned int active : 1;
-    unsigned int autostart : 1;
-
-    struct qemud_network *next;
-};
 
 
 enum qemud_mode {
@@ -333,25 +123,9 @@ struct qemud_server {
 struct qemud_server {
     int nsockets;
     struct qemud_socket *sockets;
-    int qemuVersion;
-    int qemuCmdFlags; /* values from enum qemud_cmd_flags */
     int nclients;
     struct qemud_client *clients;
     int sigread;
-    int nvmfds;
-    int nactivevms;
-    int ninactivevms;
-    struct qemud_vm *vms;
-    int nextvmid;
-    int nactivenetworks;
-    int ninactivenetworks;
-    struct qemud_network *networks;
-    brControl *brctl;
-    iptablesContext *iptables;
-    char *configDir;
-    char *autostartDir;
-    char *networkConfigDir;
-    char *networkAutostartDir;
     char logDir[PATH_MAX];
     unsigned int shutdown : 1;
 };
@@ -372,17 +146,6 @@ void remoteDispatchClientRequest (struct
 void remoteDispatchClientRequest (struct qemud_server *server,
                                   struct qemud_client *client);
 
-static inline int
-qemudIsActiveVM(struct qemud_vm *vm)
-{
-    return vm->id != -1;
-}
-
-static inline int
-qemudIsActiveNetwork(struct qemud_network *network)
-{
-    return network->active;
-}
 
 #endif
 
diff -r af6d5f54a13a qemud/qemud.c
--- a/qemud/qemud.c	Sun Jun 17 22:11:10 2007 -0400
+++ b/qemud/qemud.c	Sun Jun 17 22:11:17 2007 -0400
@@ -207,7 +207,7 @@ static void qemudDispatchSignalEvent(int
     case SIGHUP:
         qemudLog(QEMUD_INFO, "Reloading configuration on SIGHUP");
         if (!remote) {
-            qemudReload(server);
+            qemudReload();
         }
         break;
 
@@ -217,7 +217,7 @@ static void qemudDispatchSignalEvent(int
         qemudLog(QEMUD_WARN, "Shutting down on signal %d", sigc);
 
         if (!remote) {
-            qemudShutdown(server);
+            qemudShutdown();
         }
 
         server->shutdown = 1;
@@ -620,11 +620,6 @@ static int qemudInitPaths(struct qemud_s
 
         unlink(roSockname);
 
-        server->configDir =
-            server->autostartDir =
-            server->networkConfigDir =
-            server->networkAutostartDir = NULL;
-
         if (snprintf(server->logDir, PATH_MAX, "%s/log/libvirt/qemu", LOCAL_STATE_DIR) >= PATH_MAX)
             goto snprintf_error;
     } else {
@@ -660,30 +655,15 @@ static int qemudInitPaths(struct qemud_s
             if (snprintf(sockname, maxlen, "@%s/.libvirt/qemud-sock", pw->pw_dir) >= maxlen)
                 goto snprintf_error;
 
+            if (snprintf(server->logDir, PATH_MAX, "%s/.libvirt/qemu/log", pw->pw_dir) >= PATH_MAX)
+                goto snprintf_error;
+
             if (asprintf (&base, "%s/.libvirt/qemu", pw->pw_dir) == -1) {
                 qemudLog (QEMUD_ERR, "out of memory in asprintf");
                 return -1;
             }
         }
 
-        /* Configuration paths are either ~/.libvirt/qemu/... (session) or
-         * /etc/libvirt/qemu/... (system).
-         */
-        if (asprintf (&server->configDir, "%s", base) == -1)
-            goto out_of_memory;
-
-        if (asprintf (&server->autostartDir, "%s/autostart", base) == -1)
-            goto out_of_memory;
-
-        if (asprintf (&server->networkConfigDir, "%s/networks", base) == -1)
-            goto out_of_memory;
-
-        if (asprintf (&server->networkAutostartDir, "%s/networks/autostart",
-                      base) == -1)
-            goto out_of_memory;
-
-        if (snprintf(server->logDir, PATH_MAX, "%s/log", base) >= PATH_MAX)
-            goto snprintf_error;
     } /* !remote */
 
     if (base) free (base);
@@ -711,7 +691,6 @@ static struct qemud_server *qemudInitial
     }
 
     /* We don't have a dom-0, so start from 1 */
-    server->nextvmid = 1;
     server->sigread = sigread;
 
     roSockname[0] = '\0';
@@ -726,7 +705,7 @@ static struct qemud_server *qemudInitial
         goto cleanup;
 
     if (!remote) /* qemud only */ {
-        if (qemudStartup(server) < 0) {
+        if (qemudStartup() < 0) {
             goto cleanup;
         }
     } else /* remote only */ {
@@ -745,17 +724,13 @@ static struct qemud_server *qemudInitial
     return server;
 
  cleanup:
+    qemudShutdown();
     if (server) {
         struct qemud_socket *sock = server->sockets;
         while (sock) {
             close(sock->fd);
             sock = sock->next;
         }
-
-        if (server->configDir) free (server->configDir);
-        if (server->autostartDir) free (server->autostartDir);
-        if (server->networkConfigDir) free (server->networkConfigDir);
-        if (server->networkAutostartDir) free (server->networkAutostartDir);
 
         free(server);
     }
@@ -1527,15 +1502,8 @@ static void qemudCleanup(struct qemud_se
         sock = next;
     }
 
-    if (server->brctl)
-        brShutdown(server->brctl);
-    if (server->iptables)
-        iptablesContextFree(server->iptables);
-
-    if (server->configDir) free (server->configDir);
-    if (server->autostartDir) free (server->autostartDir);
-    if (server->networkConfigDir) free (server->networkConfigDir);
-    if (server->networkAutostartDir) free (server->networkAutostartDir);
+
+    qemudShutdown();
 
     free(server);
 }

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]