[patch 10/12] Add virNetworkGetBridgeName()

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

 



Add virNetworkGetBridgeName() so that we can look up what bridge
a Xen guest should connect to in order to join a given network.

Note, we need this so that we can lookup which bridge the guest's
backend interface should be enslaved to in order for the guest
to join a specific network.

Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx>

Index: libvirt-foo/include/libvirt/libvirt.h.in
===================================================================
--- libvirt-foo.orig/include/libvirt/libvirt.h.in	2007-02-14 15:33:23.000000000 +0000
+++ libvirt-foo.orig/include/libvirt/libvirt.h.in	2007-02-14 15:33:23.000000000 +0000
@@ -526,6 +526,7 @@ int			virNetworkGetUUIDString	(virNetwor
 						 char *buf);
 char *			virNetworkGetXMLDesc	(virNetworkPtr network,
 						 int flags);
+char *			virNetworkGetBridgeName (virNetworkPtr network);
 
 #ifdef __cplusplus
 }
Index: libvirt-foo/src/driver.h
===================================================================
--- libvirt-foo.orig/src/driver.h	2007-02-14 15:33:23.000000000 +0000
+++ libvirt-foo.orig/src/driver.h	2007-02-14 15:33:23.000000000 +0000
@@ -220,6 +220,8 @@ typedef int
 typedef char *
 	(*virDrvNetworkDumpXML)		(virNetworkPtr network,
 					 int flags);
+typedef char *
+	(*virDrvNetworkGetBridgeName)	(virNetworkPtr network);
 
 typedef struct _virNetworkDriver virNetworkDriver;
 typedef virNetworkDriver *virNetworkDriverPtr;
@@ -245,6 +247,7 @@ struct _virNetworkDriver {
 	virDrvNetworkCreate		networkCreate;
 	virDrvNetworkDestroy		networkDestroy;
 	virDrvNetworkDumpXML		networkDumpXML;
+	virDrvNetworkGetBridgeName	networkGetBridgeName;
 };
 
 
Index: libvirt-foo/src/libvirt.c
===================================================================
--- libvirt-foo.orig/src/libvirt.c	2007-02-14 15:37:08.000000000 +0000
+++ libvirt-foo.orig/src/libvirt.c	2007-02-14 15:37:08.000000000 +0000
@@ -2731,3 +2731,38 @@ virNetworkGetXMLDesc(virNetworkPtr netwo
     }
     return(ret);
 }
