mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-26 18:41:17 +00:00
Tue Feb 14 16:17:51 IST 2007 Mark McLoughlin <markmc@redhat.com>
* include/libvirt/libvirt.h.in, src/libvirt.c: add virNetworkGetBridgeName() to allow finding out what bridge to connect to in order to join a network. * src/driver.h: add networkGetBridgeName() to vtable. * qemud/protocol.h: add the request and reply to the qemud protocol. * qemud/dispatch.c, qemud/driver.[ch]: handle them here. * src/qemu_internal.c: implement GetBridgeName() in the qemu driver. * src/libvirt_sym.version: add new symbol.
This commit is contained in:
parent
d4a9a0d607
commit
8356c43e42
19
ChangeLog
19
ChangeLog
@ -1,3 +1,22 @@
|
|||||||
|
Tue Feb 14 16:17:51 IST 2007 Mark McLoughlin <markmc@redhat.com>
|
||||||
|
|
||||||
|
* include/libvirt/libvirt.h.in, src/libvirt.c: add
|
||||||
|
virNetworkGetBridgeName() to allow finding out what
|
||||||
|
bridge to connect to in order to join a network.
|
||||||
|
|
||||||
|
* src/driver.h: add networkGetBridgeName() to vtable.
|
||||||
|
|
||||||
|
* qemud/protocol.h: add the request and reply to
|
||||||
|
the qemud protocol.
|
||||||
|
|
||||||
|
* qemud/dispatch.c, qemud/driver.[ch]: handle them
|
||||||
|
here.
|
||||||
|
|
||||||
|
* src/qemu_internal.c: implement GetBridgeName()
|
||||||
|
in the qemu driver.
|
||||||
|
|
||||||
|
* src/libvirt_sym.version: add new symbol.
|
||||||
|
|
||||||
Tue Feb 14 16:14:32 IST 2007 Mark McLoughlin <markmc@redhat.com>
|
Tue Feb 14 16:14:32 IST 2007 Mark McLoughlin <markmc@redhat.com>
|
||||||
|
|
||||||
* src/xend_internal.c, src/xm_internal.c: pass the
|
* src/xend_internal.c, src/xm_internal.c: pass the
|
||||||
|
@ -526,6 +526,7 @@ int virNetworkGetUUIDString (virNetworkPtr network,
|
|||||||
char *buf);
|
char *buf);
|
||||||
char * virNetworkGetXMLDesc (virNetworkPtr network,
|
char * virNetworkGetXMLDesc (virNetworkPtr network,
|
||||||
int flags);
|
int flags);
|
||||||
|
char * virNetworkGetBridgeName (virNetworkPtr network);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -699,6 +699,24 @@ static int qemudDispatchNetworkDumpXML(struct qemud_server *server, struct qemud
|
|||||||
return 0;
|
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,
|
typedef int (*clientFunc)(struct qemud_server *server, struct qemud_client *client,
|
||||||
struct qemud_packet *in, struct qemud_packet *out);
|
struct qemud_packet *in, struct qemud_packet *out);
|
||||||
@ -740,6 +758,7 @@ clientFunc funcsTransmitRW[QEMUD_PKT_MAX] = {
|
|||||||
qemudDispatchNetworkStart,
|
qemudDispatchNetworkStart,
|
||||||
qemudDispatchNetworkDestroy,
|
qemudDispatchNetworkDestroy,
|
||||||
qemudDispatchNetworkDumpXML,
|
qemudDispatchNetworkDumpXML,
|
||||||
|
qemudDispatchNetworkGetBridgeName,
|
||||||
};
|
};
|
||||||
|
|
||||||
clientFunc funcsTransmitRO[QEMUD_PKT_MAX] = {
|
clientFunc funcsTransmitRO[QEMUD_PKT_MAX] = {
|
||||||
@ -776,6 +795,7 @@ clientFunc funcsTransmitRO[QEMUD_PKT_MAX] = {
|
|||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
qemudDispatchNetworkDumpXML,
|
qemudDispatchNetworkDumpXML,
|
||||||
|
qemudDispatchNetworkGetBridgeName,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -743,6 +743,20 @@ int qemudNetworkDumpXML(struct qemud_server *server, const unsigned char *uuid,
|
|||||||
return 0;
|
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:
|
* Local variables:
|
||||||
* indent-tabs-mode: nil
|
* indent-tabs-mode: nil
|
||||||
|
@ -113,6 +113,10 @@ int qemudNetworkDumpXML(struct qemud_server *server,
|
|||||||
const unsigned char *uuid,
|
const unsigned char *uuid,
|
||||||
char *xml,
|
char *xml,
|
||||||
int xmllen);
|
int xmllen);
|
||||||
|
int qemudNetworkGetBridgeName(struct qemud_server *server,
|
||||||
|
const unsigned char *uuid,
|
||||||
|
char *ifname,
|
||||||
|
int ifnamelen);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#define QEMUD_PROTOCOL_H__
|
#define QEMUD_PROTOCOL_H__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <net/if.h> /* for IF_NAMESIZE */
|
||||||
|
|
||||||
/* List of different packet types which can be sent */
|
/* List of different packet types which can be sent */
|
||||||
enum {
|
enum {
|
||||||
@ -62,6 +63,7 @@ enum {
|
|||||||
QEMUD_PKT_NETWORK_START,
|
QEMUD_PKT_NETWORK_START,
|
||||||
QEMUD_PKT_NETWORK_DESTROY,
|
QEMUD_PKT_NETWORK_DESTROY,
|
||||||
QEMUD_PKT_NETWORK_DUMP_XML,
|
QEMUD_PKT_NETWORK_DUMP_XML,
|
||||||
|
QEMUD_PKT_NETWORK_GET_BRIDGE_NAME,
|
||||||
|
|
||||||
QEMUD_PKT_MAX,
|
QEMUD_PKT_MAX,
|
||||||
} qemud_packet_type;
|
} qemud_packet_type;
|
||||||
@ -73,6 +75,7 @@ enum {
|
|||||||
#define QEMUD_UUID_RAW_LEN 16
|
#define QEMUD_UUID_RAW_LEN 16
|
||||||
#define QEMUD_MAX_NAME_LEN 50
|
#define QEMUD_MAX_NAME_LEN 50
|
||||||
#define QEMUD_MAX_XML_LEN 4096
|
#define QEMUD_MAX_XML_LEN 4096
|
||||||
|
#define QEMUD_MAX_IFNAME_LEN IF_NAMESIZE
|
||||||
#define QEMUD_MAX_NUM_DOMAINS 100
|
#define QEMUD_MAX_NUM_DOMAINS 100
|
||||||
#define QEMUD_MAX_NUM_NETWORKS 100
|
#define QEMUD_MAX_NUM_NETWORKS 100
|
||||||
#define QEMUD_MAX_ERROR_LEN 1024
|
#define QEMUD_MAX_ERROR_LEN 1024
|
||||||
@ -270,6 +273,12 @@ union qemud_packet_data {
|
|||||||
struct {
|
struct {
|
||||||
char xml[QEMUD_MAX_XML_LEN];
|
char xml[QEMUD_MAX_XML_LEN];
|
||||||
} networkDumpXMLReply;
|
} networkDumpXMLReply;
|
||||||
|
struct {
|
||||||
|
unsigned char uuid[QEMUD_UUID_RAW_LEN];
|
||||||
|
} networkGetBridgeNameRequest;
|
||||||
|
struct {
|
||||||
|
char ifname[QEMUD_MAX_IFNAME_LEN];
|
||||||
|
} networkGetBridgeNameReply;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Each packet has header & data */
|
/* Each packet has header & data */
|
||||||
|
@ -220,6 +220,8 @@ typedef int
|
|||||||
typedef char *
|
typedef char *
|
||||||
(*virDrvNetworkDumpXML) (virNetworkPtr network,
|
(*virDrvNetworkDumpXML) (virNetworkPtr network,
|
||||||
int flags);
|
int flags);
|
||||||
|
typedef char *
|
||||||
|
(*virDrvNetworkGetBridgeName) (virNetworkPtr network);
|
||||||
|
|
||||||
typedef struct _virNetworkDriver virNetworkDriver;
|
typedef struct _virNetworkDriver virNetworkDriver;
|
||||||
typedef virNetworkDriver *virNetworkDriverPtr;
|
typedef virNetworkDriver *virNetworkDriverPtr;
|
||||||
@ -245,6 +247,7 @@ struct _virNetworkDriver {
|
|||||||
virDrvNetworkCreate networkCreate;
|
virDrvNetworkCreate networkCreate;
|
||||||
virDrvNetworkDestroy networkDestroy;
|
virDrvNetworkDestroy networkDestroy;
|
||||||
virDrvNetworkDumpXML networkDumpXML;
|
virDrvNetworkDumpXML networkDumpXML;
|
||||||
|
virDrvNetworkGetBridgeName networkGetBridgeName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2731,3 +2731,38 @@ virNetworkGetXMLDesc(virNetworkPtr network, int flags)
|
|||||||
}
|
}
|
||||||
return(ret);
|
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);
|
||||||
|
}
|
||||||
|
@ -75,6 +75,7 @@
|
|||||||
virNetworkGetUUID;
|
virNetworkGetUUID;
|
||||||
virNetworkGetUUIDString;
|
virNetworkGetUUIDString;
|
||||||
virNetworkGetXMLDesc;
|
virNetworkGetXMLDesc;
|
||||||
|
virNetworkGetBridgeName;
|
||||||
|
|
||||||
local: *;
|
local: *;
|
||||||
};
|
};
|
||||||
|
@ -1077,6 +1077,22 @@ static char * qemuNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUS
|
|||||||
return strdup(reply.data.networkDumpXMLReply.xml);
|
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 = {
|
static virDriver qemuDriver = {
|
||||||
VIR_DRV_QEMU,
|
VIR_DRV_QEMU,
|
||||||
"QEMU",
|
"QEMU",
|
||||||
@ -1134,6 +1150,7 @@ static virNetworkDriver qemuNetworkDriver = {
|
|||||||
qemuNetworkCreate, /* networkCreate */
|
qemuNetworkCreate, /* networkCreate */
|
||||||
qemuNetworkDestroy, /* networkDestroy */
|
qemuNetworkDestroy, /* networkDestroy */
|
||||||
qemuNetworkDumpXML, /* networkDumpXML */
|
qemuNetworkDumpXML, /* networkDumpXML */
|
||||||
|
qemuNetworkGetBridgeName, /* networkGetBridgeName */
|
||||||
};
|
};
|
||||||
|
|
||||||
void qemuRegister(void) {
|
void qemuRegister(void) {
|
||||||
@ -1141,7 +1158,6 @@ void qemuRegister(void) {
|
|||||||
virRegisterDriver(&qemuNetworkDriver);
|
virRegisterDriver(&qemuNetworkDriver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
* indent-tabs-mode: nil
|
* indent-tabs-mode: nil
|
||||||
|
Loading…
Reference in New Issue
Block a user