[PATCH] Add support for bridge type NICs

# HG changeset patch # User snmishra@us.ibm.com # Date 1245184531 25200 # Node ID 27f3f7f05eb78bd009451009ac7c472f0ffa9332 # Parent a57141febd4a5b6dbae71e96b16264dd1240642d 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. Signed-off-by: Sharad Mishra <snmishra@us.ibm.com> diff -r a57141febd4a -r 27f3f7f05eb7 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Fri Jun 12 16:14:40 2009 -0700 +++ b/libxkutil/device_parsing.h Tue Jun 16 13:35:31 2009 -0700 @@ -47,6 +47,7 @@ char *mac; char *source; char *model; + char *name; }; struct mem_device { diff -r a57141febd4a -r 27f3f7f05eb7 libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Fri Jun 12 16:14:40 2009 -0700 +++ b/libxkutil/xmlgen.c Tue Jun 16 13:35:31 2009 -0700 @@ -168,7 +168,12 @@ tmp = xmlNewChild(nic, NULL, BAD_CAST "source", NULL); if (tmp == NULL) return XML_ERROR; - xmlNewProp(tmp, BAD_CAST src_type, BAD_CAST dev->source); + if (STREQC(src_type, "bridge")) { + xmlNewProp(tmp, BAD_CAST src_type, BAD_CAST dev->name); + } else { + xmlNewProp(tmp, BAD_CAST src_type, + BAD_CAST dev->source); + } } return NULL; @@ -225,7 +230,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 a57141febd4a -r 27f3f7f05eb7 schema/ResourceAllocationSettingData.mof --- a/schema/ResourceAllocationSettingData.mof Fri Jun 12 16:14:40 2009 -0700 +++ b/schema/ResourceAllocationSettingData.mof Tue Jun 16 13:35:31 2009 -0700 @@ -57,6 +57,10 @@ [Description ("Interface type")] string NetworkType; + [Description ("Bridge name")] + string NetworkName; + + }; [Description ("KVM virtual network configuration"), @@ -68,6 +72,9 @@ [Description ("Interface type")] string NetworkType; + [Description ("Bridge name")] + string NetworkName; + }; [Description ("LXC virtual network configuration"), diff -r a57141febd4a -r 27f3f7f05eb7 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Fri Jun 12 16:14:40 2009 -0700 +++ b/src/Virt_VirtualSystemManagementService.c Tue Jun 16 13:35:31 2009 -0700 @@ -59,6 +59,7 @@ #define DEFAULT_MAC_PREFIX "00:16:3e" #define DEFAULT_XEN_WEIGHT 1024 +#define BRIDGE_TYPE "bridge" const static CMPIBroker *_BROKER; @@ -553,7 +554,20 @@ dev->id = strdup(dev->dev.net.mac); free(dev->dev.net.type); - dev->dev.net.type = strdup("network"); + if (cu_get_str_prop(inst, "NetworkType", &val) == CMPI_RC_OK) { + if (STREQC(val, BRIDGE_TYPE)) { + dev->dev.net.type = strdup(BRIDGE_TYPE); + if (cu_get_str_prop(inst, "NetworkName", &val) == + CMPI_RC_OK) { + dev->dev.net.name = strdup(val); + } else { + return "No Network bridge name specified"; + } + } else { + dev->dev.net.type = strdup("network"); + } + } + if (cu_get_str_prop(inst, "PoolID", &val) != CMPI_RC_OK) val = _default_network(inst, ns);

diff -r a57141febd4a -r 27f3f7f05eb7 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Fri Jun 12 16:14:40 2009 -0700 +++ b/libxkutil/device_parsing.h Tue Jun 16 13:35:31 2009 -0700 @@ -47,6 +47,7 @@ char *mac; char *source; char *model; + char *name;
This is a hard tab, it should be 8 spaces.
diff -r a57141febd4a -r 27f3f7f05eb7 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Fri Jun 12 16:14:40 2009 -0700 +++ b/src/Virt_VirtualSystemManagementService.c Tue Jun 16 13:35:31 2009 -0700 @@ -59,6 +59,7 @@
#define DEFAULT_MAC_PREFIX "00:16:3e" #define DEFAULT_XEN_WEIGHT 1024 +#define BRIDGE_TYPE "bridge"
const static CMPIBroker *_BROKER;
@@ -553,7 +554,20 @@ dev->id = strdup(dev->dev.net.mac);
free(dev->dev.net.type); - dev->dev.net.type = strdup("network"); + if (cu_get_str_prop(inst, "NetworkType", &val) == CMPI_RC_OK) { + if (STREQC(val, BRIDGE_TYPE)) { + dev->dev.net.type = strdup(BRIDGE_TYPE); + if (cu_get_str_prop(inst, "NetworkName", &val) == + CMPI_RC_OK) { + dev->dev.net.name = strdup(val); + } else { + return "No Network bridge name specified"; + } + } else { + dev->dev.net.type = strdup("network");
This will cause a seg fault if the user doesn't specify a value for the NetworkType attribute. So you'll either need to make NetworkType mandatory (and return an error if its not specified), or allow the guest to be crated with a network type interface in the case where 1) NetworkType is specified 2) NetworkType is "network"
+ } + } +
if (cu_get_str_prop(inst, "PoolID", &val) != CMPI_RC_OK) val = _default_network(inst, ns);
For either case, these lines need to be moved as appropriate. If the interface type is bridge, you'll want to ignore the PoolID value (or return an error - since the PoolID value should only be set for network type interfaces). Also, the following lines only pertain to network interface types: if (val == NULL) return "No NetworkPool specified and no default available"; free(dev->dev.net.source); dev->dev.net.source = name_from_pool_id(val); This bit of code shouldn't be executed for bridge type interfaces. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Sharad Mishra