+
+/**
+ * virNetworkGetBridgeName:
+ * @network: a network object
+ *
+ * Return a bridge interface name to which a domain may connect
+ * a network interface in order to join the network.
+ *
+ * Returns a 0 terminated interface name, or NULL in case of error.
+ *         the caller must free() the returned value.
+ */
+char *
+virNetworkGetBridgeName(virNetworkPtr network)
+{
+    int i;
+    char *ret = NULL;
+    if (!VIR_IS_NETWORK(network)) {
+        virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        return (NULL);
+    }
+
+    for (i = 0;i < network->conn->nb_network_drivers;i++) {
+	if ((network->conn->networkDrivers[i] != NULL) &&
+	    (network->conn->networkDrivers[i]->networkGetBridgeName != NULL)) {
+            ret = network->conn->networkDrivers[i]->networkGetBridgeName(network);
+	    if (ret)
+	        break;
+	}
+    }
+    if (!ret) {
+        virLibConnError(network->conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+        return (NULL);
+    }
+    return(ret);
+}
Index: libvirt-foo/qemud/dispatch.c
===================================================================
--- libvirt-foo.orig/qemud/dispatch.c	2007-02-14 15:46:58.000000000 +0000
+++ libvirt-foo.orig/qemud/dispatch.c	2007-02-14 15:46:58.000000000 +0000
@@ -699,6 +699,24 @@ static int qemudDispatchNetworkDumpXML(s
     return 0;
 }
 
+static int qemudDispatchNetworkGetBridgeName(struct qemud_server *server, struct qemud_client *client,
+                                             struct qemud_packet *in, struct qemud_packet *out) {
+    if (in->header.dataSize != sizeof(in->data.networkGetBridgeNameRequest))
+        return -1;
+
+    int ret = qemudNetworkGetBridgeName(server,
+                                        in->data.networkDumpXMLRequest.uuid,
+                                        out->data.networkGetBridgeNameReply.ifname, QEMUD_MAX_IFNAME_LEN);
+    if (ret < 0) {
+        if (qemudDispatchFailure(server, client, out) < 0)
+            return -1;
+    } else {
+        out->header.type = QEMUD_PKT_NETWORK_GET_BRIDGE_NAME;
+        out->header.dataSize = sizeof(out->data.networkGetBridgeNameReply);
+    }
+    return 0;
+}
+
 
 typedef int (*clientFunc)(struct qemud_server *server, struct qemud_client *client,
                           struct qemud_packet *in, struct qemud_packet *out);
@@ -740,6 +758,7 @@ clientFunc funcsTransmitRW[QEMUD_PKT_MAX
     qemudDispatchNetworkStart,
     qemudDispatchNetworkDestroy,
     qemudDispatchNetworkDumpXML,
+    qemudDispatchNetworkGetBridgeName,
 };
 
 clientFunc funcsTransmitRO[QEMUD_PKT_MAX] = {
@@ -776,6 +795,7 @@ clientFunc funcsTransmitRO[QEMUD_PKT_MAX
     NULL,
     NULL,
     qemudDispatchNetworkDumpXML,
+    qemudDispatchNetworkGetBridgeName,
 };
 
 /*
Index: libvirt-foo/qemud/driver.c
===================================================================
--- libvirt-foo.orig/qemud/driver.c	2007-02-14 15:54:56.000000000 +0000
+++ libvirt-foo.orig/qemud/driver.c	2007-02-14 15:54:56.000000000 +0000
@@ -743,6 +743,20 @@ 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);
+
+    if (!network) {
+        qemudReportError(server, VIR_ERR_INVALID_NETWORK, "no network with matching id");
+        return -1;
+    }
+
+    strncpy(ifname, network->bridge, ifnamelen);
+    ifname[ifnamelen-1] = '\0';
+
+    return 0;
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
Index: libvirt-foo/qemud/driver.h
===================================================================
--- libvirt-foo.orig/qemud/driver.h	2007-02-14 15:46:58.000000000 +0000
+++ libvirt-foo.orig/qemud/driver.h	2007-02-14 15:46:58.000000000 +0000
@@ -113,6 +113,10 @@ int qemudNetworkDumpXML(struct qemud_ser
                         const unsigned char *uuid,
                         char *xml,
                         int xmllen);
+int qemudNetworkGetBridgeName(struct qemud_server *server,
+                              const unsigned char *uuid,
+                              char *ifname,
+                              int ifnamelen);
 
 #endif
 
Index: libvirt-foo/qemud/protocol.h
===================================================================
--- libvirt-foo.orig/qemud/protocol.h	2007-02-14 15:46:58.000000000 +0000
+++ libvirt-foo.orig/qemud/protocol.h	2007-02-14 15:46:58.000000000 +0000
@@ -26,6 +26,7 @@
 #define QEMUD_PROTOCOL_H__
 
 #include <stdint.h>
+#include <net/if.h> /* for IF_NAMESIZE */
 
 /* List of different packet types which can be sent */
 enum {
@@ -62,6 +63,7 @@ enum {
     QEMUD_PKT_NETWORK_START,
     QEMUD_PKT_NETWORK_DESTROY,
     QEMUD_PKT_NETWORK_DUMP_XML,
+    QEMUD_PKT_NETWORK_GET_BRIDGE_NAME,
 
     QEMUD_PKT_MAX,
 } qemud_packet_type;
@@ -73,6 +75,7 @@ enum {
 #define QEMUD_UUID_RAW_LEN 16
 #define QEMUD_MAX_NAME_LEN 50
 #define QEMUD_MAX_XML_LEN 4096
+#define QEMUD_MAX_IFNAME_LEN IF_NAMESIZE
 #define QEMUD_MAX_NUM_DOMAINS 100
 #define QEMUD_MAX_NUM_NETWORKS 100
 #define QEMUD_MAX_ERROR_LEN 1024
@@ -270,6 +273,12 @@ union qemud_packet_data {
     struct {
         char xml[QEMUD_MAX_XML_LEN];
     } networkDumpXMLReply;
+    struct {
+        unsigned char uuid[QEMUD_UUID_RAW_LEN];
+    } networkGetBridgeNameRequest;
+    struct {
+        char ifname[QEMUD_MAX_IFNAME_LEN];
+    } networkGetBridgeNameReply;
 };
 
 /* Each packet has header & data */
Index: libvirt-foo/src/qemu_internal.c
===================================================================
--- libvirt-foo.orig/src/qemu_internal.c	2007-02-14 15:51:56.000000000 +0000
+++ libvirt-foo.orig/src/qemu_internal.c	2007-02-14 15:51:56.000000000 +0000
@@ -1077,6 +1077,22 @@ static char * qemuNetworkDumpXML(virNetw
     return strdup(reply.data.networkDumpXMLReply.xml);
 }
 
+static char * qemuNetworkGetBridgeName(virNetworkPtr network) {
+    struct qemud_packet req, reply;
+
+    req.header.type = QEMUD_PKT_NETWORK_GET_BRIDGE_NAME;
+    req.header.dataSize = sizeof(req.data.networkGetBridgeNameRequest);
+    memmove(req.data.networkGetBridgeNameRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN);
+
+    if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) {
+        return NULL;
+    }
+
+    reply.data.networkGetBridgeNameReply.ifname[QEMUD_MAX_IFNAME_LEN-1] = '\0';
+
+    return strdup(reply.data.networkGetBridgeNameReply.ifname);
+}
+
 static virDriver qemuDriver = {
     VIR_DRV_QEMU,
     "QEMU",
@@ -1134,6 +1150,7 @@ static virNetworkDriver qemuNetworkDrive
     qemuNetworkCreate, /* networkCreate */
     qemuNetworkDestroy, /* networkDestroy */
     qemuNetworkDumpXML, /* networkDumpXML */
+    qemuNetworkGetBridgeName, /* networkGetBridgeName */
 };
 
 void qemuRegister(void) {
@@ -1141,7 +1158,6 @@ void qemuRegister(void) {
     virRegisterDriver(&qemuNetworkDriver);
 }
 
-
 /*
  * Local variables:
  *  indent-tabs-mode: nil
Index: libvirt-foo/src/libvirt_sym.version
===================================================================
--- libvirt-foo.orig/src/libvirt_sym.version	2007-02-14 15:33:23.000000000 +0000
+++ libvirt-foo.orig/src/libvirt_sym.version	2007-02-14 15:33:23.000000000 +0000
@@ -75,6 +75,7 @@
 	virNetworkGetUUID;
 	virNetworkGetUUIDString;
 	virNetworkGetXMLDesc;
+	virNetworkGetBridgeName;
 
     local: *;
 };

-- 


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]