]> xenbits.xensource.com Git - libvirt.git/commitdiff
Move code relating to vm/network lookups into conf.c
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 26 Jun 2007 22:42:47 +0000 (22:42 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 26 Jun 2007 22:42:47 +0000 (22:42 +0000)
ChangeLog
qemud/conf.c
qemud/conf.h
qemud/dispatch.c
qemud/driver.c
qemud/driver.h

index 83049c23d24131e986805bc84ac0d26d94f5e9f8..f27158f3d8391aa21f0a1d3ce64d66e8d39bf477 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Jun 26 18:41:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
+
+       * qemud/conf.c, qemud/conf.h, qemud/dispatch.c, qemud/driver.c,
+       qemud/driver.h: Move code related to looking up VMs/networks
+       into the conf.c
+
 Tue Jun 26 18:35:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
 
        * qemud/conf.c, qemud/dispatch.c, qemud/driver.c, qemud/driver.h
index 8fdcfb17f8982ecdbe137a542a3a0ced9d5252bb..98fe03a4eb98d80801057811628a2921f51cf423 100644 (file)
@@ -66,6 +66,70 @@ void qemudReportError(virConnectPtr conn,
                     NULL, NULL, NULL, -1, -1, errorMessage);
 }
 
+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)
+            return vm;
+        vm = vm->next;
+    }
+
+    return NULL;
+}
+
+struct qemud_vm *qemudFindVMByUUID(const struct qemud_driver *driver,
+                                   const unsigned char *uuid) {
+    struct qemud_vm *vm = driver->vms;
+
+    while (vm) {
+        if (!memcmp(vm->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
+            return vm;
+        vm = vm->next;
+    }
+
+    return NULL;
+}
+
+struct qemud_vm *qemudFindVMByName(const struct qemud_driver *driver,
+                                   const char *name) {
+    struct qemud_vm *vm = driver->vms;
+
+    while (vm) {
+        if (!strcmp(vm->def->name, name))
+            return vm;
+        vm = vm->next;
+    }
+
+    return NULL;
+}
+
+struct qemud_network *qemudFindNetworkByUUID(const struct qemud_driver *driver,
+                                             const unsigned char *uuid) {
+    struct qemud_network *network = driver->networks;
+
+    while (network) {
+        if (!memcmp(network->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
+            return network;
+        network = network->next;
+    }
+
+    return NULL;
+}
+
+struct qemud_network *qemudFindNetworkByName(const struct qemud_driver *driver,
+                                             const char *name) {
+    struct qemud_network *network = driver->networks;
+
+    while (network) {
+        if (!strcmp(network->def->name, name))
+            return network;
+        network = network->next;
+    }
+
+    return NULL;
+}
+
 
 /* Free all memory associated with a struct qemud_vm object */
 void qemudFreeVMDef(struct qemud_vm_def *def) {
index c60df36d1609b74c0497a183dcad6d6ac7eee8d7..5ab82b783ad4371d6f7c4ac4b4183798064cca8d 100644 (file)
@@ -24,6 +24,8 @@
 #ifndef __QEMUD_CONF_H
 #define __QEMUD_CONF_H
 
+#include "../src/internal.h"
+
 /* Different types of QEMU acceleration possible */
 enum qemud_vm_virt_type {
     QEMUD_VIRT_QEMU,
index 23b7ba1b66b0a39dfdb8e23ea51d0a87069e5835..64ab5a7aeeb6d8004ba2b88a4402c69299160b76 100644 (file)
@@ -31,6 +31,7 @@
 #include <libvirt/virterror.h>
 
 #include "internal.h"
+#include "../src/internal.h"
 #include "driver.h"
 #include "dispatch.h"
 #include "conf.h"
@@ -105,15 +106,10 @@ qemudDispatchGetCapabilities (struct qemud_packet_client_data *in ATTRIBUTE_UNUS
 {
     char *xml = qemudGetCapabilities(&conn);
 
-    if (strlen(xml) > QEMUD_MAX_XML_LEN) {
-        qemudReportError(&conn, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
-        qemudDispatchFailure(out);
-        free(xml);
-        return 0;
-    }
-
     out->type = QEMUD_SERVER_PKT_GET_CAPABILITIES;
-    strcpy (out->qemud_packet_server_data_u.getCapabilitiesReply.xml, xml);
+    strncpy (out->qemud_packet_server_data_u.getCapabilitiesReply.xml, xml,
+             QEMUD_MAX_XML_LEN-1);
+    out->qemud_packet_server_data_u.getCapabilitiesReply.xml[QEMUD_MAX_XML_LEN-1] = '\0';
     free(xml);
     return 0;
 }
@@ -915,7 +911,8 @@ int qemudDispatch(struct qemud_server *server ATTRIBUTE_UNUSED,
 
     if (!funcs[type]) {
         qemudDebug("Illegal operation requested");
-        qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_DENIED, NULL);
+        __virRaiseError(&conn, NULL, NULL, VIR_FROM_QEMU, VIR_ERR_OPERATION_DENIED, VIR_ERR_ERROR,
+                        NULL, NULL, NULL, -1, -1, "Illegal operation requested");
         qemudDispatchFailure(out);
     } else {
         if ((funcs[type])(in, out) < 0) {
index 8f601e877a9c20beeb52b6ec366de274fab894c4..00b30a45944cff3af3c8fdb45aa90a50e78c75c1 100644 (file)
@@ -51,6 +51,7 @@
 #include "event.h"
 #include "../src/buf.h"
 #include "driver.h"
+#include "conf.h"
 
 static int qemudSetCloseExec(int fd) {
     int flags;
@@ -82,6 +83,19 @@ static int qemudSetNonBlock(int fd) {
 
 
 static void qemudDispatchVMEvent(int fd, int events, void *opaque);
+int qemudStartVMDaemon(struct qemud_driver *driver,
+                       struct qemud_vm *vm);
+
+int qemudShutdownVMDaemon(struct qemud_driver *driver,
+                          struct qemud_vm *vm);
+
+int qemudStartNetworkDaemon(struct qemud_driver *driver,
+                            struct qemud_network *network);
+
+int qemudShutdownNetworkDaemon(struct qemud_driver *driver,
+                               struct qemud_network *network);
+
+struct qemud_driver *qemu_driver = NULL;
 
 
 static
@@ -120,8 +134,6 @@ void qemudAutostartConfigs(struct qemud_driver *driver) {
     }
 }
 
-struct qemud_driver *qemu_driver = NULL;
-
 int qemudStartup(void) {
     uid_t uid = geteuid();
     struct passwd *pw;
@@ -720,6 +732,8 @@ static int qemudVMData(struct qemud_driver *driver ATTRIBUTE_UNUSED,
                      strerror(errno));
         }
     }
+
+    qemudAutostartConfigs(qemu_driver);
 }
 
 
@@ -1662,43 +1676,6 @@ static int qemudGetProcessInfo(unsigned long long *cpuTime, int pid) {
     return 0;
 }
 
-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)
-            return vm;
-        vm = vm->next;
-    }
-
-    return NULL;
-}
-
-struct qemud_vm *qemudFindVMByUUID(const struct qemud_driver *driver,
-                                   const unsigned char *uuid) {
-    struct qemud_vm *vm = driver->vms;
-
-    while (vm) {
-        if (!memcmp(vm->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
-            return vm;
-        vm = vm->next;
-    }
-
-    return NULL;
-}
-
-struct qemud_vm *qemudFindVMByName(const struct qemud_driver *driver,
-                                   const char *name) {
-    struct qemud_vm *vm = driver->vms;
-
-    while (vm) {
-        if (!strcmp(vm->def->name, name))
-            return vm;
-        vm = vm->next;
-    }
-
-    return NULL;
-}
 
 virDomainPtr qemudDomainLookupByID(virConnectPtr conn ATTRIBUTE_UNUSED,
                                    int id) {
@@ -2147,32 +2124,6 @@ int qemudDomainSetAutostart(virDomainPtr dom,
     return 0;
 }
 
-struct qemud_network *qemudFindNetworkByUUID(const struct qemud_driver *driver,
-                                             const unsigned char *uuid) {
-    struct qemud_network *network = driver->networks;
-
-    while (network) {
-        if (!memcmp(network->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
-            return network;
-        network = network->next;
-    }
-
-    return NULL;
-}
-
-struct qemud_network *qemudFindNetworkByName(const struct qemud_driver *driver,
-                                             const char *name) {
-    struct qemud_network *network = driver->networks;
-
-    while (network) {
-        if (!strcmp(network->def->name, name))
-            return network;
-        network = network->next;
-    }
-
-    return NULL;
-}
-
 virNetworkPtr qemudNetworkLookupByUUID(virConnectPtr conn ATTRIBUTE_UNUSED,
                                      const unsigned char *uuid) {
     struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
index f1772614dc70e03af254f7dd48a391f40fbb9de9..b4228757e1ef1155889991e465c04b6383217839 100644 (file)
 
 #include "internal.h"
 #include "../src/internal.h"
-#include "conf.h"
-
-int qemudStartVMDaemon(struct qemud_driver *driver,
-                       struct qemud_vm *vm);
-
-int qemudShutdownVMDaemon(struct qemud_driver *driver,
-                          struct qemud_vm *vm);
-
-int qemudStartNetworkDaemon(struct qemud_driver *driver,
-                            struct qemud_network *network);
-
-int qemudShutdownNetworkDaemon(struct qemud_driver *driver,
-                               struct qemud_network *network);
 
 int qemudStartup(void);
 void qemudReload(void);