提交 381fa1fc 编写于 作者: D Daniel P. Berrange

Switch QEMU driver over to generic network APIs

上级 d78c0a68
Fri Jul 11 18:32:59 BST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/bridge.c, src/bridge.h, src/qemu_conf.c, src/qemu_conf.h,
src/qemu_driver.c: Switch over to generic network APIs
Fri Jul 11 17:39:59 BST 2008 Daniel P. Berrange <berrange@redhat.com> Fri Jul 11 17:39:59 BST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/test.c, src/test.h: Convert to the new domain XML apis * src/test.c, src/test.h: Convert to the new domain XML apis
......
...@@ -116,60 +116,41 @@ brShutdown(brControl *ctl) ...@@ -116,60 +116,41 @@ brShutdown(brControl *ctl)
/** /**
* brAddBridge: * brAddBridge:
* @ctl: bridge control pointer * @ctl: bridge control pointer
* @nameOrFmt: the bridge name (or name template) * @name: the bridge name
* @name: pointer to @maxlen bytes to store the bridge name
* @maxlen: size of @name array
* *
* This function register a new bridge, @nameOrFmt can be either * This function register a new bridge
* a fixed name or a name template with '%d' for dynamic name allocation.
* in either case the final name for the bridge will be stored in @name.
* *
* Returns 0 in case of success or an errno code in case of failure. * Returns 0 in case of success or an errno code in case of failure.
*/ */
#ifdef SIOCBRADDBR #ifdef SIOCBRADDBR
int int
brAddBridge(brControl *ctl, brAddBridge(brControl *ctl,
const char *nameOrFmt, char **name)
char *name,
int maxlen)
{ {
int id, subst; if (!ctl || !ctl->fd || !name)
if (!ctl || !ctl->fd || !nameOrFmt || !name)
return EINVAL; return EINVAL;
if (maxlen >= BR_IFNAME_MAXLEN) if (*name) {
maxlen = BR_IFNAME_MAXLEN; if (ioctl(ctl->fd, SIOCBRADDBR, *name) == 0)
subst = id = 0;
if (strstr(nameOrFmt, "%d"))
subst = 1;
do {
char try[BR_IFNAME_MAXLEN];
int len;
if (subst) {
len = snprintf(try, maxlen, nameOrFmt, id);
if (len >= maxlen)
return EADDRINUSE;
} else {
len = strlen(nameOrFmt);
if (len >= maxlen - 1)
return EINVAL;
strncpy(try, nameOrFmt, len);
try[len] = '\0';
}
if (ioctl(ctl->fd, SIOCBRADDBR, try) == 0) {
strncpy(name, try, maxlen);
return 0; return 0;
} } else {
int id = 0;
do {
char try[50];
snprintf(try, sizeof(try), "virbr%d", id);
if (ioctl(ctl->fd, SIOCBRADDBR, try) == 0) {
if (!(*name = strdup(try))) {
ioctl(ctl->fd, SIOCBRDELBR, name);
return ENOMEM;
}
return 0;
}
id++; id++;
} while (subst && id <= MAX_BRIDGE_ID); } while (id < MAX_BRIDGE_ID);
}
return errno; return errno;
} }
......
...@@ -47,9 +47,7 @@ int brInit (brControl **ctl); ...@@ -47,9 +47,7 @@ int brInit (brControl **ctl);
void brShutdown (brControl *ctl); void brShutdown (brControl *ctl);
int brAddBridge (brControl *ctl, int brAddBridge (brControl *ctl,
const char *nameOrFmt, char **name);
char *name,
int maxlen);
int brDeleteBridge (brControl *ctl, int brDeleteBridge (brControl *ctl,
const char *name); const char *name);
......
此差异已折叠。
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "bridge.h" #include "bridge.h"
#include "iptables.h" #include "iptables.h"
#include "capabilities.h" #include "capabilities.h"
#include "network_conf.h"
#include <netinet/in.h> #include <netinet/in.h>
#include <sched.h> #include <sched.h>
...@@ -96,12 +97,6 @@ enum qemud_vm_net_type { ...@@ -96,12 +97,6 @@ enum qemud_vm_net_type {
QEMUD_NET_BRIDGE, QEMUD_NET_BRIDGE,
}; };
/* 2 possible types of forwarding */
enum qemud_vm_net_forward_type {
QEMUD_NET_FORWARD_NAT,
QEMUD_NET_FORWARD_ROUTE,
};
#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_ERROR_LEN 1024 #define QEMUD_MAX_ERROR_LEN 1024
...@@ -349,53 +344,6 @@ struct qemud_vm { ...@@ -349,53 +344,6 @@ struct qemud_vm {
struct qemud_vm *next; 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[VIR_UUID_BUFLEN];
char name[QEMUD_MAX_NAME_LEN];
char bridge[BR_IFNAME_MAXLEN];
int disableSTP;
int forwardDelay;
int forward;
int forwardMode; /* From qemud_vm_net_forward_type */
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 */ /* Main driver state */
struct qemud_driver { struct qemud_driver {
int qemuVersion; int qemuVersion;
...@@ -403,9 +351,9 @@ struct qemud_driver { ...@@ -403,9 +351,9 @@ struct qemud_driver {
int ninactivevms; int ninactivevms;
struct qemud_vm *vms; struct qemud_vm *vms;
int nextvmid; int nextvmid;
int nactivenetworks;
int ninactivenetworks; virNetworkObjPtr networks;
struct qemud_network *networks;
brControl *brctl; brControl *brctl;
iptablesContext *iptables; iptablesContext *iptables;
char *configDir; char *configDir;
...@@ -428,12 +376,6 @@ qemudIsActiveVM(const struct qemud_vm *vm) ...@@ -428,12 +376,6 @@ qemudIsActiveVM(const struct qemud_vm *vm)
return vm->id != -1; return vm->id != -1;
} }
static inline int
qemudIsActiveNetwork(const struct qemud_network *network)
{
return network->active;
}
void qemudReportError(virConnectPtr conn, void qemudReportError(virConnectPtr conn,
virDomainPtr dom, virDomainPtr dom,
virNetworkPtr net, virNetworkPtr net,
...@@ -451,11 +393,6 @@ struct qemud_vm *qemudFindVMByUUID(const struct qemud_driver *driver, ...@@ -451,11 +393,6 @@ struct qemud_vm *qemudFindVMByUUID(const struct qemud_driver *driver,
struct qemud_vm *qemudFindVMByName(const struct qemud_driver *driver, struct qemud_vm *qemudFindVMByName(const struct qemud_driver *driver,
const char *name); const char *name);
struct qemud_network *qemudFindNetworkByUUID(const struct qemud_driver *driver,
const unsigned char *uuid);
struct qemud_network *qemudFindNetworkByName(const struct qemud_driver *driver,
const char *name);
virCapsPtr qemudCapsInit (void); virCapsPtr qemudCapsInit (void);
int qemudExtractVersion (virConnectPtr conn, int qemudExtractVersion (virConnectPtr conn,
...@@ -501,30 +438,6 @@ char * qemudGenerateXML (virConnectPtr conn, ...@@ -501,30 +438,6 @@ char * qemudGenerateXML (virConnectPtr conn,
struct qemud_vm_def *def, struct qemud_vm_def *def,
int live); int live);
void qemudFreeNetworkDef (struct qemud_network_def *def);
void qemudFreeNetwork (struct qemud_network *network);
struct qemud_network *
qemudAssignNetworkDef (virConnectPtr conn,
struct qemud_driver *driver,
struct qemud_network_def *def);
void qemudRemoveInactiveNetwork (struct qemud_driver *driver,
struct qemud_network *network);
struct qemud_network_def *
qemudParseNetworkDef (virConnectPtr conn,
struct qemud_driver *driver,
const char *xmlStr,
const char *displayName);
int qemudSaveNetworkDef (virConnectPtr conn,
struct qemud_driver *driver,
struct qemud_network *network,
struct qemud_network_def *def);
char * qemudGenerateNetworkXML (virConnectPtr conn,
struct qemud_driver *driver,
struct qemud_network *network,
struct qemud_network_def *def);
const char *qemudVirtTypeToString (int type); const char *qemudVirtTypeToString (int type);
#endif /* WITH_QEMU */ #endif /* WITH_QEMU */
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册