[PATCH] Plan9fs (aka 9pfs, VirtFS) support for QEMU/KVM environment
by Deepak C Shetty
VirtFS is virtualization aware file system pass-through which provides the
functionality to share host file system inside the guest. Its supported in
libvirt via the <filesystem> xml node/tag. This patch introduces the
filesystem support in KVM_DiskRASD and its associated changes needed to
support VirtFS in libvirt-cim.
For further details...
Virtfs home page/wiki : http://v9fs.sourceforge.net/
Virtfs setup for QEMU : http://wiki.qemu.org/Documentation/9psetup
Virtfs support in libvirt :
http://libvirt.org/formatdomain.html#elementsFilesystems
An example of the <filesystem> node in libvirt, supporting VirtFS...
<filesystem type='mount' accessmode='passthrough'>
<driver type='path'/>
<source dir='/export/to/guest'/>
<target dir='/import/from/host'/>
<readonly/>
</filesystem>
Signed-off-by: Deepak C Shetty <deepakcs(a)linux.vnet.ibm.com>
---
libxkutil/device_parsing.c | 8 ++++++++
libxkutil/device_parsing.h | 1 +
libxkutil/xmlgen.c | 15 +++++++++++++++
schema/ResourceAllocationSettingData.mof | 7 +++++--
src/Virt_RASD.c | 6 ++++++
src/Virt_RASD.h | 1 +
src/Virt_VirtualSystemManagementService.c | 8 ++++++++
7 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 371838f..6a09e7d 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -65,6 +65,7 @@ static void cleanup_disk_device(struct disk_device *dev)
free(dev->source);
free(dev->virtual_dev);
free(dev->bus_type);
+ free(dev->access_mode);
}
static void cleanup_vsi_device(struct vsi_device *dev)
@@ -220,6 +221,8 @@ static int parse_fs_device(xmlNode *dnode, struct virt_device **vdevs)
goto err;
}
+ ddev->access_mode = get_attr_value(dnode, "accessmode");
+
for (child = dnode->children; child != NULL; child = child->next) {
if (XSTREQ(child->name, "source")) {
ddev->source = get_attr_value(child, "dir");
@@ -233,6 +236,8 @@ static int parse_fs_device(xmlNode *dnode, struct virt_device **vdevs)
CU_DEBUG("No target dir");
goto err;
}
+ } else if (XSTREQ(child->name, "driver")) {
+ ddev->driver_type = get_attr_value(child, "type");
}
}
@@ -870,6 +875,7 @@ struct virt_device *virt_device_dup(struct virt_device *_dev)
DUP_FIELD(dev, _dev, dev.disk.source);
DUP_FIELD(dev, _dev, dev.disk.virtual_dev);
DUP_FIELD(dev, _dev, dev.disk.bus_type);
+ DUP_FIELD(dev, _dev, dev.disk.access_mode);
dev->dev.disk.disk_type = _dev->dev.disk.disk_type;
dev->dev.disk.readonly = _dev->dev.disk.readonly;
dev->dev.disk.shareable = _dev->dev.disk.shareable;
@@ -1436,6 +1442,8 @@ int disk_type_from_file(const char *path)
return DISK_PHY;
else if (S_ISREG(s.st_mode))
return DISK_FILE;
+ else if (S_ISDIR(s.st_mode))
+ return DISK_FS;
else
return DISK_UNKNOWN;
}
diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h
index ab104d9..6bed040 100644
--- a/libxkutil/device_parsing.h
+++ b/libxkutil/device_parsing.h
@@ -55,6 +55,7 @@ struct disk_device {
bool shareable;
char *bus_type;
char *cache;
+ char *access_mode; /* access modes for DISK_FS (filesystem) type */
};
struct net_device {
diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index 4cca75b..44a6158 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -152,6 +152,21 @@ static const char *disk_fs_xml(xmlNodePtr root, struct disk_device *dev)
if (fs == NULL)
return XML_ERROR;
+ /* filesystem prop 'type' not needed to be generated, as it defaults
+ to 'mount' in libvirt, the only supported value for now. */
+
+ /* filesystem prop 'accessmode' defaults to 'passthrough' in libvirt.
+ So generate here if specified by user, else leave it to libvirt. */
+
+ if (dev->access_mode) {
+ xmlNewProp(fs, BAD_CAST "accessmode", BAD_CAST dev->access_mode);
+ }
+
+ if(dev->driver_type) {
+ tmp = xmlNewChild(fs, NULL, BAD_CAST "driver", NULL);
+ xmlNewProp(tmp, BAD_CAST "type", BAD_CAST dev->driver_type);
+ }
+
tmp = xmlNewChild(fs, NULL, BAD_CAST "source", NULL);
if (tmp == NULL)
return XML_ERROR;
diff --git a/schema/ResourceAllocationSettingData.mof b/schema/ResourceAllocationSettingData.mof
index 3da503d..108dff7 100644
--- a/schema/ResourceAllocationSettingData.mof
+++ b/schema/ResourceAllocationSettingData.mof
@@ -40,8 +40,8 @@ class KVM_DiskResourceAllocationSettingData : KVM_ResourceAllocationSettingData
string VirtualDevice;
[Description ("Device emulation type"),
- ValueMap {"0", "1", "2"},
- Values {"Disk", "CDROM", "floppy"}]
+ ValueMap {"0", "1", "2", "3"},
+ Values {"Disk", "CDROM", "floppy", "filesystem"}]
uint16 EmulatedType;
[Description ("Bus type of the device")]
@@ -58,6 +58,9 @@ class KVM_DiskResourceAllocationSettingData : KVM_ResourceAllocationSettingData
[Description ("cache setting for device")]
string DriverCache;
+
+ [Description ("filesystem access mode")]
+ string AccessMode;
};
[Description ("LXC virtual disk configuration"),
diff --git a/src/Virt_RASD.c b/src/Virt_RASD.c
index 9305c8d..29bf10d 100644
--- a/src/Virt_RASD.c
+++ b/src/Virt_RASD.c
@@ -397,6 +397,12 @@ static CMPIStatus set_disk_rasd_params(const CMPIBroker *broker,
(CMPIValue *)dev->dev.disk.cache,
CMPI_chars);
+ if(dev->dev.disk.access_mode)
+ CMSetProperty(inst,
+ "AccessMode",
+ (CMPIValue *)dev->dev.disk.access_mode,
+ CMPI_chars);
+
virStoragePoolFree(pool);
virStorageVolFree(vol);
virConnectClose(conn);
diff --git a/src/Virt_RASD.h b/src/Virt_RASD.h
index 550543a..cef4224 100644
--- a/src/Virt_RASD.h
+++ b/src/Virt_RASD.h
@@ -26,6 +26,7 @@
#define VIRT_DISK_TYPE_DISK 0
#define VIRT_DISK_TYPE_CDROM 1
#define VIRT_DISK_TYPE_FLOPPY 2
+#define VIRT_DISK_TYPE_FS 3
char *rasd_to_xml(CMPIInstance *rasd);
diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c
index 21979c3..3cdca86 100644
--- a/src/Virt_VirtualSystemManagementService.c
+++ b/src/Virt_VirtualSystemManagementService.c
@@ -1022,6 +1022,8 @@ static const char *disk_rasd_to_vdev(CMPIInstance *inst,
}
else if (type == VIRT_DISK_TYPE_FLOPPY)
dev->dev.disk.device = strdup("floppy");
+ else if (type == VIRT_DISK_TYPE_FS)
+ dev->dev.disk.device = strdup("filesystem");
else
return "Invalid value for EmulatedType";
@@ -1056,6 +1058,12 @@ static const char *disk_rasd_to_vdev(CMPIInstance *inst,
else
dev->dev.disk.cache = strdup(val);
+ free(dev->dev.disk.access_mode);
+ if (cu_get_str_prop(inst, "AccessMode", &val) != CMPI_RC_OK)
+ dev->dev.disk.access_mode = NULL;
+ else
+ dev->dev.disk.access_mode = strdup(val);
+
free(dev->id);
dev->id = strdup(dev->dev.disk.virtual_dev);
12 years, 9 months
Support for libvirt domain events implementation
by Eduardo Lima (Etrunko)
[PATCH 1/2] VirtualSystemManagementService: Remove dead code
- This patch simply removes some code that was already commented for some time
[PATCH 2/2] ComputerSystemIndication: Support libvirt domain events
- This one actually does the job. See its description for more details.
Best regards, Etrunko
--
Eduardo de Barros Lima
Software Engineer, Open Virtualization
Linux Technology Center - IBM/Brazil
eblima(a)br.ibm.com
12 years, 10 months
[PATCH] Network QoS Patch2
by Gareth S Bestor
From: Gareth S. Bestor <bestor(a)us.ibm.com>
This patch updates the earlier patch to libvirt-cim for network bandwidth QOS
support. Previous patch had to perform all external host 'tc' (traffic control)
commands from within libvirt-cim providers, because earlier versions of
libvirt lacked native QoS support. libvirt 0.9.4 added native QoS support;
this new patch for libvirt-cim removes earlier QoS hacks in favor of directly
exploiting libvirt equivalent QoS function and configuration. Note, libvirt
supports three tunables for network bandwidth QoS: average, peak and burst,
for both inbound and outbound traffic independently.
This revised libvirt-cim patch only exposes - as previously - inbound traffic
QoS, but adds peak to previous average tunable support.
Selection of earlier (libvirt-cim QoS hack) vs latter (native libvirt QoS)
is done at compile-time based on libvirt version being built against.
As previously, QoS capabilites are exposed on the virtual network pool, and
the QoS setting for a specific guest's NIC are exposed on the associated
network device RASD. QoS settings may be specified during guest creation
(DefineSystem) or guest modification (ModifyResourceSettings).
Signed-off-by: Gareth S. Bestor <bestor(a)us.ibm.com>
---
libxkutil/device_parsing.c | 34 +++++++++++++++++++++
libxkutil/device_parsing.h | 2 +
libxkutil/xmlgen.c | 39 ++++++++++++++++++++++++
src/Virt_RASD.c | 33 ++++++++++++++++++--
src/Virt_SettingsDefineCapabilities.c | 47 +++++++++++++++++++++++++----
src/Virt_VirtualSystemManagementService.c | 22 +++++++++++++-
6 files changed, 166 insertions(+), 11 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 371838f..7eaa63e 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -444,7 +444,39 @@ static int parse_net_device(xmlNode *inode, struct virt_device **vdevs)
ndev->filter_ref = get_attr_value(child, "filter");
} else if (XSTREQ(child->name, "virtualport")) {
parse_vsi_device(child, ndev);
+#if LIBVIR_VERSION_NUMBER >= 9000
+ } else if (XSTREQ(child->name, "bandwidth")) {
+ /* Network QoS bandwidth support */
+ xmlNode *grandchild = NULL;
+ for (grandchild = child->children;
+ grandchild != NULL;
+ grandchild = grandchild->next) {
+ if (XSTREQ(grandchild->name, "inbound")) {
+ /* Only expose inbound bandwidth */
+ char *val;
+
+ val = get_attr_value(grandchild,
+ "average");
+ if (val != NULL) {
+ sscanf(val, "%" PRIu64,
+ &ndev->reservation);
+ free(val);
+ } else
+ ndev->reservation = 0;
+
+ val = get_attr_value(grandchild,
+ "peak");
+ if (val != NULL) {
+ sscanf(val, "%" PRIu64,
+ &ndev->limit);
+ free(val);
+ } else
+ ndev->limit = 0;
+ break;
+ }
+ }
}
+#endif
}
@@ -861,6 +893,8 @@ struct virt_device *virt_device_dup(struct virt_device *_dev)
DUP_FIELD(dev, _dev, dev.net.vsi.instance_id);
DUP_FIELD(dev, _dev, dev.net.vsi.filter_ref);
DUP_FIELD(dev, _dev, dev.net.vsi.profile_id);
+ dev->dev.net.reservation = _dev->dev.net.reservation;
+ dev->dev.net.limit = _dev->dev.net.limit;
} else if (dev->type == CIM_RES_TYPE_DISK) {
DUP_FIELD(dev, _dev, dev.disk.type);
DUP_FIELD(dev, _dev, dev.disk.device);
diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h
index ab104d9..f24268b 100644
--- a/libxkutil/device_parsing.h
+++ b/libxkutil/device_parsing.h
@@ -66,6 +66,8 @@ struct net_device {
char *device;
char *net_mode;
char *filter_ref;
+ uint64_t reservation;
+ uint64_t limit;
struct vsi_device vsi;
};
diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index aae1e51..638cffe 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -320,6 +320,45 @@ static const char *net_xml(xmlNodePtr root, struct domain *dominfo)
BAD_CAST net->filter_ref);
}
+#if LIBVIR_VERSION_NUMBER >= 9000
+ /* Network QoS settings saved under <bandwidth> XML section */
+ if (net->reservation || net->limit) {
+ int ret;
+ char *string = NULL;
+
+ tmp = xmlNewChild(nic, NULL,
+ BAD_CAST "bandwidth", NULL);
+ if (tmp == NULL)
+ return XML_ERROR;
+
+ /* Set inbound bandwidth from Reservation & Limit */
+ tmp = xmlNewChild(tmp, NULL,
+ BAD_CAST "inbound", NULL);
+ if (tmp == NULL)
+ return XML_ERROR;
+
+ if (net->reservation) {
+ ret = asprintf(&string, "%" PRIu64,
+ net->reservation);
+ if (ret == -1)
+ return XML_ERROR;
+ xmlNewProp(tmp, BAD_CAST "average",
+ BAD_CAST string);
+ free(string);
+ }
+
+ if (net->limit) {
+ ret = asprintf(&string, "%" PRIu64,
+ net->limit);
+ if (ret == -1)
+ return XML_ERROR;
+ xmlNewProp(tmp, BAD_CAST "peak",
+ BAD_CAST string);
+ free(string);
+ }
+ }
+#endif
+
if (STREQ(dev->dev.net.type, "network"))
msg = set_net_source(nic, net, "network");
else if (STREQ(dev->dev.net.type, "bridge"))
diff --git a/src/Virt_RASD.c b/src/Virt_RASD.c
index e148674..a868c21 100644
--- a/src/Virt_RASD.c
+++ b/src/Virt_RASD.c
@@ -39,6 +39,7 @@
#include "svpc_types.h"
#include "Virt_Device.h"
+#if LIBVIR_VERSION_NUMBER < 9000
/* Network QoS support */
#define QOSCMD_MAC2BANDWIDTH "_ROOT=$(tc class show dev %s | awk '($4==\"root\")\
{print $3}')\n _ID=$(tc filter show dev %s | awk 'BEGIN {RS=\"\\nfilter\"} (NR>2)\
@@ -48,6 +49,7 @@ m1,m2,m3,m4,m5,m6,$18)}' | awk -v mm=%s '($1==mm){print $2}')\n \
if [[ -n \"$_ID\" ]]; then\n tc class show dev %s | awk -v rr=$_ROOT -v id=$_ID \
'($4==\"parent\" && $5==rr && $3==id){print \
substr($13,1,(index($13,\"Kbit\")-1))}'\n fi\n"
+#endif
const static CMPIBroker *_BROKER;
@@ -463,11 +465,7 @@ static CMPIStatus set_net_rasd_params(const CMPIBroker *broker,
const struct virt_device *dev,
CMPIInstance *inst)
{
- FILE *pipe = NULL;
- char *cmd = NULL;
- uint64_t val = 0;
CMPIStatus s = {CMPI_RC_OK, NULL};
- int i;
CMSetProperty(inst,
"NetworkType",
@@ -485,8 +483,14 @@ static CMPIStatus set_net_rasd_params(const CMPIBroker *broker,
(CMPIValue *)dev->dev.net.source,
CMPI_chars);
+#if LIBVIR_VERSION_NUMBER < 9000
/* Network QoS support */
if ((dev->dev.net.mac != NULL) && (dev->dev.net.source != NULL)) {
+ FILE *pipe = NULL;
+ char *cmd = NULL;
+ uint64_t val = 0;
+ int i;
+
/* Get tc performance class bandwidth for this MAC addr */
i = asprintf(&cmd, QOSCMD_MAC2BANDWIDTH, dev->dev.net.source,
dev->dev.net.source,
@@ -511,6 +515,25 @@ static CMPIStatus set_net_rasd_params(const CMPIBroker *broker,
}
free(cmd);
}
+#else
+ if (dev->dev.net.reservation) {
+ CMSetProperty(inst,
+ "Reservation",
+ (CMPIValue *)&(dev->dev.net.reservation),
+ CMPI_uint64);
+
+ if (dev->dev.net.limit)
+ CMSetProperty(inst,
+ "Limit",
+ (CMPIValue *)&(dev->dev.net.limit),
+ CMPI_uint64);
+
+ CMSetProperty(inst,
+ "AllocationUnits",
+ (CMPIValue *)"KiloBytes per Second",
+ CMPI_chars);
+ }
+#endif
if ((dev->dev.net.source != NULL) &&
(STREQ(dev->dev.net.type, "direct")))
@@ -543,7 +566,9 @@ static CMPIStatus set_net_rasd_params(const CMPIBroker *broker,
(CMPIValue *)dev->dev.net.poolid,
CMPI_chars);
+#if LIBVIR_VERSION_NUMBER < 9000
out:
+#endif
return s;
}
diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c
index 129749e..660103a 100644
--- a/src/Virt_SettingsDefineCapabilities.c
+++ b/src/Virt_SettingsDefineCapabilities.c
@@ -74,9 +74,11 @@ const static CMPIBroker *_BROKER;
#define NEW_VOL_RASD 2
/* QoS Network support */
+#if LIBVIR_VERSION_NUMBER < 9000
#define QOSCMD_LISTCLASSES "_ROOT=$(tc class show dev %s | awk '($4==\"root\")\
{print $3}')\n tc class show dev %s | awk -v rr=$_ROOT \
'($4==\"parent\" && $5==rr){print $3\" \"$13}'\n"
+#endif
static bool system_has_vt(virConnectPtr conn)
{
@@ -567,6 +569,8 @@ static CMPIStatus set_net_props(int type,
const char *net_type,
const char *net_name,
uint64_t num_nics,
+ uint64_t reservation,
+ uint64_t limit,
const char *device,
const char *src_dev,
const char *net_mode,
@@ -594,6 +598,21 @@ static CMPIStatus set_net_props(int type,
CMSetProperty(inst, "VirtualQuantity",
(CMPIValue *)&num_nics, CMPI_uint64);
+#if LIBVIR_VERSION_NUMBER >= 9000
+ /* Network QoS support for later libvirt versions */
+ if (reservation)
+ CMSetProperty(inst, "Reservation",
+ (CMPIValue *)&reservation, CMPI_uint64);
+
+ if (limit)
+ CMSetProperty(inst, "Limit",
+ (CMPIValue *)&reservation, CMPI_uint64);
+
+ if (reservation || limit)
+ CMSetProperty(inst, "AllocationUnits",
+ (CMPIValue *)"KiloBytes per Second", CMPI_chars);
+#endif
+
if (device != NULL)
CMSetProperty(inst, "VirtualDevice",
(CMPIValue *)device, CMPI_chars);
@@ -647,6 +666,8 @@ static CMPIStatus net_template(const CMPIObjectPath *ref,
{
bool ret;
uint64_t num_nics;
+ uint64_t reservation = 0;
+ uint64_t limit = 0;
const char *id;
CMPIStatus s = {CMPI_RC_OK, NULL};
int i,j;
@@ -658,16 +679,21 @@ static CMPIStatus net_template(const CMPIObjectPath *ref,
switch (template_type) {
case SDC_RASD_MIN:
num_nics = 0;
+ reservation = 1;
+ limit = 1;
id = "Minimum";
break;
case SDC_RASD_MAX:
ret = get_max_nics(ref, &num_nics, &s);
if (!ret)
goto out;
+ /* No apparant maximum reservation or limit QoS setting in libvirt! */
id = "Maximum";
break;
case SDC_RASD_INC:
num_nics = 1;
+ reservation = 1;
+ limit = 1;
id = "Increment";
break;
case SDC_RASD_DEF:
@@ -689,7 +715,9 @@ static CMPIStatus net_template(const CMPIObjectPath *ref,
id,
type[i],
name[i],
- num_nics,
+ num_nics,
+ reservation,
+ limit,
device[j],
NULL,
NULL,
@@ -707,22 +735,26 @@ static CMPIStatus net_template(const CMPIObjectPath *ref,
}
s = set_net_props(template_type, ref, id, "direct", NULL,
- num_nics, NULL, "eth1", "vepa", NULL,
+ num_nics, reservation, limit,
+ NULL, "eth1", "vepa", NULL,
NULL, NULL, NULL, NULL, NULL, NULL, list);
/* profile id*/
s = set_net_props(template_type, ref, id, "direct", NULL,
- num_nics, NULL, "eth1", "vepa", NULL,
+ num_nics, reservation, limit,
+ NULL, "eth1", "vepa", NULL,
"802.1Qbh", NULL, NULL, NULL,
NULL, "my_profile", list);
/* no profile id but with instance id*/
s = set_net_props(template_type, ref, id, "direct", NULL,
- num_nics, NULL, "eth1", "vepa", NULL,
+ num_nics, reservation, limit,
+ NULL, "eth1", "vepa", NULL,
"802.1Qbg", "managerid", "typeid",
"typeidversion", "instanceid", NULL,
list);
/* no profile id and no instance id*/
s = set_net_props(template_type, ref, id, "direct", NULL,
- num_nics, NULL, "eth1", "vepa", NULL,
+ num_nics, reservation, limit,
+ NULL, "eth1", "vepa", NULL,
"802.1Qbg", "managerid", "typeid",
"typeidversion", "NULL", "NULL", list);
@@ -814,6 +846,7 @@ static CMPIStatus set_net_pool_props(const CMPIObjectPath *ref,
return s;
}
+#if LIBVIR_VERSION_NUMBER < 9000
static char * get_bridge_name(virConnectPtr conn, const char *name)
{
char *bridge = NULL;
@@ -913,7 +946,7 @@ static CMPIStatus qos_hack(
return s;
}
-
+#endif
static CMPIStatus net_pool_template(const CMPIObjectPath *ref,
int template_type,
@@ -2086,8 +2119,10 @@ static CMPIStatus sdc_rasds_for_type(const CMPIObjectPath *ref,
}
}
+#if LIBVIR_VERSION_NUMBER < 9000
if (type == CIM_RES_TYPE_NET)
s = qos_hack(ref, list);
+#endif
out:
return s;
diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c
index 0141515..4e16b81 100644
--- a/src/Virt_VirtualSystemManagementService.c
+++ b/src/Virt_VirtualSystemManagementService.c
@@ -68,6 +68,7 @@
#define RASD_IND_DELETED "ResourceAllocationSettingDataDeletedIndication"
#define RASD_IND_MODIFIED "ResourceAllocationSettingDataModifiedIndication"
+#if LIBVIR_VERSION_NUMBER < 9000
/* Network QoS support */
#define QOSCMD_BANDWIDTH2ID "_ROOT=$(tc class show dev %s | awk '($4==\"root\")\
{print $3}')\n tc class show dev %s | awk -v rr=$_ROOT -v bw=%uKbit \
@@ -96,6 +97,7 @@ $U32 match u16 0x0800 0xFFFF at -2 match u16 0x$ME2 0xFFFF at -4 match u32 \
ffff: prio 50 u32\"; $U32 match u16 0x0800 0xFFFF at -2 match u32 0x$MI2 \
0xFFFFFFFF at -12 match u16 0x$MI1 0xFFFF at -14 police rate %uKbit burst 15k \
drop\n"
+#endif
const static CMPIBroker *_BROKER;
@@ -105,6 +107,7 @@ enum ResourceAction {
RESOURCE_MOD,
};
+#if LIBVIR_VERSION_NUMBER < 9000
/* Network QoS support */
static CMPIStatus add_qos_for_mac(const uint64_t qos,
const char *mac,
@@ -202,6 +205,7 @@ static CMPIStatus remove_qos_for_mac(const uint64_t qos,
free(cmd);
return s;
}
+#endif
static CMPIStatus check_uuid_in_use(const CMPIObjectPath *ref,
struct domain *domain)
@@ -973,6 +977,15 @@ static const char *net_rasd_to_vdev(CMPIInstance *inst,
dev->dev.net.model = NULL;
else
dev->dev.net.model = strdup(val);
+
+ if (cu_get_u64_prop(inst, "Reservation",
+ &dev->dev.net.reservation) != CMPI_RC_OK)
+ dev->dev.net.reservation = 0;
+
+ if (cu_get_u64_prop(inst, "Limit",
+ &dev->dev.net.limit) != CMPI_RC_OK)
+ dev->dev.net.limit = 0;
+
out:
free(network);
return msg;
@@ -1645,8 +1658,10 @@ static const char *classify_resources(CMPIArray *resources,
} else if (type == CIM_RES_TYPE_NET) {
struct virt_device dev;
int ncount = count + domain->dev_net_ct;
+#if LIBVIR_VERSION_NUMBER < 9000
uint64_t qos_val = 0;
const char *qos_unitstr;
+#endif
memset(&dev, 0, sizeof(dev));
msg = rasd_to_vdev(inst,
@@ -1659,6 +1674,7 @@ static const char *classify_resources(CMPIArray *resources,
ncount,
&domain->dev_net_ct);
+#if LIBVIR_VERSION_NUMBER < 9000
/* Network QoS support */
if (((&dev)->dev.net.mac != NULL) &&
((&dev)->dev.net.source != NULL) &&
@@ -1672,6 +1688,7 @@ static const char *classify_resources(CMPIArray *resources,
(&dev)->dev.net.mac,
(&dev)->dev.net.source);
}
+#endif
} else if (type == CIM_RES_TYPE_GRAPHICS) {
struct virt_device dev;
int gcount = count + domain->dev_graphics_ct;
@@ -2763,14 +2780,16 @@ static CMPIStatus resource_mod(struct domain *dominfo,
(type == CIM_RES_TYPE_INPUT))
cu_statusf(_BROKER, &s, CMPI_RC_OK, "");
else {
+#if LIBVIR_VERSION_NUMBER < 9000
uint64_t qos_val = 0;
const char *qos_unitstr;
-
+#endif
s = _resource_dynamic(dominfo,
dev,
RESOURCE_MOD,
CLASSNAME(op));
+#if LIBVIR_VERSION_NUMBER < 9000
/* Network QoS support */
if ((type == CIM_RES_TYPE_NET) &&
(dev->dev.net.mac != NULL) &&
@@ -2785,6 +2804,7 @@ static CMPIStatus resource_mod(struct domain *dominfo,
dev->dev.net.mac,
dev->dev.net.source);
}
+#endif
}
break;
}
--
1.7.1
12 years, 11 months
[PATCH 05/15] vlan extension - CIM model - add class EASD
by Wayne Xia
add the class Net_EthernetPortAllocationSettingData. According To DSP1050,
there are two kinds of EASD, EASD_EA and EASD_EC, which describe Ethernetprot
settings and connection settings.
Signed-off-by: Wayne Xia <xiawenc(a)linux.vnet.ibm.com>
---
schema/EthernetPortAllocationSettingData.mof | 21 +
.../EthernetPortAllocationSettingData.registration | 3 +
src/Virt_EASD.c | 733 ++++++++++++++++++++
src/Virt_EASD.h | 61 ++
4 files changed, 818 insertions(+), 0 deletions(-)
create mode 100644 schema/EthernetPortAllocationSettingData.mof
create mode 100644 schema/EthernetPortAllocationSettingData.registration
create mode 100644 src/Virt_EASD.c
create mode 100644 src/Virt_EASD.h
diff --git a/schema/EthernetPortAllocationSettingData.mof b/schema/EthernetPortAllocationSettingData.mof
new file mode 100644
index 0000000..8a1b38b
--- /dev/null
+++ b/schema/EthernetPortAllocationSettingData.mof
@@ -0,0 +1,21 @@
+// Copyright IBM Corp. 2011
+
+[Description ("Virtutal EthernetPort Setting Data"),
+ Provider("cmpi::Virt_EASD")
+]
+
+class Net_EthernetPortAllocationSettingData : CIM_EthernetPortAllocationSettingData
+{
+ uint16 PortVID;
+ uint16 DesiredEndPointMode;
+
+ [Description("VLAN type of the port, "
+ "Now only support IEEE 802.1.q."),
+ ValueMap { "0", "1", "2", "3" },
+ Values { "Not VLAN", "IEEE 802.1.q", "IEEE 802.1.qbg", "IEEE 802.1.qbh" }]
+ uint16 VLANType;
+
+ uint16 ReorderHdr;
+ string VLANQosIngress;
+ string VLANQosEgress;
+};
diff --git a/schema/EthernetPortAllocationSettingData.registration b/schema/EthernetPortAllocationSettingData.registration
new file mode 100644
index 0000000..bedd029
--- /dev/null
+++ b/schema/EthernetPortAllocationSettingData.registration
@@ -0,0 +1,3 @@
+# Copyright IBM Corp. 2011
+# Classname Namespace ProviderName ProviderModule ProviderTypes
+Net_EthernetPortAllocationSettingData root/virt Virt_EASD Virt_EASD instance
diff --git a/src/Virt_EASD.c b/src/Virt_EASD.c
new file mode 100644
index 0000000..cb786a5
--- /dev/null
+++ b/src/Virt_EASD.c
@@ -0,0 +1,733 @@
+/*
+ * Copyright IBM Corp. 2011
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc(a)cn.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <sys/stat.h>
+
+#include <cmpidt.h>
+#include <cmpift.h>
+#include <cmpimacs.h>
+
+#include <libcmpiutil/libcmpiutil.h>
+#include <libcmpiutil/std_instance.h>
+
+#include "misc_util.h"
+#include "cs_util.h"
+#include "infostore.h"
+
+#include "Virt_EASD.h"
+#include "svpc_types.h"
+#include "Virt_Device.h"
+#include "Virt_VirtualEthernetSwitchSystem.h"
+#include "network_model.h"
+
+static const CMPIBroker *_BROKER;
+
+static int set_primary_for_easd(const CMPIBroker *broker, const char* prefix,
+ EthIface *piface, int type, CMPIInstance *instance)
+{
+ char *eth_name, *easd_name;
+ int asret;
+ uint16_t res_type = CIM_NUM_SWITCHPORT;
+ uint16_t vlan_mode;
+
+ if (piface->name == NULL) {
+ return 0;
+ }
+
+ eth_name = get_ethportsd_name_from_iface(piface->name, type);
+ asret = asprintf(&easd_name, "%s/%s", prefix, eth_name);
+
+ CMSetProperty(instance, "InstanceID",
+ (CMPIValue *)easd_name, CMPI_chars);
+ CMSetProperty(instance, "ElementName",
+ (CMPIValue *)eth_name, CMPI_chars);
+ SAFE_FREE(easd_name);
+ SAFE_FREE(eth_name);
+
+ CMSetProperty(instance, "ResourceType",
+ (CMPIValue *)&res_type, CMPI_uint16);
+
+ if (piface->eth_type == ETH_TYPE_PHYSICAL) {
+ vlan_mode = CIM_NUM_VLAN_MODE_TRUNK;
+ CMSetProperty(instance, "DesiredEndPointMode",
+ (CMPIValue *)&vlan_mode, CMPI_uint16);
+ }
+
+
+ if (piface->mac != NULL) {
+ CMSetProperty(instance, "Address",
+ (CMPIValue *)piface->mac, CMPI_chars);
+ }
+
+ return 1;
+}
+
+static int set_secondary_for_easd(const CMPIBroker *broker, EthIface *piface,
+ CMPIInstance *instance)
+{
+ VLAN_Prop *pvlan;
+ VLAN_Prop_8021q *pvlan8021q;
+ uint16_t vid, hdr;
+ CMPIArray *conn_array;
+ CMPIString *cm_str;
+ char *str = NULL, *egress = NULL, *ingress = NULL;
+ CMPIStatus s;
+ int ret;
+ uint16_t vlantype = 0;
+ uint16_t visibility = CIM_NUM_CONSUMERVISIBILITY_VIRTUALIZED;
+
+ if (piface->eth_type == ETH_TYPE_PHYSICAL) {
+ visibility = CIM_NUM_CONSUMERVISIBILITY_PASSEDTHROUGH;
+ }
+ CMSetProperty(instance, "ConsumerVisibility",
+ (CMPIValue *)&visibility, CMPI_uint16);
+
+ if ((piface->eth_type != ETH_TYPE_VLAN) ||
+ (piface->pvlan_prop == NULL)) {
+ goto out;
+ }
+ pvlan = piface->pvlan_prop;
+
+ if (pvlan->vlan_type == VLAN_TYPE_802_1_Q) {
+ pvlan8021q = &(pvlan->props.prop_8021q);
+ vid = pvlan8021q->vlan_id;
+ CMSetProperty(instance, "PortVID",
+ (CMPIValue *)&vid, CMPI_uint16);
+
+ str = vlanid_to_connection_name(vid);
+ conn_array = CMNewArray(broker, 1, CMPI_string, &s);
+ if ((s.rc != CMPI_RC_OK) || (str == NULL)) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Error creating Connection "
+ "list and its string");
+ CU_DEBUG("CMNewArray or string creation failed");
+ goto out;
+ }
+ cm_str = CMNewString(broker, str, &s);
+ if (s.rc != CMPI_RC_OK) {
+ CU_DEBUG("Error creating CMPIString");
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Error creating CMPIString for "
+ "BootDevices item");
+
+ goto out;
+ }
+ CMSetArrayElementAt(conn_array, 0, (CMPIValue *)&cm_str,
+ CMPI_string);
+ CMSetProperty(instance, "Connection",
+ (CMPIValue *)&conn_array, CMPI_stringA);
+ hdr = pvlan8021q->reorder_hdr;
+ CMSetProperty(instance, "ReorderHdr",
+ (CMPIValue *)&hdr, CMPI_uint16);
+
+ if ((pvlan8021q->ingress.count > 0) &&
+ (pvlan8021q->ingress.count <= 8)) {
+ ret = vlan_8021q_qos_num_to_str(&ingress,
+ &(pvlan8021q->ingress));
+ if (ret == 1) {
+ CMSetProperty(instance, "VLANQosIngress",
+ (CMPIValue *)ingress, CMPI_chars);
+ } else {
+ CU_DEBUG("failed to generate vlan qos "
+ "string.");
+ }
+ }
+ if ((pvlan8021q->egress.count > 0) &&
+ (pvlan8021q->egress.count <= 8)) {
+ ret = vlan_8021q_qos_num_to_str(&egress,
+ &(pvlan8021q->egress));
+ if (ret == 1) {
+ CMSetProperty(instance, "VLANQosEgress",
+ (CMPIValue *)egress, CMPI_chars);
+ } else {
+ CU_DEBUG("failed to generate vlan qos "
+ "string.");
+ }
+ }
+ vlantype = 1;
+ }
+ CMSetProperty(instance, "VLANType",
+ (CMPIValue *)&vlantype, CMPI_uint16);
+
+out:
+ SAFE_FREE(str);
+ SAFE_FREE(egress);
+ SAFE_FREE(ingress);
+ return 1;
+}
+
+static CMPIStatus add_conn_properties(const CMPIBroker *broker,
+ EthIface *piface,
+ const char *prefix,
+ const char *dest,
+ CMPIInstance *instance)
+{
+ CMPIStatus s = {CMPI_RC_ERR_FAILED, NULL};
+ char *eth_name, *easd_name;
+ int asret;
+ CMPIArray *array;
+ CMPIString *tmp;
+
+ if (piface->name == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "device name not set");
+ goto out;
+ }
+ if (dest == NULL) {
+ CU_DEBUG("warn: connection dest is NULL.");
+ }
+
+ eth_name = get_ethportsd_name_from_iface(piface->name, EASD_TYPE_EA);
+ asret = asprintf(&easd_name, "%s:%s", prefix, eth_name);
+ CMSetProperty(instance, "Parent",
+ (CMPIValue *)easd_name, CMPI_chars);
+ SAFE_FREE(easd_name);
+ SAFE_FREE(eth_name);
+
+ array = CMNewArray(broker, 1, CMPI_string, &s);
+ tmp = CMNewString(broker, dest, NULL);
+ CMSetArrayElementAt(array, 0, &(tmp), CMPI_string);
+ CMSetProperty(instance, "HostResource",
+ (CMPIValue *)&array, CMPI_stringA);
+
+
+ out:
+ return s;
+}
+
+static CMPIStatus set_properties(const CMPIBroker *broker,
+ EthIface *piface,
+ const char *prefix,
+ const char *dest,
+ int type,
+ CMPIInstance *instance)
+{
+ CMPIStatus s = {CMPI_RC_ERR_FAILED, NULL};
+ char *errstr;
+
+ if (!set_primary_for_easd(broker, prefix, piface, type, instance)) {
+ errstr = "failed to set primary properties for instance.";
+ CU_DEBUG("%s, iface name %s.", errstr, piface->name);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ errstr);
+ goto out;
+ }
+
+ if (type == EASD_TYPE_EA) {
+ if (!set_secondary_for_easd(broker, piface, instance)) {
+ errstr = "failed to set secondary properties"
+ " for instance.";
+ CU_DEBUG("%s, iface name %s.", errstr, piface->name);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ errstr);
+ goto out;
+ }
+ } else {
+ s = add_conn_properties(broker,
+ piface,
+ prefix,
+ dest,
+ instance);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+ }
+
+ cu_statusf(broker, &s,
+ CMPI_RC_OK,
+ "");
+
+ out:
+ return s;
+}
+
+static CMPIStatus instance_from_easd_build(const CMPIBroker *broker,
+ EthIface *piface,
+ const char *prefix,
+ const char *dest,
+ int type,
+ const CMPIObjectPath *reference,
+ const char **properties,
+ CMPIInstance **_inst)
+{
+ CMPIInstance *inst = NULL;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ const char *keys[] = {"InstanceID", NULL};
+
+ inst = get_typed_instance(broker,
+ NETWORK_CLASS_PREFIX,
+ "EthernetPortAllocationSettingData",
+ NAMESPACE(reference));
+ if (inst == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to init SwitchSystem instance");
+ goto out;
+ }
+
+
+ s = CMSetPropertyFilter(inst, properties, keys);
+ if (s.rc != CMPI_RC_OK) {
+ CU_DEBUG("Unable to set property filter: %d", s.rc);
+ }
+
+ s = set_properties(broker,
+ piface,
+ prefix,
+ dest,
+ type,
+ inst);
+
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+
+ *_inst = inst;
+
+ out:
+ return s;
+}
+
+/* vsname and req_type are filter conditions */
+static CMPIStatus instance_from_easd(const CMPIBroker *broker,
+ EthIface *piface,
+ const char *vsname,
+ int req_type,
+ const CMPIObjectPath *reference,
+ const char **properties,
+ struct inst_list *plist)
+{
+
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst = NULL;
+ char *br1_name = NULL, *br2_name = NULL;
+
+ CU_DEBUG("enter instance_for_easd with vsname %s, type %d.",
+ vsname, req_type);
+ get_possible_bridge_name_for_cim_model(piface, &br1_name, &br2_name);
+ if (br1_name == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "failed to find any bridge for the port.");
+ CU_DEBUG("failed to find any bridge for the port %s.",
+ piface->name);
+ goto out;
+ }
+
+ /* building the EA instance */
+ if (!(req_type&EASD_TYPE_EA)) {
+ goto ea_build_end;
+ }
+ if ((vsname == NULL) || (0 == strcmp(vsname, br1_name))) {
+ inst = NULL;
+ s = instance_from_easd_build(broker,
+ piface,
+ br1_name,
+ NULL,
+ EASD_TYPE_EA,
+ reference,
+ properties,
+ &inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+ inst_list_add(plist, inst);
+ }
+
+ /* following is to make it comform to CIM profile which require two
+ ethports connectted to pNIC and vswitch, but we have only one piface
+ on linux indicating it is connected to pNIC and bridge at sametime */
+ if (br2_name == NULL) {
+ goto out;
+ }
+
+ if ((vsname == NULL) || (0 == strcmp(vsname, br2_name))) {
+ inst = NULL;
+ s = instance_from_easd_build(broker,
+ piface,
+ br2_name,
+ NULL,
+ EASD_TYPE_EA,
+ reference,
+ properties,
+ &inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+ inst_list_add(plist, inst);
+ }
+ ea_build_end:
+
+ /* building the EC instance */
+ if (!(req_type&EASD_TYPE_EC)) {
+ goto ec_build_end;
+ }
+ if ((br1_name == NULL) || (br2_name == NULL)) {
+ goto ec_build_end;
+ }
+ /* connection exist, so a EC_easd should be added for each bridge */
+ if ((vsname == NULL) || (0 == strcmp(vsname, br1_name))) {
+ inst = NULL;
+ s = instance_from_easd_build(broker,
+ piface,
+ br1_name,
+ br2_name,
+ EASD_TYPE_EC,
+ reference,
+ properties,
+ &inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+ inst_list_add(plist, inst);
+ }
+ if ((vsname == NULL) || (0 == strcmp(vsname, br2_name))) {
+ inst = NULL;
+ s = instance_from_easd_build(broker,
+ piface,
+ br2_name,
+ br1_name,
+ EASD_TYPE_EC,
+ reference,
+ properties,
+ &inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+ inst_list_add(plist, inst);
+ }
+ ec_build_end:
+
+ out:
+ SAFE_FREE(br1_name);
+ SAFE_FREE(br2_name);
+ return s;
+}
+
+CMPIStatus get_easd_by_name(const CMPIBroker *broker,
+ const char *prefix,
+ const char *name,
+ const CMPIObjectPath *reference,
+ const char **properties,
+ CMPIInstance **_inst)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst = NULL;
+ char *eth_name = NULL;
+ char *dest = NULL;
+ char *errstr;
+ int ret;
+ int type;
+ EthIfacesList ifaces_list;
+ struct inst_list list;
+
+ CU_DEBUG("####prefix %s", prefix);
+ eth_ifaceslist_init(&ifaces_list);
+ inst_list_init(&list);
+
+ eth_name = get_iface_name_from_ethportsd(name, &type);
+ if (eth_name == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "failed to convert instance name");
+ CU_DEBUG("ethport name %s failed to convert.", name);
+ goto out;
+ }
+
+ ret = get_host_ifaces(&ifaces_list,
+ eth_iface_filter_cim_ethport_for_name, eth_name);
+
+ if (ret != 1) {
+ errstr = get_host_iface_error_reason(ret);
+ CU_DEBUG("error num %d returned, reason %s.", ret, errstr);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ errstr);
+ goto out;
+ }
+ if (ifaces_list.count != 1) {
+ errstr = "expected ethport not found.";
+ CU_DEBUG("%d ethportd found.", ifaces_list.count);
+ eth_ifaceslist_print(&ifaces_list);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ errstr);
+ goto out;
+ }
+
+ inst = NULL;
+ s = instance_from_easd(broker,
+ ifaces_list.pifaces[0],
+ prefix,
+ type,
+ reference,
+ properties,
+ &list);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+
+ if (list.cur == 0) {
+ CU_DEBUG("%d instance found, expect is 1.", list.cur);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "no such instance.");
+ goto out;
+ }
+
+ if (list.cur > 1) {
+ CU_DEBUG("%d instance found, expect is 1.", list.cur);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "instance found do not match expectation");
+ goto out;
+ }
+
+ *_inst = list.list[0];
+ list.list[0] = NULL;
+
+ out:
+ eth_ifaceslist_uninit(&ifaces_list);
+ inst_list_free(&list);
+ SAFE_FREE(eth_name);
+ SAFE_FREE(dest);
+ return s;
+}
+
+CMPIStatus get_easd_by_id(const CMPIBroker *broker,
+ const char *id,
+ const CMPIObjectPath *reference,
+ const char **properties,
+ CMPIInstance **_inst)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ char *prefix = NULL;
+ char *suffix = NULL;
+ if (id == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_INVALID_PARAMETER,
+ "ID is NULL'", id);
+ }
+ if (!parse_fq_devid(id, &prefix, &suffix) || (prefix == NULL) ||
+ (suffix == NULL)) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_INVALID_PARAMETER,
+ "Invalid InstanceID `%s'", id);
+ goto out;
+ }
+ s = get_easd_by_name(broker, prefix, suffix, reference,
+ properties, _inst);
+
+ out:
+ SAFE_FREE(prefix);
+ SAFE_FREE(suffix);
+ return s;
+}
+
+CMPIStatus get_easd_by_ref(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const char **properties,
+ CMPIInstance **_inst)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst = NULL;
+ char *name = NULL;
+ char *prefix = NULL;
+ const char *id;
+
+ if (cu_get_str_path(reference, "InstanceID", &id) != CMPI_RC_OK) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance (InstanceID)");
+ goto out;
+ }
+ if ((!parse_fq_devid(id, &prefix, &name)) ||
+ (name == NULL) || (prefix == NULL)) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "Failed to translate (InstanceID)");
+ goto out;
+ }
+
+ s = get_easd_by_name(broker, prefix, name, reference,
+ properties, &inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+
+ s = cu_validate_ref(broker, reference, inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+
+ *_inst = inst;
+
+ out:
+ free(name);
+ free(prefix);
+
+ return s;
+}
+
+
+CMPIStatus enum_easds(const CMPIBroker *broker,
+ const char *ref_vsname,
+ const CMPIObjectPath *reference,
+ const char **properties,
+ struct inst_list *plist)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ EthIfacesList ifaces_list;
+ int ret, i;
+ char *errstr;
+
+ eth_ifaceslist_init(&ifaces_list);
+
+ ret = get_host_ifaces(&ifaces_list,
+ eth_iface_filter_cim_ethport, NULL);
+ if (ret != 1) {
+ errstr = get_host_iface_error_reason(ret);
+ CU_DEBUG("error num %d returned, reason %s.", ret, errstr);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ errstr);
+ goto out;
+ }
+ CU_DEBUG("enum easd, found following devices.")
+ eth_ifaceslist_print(&ifaces_list);
+
+ i = 0;
+ while (i < ifaces_list.count) {
+ s = instance_from_easd(broker,
+ ifaces_list.pifaces[i],
+ ref_vsname,
+ EASD_TYPE_EA|EASD_TYPE_EC,
+ reference,
+ properties,
+ plist);
+ i++;
+ /* this should never fail */
+ if (s.rc != CMPI_RC_OK) {
+ CU_DEBUG("unexpected fail.");
+ break;
+ }
+ }
+
+
+ out:
+ eth_ifaceslist_uninit(&ifaces_list);
+
+ return s;
+}
+
+static CMPIStatus return_enum_easds(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const CMPIResult *results,
+ const char **properties,
+ const bool names_only)
+{
+ struct inst_list list;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ inst_list_init(&list);
+ s = enum_easds(broker, NULL, reference, properties, &list);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+
+ if (names_only) {
+ cu_return_instance_names(results, &list);
+ } else {
+ cu_return_instances(results, &list);
+ }
+
+ out:
+ inst_list_free(&list);
+ return s;
+}
+
+static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self,
+ const CMPIContext *context,
+ const CMPIResult *results,
+ const CMPIObjectPath *reference)
+{
+ return return_enum_easds(_BROKER, reference, results,
+ NULL, true);
+}
+
+static CMPIStatus EnumInstances(CMPIInstanceMI *self,
+ const CMPIContext *context,
+ const CMPIResult *results,
+ const CMPIObjectPath *reference,
+ const char **properties)
+{
+
+ return return_enum_easds(_BROKER, reference, results,
+ properties, false);
+}
+
+static CMPIStatus GetInstance(CMPIInstanceMI *self,
+ const CMPIContext *context,
+ const CMPIResult *results,
+ const CMPIObjectPath *ref,
+ const char **properties)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst = NULL;
+
+ s = get_easd_by_ref(_BROKER, ref, properties, &inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+
+ CMReturnInstance(results, inst);
+
+ out:
+ return s;
+}
+
+DEFAULT_CI();
+DEFAULT_MI();
+DEFAULT_DI();
+DEFAULT_INST_CLEANUP();
+DEFAULT_EQ();
+
+STD_InstanceMIStub(,
+ Virt_EASD,
+ _BROKER,
+ libvirt_cim_init());
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-set-style: "K&R"
+ * tab-width: 8
+ * c-basic-offset: 8
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/src/Virt_EASD.h b/src/Virt_EASD.h
new file mode 100644
index 0000000..215553b
--- /dev/null
+++ b/src/Virt_EASD.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright IBM Corp. 2011
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc(a)cn.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __VIRT_EASD_H
+#define __VIRT_EASD_H
+
+#include "device_parsing.h"
+
+CMPIStatus enum_easds(const CMPIBroker *broker,
+ const char *ref_vsname,
+ const CMPIObjectPath *reference,
+ const char **properties,
+ struct inst_list *plist);
+
+CMPIStatus get_easd_by_name(const CMPIBroker *broker,
+ const char *prefix,
+ const char *name,
+ const CMPIObjectPath *reference,
+ const char **properties,
+ CMPIInstance **_inst);
+
+CMPIStatus get_easd_by_id(const CMPIBroker *broker,
+ const char *id,
+ const CMPIObjectPath *reference,
+ const char **properties,
+ CMPIInstance **_inst);
+
+CMPIStatus get_easd_by_ref(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const char **properties,
+ CMPIInstance **_inst);
+
+
+#endif
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-set-style: "K&R"
+ * tab-width: 8
+ * c-basic-offset: 8
+ * indent-tabs-mode: nil
+ * End:
+ */
--
1.7.6
12 years, 11 months
[PATCH 01/15] vlan extension-makefile change
by Wayne Xia
this patch modifies the makefiles to add new files to be compiled
Signed-off-by: Wayne Xia <xiawenc(a)linux.vnet.ibm.com>
---
Makefile.am | 16 ++++++++++++++--
libxkutil/Makefile.am | 11 +++++++++--
src/Makefile.am | 49 +++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 64 insertions(+), 12 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 5f004ec..32b84df 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -63,7 +63,13 @@ MOFS = \
schema/EntriesInFilterList.mof \
schema/NestedFilterList.mof \
schema/AppliedFilterList.mof \
- schema/HostedFilterList.mof
+ schema/HostedFilterList.mof \
+ schema/VirtualEthernetSwitchSystem.mof \
+ schema/VirtualEthernetSwitchSystemManagementService.mof \
+ schema/VirtualEthernetSwitchSystemSettingData.mof \
+ schema/EthernetPort.mof \
+ schema/EthernetPortAllocationSettingData.mof \
+ schema/VESSSDComponent.mof
INTEROP_MOFS = \
schema/ComputerSystem.mof \
@@ -150,7 +156,13 @@ REGS = \
schema/EntriesInFilterList.registration \
schema/NestedFilterList.registration \
schema/AppliedFilterList.registration \
- schema/HostedFilterList.registration
+ schema/HostedFilterList.registration \
+ schema/VirtualEthernetSwitchSystem.registration \
+ schema/VirtualEthernetSwitchSystemManagementService.registration \
+ schema/VirtualEthernetSwitchSystemSettingData.registration \
+ schema/EthernetPort.registration \
+ schema/EthernetPortAllocationSettingData.registration \
+ schema/VESSSDComponent.registration
INTEROP_REGS = \
schema/RegisteredProfile.registration \
diff --git a/libxkutil/Makefile.am b/libxkutil/Makefile.am
index f6abce5..c5ac53c 100644
--- a/libxkutil/Makefile.am
+++ b/libxkutil/Makefile.am
@@ -5,12 +5,19 @@ AM_CFLAGS = $(CFLAGS_STRICT) \
-DLIBVIRTCIM_CONF=\"@sysconfdir@/@PACKAGE@.conf\"
noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h infostore.h \
- pool_parsing.h acl_parsing.h
+ pool_parsing.h acl_parsing.h \
+ network_model.h \
+ host_network_API.h host_network_basic.h host_network_helper.h \
+ host_network_implement_cmdline.h host_network_error.h
lib_LTLIBRARIES = libxkutil.la
libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \
- xmlgen.c infostore.c pool_parsing.c acl_parsing.c
+ xmlgen.c infostore.c pool_parsing.c acl_parsing.c \
+ network_model.c \
+ host_network_API.c host_network_basic.c host_network_helper.c \
+ host_network_implement_cmdline.c
+
libxkutil_la_LDFLAGS = -version-info @VERSION_INFO@
libxkutil_la_LIBADD = @LIBVIRT_LIBS@ \
@LIBUUID_LIBS@
diff --git a/src/Makefile.am b/src/Makefile.am
index e4e8aa1..b067666 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,7 +25,12 @@ noinst_HEADERS = profiles.h svpc_types.h \
Virt_ConsoleRedirectionServiceCapabilities.h \
Virt_KVMRedirectionSAP.h \
Virt_FilterList.h \
- Virt_FilterEntry.h
+ Virt_FilterEntry.h \
+ Virt_VirtualEthernetSwitchSystem.h \
+ Virt_VirtualEthernetSwitchSystemManagementService.h \
+ Virt_VESSSD.h \
+ Virt_EthernetPort.h \
+ Virt_EASD.h
XKUADD = $(top_builddir)/libxkutil/libxkutil.la
@@ -86,7 +91,13 @@ provider_LTLIBRARIES = libVirt_ComputerSystem.la \
libVirt_EntriesInFilterList.la \
libVirt_NestedFilterList.la \
libVirt_HostedFilterList.la \
- libVirt_AppliedFilterList.la
+ libVirt_AppliedFilterList.la \
+ libVirt_VirtualEthernetSwitchSystem.la \
+ libVirt_VirtualEthernetSwitchSystemManagementService.la \
+ libVirt_VESSSD.la \
+ libVirt_EthernetPort.la \
+ libVirt_EASD.la \
+ libVirt_VESSSDComponent.la
libVirt_ComputerSystem_la_SOURCES = Virt_ComputerSystem.c
libVirt_ComputerSystem_la_DEPENDENCIES = libVirt_VirtualSystemSnapshotService.la
@@ -117,9 +128,9 @@ libVirt_VirtualSystemManagementCapabilities_la_DEPENDENCIES = libVirt_HostSystem
libVirt_VirtualSystemManagementCapabilities_la_SOURCES = Virt_VirtualSystemManagementCapabilities.c
libVirt_VirtualSystemManagementCapabilities_la_LIBADD = -lVirt_HostSystem
-libVirt_SystemDevice_la_DEPENDENCIES = libVirt_ComputerSystem.la libVirt_Device.la
+libVirt_SystemDevice_la_DEPENDENCIES = libVirt_ComputerSystem.la libVirt_Device.la libVirt_VirtualEthernetSwitchSystem.la libVirt_EthernetPort.la
libVirt_SystemDevice_la_SOURCES = Virt_SystemDevice.c
-libVirt_SystemDevice_la_LIBADD = -lVirt_ComputerSystem -lVirt_Device
+libVirt_SystemDevice_la_LIBADD = -lVirt_ComputerSystem -lVirt_Device -lVirt_VirtualEthernetSwitchSystem -lVirt_EthernetPort
libVirt_VSSD_la_SOURCES = Virt_VSSD.c
libVirt_HostSystem_la_SOURCES = Virt_HostSystem.c
@@ -188,9 +199,9 @@ libVirt_VSSDComponent_la_DEPENDENCIES = libVirt_VSSD.la libVirt_RASD.la
libVirt_VSSDComponent_la_SOURCES = Virt_VSSDComponent.c
libVirt_VSSDComponent_la_LIBADD = -lVirt_VSSD -lVirt_RASD
-libVirt_SettingsDefineState_la_DEPENDENCIES = libVirt_Device.la libVirt_RASD.la libVirt_VSSD.la libVirt_ComputerSystem.la
+libVirt_SettingsDefineState_la_DEPENDENCIES = libVirt_Device.la libVirt_RASD.la libVirt_VSSD.la libVirt_ComputerSystem.la libVirt_VirtualEthernetSwitchSystem.la libVirt_VESSSD.la libVirt_EASD.la libVirt_EthernetPort.la
libVirt_SettingsDefineState_la_SOURCES = Virt_SettingsDefineState.c
-libVirt_SettingsDefineState_la_LIBADD = -lVirt_Device -lVirt_RASD -lVirt_VSSD -lVirt_ComputerSystem
+libVirt_SettingsDefineState_la_LIBADD = -lVirt_Device -lVirt_RASD -lVirt_VSSD -lVirt_ComputerSystem -lVirt_VirtualEthernetSwitchSystem -lVirt_VESSSD -lVirt_EASD -lVirt_EthernetPort
libVirt_ResourceAllocationFromPool_la_DEPENDENCIES = libVirt_DevicePool.la libVirt_RASD.la
libVirt_ResourceAllocationFromPool_la_SOURCES = Virt_ResourceAllocationFromPool.c
@@ -204,9 +215,9 @@ libVirt_HostedService_la_DEPENDENCIES = libVirt_VirtualSystemManagementService.l
libVirt_HostedService_la_SOURCES = Virt_HostedService.c
libVirt_HostedService_la_LIBADD = -lVirt_VirtualSystemManagementService -lVirt_ResourcePoolConfigurationService -lVirt_VSMigrationService -lVirt_HostSystem -lVirt_ConsoleRedirectionService
-libVirt_ElementSettingData_la_DEPENDENCIES = libVirt_VSSD.la libVirt_RASD.la
+libVirt_ElementSettingData_la_DEPENDENCIES = libVirt_VSSD.la libVirt_RASD.la libVirt_EASD.la libVirt_VESSSD.la libVirt_EthernetPort.la
libVirt_ElementSettingData_la_SOURCES = Virt_ElementSettingData.c
-libVirt_ElementSettingData_la_LIBADD = -lVirt_VSSD -lVirt_RASD
+libVirt_ElementSettingData_la_LIBADD = -lVirt_VSSD -lVirt_RASD -lVirt_EASD -lVirt_VESSSD -lVirt_EthernetPort
libVirt_VSMigrationCapabilities_la_SOURCES = Virt_VSMigrationCapabilities.c
@@ -275,3 +286,25 @@ libVirt_HostedFilterList_la_LIBADD = -lVirt_HostSystem -lVirt_FilterList
libVirt_AppliedFilterList_la_DEPENDENCIES = libVirt_Device.la libVirt_FilterList.la
libVirt_AppliedFilterList_la_SOURCES = Virt_AppliedFilterList.c
libVirt_AppliedFilterList_la_LIBADD = -lVirt_Device -lVirt_FilterList
+
+libVirt_VirtualEthernetSwitchSystem_la_SOURCES = Virt_VirtualEthernetSwitchSystem.c
+
+libVirt_VESSSD_la_DEPENDENCIES = libVirt_VirtualEthernetSwitchSystem.la
+libVirt_VESSSD_la_SOURCES = Virt_VESSSD.c
+libVirt_VESSSD_la_LIBADD = -lVirt_VirtualEthernetSwitchSystem
+
+libVirt_EthernetPort_la_DEPENDENCIES = libVirt_EASD.la
+libVirt_EthernetPort_la_SOURCES = Virt_EthernetPort.c
+libVirt_EthernetPort_la_LIBADD = -lVirt_EASD
+
+libVirt_EASD_la_DEPENDENCIES = libVirt_VirtualEthernetSwitchSystem.la
+libVirt_EASD_la_SOURCES = Virt_EASD.c
+libVirt_EASD_la_LIBADD = -lVirt_VirtualEthernetSwitchSystem
+
+libVirt_VirtualEthernetSwitchSystemManagementService_la_DEPENDENCIES = libVirt_VirtualEthernetSwitchSystem.la libVirt_VESSSD.la libVirt_EASD.la libVirt_HostSystem.la libVirt_VirtualSystemManagementService.la
+libVirt_VirtualEthernetSwitchSystemManagementService_la_SOURCES = Virt_VirtualEthernetSwitchSystemManagementService.c
+libVirt_VirtualEthernetSwitchSystemManagementService_la_LIBADD = -lVirt_VirtualEthernetSwitchSystem -lVirt_VESSSD -lVirt_EASD -lVirt_HostSystem -lVirt_VirtualSystemManagementService
+
+libVirt_VESSSDComponent_la_DEPENDENCIES = libVirt_VESSSD.la libVirt_EASD.la
+libVirt_VESSSDComponent_la_SOURCES = Virt_VESSSDComponent.c
+libVirt_VESSSDComponent_la_LIBADD = -lVirt_VESSSD -lVirt_EASD
--
1.7.6
12 years, 11 months
[PATCH 00/15] vlan extension
by Wayne Xia
These patches would do following things: building up the network system CIM
model, building up basic framework and functions below to implement the
configuration, add the bridge and vlan802.1.q configuration capabilities in
CIM model and library below.
Now this patch implement the functionalities with commandline style, which
means it depends on command ip, ifconfig, brctl and /proc/net/vlan/. In this
way it is very sensitive to these command's output format. Maybe another
implemetion could avoid that in the future.
Since libvirt-cim is not a daemon program that would always be brought up
when the emulator was up, so there lacks a mechnism to save the configuration
and set them when system reboot, so these patch uses system directory
/etc/sysconfig/network-script/
to store the settings.
The things above means that a linux kernel later than 2.6 and RedHat
distribution is needed. Other distriution may work but not tested. If
the implemention goes to libvirt the restrict would be removed.
Related profiles: the most important are DSP1050, DSP1097, DSP 2025(draft),
Other are: DSP1041, DSP1014.
Typical usage: assuming you have pNIC eth0. Use following xml files passed
to wbemexec could create bridge testbr with eth0.10 attached, which means all
VMs connecting to testbr would have access to IEEE802.1.q vlan 10.
XML 1
<?xml version="1.0" encoding="utf-8" ?>
<CIM CIMVERSION="2.0" DTDVERSION="2.0">
<MESSAGE ID="4711" PROTOCOLVERSION="1.0">
<SIMPLEREQ>
<METHODCALL NAME="DefineSystem">
<LOCALINSTANCEPATH>
<LOCALNAMESPACEPATH>
<NAMESPACE NAME="root"></NAMESPACE><NAMESPACE NAME="virt"></NAMESPACE>
</LOCALNAMESPACEPATH>
<INSTANCENAME CLASSNAME="Net_VirtualEthernetSwitchSystemManagementService">
<KEYBINDING NAME="CreationClassName"><KEYVALUE VALUETYPE="string">Net_VirtualEthernetSwitchSystemManagementService</KEYVALUE></KEYBINDING>
<KEYBINDING NAME="Name"><KEYVALUE VALUETYPE="string">Management Service</KEYVALUE></KEYBINDING>
<KEYBINDING NAME="SystemCreationClassName"><KEYVALUE VALUETYPE="string">KVM_HostSystem</KEYVALUE></KEYBINDING>
<KEYBINDING NAME="SystemName"><KEYVALUE VALUETYPE="string">unknown</KEYVALUE></KEYBINDING>
</INSTANCENAME>
</LOCALINSTANCEPATH>
<PARAMVALUE NAME="SystemSettings" PARAMTYPE="string">
<VALUE>
instance of Net_VirtualEthernetSwitchSystemSettingData {
VirtualSystemIdentifier ="VS_testbr1";
STP = 1;
};
</VALUE>
</PARAMVALUE>
</METHODCALL>
</SIMPLEREQ>
</MESSAGE>
</CIM>
XML 2
<?xml version="1.0" encoding="utf-8" ?>
<CIM CIMVERSION="2.0" DTDVERSION="2.0">
<MESSAGE ID="4711" PROTOCOLVERSION="1.0">
<SIMPLEREQ>
<METHODCALL NAME="AddResourceSettings">
<LOCALINSTANCEPATH>
<LOCALNAMESPACEPATH>
<NAMESPACE NAME="root"></NAMESPACE><NAMESPACE NAME="virt"></NAMESPACE>
</LOCALNAMESPACEPATH>
<INSTANCENAME CLASSNAME="Net_VirtualEthernetSwitchSystemManagementService">
<KEYBINDING NAME="CreationClassName"><KEYVALUE VALUETYPE="string">Net_VirtualEthernetSwitchSystemManagementService</KEYVALUE></KEYBINDING>
<KEYBINDING NAME="Name"><KEYVALUE VALUETYPE="string">Management Service</KEYVALUE></KEYBINDING>
<KEYBINDING NAME="SystemCreationClassName"><KEYVALUE VALUETYPE="string">KVM_HostSystem</KEYVALUE></KEYBINDING>
<KEYBINDING NAME="SystemName"><KEYVALUE VALUETYPE="string">unknown</KEYVALUE></KEYBINDING>
</INSTANCENAME>
</LOCALINSTANCEPATH>
<PARAMVALUE NAME="AffectedConfiguration">
<VALUE.REFERENCE>
<INSTANCENAME CLASSNAME="Net_VirtualEthernetSwitchSettingData">
<KEYBINDING NAME="InstanceID"><KEYVALUE VALUETYPE="string">Virt:VS_eth0</KEYVALUE></KEYBINDING>
</INSTANCENAME>
</VALUE.REFERENCE>
</PARAMVALUE>
<PARAMVALUE NAME="ResourceSettings" PARAMTYPE="string">
<VALUE.ARRAY>
<VALUE>
instance of Net_EthernetPortAllocationSettingData {
InstanceID = "VS_eth0/EA_eth0.10";
ElementName = "EA_eth0.10";
VLANType = 1;
Connection = {"VLAN10"};
ReorderHdr = 0;
};
</VALUE>
<VALUE>
instance of Net_EthernetPortAllocationSettingData {
InstanceID = "VS_eth0/EC_eth0.10";
HostResource = {"VS_testbr1"};
Parent = "EA_eth0.10";
};
</VALUE>
</VALUE.ARRAY>
</PARAMVALUE>
</METHODCALL>
</SIMPLEREQ>
</MESSAGE>
</CIM>
Wayne Xia (15):
vlan extension - makefile change
vlan extension - CIM model - add class VESS
vlan extension - CIM model - add class VESSSD
vlan extension - CIM model - add class EthernetPort
vlan extension - CIM model - add class
EthernetPortAllocationSettingData
vlan extension - CIM model - add association Net_SettingsDeineState
vlan extension - CIM model - add association Net_SystemDevice
vlan extension - CIM model - add association Net_VESSSDComponent
vlan extension - CIM model - add association Net_ElementSettingData
vlan extension - CIM model - add core class VESSMS
vlan extension - CIM model - add help functions
vlan extension - function lib - add the API
vlan extension - function lib - add the core structure
vlan extension - function lib - add the helper functions
vlan extension - function lib - add the implemention of commandline
Makefile.am | 16 +-
libxkutil/Makefile.am | 11 +-
libxkutil/host_network_API.c | 150 ++
libxkutil/host_network_API.h | 32 +
libxkutil/host_network_basic.c | 639 +++++++
libxkutil/host_network_basic.h | 166 ++
libxkutil/host_network_error.h | 28 +
libxkutil/host_network_helper.c | 659 +++++++
libxkutil/host_network_helper.h | 192 ++
libxkutil/host_network_implement_cmdline.c | 2002 ++++++++++++++++++++
libxkutil/host_network_implement_cmdline.h | 55 +
libxkutil/network_model.c | 466 +++++
libxkutil/network_model.h | 105 +
schema/ElementSettingData.mof | 16 +-
schema/ElementSettingData.registration | 4 +-
schema/EthernetPort.mof | 4 +
schema/EthernetPort.registration | 3 +
schema/EthernetPortAllocationSettingData.mof | 21 +
.../EthernetPortAllocationSettingData.registration | 3 +
schema/SettingsDefineState.mof | 9 +-
schema/SettingsDefineState.registration | 3 +-
schema/SystemDevice.mof | 18 +-
schema/SystemDevice.registration | 3 +-
schema/VESSSDComponent.mof | 8 +
schema/VESSSDComponent.registration | 3 +
schema/VirtualEthernetSwitchSystem.mof | 10 +
schema/VirtualEthernetSwitchSystem.registration | 3 +
...irtualEthernetSwitchSystemManagementService.mof | 14 +
...ernetSwitchSystemManagementService.registration | 3 +
schema/VirtualEthernetSwitchSystemSettingData.mof | 27 +
...ualEthernetSwitchSystemSettingData.registration | 3 +
src/Makefile.am | 49 +-
src/Virt_EASD.c | 733 +++++++
src/Virt_EASD.h | 61 +
src/Virt_ElementSettingData.c | 229 +++-
src/Virt_EthernetPort.c | 565 ++++++
src/Virt_EthernetPort.h | 58 +
src/Virt_HostSystem.c | 2 +-
src/Virt_HostSystem.h | 2 +
src/Virt_SettingsDefineState.c | 256 +++
src/Virt_SystemDevice.c | 126 ++
src/Virt_VESSSD.c | 372 ++++
src/Virt_VESSSD.h | 39 +
src/Virt_VESSSDComponent.c | 181 ++
src/Virt_VirtualEthernetSwitchSystem.c | 483 +++++
src/Virt_VirtualEthernetSwitchSystem.h | 52 +
..._VirtualEthernetSwitchSystemManagementService.c | 1342 +++++++++++++
..._VirtualEthernetSwitchSystemManagementService.h | 31 +
src/Virt_VirtualSystemManagementService.c | 17 +-
src/Virt_VirtualSystemManagementService.h | 10 +
50 files changed, 9255 insertions(+), 29 deletions(-)
create mode 100644 libxkutil/host_network_API.c
create mode 100644 libxkutil/host_network_API.h
create mode 100644 libxkutil/host_network_basic.c
create mode 100644 libxkutil/host_network_basic.h
create mode 100644 libxkutil/host_network_error.h
create mode 100644 libxkutil/host_network_helper.c
create mode 100644 libxkutil/host_network_helper.h
create mode 100644 libxkutil/host_network_implement_cmdline.c
create mode 100644 libxkutil/host_network_implement_cmdline.h
create mode 100644 libxkutil/network_model.c
create mode 100644 libxkutil/network_model.h
create mode 100644 schema/EthernetPort.mof
create mode 100644 schema/EthernetPort.registration
create mode 100644 schema/EthernetPortAllocationSettingData.mof
create mode 100644 schema/EthernetPortAllocationSettingData.registration
create mode 100644 schema/VESSSDComponent.mof
create mode 100644 schema/VESSSDComponent.registration
create mode 100644 schema/VirtualEthernetSwitchSystem.mof
create mode 100644 schema/VirtualEthernetSwitchSystem.registration
create mode 100644 schema/VirtualEthernetSwitchSystemManagementService.mof
create mode 100644 schema/VirtualEthernetSwitchSystemManagementService.registration
create mode 100644 schema/VirtualEthernetSwitchSystemSettingData.mof
create mode 100644 schema/VirtualEthernetSwitchSystemSettingData.registration
create mode 100644 src/Virt_EASD.c
create mode 100644 src/Virt_EASD.h
create mode 100644 src/Virt_EthernetPort.c
create mode 100644 src/Virt_EthernetPort.h
create mode 100644 src/Virt_VESSSD.c
create mode 100644 src/Virt_VESSSD.h
create mode 100644 src/Virt_VESSSDComponent.c
create mode 100644 src/Virt_VirtualEthernetSwitchSystem.c
create mode 100644 src/Virt_VirtualEthernetSwitchSystem.h
create mode 100644 src/Virt_VirtualEthernetSwitchSystemManagementService.c
create mode 100644 src/Virt_VirtualEthernetSwitchSystemManagementService.h
--
1.7.6
12 years, 11 months
[PATCH 02/15] vlan extension - CIM model - add class VESS
by Wayne Xia
this patch added the Net_VirtualEthernetSwitchSystem class.
Signed-off-by: Wayne Xia <xiawenc(a)linux.vnet.ibm.com>
---
schema/VirtualEthernetSwitchSystem.mof | 10 +
schema/VirtualEthernetSwitchSystem.registration | 3 +
src/Virt_VirtualEthernetSwitchSystem.c | 483 +++++++++++++++++++++++
src/Virt_VirtualEthernetSwitchSystem.h | 52 +++
4 files changed, 548 insertions(+), 0 deletions(-)
create mode 100644 schema/VirtualEthernetSwitchSystem.mof
create mode 100644 schema/VirtualEthernetSwitchSystem.registration
create mode 100644 src/Virt_VirtualEthernetSwitchSystem.c
create mode 100644 src/Virt_VirtualEthernetSwitchSystem.h
diff --git a/schema/VirtualEthernetSwitchSystem.mof b/schema/VirtualEthernetSwitchSystem.mof
new file mode 100644
index 0000000..5c016fd
--- /dev/null
+++ b/schema/VirtualEthernetSwitchSystem.mof
@@ -0,0 +1,10 @@
+// Copyright IBM Corp. 2011
+[Description (
+ "A class derived from CIM_ComputerSystem to represent "
+ "the Virtual Bridge on the host."),
+ Provider("cmpi::Virt_VirtualEthernetSwitchSystem")
+]
+class Net_VirtualEthernetSwitchSystem : CIM_ComputerSystem
+{
+
+};
diff --git a/schema/VirtualEthernetSwitchSystem.registration b/schema/VirtualEthernetSwitchSystem.registration
new file mode 100644
index 0000000..4cd6bf4
--- /dev/null
+++ b/schema/VirtualEthernetSwitchSystem.registration
@@ -0,0 +1,3 @@
+# Copyright IBM Corp. 2007
+# Classname Namespace ProviderName ProviderModule ProviderTypes
+Net_VirtualEthernetSwitchSystem root/virt Virt_VirtualEthernetSwitchSystem Virt_VirtualEthernetSwitchSystem instance method
diff --git a/src/Virt_VirtualEthernetSwitchSystem.c b/src/Virt_VirtualEthernetSwitchSystem.c
new file mode 100644
index 0000000..1998205
--- /dev/null
+++ b/src/Virt_VirtualEthernetSwitchSystem.c
@@ -0,0 +1,483 @@
+/*
+ * Copyright IBM Corp. 2011
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc(a)cn.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+
+#include <cmpidt.h>
+#include <cmpift.h>
+#include <cmpimacs.h>
+
+#include <libvirt/libvirt.h>
+
+#include "cs_util.h"
+#include <libcmpiutil/libcmpiutil.h>
+#include "misc_util.h"
+#include "infostore.h"
+#include "device_parsing.h"
+
+#include <libcmpiutil/std_invokemethod.h>
+#include <libcmpiutil/std_instance.h>
+#include <libcmpiutil/std_indication.h>
+
+#include "Virt_VirtualEthernetSwitchSystem.h"
+#include "Virt_HostSystem.h"
+#include "Virt_VirtualSystemSnapshotService.h"
+#include "network_model.h"
+
+static const CMPIBroker *_BROKER;
+
+static int set_primary_for_switch(const CMPIBroker *broker, EthIface *piface,
+ CMPIInstance *instance)
+{
+ char *name;
+ uint16_t dedicated;
+ CMPIArray *array;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+
+ if (piface->name == NULL) {
+ return 0;
+ }
+
+ name = get_switch_name_from_iface(piface->name);
+ CMSetProperty(instance, "Name",
+ (CMPIValue *)name, CMPI_chars);
+ CMSetProperty(instance, "ElementName",
+ (CMPIValue *)name, CMPI_chars);
+ SAFE_FREE(name);
+
+ array = CMNewArray(broker, 1, CMPI_uint16, &s);
+ if ((s.rc != CMPI_RC_OK) || (CMIsNullObject(array))) {
+ return 0;
+ }
+ dedicated = CIM_NUM_SWITCH_DEDICATED;
+ CMSetArrayElementAt(array, 0, &dedicated, CMPI_uint16);
+ CMSetProperty(instance, "Dedicated",
+ (CMPIValue *)&array, CMPI_uint16A);
+
+ return 1;
+}
+
+static int set_secondary_for_switch(const CMPIBroker *broker, EthIface *piface,
+ CMPIInstance *instance)
+{
+ int state;
+ if (piface->run_prop.state == ETH_STATE_DOWN) {
+ state = CIM_STATE_DISABLED;
+ } else if (piface->run_prop.state == ETH_STATE_UP) {
+ state = CIM_STATE_ENABLED;
+ } else {
+ state = CIM_STATE_UNKNOWN;
+ }
+ CMSetProperty(instance, "EnabledState",
+ (CMPIValue *)&state, CMPI_uint16);
+ CMSetProperty(instance, "RequestedState",
+ (CMPIValue *)&state, CMPI_uint16);
+
+ return 1;
+}
+
+/* Populate an instance with information from a switch */
+static CMPIStatus set_properties(const CMPIBroker *broker,
+ EthIface *piface,
+ const char *prefix,
+ CMPIInstance *instance)
+{
+ CMPIStatus s = {CMPI_RC_ERR_FAILED, NULL};
+ char *errstr;
+
+ if (!set_primary_for_switch(broker, piface, instance)) {
+ errstr = "failed to set primary properties for instance.";
+ CU_DEBUG("%s, iface name %s.", errstr, piface->name);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ errstr);
+ goto out;
+ }
+ if (!set_secondary_for_switch(broker, piface, instance)) {
+ errstr = "failed to set secondary properties for instance.";
+ CU_DEBUG("%s, iface name %s.", errstr, piface->name);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ errstr);
+ goto out;
+ }
+
+ cu_statusf(broker, &s,
+ CMPI_RC_OK,
+ "");
+
+ out:
+ return s;
+}
+
+static CMPIStatus instance_from_switch(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ EthIface *piface,
+ CMPIInstance **_inst)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst = NULL;
+
+ inst = get_typed_instance(broker,
+ NETWORK_CLASS_PREFIX,
+ "VirtualEthernetSwitchSystem",
+ NAMESPACE(reference));
+ if (inst == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to init VirtualEthernetSwitchSystem instance");
+ goto out;
+ }
+
+ s = set_properties(broker,
+ piface,
+ NETWORK_CLASS_PREFIX,
+ inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+ *_inst = inst;
+
+ out:
+ return s;
+}
+
+CMPIStatus enum_switches(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const CMPIResult *results,
+ bool names_only)
+{
+ struct inst_list list;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ EthIfacesList ifaces_list;
+ int ret, i;
+ char *errstr;
+
+ inst_list_init(&list);
+ eth_ifaceslist_init(&ifaces_list);
+
+ ret = get_host_ifaces(&ifaces_list,
+ eth_iface_filter_cim_switch, NULL);
+ if (ret != 1) {
+ errstr = get_host_iface_error_reason(ret);
+ CU_DEBUG("error num %d returned, reason %s.", ret, errstr);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ errstr);
+ goto out;
+ }
+
+ i = 0;
+ while (i < ifaces_list.count) {
+ CMPIInstance *inst = NULL;
+
+ s = instance_from_switch(broker,
+ reference,
+ ifaces_list.pifaces[i],
+ &inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+ inst_list_add(&list, inst);
+ i++;
+ }
+
+ if (names_only) {
+ cu_return_instance_names(results, &list);
+ } else {
+ cu_return_instances(results, &list);
+ }
+
+ out:
+ inst_list_free(&list);
+ eth_ifaceslist_uninit(&ifaces_list);
+
+ return s;
+}
+
+CMPIStatus get_switch_by_name(const CMPIBroker *broker,
+ const char *name,
+ const CMPIObjectPath *reference,
+ CMPIInstance **_inst)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst = NULL;
+ char *eth_name = NULL;
+ char *errstr;
+ int ret;
+ EthIfacesList ifaces_list;
+
+ eth_ifaceslist_init(&ifaces_list);
+
+ eth_name = get_iface_name_from_switch(name);
+ if (eth_name == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "failed to convert switch_name");
+ CU_DEBUG("switch name %s failed to convert.", name);
+ goto out;
+ }
+
+ ret = get_host_ifaces(&ifaces_list,
+ eth_iface_filter_cim_switch_for_name, eth_name);
+ if (ret != 1) {
+ errstr = get_host_iface_error_reason(ret);
+ CU_DEBUG("error num %d returned, reason %s.", ret, errstr);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ errstr);
+ goto out;
+ }
+ if (ifaces_list.count != 1) {
+ errstr = "expected switch not found.";
+ CU_DEBUG("%s\n", errstr);
+ eth_ifaceslist_print(&ifaces_list);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ errstr);
+ goto out;
+ }
+
+ s = instance_from_switch(broker,
+ reference,
+ ifaces_list.pifaces[0],
+ &inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+
+ *_inst = inst;
+
+ out:
+ eth_ifaceslist_uninit(&ifaces_list);
+ SAFE_FREE(eth_name);
+ return s;
+}
+
+CMPIStatus get_switch_by_ref(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ CMPIInstance **_inst)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst = NULL;
+ const char *name = NULL;
+
+ if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "No domain name specified");
+ goto out;
+ }
+
+ s = get_switch_by_name(broker, name, reference, &inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+
+ s = cu_validate_ref(broker, reference, inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+
+ *_inst = inst;
+
+ out:
+
+ return s;
+}
+
+static CMPIStatus __state_change(const CMPIBroker *broker,
+ const char *name,
+ uint16_t state,
+ const CMPIObjectPath *ref)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ EthIface iface;
+ int iface_state;
+ int ret;
+ char *errstr;
+
+ eth_iface_init(&iface);
+ iface.name = get_iface_name_from_switch(name);
+ if (iface.name == NULL) {
+ errstr = "failed to get iface name.";
+ CU_DEBUG("for %s, %s.", name, errstr);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ errstr);
+ goto out;
+ }
+ if (state == CIM_STATE_ENABLED) {
+ iface_state = ETH_STATE_UP;
+ } else if (state == CIM_STATE_DISABLED) {
+ iface_state = ETH_STATE_DOWN;
+ } else {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_NOT_SUPPORTED,
+ "State not supported");
+ goto out;
+ }
+
+ ret = change_state_host_iface(&iface, iface_state);
+ if (ret != 1) {
+ errstr = get_host_iface_error_reason(ret);
+ CU_DEBUG("error num %d returned, reason %s.", ret, errstr);
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ errstr);
+ goto out;
+ }
+
+
+ out:
+ eth_iface_uninit(&iface);
+ return s;
+}
+
+static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self,
+ const CMPIContext *context,
+ const CMPIResult *results,
+ const CMPIObjectPath *reference)
+{
+ return enum_switches(_BROKER, reference, results, true);
+}
+
+static CMPIStatus EnumInstances(CMPIInstanceMI *self,
+ const CMPIContext *context,
+ const CMPIResult *results,
+ const CMPIObjectPath *reference,
+ const char **properties)
+{
+ return enum_switches(_BROKER, reference, results, false);
+}
+
+static CMPIStatus GetInstance(CMPIInstanceMI *self,
+ const CMPIContext *context,
+ const CMPIResult *results,
+ const CMPIObjectPath *reference,
+ const char **properties)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst = NULL;
+
+ s = get_switch_by_ref(_BROKER, reference, &inst);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+
+ CMReturnInstance(results, inst);
+
+ out:
+ return s;
+}
+
+DEFAULT_CI();
+DEFAULT_MI();
+DEFAULT_DI();
+DEFAULT_EQ();
+DEFAULT_INST_CLEANUP();
+
+static CMPIStatus state_change(CMPIMethodMI *self,
+ const CMPIContext *context,
+ const CMPIResult *results,
+ const CMPIObjectPath *reference,
+ const CMPIArgs *argsin,
+ CMPIArgs *argsout)
+{
+ CMPIStatus s;
+ CMPIInstance *prev_inst = NULL;
+ uint16_t state;
+ int ret;
+ const char *name = NULL;
+ uint32_t rc = 1;
+
+ ret = cu_get_u16_arg(argsin, "RequestedState", &state);
+ if (ret != CMPI_RC_OK) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_INVALID_PARAMETER,
+ "Invalid RequestedState");
+ goto out;
+ }
+
+ if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Name key not specified");
+ goto out;
+ }
+
+ s = get_switch_by_name(_BROKER, name, reference, &prev_inst);
+ if (s.rc != CMPI_RC_OK || prev_inst == NULL) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_INVALID_PARAMETER,
+ "Unable to get instance for guest '%s'",
+ name);
+ goto out;
+ }
+
+ s = __state_change(_BROKER, name, state, reference);
+
+ if (s.rc == CMPI_RC_OK) {
+ rc = 0;
+ }
+ out:
+ CMReturnData(results, &rc, CMPI_uint32);
+
+ return s;
+}
+
+STD_InstanceMIStub(,
+ Virt_VirtualEthernetSwitchSystem,
+ _BROKER,
+ libvirt_cim_init());
+
+static struct method_handler RequestStateChange = {
+ .name = "RequestStateChange",
+ .handler = state_change,
+ .args = {{"RequestedState", CMPI_uint16, false},
+ {"TimeoutPeriod", CMPI_dateTime, true},
+ ARG_END
+ }
+};
+
+static struct method_handler *my_handlers[] = {
+ &RequestStateChange,
+ NULL
+};
+
+STDIM_MethodMIStub(,
+ Virt_VirtualEthernetSwitchSystem,
+ _BROKER,
+ libvirt_cim_init(),
+ my_handlers);
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-set-style: "K&R"
+ * tab-width: 8
+ * c-basic-offset: 8
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/src/Virt_VirtualEthernetSwitchSystem.h b/src/Virt_VirtualEthernetSwitchSystem.h
new file mode 100644
index 0000000..de8587b
--- /dev/null
+++ b/src/Virt_VirtualEthernetSwitchSystem.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright IBM Corp. 2011
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc(a)cn.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __VIRT_VIRTUALETHERNETSWITCHSYSTEM_H
+#define __VIRT_VIRTUALETHERNETSWITCHSYSTEM_H
+
+#include "misc_util.h"
+
+CMPIStatus enum_switches(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const CMPIResult *results,
+ bool names_only);
+
+CMPIStatus get_switch_by_ref(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ CMPIInstance **_inst);
+
+
+CMPIStatus get_switch_by_name(const CMPIBroker *broker,
+ const char *name,
+ const CMPIObjectPath *reference,
+ CMPIInstance **_inst);
+
+
+#endif
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-set-style: "K&R"
+ * tab-width: 8
+ * c-basic-offset: 8
+ * indent-tabs-mode: nil
+ * End:
+ */
--
1.7.6
12 years, 11 months
[PATCH 0/4] cimtest - VLAN extension
by Wayne Xia
These patches would add basic testcases about modifying host networks.
Additional usecases such as association was not included. With this user
could understand the usecase easier and also reduce the testing burden
when libvirt-cim code was modified. It works with libvirt-cim V2 patch, and
it should also work with later changes, if the test cases were confirmed to
be correct scenior according to DSP profiles.
Wayne Xia (4):
cimtest - VLAN extension - add basic functions
cimtest - VLAN extension - bridge testing
cimtest - VLAN extension - 802.1.q port testing
cimtest - VLAN extension - connecting of bridge and port
.../cimtest/HostNetwork/01_VESSMS_Bridge.py | 78 ++++
.../cimtest/HostNetwork/02_VESSMS_EASD_EA.py | 84 ++++
.../cimtest/HostNetwork/03_VESSMS_EASD_EC.py | 101 +++++
suites/libvirt-cim/lib/XenKvmLib/host_network.py | 410 ++++++++++++++++++++
4 files changed, 673 insertions(+), 0 deletions(-)
create mode 100644 suites/libvirt-cim/cimtest/HostNetwork/01_VESSMS_Bridge.py
create mode 100644 suites/libvirt-cim/cimtest/HostNetwork/02_VESSMS_EASD_EA.py
create mode 100644 suites/libvirt-cim/cimtest/HostNetwork/03_VESSMS_EASD_EC.py
create mode 100644 suites/libvirt-cim/lib/XenKvmLib/host_network.py
--
1.7.6
12 years, 11 months
[PATCH] [TEST] Use python-lxml instead of PyXML
by Eduardo Lima (Etrunko)
From: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
PyXML is a legacy python XML library which won't work with recent versions of
python unless you patch the code. The following link describes the problem:
http://stackoverflow.com/questions/4953600/pyxml-on-ubuntu
In summary, when trying to install PyXML with easy_install, you get an error
because it tries to use 'as' which is a reserved keyword introduced in python
2.5.
This patch removes dependency of PyXML in favor of python-lxml, which provides
bindings to the very complete and fast libxml2:
http://lxml.de/intro.html
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
---
suites/libvirt-cim/cimtest/FilterList/helper.py | 8 +--
.../12_referenced_config.py | 14 +---
.../24_define_sys_features.py | 6 +-
suites/libvirt-cim/lib/XenKvmLib/test_xml.py | 27 +++---
suites/libvirt-cim/lib/XenKvmLib/vxml.py | 95 ++++++++++----------
5 files changed, 69 insertions(+), 81 deletions(-)
diff --git a/suites/libvirt-cim/cimtest/FilterList/helper.py b/suites/libvirt-cim/cimtest/FilterList/helper.py
index 138f941..9ae2f62 100644
--- a/suites/libvirt-cim/cimtest/FilterList/helper.py
+++ b/suites/libvirt-cim/cimtest/FilterList/helper.py
@@ -35,11 +35,7 @@ from XenKvmLib.vxml import get_class
import VirtLib
from VirtLib.utils import run_remote
-try:
- from xml.etree import cElementTree as ElementTree
-except:
- from xml.etree import ElementTree
-
+from lxml import etree
class BaseTestObject(object):
@@ -247,7 +243,7 @@ class FilterListTest(BaseTestObject):
# Remove all unecessary spaces and new lines
_xml = "".join([a.strip() for a in out.split("\n") if a])
- return ElementTree.fromstring(_xml)
+ return etree.fromstring(_xml)
# libvirt_filter_dumpxml
def libvirt_entries_in_filter_lists(self):
diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/12_referenced_config.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/12_referenced_config.py
index 7af65fd..24b47e9 100644
--- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/12_referenced_config.py
+++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/12_referenced_config.py
@@ -102,20 +102,8 @@ def setup_second_guest(ip, virt, cxml2, ref):
return PASS, "define"
def get_dom_disk_src(xml, ip):
- disk_list = []
-
xml.dumpxml(ip)
- myxml = xml.get_formatted_xml()
-
- lines = myxml.splitlines()
- for l in lines:
- if l.find("source file=") != -1:
- disk = l.split('=')[1]
- disk = disk.lstrip('\'')
- disk = disk.rstrip('\'/>')
- disk_list.append(disk)
-
- return disk_list
+ return xml.xdoc.xpath("/domain/devices/disk/source/@file")
@do_main(sup_types)
def main():
diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/24_define_sys_features.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/24_define_sys_features.py
index 9716cd1..42c59ec 100644
--- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/24_define_sys_features.py
+++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/24_define_sys_features.py
@@ -48,13 +48,13 @@ def main():
cxml.dumpxml(options.ip)
- if cxml.xml_get_pae() == None:
+ if cxml.xml_get_pae() is None:
raise Exception("Failed to set pae for dom: %s" % default_dom)
- if cxml.xml_get_acpi() == None:
+ if cxml.xml_get_acpi() is None:
raise Exception("Failed to set acpi for dom: %s" % default_dom)
- if cxml.xml_get_apic() == None:
+ if cxml.xml_get_apic() is None:
raise Exception("Failed to set apic for dom: %s" % default_dom)
status = PASS
diff --git a/suites/libvirt-cim/lib/XenKvmLib/test_xml.py b/suites/libvirt-cim/lib/XenKvmLib/test_xml.py
index 033275b..b32ae4c 100755
--- a/suites/libvirt-cim/lib/XenKvmLib/test_xml.py
+++ b/suites/libvirt-cim/lib/XenKvmLib/test_xml.py
@@ -29,8 +29,7 @@ import os
import sys
import random
from VirtLib import utils
-from xml import xpath
-from xml.dom import minidom, Node
+from lxml import etree
from CimTest.Globals import logger
from XenKvmLib.test_doms import set_uuid, create_vnet
from VirtLib.live import available_bridges
@@ -212,22 +211,26 @@ def dumpxml(name, server, virt="Xen"):
return o
def get_value_xpath(xmlStr, xpathStr):
- xmldoc = minidom.parseString(xmlStr)
- nodes = xpath.Evaluate(xpathStr, xmldoc.documentElement)
+ xmldoc = etree.fromstring(xmlStr)
+ nodes = xmldoc.xpath(xpathStr)
if len(nodes) != 1:
raise LookupError('Zero or multiple xpath results found!')
node = nodes[0]
- if node.nodeType == Node.ATTRIBUTE_NODE:
- return node.value
- if node.nodeType == Node.TEXT_NODE:
- return node.toxml()
- if node.nodeType == Node.ELEMENT_NODE:
+ ret = ''
+
+ if etree.iselement(node):
+ ret = node.text
+ for child in node:
+ ret = ret + child.text
+ elif isinstance(node, str):
+ ret = node
+
+ if ret is None:
ret = ''
- for child in node.childNodes:
- ret = ret + child.toxml()
- return ret
+
+ return ret
def xml_get_dom_name(xmlStr):
return get_value_xpath(xmlStr,
diff --git a/suites/libvirt-cim/lib/XenKvmLib/vxml.py b/suites/libvirt-cim/lib/XenKvmLib/vxml.py
index 15859c1..51a4166 100644
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py
@@ -34,15 +34,10 @@ import sys
import random
import platform
import tempfile
-from time import sleep
import pywbem
-from xml.dom import minidom, Node
-from xml import xpath
-try:
- from xml.etree import cElementTree as ElementTree
-except:
- from xml.etree import ElementTree
+from lxml import etree
+from time import sleep
from VirtLib import utils, live
from XenKvmLib.xm_virt_util import get_bridge_from_network_xml, bootloader, \
@@ -64,35 +59,37 @@ class XMLClass:
xdoc = None
def __init__(self):
- self.xdoc = minidom.Document()
self.refresh()
def __str__(self):
return self.xml_string
def refresh(self):
- self.xml_string = self.xdoc.toxml()
+ if self.xdoc is not None:
+ self.xml_string = etree.tostring(self.xdoc)
def get_node(self, ixpath):
- node_list = xpath.Evaluate(ixpath, self.xdoc.documentElement)
+ if self.xdoc is None:
+ return None
+
+ node_list = self.xdoc.xpath(ixpath)
if len(node_list) != 1:
raise LookupError('Zero or multiple nodes found for XPath' + ixpath)
return node_list[0]
+
def add_sub_node(self, parent, node_name, text_cdata=None, **attrs):
if isinstance(parent, basestring):
pnode = self.get_node(parent)
else:
pnode = parent
- node = self.xdoc.createElement(node_name)
-
- for key in attrs.keys():
- node.setAttribute(key, str(attrs[key]))
-
- if text_cdata is not None:
- node.appendChild(self.xdoc.createTextNode(str(text_cdata)))
+ if pnode is None:
+ self.xdoc = etree.Element(node_name, **attrs)
+ node = self.xdoc
+ else:
+ node = etree.SubElement(pnode, node_name, **attrs)
- pnode.appendChild(node)
+ node.text = str(text_cdata)
self.refresh()
return node
@@ -103,13 +100,7 @@ class XMLClass:
else:
pnode = parent
- for cnode in pnode.childNodes:
- pnode.removeChild(cnode)
- cnode.unlink()
-
- if text_cdata is not None:
- pnode.appendChild(self.xdoc.createTextNode(str(text_cdata)))
-
+ pnode.text = str(text_cdata)
self.refresh()
def set_attributes(self, node, **attrs):
@@ -118,8 +109,8 @@ class XMLClass:
else:
pnode = node
- for key in attrs.keys():
- pnode.setAttribute(key, str(attrs[key]))
+ for key, val in attrs.items():
+ pnode.set(key, val)
self.refresh()
@@ -127,7 +118,7 @@ class XMLClass:
'''Don't use this to define domain.
Extra newline in the text node fails libvirt
'''
- return self.xdoc.toprettyxml()
+ return etree.tostring(self.xdoc, pretty_print=True)
def get_value_xpath(self, xpathStr):
try:
@@ -136,15 +127,19 @@ class XMLClass:
logger.info('Zero or multiple node found')
return None
- if node.nodeType == Node.ATTRIBUTE_NODE:
- return node.value
- if node.nodeType == Node.TEXT_NODE:
- return node.toxml()
- if node.nodeType == Node.ELEMENT_NODE:
+ ret = ''
+
+ if etree.iselement(node):
+ ret = node.text
+ for child in node:
+ ret = ret + child.text
+ elif isinstance(node, basestring):
+ ret = node
+
+ if ret is None:
ret = ''
- for child in node.childNodes:
- ret = ret + child.toxml()
- return ret
+
+ return ret
class Virsh:
@@ -220,7 +215,7 @@ class NetXML(Virsh, XMLClass):
def _parse_net_dumpxml(_xml):
try:
- root = ElementTree.fromstring(_xml)
+ root = etree.fromstring(_xml)
ip_element = root.find("ip")
return ip_element.get("address")
except:
@@ -247,7 +242,7 @@ class NetXML(Virsh, XMLClass):
return None
else:
self.xml_string = net_xml
- self.xdoc = minidom.parseString(self.xml_string)
+ self.xdoc = etree.fromstring(self.xml_string)
return
network = self.add_sub_node(self.xdoc, 'network')
@@ -337,7 +332,7 @@ class PoolXML(Virsh, XMLClass):
return None
else:
self.xml_string = disk_xml
- self.xdoc = minidom.parseString(self.xml_string)
+ self.xdoc = etree.fromstring(self.xml_string)
return
pool = self.add_sub_node(self.xdoc, 'pool', type='dir')
@@ -547,8 +542,9 @@ class VirtXML(Virsh, XMLClass):
cmd = 'virsh -c %s dumpxml %s 2>/dev/null' % (self.vuri, self.dname)
s, o = utils.run_remote(ip, cmd)
if s == 0:
- self.xml_string = o
- self.xdoc = minidom.parseString(self.xml_string)
+ o = "".join([i.strip() for i in o.split("\n") if i])
+ self.xdoc = etree.fromstring(o)
+ self.refresh()
def _set_emulator(self, emu):
self.add_sub_node('/domain/devices', 'emulator', emu)
@@ -562,7 +558,7 @@ class VirtXML(Virsh, XMLClass):
# pick the 1st virtual bridge
br = br_list[0]
interface = self.get_node('/domain/devices/interface')
- interface.setAttribute('type', 'bridge')
+ interface.set('type', 'bridge')
self.add_sub_node(interface, 'source', bridge=br)
return br
@@ -570,20 +566,25 @@ class VirtXML(Virsh, XMLClass):
def _set_vbridge(self, ip, virt_type, net_name):
vbr = get_bridge_from_network_xml(net_name, ip, virt=virt_type)
- interface = self.get_node('/domain/devices/interface')
- interface.setAttribute('type', 'bridge')
- self.add_sub_node(interface, 'source', bridge=vbr)
+ if vbr is not None:
+ interface = self.get_node('/domain/devices/interface')
+ interface.set('type', 'bridge')
+ self.add_sub_node(interface, 'source', bridge=vbr)
return vbr
def set_interface_details(self, devices, net_mac, net_type, net_name,
virt_type):
interface = self.add_sub_node(devices, 'interface', type=net_type)
- self.add_sub_node(interface, 'mac', address=net_mac)
+
+ if net_mac:
+ self.add_sub_node(interface, 'mac', address=net_mac)
+
if net_type == 'bridge':
self._set_vbridge(CIM_IP, virt_type, net_name)
elif net_type == 'network':
- self.add_sub_node(interface, 'source', network=net_name)
+ if net_name:
+ self.add_sub_node(interface, 'source', network=net_name)
elif net_type == 'ethernet':
pass
elif net_type == 'user':
--
1.7.4.4
12 years, 11 months
Freeze in preparation for 0.6.0
by Chip Vincent
I just wanted to send out a quick summary of our next release plans.
We recently released 0.5.15 with lots of bugs fixes and plan to release 0.6.0
before the end of the year. For all intents and purposes, I'm considering the
current release frozen for the next week while we test and stabilize. There are
3 exceptions to this freeze: 1) the final domain events patch, 2) a potential
QoS update to use libvirt APIs, and 3) read-only support for host VLANs and bridges.
I've added the tag 'release_0_6_candidate' so you can download and test the
release candidate over the next week. Feedback welcome.
Thanks,
--
Chip Vincent
Open Virtualization
IBM Linux Technology Center
cvincent(a)linux.vnet.ibm.com
12 years, 11 months