[Libvir] PATCH 11/20: shuffles code from driver to conf file

Daniel P. Berrange berrange at redhat.com
Fri Jun 22 01:59:39 UTC 2007


This patch is just shuffling a little code from the driver.c file into
the conf.c file. This is to give a clear separation between methods 
which implement QEMU driver functionality, vs those which deal with
manipulating VM / network config objects.

 conf.c     |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 conf.h     |    2 +
 dispatch.c |   15 ++++-------
 driver.c   |   81 ++++++++++++-------------------------------------------------
 driver.h   |   13 ---------
 5 files changed, 88 insertions(+), 87 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  -=| 
-------------- next part --------------
diff -r ed99bc6abc58 qemud/conf.c
--- a/qemud/conf.c	Thu Jun 21 21:20:50 2007 -0400
+++ b/qemud/conf.c	Thu Jun 21 21:20:52 2007 -0400
@@ -64,6 +64,70 @@ void qemudReportError(virConnectPtr conn
 
     __virRaiseError(conn, dom, net, VIR_FROM_QEMU, code, VIR_ERR_ERROR,
                     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;
 }
 
 
diff -r ed99bc6abc58 qemud/conf.h
--- a/qemud/conf.h	Thu Jun 21 21:20:50 2007 -0400
+++ b/qemud/conf.h	Thu Jun 21 21:20:52 2007 -0400
@@ -23,6 +23,8 @@
 
 #ifndef __QEMUD_CONF_H
 #define __QEMUD_CONF_H
+
+#include "../src/internal.h"
 
 /* Different types of QEMU acceleration possible */
 enum qemud_vm_virt_type {
diff -r ed99bc6abc58 qemud/dispatch.c
--- a/qemud/dispatch.c	Thu Jun 21 21:20:50 2007 -0400
+++ b/qemud/dispatch.c	Thu Jun 21 21:20:52 2007 -0400
@@ -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 qem
 {
     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 *s
 
     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) {
diff -r ed99bc6abc58 qemud/driver.c
--- a/qemud/driver.c	Thu Jun 21 21:20:50 2007 -0400
+++ b/qemud/driver.c	Thu Jun 21 21:20:52 2007 -0400
@@ -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
@@ -119,8 +133,6 @@ void qemudAutostartConfigs(struct qemud_
         vm = next;
     }
 }
-
-struct qemud_driver *qemu_driver = NULL;
 
 int qemudStartup(void) {
     uid_t uid = geteuid();
@@ -720,6 +732,8 @@ static int qemudVMData(struct qemud_driv
                      strerror(errno));
         }
     }
+
+    qemudAutostartConfigs(qemu_driver);
 }
 
 
@@ -1658,43 +1672,6 @@ static int qemudGetProcessInfo(unsigned 
     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) {
@@ -2141,32 +2118,6 @@ int qemudDomainSetAutostart(virDomainPtr
     vm->autostart = autostart;
 
     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,
diff -r ed99bc6abc58 qemud/driver.h
--- a/qemud/driver.h	Thu Jun 21 21:20:50 2007 -0400
+++ b/qemud/driver.h	Thu Jun 21 21:20:52 2007 -0400
@@ -27,19 +27,6 @@
 
 #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);


More information about the libvir-list mailing list