# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1200676457 28800
# Node ID d7cbd655da4e98984ea25a4263b2ed030dec4b58
# Parent 68b0c4f23d9e7a9ee93ce331c288f2a13aab649c
Add network interface parsing for KVM domains
Changes:
- Fixed printf() debugs
- Changed the source/type validation to better catch unsupported
configs.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 68b0c4f23d9e -r d7cbd655da4e libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c Fri Jan 18 09:13:56 2008 -0800
+++ b/libxkutil/device_parsing.c Fri Jan 18 09:14:17 2008 -0800
@@ -44,6 +44,7 @@
#define GRAPHICS_XPATH (xmlChar *)"/domain/devices/graphics"
#define DEFAULT_BRIDGE "xenbr0"
+#define DEFAULT_NETWORK "default"
#define XSTREQ(x, y) (STREQ((char *)x, y))
#define MAX(a,b) (((a)>(b))?(a):(b))
@@ -61,7 +62,7 @@ static void cleanup_net_device(struct ne
{
free(dev->type);
free(dev->mac);
- free(dev->bridge);
+ free(dev->source);
}
static void cleanup_emu_device(struct emu_device *dev)
@@ -216,18 +217,35 @@ static int parse_net_device(xmlNode *ino
if (ndev->mac == NULL)
goto err;
} else if (XSTREQ(child->name, "source")) {
- ndev->bridge = get_attr_value(child, "bridge");
- if (ndev->bridge == NULL)
- goto err;
+ ndev->source = get_attr_value(child, "bridge");
+ if (ndev->source != NULL)
+ continue;
+ ndev->source = get_attr_value(child, "network");
+ if (ndev->source != NULL)
+ continue;
+ goto err;
}
}
if (ndev->mac == NULL)
goto err;
- if (ndev->bridge == NULL) {
- ndev->bridge = strdup(DEFAULT_BRIDGE);
- printf("No bridge, taking default of `%s'\n",
ndev->bridge);
+ if (ndev->source == NULL) {
+ if (STREQC(ndev->type, "bridge")) {
+ ndev->source = strdup(DEFAULT_BRIDGE);
+ CU_DEBUG("No bridge, taking default of `%s'\n",
+ ndev->source);
+ } else if (STREQC(ndev->type, "network")) {
+ ndev->source = strdup(DEFAULT_NETWORK);
+ CU_DEBUG("No network, taking default of `%s'\n",
+ ndev->source);
+ } else {
+ /* This likely indicates an unsupported
+ * network configuration
+ */
+ CU_DEBUG("No network source, and no known default");
+ goto err;
+ }
}
vdev->type = VIRT_DEV_NET;
@@ -517,7 +535,7 @@ struct virt_device *virt_device_dup(stru
if (dev->type == VIRT_DEV_NET) {
DUP_FIELD(dev, _dev, dev.net.mac);
DUP_FIELD(dev, _dev, dev.net.type);
- DUP_FIELD(dev, _dev, dev.net.bridge);
+ DUP_FIELD(dev, _dev, dev.net.source);
} else if (dev->type == VIRT_DEV_DISK) {
DUP_FIELD(dev, _dev, dev.disk.type);
DUP_FIELD(dev, _dev, dev.disk.device);
diff -r 68b0c4f23d9e -r d7cbd655da4e libxkutil/device_parsing.h
--- a/libxkutil/device_parsing.h Fri Jan 18 09:13:56 2008 -0800
+++ b/libxkutil/device_parsing.h Fri Jan 18 09:14:17 2008 -0800
@@ -41,7 +41,7 @@ struct net_device {
struct net_device {
char *type;
char *mac;
- char *bridge;
+ char *source;
};
struct mem_device {
diff -r 68b0c4f23d9e -r d7cbd655da4e src/Virt_DevicePool.c
--- a/src/Virt_DevicePool.c Fri Jan 18 09:13:56 2008 -0800
+++ b/src/Virt_DevicePool.c Fri Jan 18 09:14:17 2008 -0800
@@ -295,7 +295,7 @@ static char *netpool_member_of(const CMP
for (i = 0; i < count; i++) {
if (STREQ((devs[i].id), dev)) {
result = _netpool_member_of(conn,
- devs[i].dev.net.bridge);
+ devs[i].dev.net.source);
break;
}
}