[Libvirt-cim] [PATCH] (#3)- Add support for bridge type NICs

Sharad Mishra snmishra at us.ibm.com
Mon Jun 22 18:41:18 UTC 2009


# HG changeset patch
# User snmishra at us.ibm.com
# Date 1245694676 25200
# Node ID 4bd5db5f544279f099b4d7565157c675cf072936
# Parent  3fa64e808da1d96eeb7e58f6f0532a4c00deba4b
(#3)- Add support for bridge type NICs.

Code was added to parse input and generate
libvirt XML to support bridge devices.
Net_RASD mof was updated to add bridge device name.
#2 - replaced hard tabs with spaces and fixed a potential
	segfault.
#3 - fixed mercurial patch issues.

Signed-off-by: Sharad Mishra <snmishra at us.ibm.com>

diff -r 3fa64e808da1 -r 4bd5db5f5442 libxkutil/device_parsing.h
--- a/libxkutil/device_parsing.h	Fri Jun 12 15:11:51 2009 -0700
+++ b/libxkutil/device_parsing.h	Mon Jun 22 11:17:56 2009 -0700
@@ -47,6 +47,7 @@
         char *mac;
         char *source;
         char *model;
+        char *name;
 };
 
 struct mem_device {
diff -r 3fa64e808da1 -r 4bd5db5f5442 libxkutil/xmlgen.c
--- a/libxkutil/xmlgen.c	Fri Jun 12 15:11:51 2009 -0700
+++ b/libxkutil/xmlgen.c	Mon Jun 22 11:17:56 2009 -0700
@@ -164,12 +164,18 @@
 {
         xmlNodePtr tmp;
 
-        if (dev->source != NULL) {
+        if ((STREQC(src_type, "bridge")) && (dev->name != NULL)) {
                 tmp = xmlNewChild(nic, NULL, BAD_CAST "source", NULL);
-                if (tmp == NULL)
+                if (tmp == NULL) 
+                        return XML_ERROR;
+                xmlNewProp(tmp, BAD_CAST src_type, BAD_CAST dev->name);
+        } else if ((STREQC(src_type, "network")) && (dev->source != NULL)) {
+                tmp = xmlNewChild(nic, NULL, BAD_CAST "source", NULL);
+                if (tmp == NULL) 
                         return XML_ERROR;
                 xmlNewProp(tmp, BAD_CAST src_type, BAD_CAST dev->source);
-        }
+        } else
+                return XML_ERROR;
 
         return NULL;
 }
@@ -225,7 +231,7 @@
                 if (STREQ(dev->dev.net.type, "network"))
                         msg = set_net_source(nic, net, "network");
                 else if (STREQ(dev->dev.net.type, "bridge"))
-                        msg = bridge_net_to_xml(root, net);
+                        msg = bridge_net_to_xml(nic, net);
                 else if (STREQ(dev->dev.net.type, "user"))
                         continue;
                 else
diff -r 3fa64e808da1 -r 4bd5db5f5442 schema/ResourceAllocationSettingData.mof
--- a/schema/ResourceAllocationSettingData.mof	Fri Jun 12 15:11:51 2009 -0700
+++ b/schema/ResourceAllocationSettingData.mof	Mon Jun 22 11:17:56 2009 -0700
@@ -57,6 +57,9 @@
       [Description ("Interface type")]
       string NetworkType;
 
+      [Description ("Bridge name")]
+      string NetworkName;
+
 };
 
 [Description ("KVM virtual network configuration"),
@@ -68,6 +71,9 @@
       [Description ("Interface type")]
       string NetworkType;
 
+      [Description ("Bridge name")]
+      string NetworkName;
+
 };
 
 [Description ("LXC virtual network configuration"),
diff -r 3fa64e808da1 -r 4bd5db5f5442 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Fri Jun 12 15:11:51 2009 -0700
+++ b/src/Virt_VirtualSystemManagementService.c	Mon Jun 22 11:17:56 2009 -0700
@@ -59,6 +59,8 @@
 
 #define DEFAULT_MAC_PREFIX "00:16:3e"
 #define DEFAULT_XEN_WEIGHT 1024
+#define BRIDGE_TYPE "bridge"
+#define NETWORK_TYPE "network"
 
 const static CMPIBroker *_BROKER;
 
@@ -553,23 +555,37 @@
         dev->id = strdup(dev->dev.net.mac);
 
         free(dev->dev.net.type);
-        dev->dev.net.type = strdup("network");
+        free(dev->dev.net.name);
+        if (cu_get_str_prop(inst, "NetworkType", &val) != CMPI_RC_OK) 
+                return "No Network Type specified";
 
-        if (cu_get_str_prop(inst, "PoolID", &val) != CMPI_RC_OK)
-                val = _default_network(inst, ns);
+        if (STREQC(val, BRIDGE_TYPE)) {
+                dev->dev.net.type = strdup(BRIDGE_TYPE);
+                if (cu_get_str_prop(inst, "NetworkName", &val) == CMPI_RC_OK) 
+                        if (strlen(val) > 0)
+                                dev->dev.net.name = strdup(val);
+                        else
+                                return "Bridge name is empty";
+                else 
+                        return "No Network bridge name specified";
+         } else if (STREQC(val, NETWORK_TYPE)) {
+                dev->dev.net.type = strdup(NETWORK_TYPE);
+                if (cu_get_str_prop(inst, "PoolID", &val) != CMPI_RC_OK)
+                        val = _default_network(inst, ns);
 
-        if (val == NULL)
-                return "No NetworkPool specified and no default available";
+                if (val == NULL)
+                        return "No NetworkPool specified no default available";
 
-        free(dev->dev.net.source);
-        dev->dev.net.source = name_from_pool_id(val);
+                free(dev->dev.net.source);
+                dev->dev.net.source = name_from_pool_id(val);
+        } else
+                return "Invalid Network Type specified";
+        free(dev->dev.net.model);
 
-        free(dev->dev.net.model);
         if (cu_get_str_prop(inst, "ResourceSubType", &val) != CMPI_RC_OK)
                 dev->dev.net.model = NULL; 
         else 
                 dev->dev.net.model = strdup(val);
-
  out:
         return msg;
 }




More information about the Libvirt-cim mailing list