# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1200511044 28800
# Node ID dc3ff9e258b404c1755d5e24f71a75a845d19b02
# Parent be7f34a7f1a879dc220eaa8f5e2eab6dd3a04420
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 be7f34a7f1a8 -r dc3ff9e258b4 libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c Wed Jan 16 09:07:38 2008 -0800
+++ b/libxkutil/device_parsing.c Wed Jan 16 11:17:24 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 be7f34a7f1a8 -r dc3ff9e258b4 libxkutil/device_parsing.h
--- a/libxkutil/device_parsing.h Wed Jan 16 09:07:38 2008 -0800
+++ b/libxkutil/device_parsing.h Wed Jan 16 11:17:24 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 be7f34a7f1a8 -r dc3ff9e258b4 src/Virt_DevicePool.c
--- a/src/Virt_DevicePool.c Wed Jan 16 09:07:38 2008 -0800
+++ b/src/Virt_DevicePool.c Wed Jan 16 11:17:24 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;
}
}