[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, 8 months
[PATCH V6 0/7] vlan extention - readonly
by xiaxia347work@163.com
From: Wenchao Xia <xiawenc(a)linux.vnet.ibm.com>
These patches add readonly portion of host network.
v6: code changes according to v5 comments, added CIM model code. Added DHCP
property in CIM model and EthIface structure.
Wenchao Xia (7):
vlan extention - readonly function libarary
vlan extention - CIM model helper
vlan extention - CIM model Makefile change
vlan extention - CIM model add VESS
vlan extention - CIM model add VESSSD
vlan extention - CIM model add EthernetPort
vlan extention - CIM model add EASD
Makefile.am | 14 +-
libxkutil/Makefile.am | 12 +-
libxkutil/misc_util.c | 48 ++
libxkutil/misc_util.h | 3 +
libxkutil/network_model_helper.c | 473 ++++++++++++
libxkutil/network_model_helper.h | 101 +++
libxkutil/network_parsing.c | 762 ++++++++++++++++++++
libxkutil/network_parsing.h | 176 +++++
libxkutil/network_parsing_test.c | 70 ++
libxkutil/xmlgen.c | 4 +-
libxkutil/xmlgen.h | 4 +
schema/EthernetPort.mof | 4 +
schema/EthernetPort.registration | 3 +
schema/EthernetPortAllocationSettingData.mof | 22 +
.../EthernetPortAllocationSettingData.registration | 3 +
schema/VirtualEthernetSwitchSystem.mof | 10 +
schema/VirtualEthernetSwitchSystem.registration | 3 +
schema/VirtualEthernetSwitchSystemSettingData.mof | 31 +
...ualEthernetSwitchSystemSettingData.registration | 3 +
src/Makefile.am | 23 +-
src/Virt_EASD.c | 709 ++++++++++++++++++
src/Virt_EASD.h | 59 ++
src/Virt_EthernetPort.c | 561 ++++++++++++++
src/Virt_EthernetPort.h | 58 ++
src/Virt_VESSSD.c | 382 ++++++++++
src/Virt_VESSSD.h | 39 +
src/Virt_VirtualEthernetSwitchSystem.c | 478 ++++++++++++
src/Virt_VirtualEthernetSwitchSystem.h | 52 ++
28 files changed, 4097 insertions(+), 10 deletions(-)
create mode 100644 libxkutil/network_model_helper.c
create mode 100644 libxkutil/network_model_helper.h
create mode 100644 libxkutil/network_parsing.c
create mode 100644 libxkutil/network_parsing.h
create mode 100644 libxkutil/network_parsing_test.c
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/VirtualEthernetSwitchSystem.mof
create mode 100644 schema/VirtualEthernetSwitchSystem.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_VirtualEthernetSwitchSystem.c
create mode 100644 src/Virt_VirtualEthernetSwitchSystem.h
12 years, 9 months
[PATCH v6 0/3] Implementation of a linked list helper
by Eduardo Lima (Etrunko)
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
This series provides a generic linked list implementation for libxkutil that is
based on the one originally developed for the libvirt domain events support
recently integrated upstream.
As test case I ported the ComputerSystemIndication provider code to use this
list implementation. In the near future it will be also used by the event loop
that I am currently working on to allow systems with libvirt older than 0.9.0
to make use of the same feature.
Other possible use cases would be to port the code of libxkutil/*_parsing* to
also use the list implementation instead of static arrays.
Changes from v5:
- Fix possible NULL dereference in list_first()
Changes from v4:
- Fix possible NULL dereference in list_last_node()
- Fix possible leak in acl_parsing.c
Changes from v3:
- Fix crashes in list_free(), list_first_node() and list_count()
- Include patch that ports the acl filter ref code to use the linked list
implementation
Changes from v2:
- Make list struct private
Changes from v1:
- Fix version iformation in Makefile.am
Eduardo Lima (Etrunko) (3):
libxkutil: Linked list helper
CSI: Use list helper implementation
ACL: Use linked list helper for filter refs
libxkutil/Makefile.am | 51 +++++--
libxkutil/acl_parsing.c | 58 +++------
libxkutil/acl_parsing.h | 5 +-
libxkutil/list_util.c | 254 +++++++++++++++++++++++++++++++++++
libxkutil/list_util.h | 73 ++++++++++
libxkutil/xmlgen.c | 30 +++-
src/Virt_ComputerSystemIndication.c | 95 ++++----------
src/Virt_NestedFilterList.c | 73 ++++++-----
8 files changed, 472 insertions(+), 167 deletions(-)
create mode 100644 libxkutil/list_util.c
create mode 100644 libxkutil/list_util.h
--
1.7.7.6
12 years, 9 months
[PATCH] [TEST] Update FilterList tests and helper
by Eduardo Lima (Etrunko)
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
According to recent changes in FilterList and FilterEntry providers.
03_create.py:
- Creation and deletion of AppliedFilterList instance
- Deletion of NestedFilterList instance
- Deletion of FilterList instance
helper.py:
- Removed warning about Deprecated use of lxml functionality
- New filter rule actions
- Match protocol id
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
---
suites/libvirt-cim/cimtest/FilterList/03_create.py | 35 +++++++++++++---
suites/libvirt-cim/cimtest/FilterList/helper.py | 42 +++++++++++++++++---
2 files changed, 64 insertions(+), 13 deletions(-)
diff --git a/suites/libvirt-cim/cimtest/FilterList/03_create.py b/suites/libvirt-cim/cimtest/FilterList/03_create.py
index e828e92..551a01f 100644
--- a/suites/libvirt-cim/cimtest/FilterList/03_create.py
+++ b/suites/libvirt-cim/cimtest/FilterList/03_create.py
@@ -38,6 +38,9 @@ from VirtLib.utils import run_remote
sup_types = ["KVM",]
domain = None
+flist_name = None
+nested_name = None
+applied_name = None
def get_filter_inst_and_inst_name(name):
try:
@@ -89,6 +92,7 @@ def create_filter_list(name):
# A NestedFilterList instance will add the "clean-traffic" filter
# as an entry of the newly created FilterList
+ global nested_name
logger.info("Creating NestedFilterList instance")
nested_name = test.CreateFilterListInstance(None, "KVM_NestedFilterList",
{"Antecedent":flist_name,
@@ -125,8 +129,11 @@ def get_nwport_inst_and_inst_name(domain_name):
def cleanup():
try:
- # Destroy filter list
- test.wbem.DeleteInstance(flist_name)
+ # Destroy filter list instances
+ for n in [applied_name, nested_name, flist_name]:
+ if n is not None:
+ logger.info("Deleting instance %s", n)
+ test.wbem.DeleteInstance(n)
except Exception, e:
logger.error("Error deleting filter list: %s", e)
@@ -165,15 +172,29 @@ def main():
# An AppliedFilterList Instance will apply the filter to the network
# port of the defined domain
- test.CreateFilterListInstance(None, "KVM_AppliedFilterList",
- {"Antecedent":nwport_name,
- "Dependent":flist_name})
+ global applied_name
+ logger.info ("Creating AppliedFilterList instance")
+ applied_name = test.CreateFilterListInstance(None, "KVM_AppliedFilterList",
+ {"Antecedent":nwport_name,
+ "Dependent":flist_name})
+ logger.info("Got AppliedFilterList name '%s'", applied_name)
+ #applied = test.GetInstance(applied_name)
+ #logger.info("Got AppliedFilterList '%s'", applied)
+
+ # Check results
+ filterref = test.libvirt_applied_filter_lists(domain_name)[0]
+ rule = helper.FilterRule(filterref)
+ if rule.filter != test_flist:
+ raise Exception("AppliedFilterList name '%s' does not match expected '%s'",
+ rule.filter, test_flist)
+
+ test.cim_applied_filter_lists(domain_name)
+ logger.info("AppliedFilterList created succesfully")
+ result = PASS
except Exception, e:
logger.error("Caught exception: %s", e)
result = FAIL
- # Check results
-
# Cleanup
cleanup()
diff --git a/suites/libvirt-cim/cimtest/FilterList/helper.py b/suites/libvirt-cim/cimtest/FilterList/helper.py
index 9ae2f62..5202fa6 100644
--- a/suites/libvirt-cim/cimtest/FilterList/helper.py
+++ b/suites/libvirt-cim/cimtest/FilterList/helper.py
@@ -252,7 +252,7 @@ class FilterListTest(BaseTestObject):
d = {}
for f in filters:
root = self.libvirt_filter_dumpxml(f[0])
- if not root:
+ if root is None:
return None
d[f] = root
@@ -307,6 +307,22 @@ class FilterListTest(BaseTestObject):
return self.Associators(_inst_name, result_class="CIM_FilterEntryBase")
# cim_entries_in_filter_list
+
+ def libvirt_applied_filter_lists(self, dom_name):
+ cmd = "virsh -q -c %s dumpxml %s 2>/dev/null" % (self.uri, dom_name)
+ ret, dom_xml = run_remote(self.server, cmd)
+ if ret:
+ logger.error("Error retrieving domain xml for %s", dom_name)
+ return None
+
+ xdoc = etree.fromstring(dom_xml)
+ filter_list = xdoc.xpath("/domain/devices/interface/filterref")
+ return filter_list
+ # libvirt_applied_filter_lists
+
+ def cim_applied_filter_lists(self, dom_name):
+ pass
+ # cim_applied_filter_lists
# FilterListTest
@@ -319,9 +335,17 @@ class FilterRule(object):
__versions = {"ip" : "4",
"ipv6": "6",}
- __actions = {"accept" : "1",
- "deny" : "2",
- "drop" : "2",}
+ __actions = {"accept" : "1",
+ "deny" : "2",
+ "drop" : "2",
+ "reject" : "3",
+ "return" : "4",
+ "continue" : "5",}
+
+ __protocolids = {"ipv4": "2048",
+ "arp" : "2054",
+ "rarp": "32821",
+ "ipv6": "34525",}
__baserule_map = {"action" : "Action",
"direction" : "Direction",
@@ -394,7 +418,7 @@ class FilterRule(object):
for e in element:
self.__dict = dict(self.__dict, **e.attrib)
- if not self.__type:
+ if self.__type is None:
self.__type = e.tag
try:
@@ -415,6 +439,12 @@ class FilterRule(object):
return self.__actions[self.__dict[key]]
elif key == "type":
return self.__type
+ elif key == "protocolid":
+ value = self.__dict[key]
+ try:
+ return self.__protocolids[value]
+ except KeyError:
+ return value
try:
return self.__dict[key]
@@ -470,7 +500,7 @@ class FilterRule(object):
# convert the property value to string
prop = instance.properties[inst_key]
val = self.__getattr__(key)
- if val.startswith("0x"):
+ if isinstance(val, str) and val.startswith("0x"):
inst_val = hex(int(prop.value))
else:
inst_val = str(prop.value)
--
1.7.7.6
12 years, 9 months
[PATCH 0/4] Update Filter{Entry,List} providers
by Eduardo Lima (Etrunko)
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
These changes are necessary due to recent changes in the libvirt network
filters specification. Cimtests were also updated to match these changes.
http://libvirt.org/formatnwfilter.html
Eduardo Lima (Etrunko) (4):
FilterEntry: Change 'Priority' property type
FilterList: Add 'Priority' property
FilterEntry: Update action property
FilterEntry: Accept protocol id string values
libxkutil/acl_parsing.c | 2 +
libxkutil/acl_parsing.h | 1 +
schema/FilterEntry.mof | 26 ++++++++++++------------
schema/FilterList.mof | 9 ++++++++
src/Makefile.am | 4 +-
src/Virt_FilterEntry.c | 49 +++++++++++++++++++++++++++++++++++-----------
src/Virt_FilterEntry.h | 6 +++++
src/Virt_FilterList.c | 5 +++-
8 files changed, 74 insertions(+), 28 deletions(-)
--
1.7.7.6
12 years, 9 months
[PATCH v5 0/3] Implementation of a linked list helper
by Eduardo Lima (Etrunko)
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
This series provides a generic linked list implementation for libxkutil that is
based on the one originally developed for the libvirt domain events support
recently integrated upstream.
As test case I ported the ComputerSystemIndication provider code to use this
list implementation. In the near future it will be also used by the event loop
that I am currently working on to allow systems with libvirt older than 0.9.0
to make use of the same feature.
Other possible use cases would be to port the code of libxkutil/*_parsing* to
also use the list implementation instead of static arrays.
Changes from v4:
- Fix possible NULL dereference in list_last_node()
- Fix possible leak in acl_parsing.c
Changes from v3:
- Fix crashes in list_free(), list_first_node() and list_count()
- Include patch that ports the acl filter ref code to use the linked list
implementation
Changes from v2:
- Make list struct private
Changes from v1:
- Fix version iformation in Makefile.am
Eduardo Lima (Etrunko) (3):
libxkutil: Linked list helper
CSI: Use list helper implementation
ACL: Use linked list helper for filter refs
libxkutil/Makefile.am | 51 +++++--
libxkutil/acl_parsing.c | 58 +++------
libxkutil/acl_parsing.h | 5 +-
libxkutil/list_util.c | 254 +++++++++++++++++++++++++++++++++++
libxkutil/list_util.h | 73 ++++++++++
libxkutil/xmlgen.c | 30 +++-
src/Virt_ComputerSystemIndication.c | 95 ++++----------
src/Virt_NestedFilterList.c | 73 ++++++-----
8 files changed, 472 insertions(+), 167 deletions(-)
create mode 100644 libxkutil/list_util.c
create mode 100644 libxkutil/list_util.h
--
1.7.7.6
12 years, 9 months
[PATCH v4 0/3] Implementation of a linked list helper
by Eduardo Lima (Etrunko)
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
This series provides a generic linked list implementation for libxkutil that is
based on the one originally developed for the libvirt domain events support
recently integrated upstream.
As test case I ported the ComputerSystemIndication provider code to use this
list implementation. In the near future it will be also used by the event loop
that I am currently working on to allow systems with libvirt older than 0.9.0
to make use of the same feature.
Other possible use cases would be to port the code of libxkutil/*_parsing* to
also use the list implementation instead of static arrays.
Changes from v3:
- Fix crashes in list_free(), list_first_node() and list_count()
- Include patch that ports the acl filter ref code to use the linked list
implementation
Changes from v2:
- Make list struct private
Changes from v1:
- Fix version iformation in Makefile.am
Eduardo Lima (Etrunko) (3):
libxkutil: Linked list helper
CSI: Use list helper implementation
ACL: Use linked list helper for filter refs
libxkutil/Makefile.am | 51 +++++--
libxkutil/acl_parsing.c | 58 ++------
libxkutil/acl_parsing.h | 5 +-
libxkutil/list_util.c | 254 +++++++++++++++++++++++++++++++++++
libxkutil/list_util.h | 73 ++++++++++
libxkutil/xmlgen.c | 30 +++-
src/Virt_ComputerSystemIndication.c | 95 ++++----------
src/Virt_NestedFilterList.c | 73 ++++++-----
8 files changed, 471 insertions(+), 168 deletions(-)
create mode 100644 libxkutil/list_util.c
create mode 100644 libxkutil/list_util.h
--
1.7.7.6
12 years, 9 months
[PATCH v4] Fix AppliedFilterList creation and deletion
by Chip Vincent
From: Chip Vincent <cvincent(a)us.ibm.com>
Fixes many small issues with the current AppliedFilterList provider.
1) Fix Create to properly return a complete object path and fix Delete to
properly parse that path.
2) Persist applied filer rules. Since it's not possible to dyanmically update
a single device, I've changed the code to modify and re-define the VM to
essentially add/remove ACL filter associations.
I also updated the code to minimize domain/device parsing overhead. For
some strange reason, our internal APIs sometimes take a virDomainPtr and
other times a struct domain * forcing providers who work with domains
*and* devices to parse everything twice. Until the internal APIs are
cleaned up, I simply parse everything once and then fetch the device
manually from the struct domain *.
3) Add VIR_DOMAIN_XML_INACTIVE to virDomainGetXML(). By default, libvirt only
returns the XML of the running domain. We need to fetch the *stored* XML
that will be used for the next boot so that all changes made while the VM
is running are preserved.
Changes from v3:
- Fix NestedFilterList DeleteInstance
- Fix remove_filter_ref() in acl_parsing.c (intend to refactor in
future patch)
Changes from v2:
- Return the correct reference in NestedFilterList
Changes from v1:
- Fix leak and other comments
- Fix all cases virDomainGetXML()
- Fix NestedFilterList Create/Delete instance
Signed-off-by: Chip Vincent <cvincent(a)us.ibm.com>
---
libxkutil/acl_parsing.c | 1 +
libxkutil/device_parsing.c | 6 ++-
src/Virt_AppliedFilterList.c | 97 +++++++++++++++++++----------------
src/Virt_ComputerSystem.c | 3 +-
src/Virt_ComputerSystemIndication.c | 3 +-
src/Virt_FilterList.c | 5 ++-
src/Virt_NestedFilterList.c | 19 +++++--
src/Virt_VSMigrationService.c | 3 +-
8 files changed, 82 insertions(+), 55 deletions(-)
diff --git a/libxkutil/acl_parsing.c b/libxkutil/acl_parsing.c
index 5b6d7bb..9c4b4b2 100644
--- a/libxkutil/acl_parsing.c
+++ b/libxkutil/acl_parsing.c
@@ -652,6 +652,7 @@ int remove_filter_ref(struct acl_filter *filter, const char *name)
/* TODO: called infrequently, but needs optimization */
old_refs = filter->refs;
+ filter->ref_ct = 0;
for (i = 0; i < filter->ref_ct; i++) {
if (STREQC(old_refs[i], name)) {
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index a1e8d6c..ff86f2a 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -996,7 +996,8 @@ int get_devices(virDomainPtr dom, struct virt_device **list, int type)
char *xml;
int ret;
- xml = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_SECURE);
+ xml = virDomainGetXMLDesc(dom,
+ VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE);
if (xml == NULL)
return 0;
@@ -1241,7 +1242,8 @@ int get_dominfo(virDomainPtr dom, struct domain **dominfo)
char *xml;
int ret;
int start;
- xml = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_SECURE);
+ xml = virDomainGetXMLDesc(dom,
+ VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE);
if (xml == NULL)
return 0;
diff --git a/src/Virt_AppliedFilterList.c b/src/Virt_AppliedFilterList.c
index bc31c14..538adf4 100644
--- a/src/Virt_AppliedFilterList.c
+++ b/src/Virt_AppliedFilterList.c
@@ -97,67 +97,60 @@ static CMPIrc cu_get_ref_path(const CMPIObjectPath *reference,
if ((s.rc != CMPI_RC_OK) || CMIsNullValue(value))
return CMPI_RC_ERR_NO_SUCH_PROPERTY;
- /* how to parse and object path? */
+ if ((value.type != CMPI_ref) || CMIsNullObject(value.value.ref))
+ return CMPI_RC_ERR_TYPE_MISMATCH;
+
+ *_reference = value.value.ref;
return CMPI_RC_OK;
}
-/* TODO: Port to libxkutil/device_parsing.c */
-static int update_device(virDomainPtr dom,
- struct virt_device *dev)
+static int update_domain(virConnectPtr conn,
+ struct domain *dominfo)
{
-#if LIBVIR_VERSION_NUMBER > 8000
char *xml = NULL;
- int flags = VIR_DOMAIN_DEVICE_MODIFY_CURRENT |
- VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
- int ret = 0;
+ virDomainPtr dom = NULL;
- xml = device_to_xml(dev);
+ xml = system_to_xml(dominfo);
if (xml == NULL) {
- CU_DEBUG("Failed to get XML for device '%s'", dev->id);
+ CU_DEBUG("Failed to get XML from domain %s", dominfo->name);
goto out;
}
- if (virDomainUpdateDeviceFlags(dom, xml, flags) != 0) {
- CU_DEBUG("Failed to dynamically update device");
+ dom = virDomainDefineXML(conn, xml);
+ if (dom == NULL) {
+ CU_DEBUG("Failed to update domain %s", dominfo->name);
goto out;
}
- ret = 1;
out:
free(xml);
+ virDomainFree(dom);
- return ret;
-#else
return 0;
-#endif
}
-/* TODO: Port to libxkutil/device_parsing.c */
-static int get_device_by_devid(virDomainPtr dom,
+static int get_device_by_devid(struct domain *dominfo,
const char *devid,
- int type,
struct virt_device **dev)
{
- int i, ret = 0;
- struct virt_device *devices = NULL;
- int count = get_devices(dom, &devices, type);
+ int i;
+ struct virt_device *devices = dominfo->dev_net;
+ int count = dominfo->dev_net_ct;
+
+ if (dev == NULL)
+ return 0;
for (i = 0; i < count; i++) {
if (STREQC(devid, devices[i].id)) {
CU_DEBUG("Found '%s'", devices[i].id);
- *dev = virt_device_dup(&devices[i]);
- if (*dev != NULL)
- ret = 1;
-
- break;
+ *dev = &devices[i];
+ return 0;
}
}
- cleanup_virt_devices(&devices, count);
-
- return ret;
+ return 1;
}
/**
@@ -425,6 +418,8 @@ static CMPIStatus CreateInstance(
struct virt_device *device = NULL;
virConnectPtr conn = NULL;
virDomainPtr dom = NULL;
+ struct domain *dominfo = NULL;
+ CMPIObjectPath *_reference = NULL;
conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s);
if (conn == NULL)
@@ -487,8 +482,12 @@ static CMPIStatus CreateInstance(
goto out;
}
- get_device_by_devid(dom, net_name, CIM_RES_TYPE_NET, &device);
- if (device == NULL) {
+ if (get_dominfo(dom, &dominfo) == 0) {
+ CU_DEBUG("Failed to get dominfo");
+ goto out;
+ }
+
+ if (get_device_by_devid(dominfo, net_name, &device) != 0) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
"Dependent.Name object does not exist");
@@ -502,14 +501,19 @@ static CMPIStatus CreateInstance(
device->dev.net.filter_ref = strdup(filter_name);
- if (update_device(dom, device) == 0) {
+ if (update_domain(conn, dominfo) != 0) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
- "Failed to update device");
+ "Failed to update domain");
goto out;
}
- CMReturnObjectPath(results, reference);
+ /* create new object path */
+ _reference = CMClone(reference, NULL);
+ CMAddKey(_reference, "Antecedent", (CMPIValue *)&antecedent, CMPI_ref);
+ CMAddKey(_reference, "Dependent", (CMPIValue *)&dependent, CMPI_ref);
+
+ CMReturnObjectPath(results, _reference);
CU_DEBUG("CreateInstance complete");
out:
@@ -542,6 +546,7 @@ static CMPIStatus DeleteInstance(
struct virt_device *device = NULL;
virConnectPtr conn = NULL;
virDomainPtr dom = NULL;
+ struct domain *dominfo = NULL;
conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s);
if (conn == NULL)
@@ -557,7 +562,7 @@ static CMPIStatus DeleteInstance(
goto out;
}
- if (cu_get_str_path(reference, "DeviceID",
+ if (cu_get_str_path(antecedent, "DeviceID",
&device_name) != CMPI_RC_OK) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
@@ -573,7 +578,7 @@ static CMPIStatus DeleteInstance(
goto out;
}
- if (cu_get_str_path(reference, "Name",
+ if (cu_get_str_path(dependent, "Name",
&filter_name) != CMPI_RC_OK) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
@@ -585,7 +590,7 @@ static CMPIStatus DeleteInstance(
if (filter == NULL) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
- "Antecedent.Name object does not exist");
+ "Dependent.Name object does not exist");
goto out;
}
@@ -600,11 +605,15 @@ static CMPIStatus DeleteInstance(
goto out;
}
- get_device_by_devid(dom, net_name, CIM_RES_TYPE_NET, &device);
- if (device == NULL) {
+ if (get_dominfo(dom, &dominfo) == 0) {
+ CU_DEBUG("Failed to get dominfo");
+ goto out;
+ }
+
+ if (get_device_by_devid(dominfo, net_name, &device) != 0) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
- "Dependent.Name object does not exist");
+ "Antecedent.Name object does not exist");
goto out;
}
@@ -613,14 +622,14 @@ static CMPIStatus DeleteInstance(
device->dev.net.filter_ref = NULL;
}
- if (update_device(dom, device) == 0) {
+ if (update_domain(conn, dominfo) != 0) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
- "Failed to update device");
+ "Failed to update domain");
goto out;
}
- CU_DEBUG("CreateInstance complete");
+ CU_DEBUG("DeleteInstance complete");
out:
free(domain_name);
diff --git a/src/Virt_ComputerSystem.c b/src/Virt_ComputerSystem.c
index 582253a..e6c7e55 100644
--- a/src/Virt_ComputerSystem.c
+++ b/src/Virt_ComputerSystem.c
@@ -926,7 +926,8 @@ static CMPIStatus domain_reset(virDomainPtr dom)
return s;
}
- xml = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_SECURE);
+ xml = virDomainGetXMLDesc(dom,
+ VIR_DOMAIN_XML_INACTIVE |VIR_DOMAIN_XML_SECURE);
if (xml == NULL) {
CU_DEBUG("Unable to retrieve domain XML");
virt_set_status(_BROKER, &s,
diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c
index eb1a71c..6ef2ddc 100644
--- a/src/Virt_ComputerSystemIndication.c
+++ b/src/Virt_ComputerSystemIndication.c
@@ -107,7 +107,8 @@ static int csi_dom_xml_set(csi_dom_xml_t *dom, virDomainPtr dom_ptr, CMPIStatus
dom->name = strdup(name);
/* xml */
- dom->xml = virDomainGetXMLDesc(dom_ptr, VIR_DOMAIN_XML_SECURE);
+ dom->xml = virDomainGetXMLDesc(dom_ptr,
+ VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE);
if (dom->xml == NULL) {
cu_statusf(_BROKER, s,
CMPI_RC_ERR_FAILED,
diff --git a/src/Virt_FilterList.c b/src/Virt_FilterList.c
index 35d18a9..5b1b6e8 100644
--- a/src/Virt_FilterList.c
+++ b/src/Virt_FilterList.c
@@ -358,7 +358,10 @@ static CMPIStatus DeleteInstance(
goto out;
}
- delete_filter(conn, filter);
+ if (delete_filter(conn, filter) != 0) {
+ CU_DEBUG("Failed to delete filter %s", filter->name);
+ goto out;
+ }
out:
cleanup_filters(&filter, 1);
diff --git a/src/Virt_NestedFilterList.c b/src/Virt_NestedFilterList.c
index 894cd7c..81c4408 100644
--- a/src/Virt_NestedFilterList.c
+++ b/src/Virt_NestedFilterList.c
@@ -98,7 +98,10 @@ static CMPIrc cu_get_ref_path(const CMPIObjectPath *reference,
if ((s.rc != CMPI_RC_OK) || CMIsNullValue(value))
return CMPI_RC_ERR_NO_SUCH_PROPERTY;
- /* how to parse and object path? */
+ if ((value.type != CMPI_ref) || CMIsNullObject(value.value.ref))
+ return CMPI_RC_ERR_TYPE_MISMATCH;
+
+ *_reference = value.value.ref;
return CMPI_RC_OK;
}
@@ -305,6 +308,7 @@ static CMPIStatus CreateInstance(
const char *child_name = NULL;
struct acl_filter *child_filter = NULL;
virConnectPtr conn = NULL;
+ CMPIObjectPath *_reference = NULL;
CU_DEBUG("Reference = %s", REF2STR(reference));
@@ -383,7 +387,12 @@ static CMPIStatus CreateInstance(
goto out;
}
- CMReturnObjectPath(results, reference);
+ /* create new object path */
+ _reference = CMClone(reference, NULL);
+ CMAddKey(_reference, "Antecedent", (CMPIValue *)&antecedent, CMPI_ref);
+ CMAddKey(_reference, "Dependent", (CMPIValue *)&dependent, CMPI_ref);
+
+ CMReturnObjectPath(results, _reference);
CU_DEBUG("CreateInstance completed");
out:
@@ -423,7 +432,7 @@ static CMPIStatus DeleteInstance(
goto out;
}
- if (cu_get_str_path(reference, "Name", &parent_name) != CMPI_RC_OK) {
+ if (cu_get_str_path(antecedent, "Name", &parent_name) != CMPI_RC_OK) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
"Unable to get Antecedent.Name property");
@@ -446,7 +455,7 @@ static CMPIStatus DeleteInstance(
goto out;
}
- if (cu_get_str_path(reference, "Name", &child_name) != CMPI_RC_OK) {
+ if (cu_get_str_path(dependent, "Name", &child_name) != CMPI_RC_OK) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
"Unable to get Dependent.Name property");
@@ -475,7 +484,7 @@ static CMPIStatus DeleteInstance(
goto out;
}
- CU_DEBUG("CreateInstance completed");
+ CU_DEBUG("DeleteInstance completed");
out:
cleanup_filters(&parent_filter, 1);
diff --git a/src/Virt_VSMigrationService.c b/src/Virt_VSMigrationService.c
index d393787..76e3d25 100644
--- a/src/Virt_VSMigrationService.c
+++ b/src/Virt_VSMigrationService.c
@@ -1070,7 +1070,8 @@ static CMPIStatus prepare_migrate(virDomainPtr dom,
{
CMPIStatus s = {CMPI_RC_OK, NULL};
- *xml = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_SECURE);
+ *xml = virDomainGetXMLDesc(dom,
+ VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE);
if (*xml == NULL) {
virt_set_status(_BROKER, &s,
--
1.7.1
12 years, 9 months
[PATCH v3 0/2] Implementation of a linked list helper
by Eduardo Lima (Etrunko)
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
This series provides a generic linked list implementation for libxkutil that is
based on the one originally developed for the libvirt domain events support
recently integrated upstream.
As test case I ported the ComputerSystemIndication provider code to use this
list implementation. In the near future it will be also used by the event loop
that I am currently working on to allow systems with libvirt older than 0.9.0
to make use of the same feature.
Other possible use cases would be to port the code of libxkutil/*_parsing* to
also use the list implementation instead of static arrays.
Changes from v2:
- Make list struct private
Changes from v1:
- Fix version iformation in Makefile.am
Eduardo Lima (Etrunko) (2):
libxkutil: Linked list helper
CSI: Use list helper implementation
libxkutil/Makefile.am | 51 ++++++--
libxkutil/list_util.c | 243 +++++++++++++++++++++++++++++++++++
libxkutil/list_util.h | 71 ++++++++++
src/Virt_ComputerSystemIndication.c | 95 ++++----------
4 files changed, 377 insertions(+), 83 deletions(-)
create mode 100644 libxkutil/list_util.c
create mode 100644 libxkutil/list_util.h
--
1.7.7.6
12 years, 9 months
[PATCH V6 7/7] vlan extention - CIM model add EASD
by xiaxia347work@163.com
From: Wenchao Xia <xiawenc(a)linux.vnet.ibm.com>
Add EASD for EthernetPort. According DSP1097, There are two kinds of EASD:
EA stands for Settings of EthernetPort, EC stands for Settings for Connection
between EthernetPort.
Signed-off-by: Wenchao Xia <xiawenc(a)linux.vnet.ibm.com>
---
schema/EthernetPortAllocationSettingData.mof | 22 +
.../EthernetPortAllocationSettingData.registration | 3 +
src/Virt_EASD.c | 709 ++++++++++++++++++++
src/Virt_EASD.h | 59 ++
4 files changed, 793 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..726bb1f
--- /dev/null
+++ b/schema/EthernetPortAllocationSettingData.mof
@@ -0,0 +1,22 @@
+// Copyright IBM Corp. 2012
+
+[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 AutoStart;
+
+ uint16 DHCP;
+
+};
diff --git a/schema/EthernetPortAllocationSettingData.registration b/schema/EthernetPortAllocationSettingData.registration
new file mode 100644
index 0000000..8925739
--- /dev/null
+++ b/schema/EthernetPortAllocationSettingData.registration
@@ -0,0 +1,3 @@
+# Copyright IBM Corp. 2012
+# 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..bdcf125
--- /dev/null
+++ b/src/Virt_EASD.c
@@ -0,0 +1,709 @@
+/*
+ * 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 "device_parsing.h"
+#include "network_model_helper.h"
+
+#include "Virt_EASD.h"
+
+static const CMPIBroker *_BROKER;
+
+static int set_primary_for_easd(const CMPIBroker *broker, const char* prefix,
+ struct 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);
+ CU_FREE(easd_name);
+ CU_FREE(eth_name);
+
+ CMSetProperty(instance, "ResourceType",
+ (CMPIValue *)&res_type, CMPI_uint16);
+
+ if (piface->eth_type == ETH_TYPE_ETHER_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,
+ struct EthIface *piface, CMPIInstance *instance)
+{
+ struct VLAN_Prop *pvlan;
+ struct VLAN_Prop_8021q *pvlan8021q;
+ uint16_t vid;
+ CMPIArray *conn_array;
+ CMPIString *cm_str;
+ char *str = NULL;
+ CMPIStatus s;
+ uint16_t vlantype = 0;
+ uint16_t visibility = CIM_NUM_CONSUMERVISIBILITY_VIRTUALIZED;
+
+ if (piface->eth_type == ETH_TYPE_ETHER_PHYSICAL) {
+ visibility = CIM_NUM_CONSUMERVISIBILITY_PASSEDTHROUGH;
+ }
+ CMSetProperty(instance, "ConsumerVisibility",
+ (CMPIValue *)&visibility, CMPI_uint16);
+
+ if (piface->protocol_prop.ipv4_prop.DHCP >= 0) {
+ CMSetProperty(instance, "DHCP",
+ (CMPIValue *)&piface->protocol_prop.ipv4_prop.DHCP,
+ CMPI_uint16);
+ }
+
+ if (piface->run_prop.boot_mode >= 0) {
+ CMSetProperty(instance, "AutoStart",
+ (CMPIValue *)&piface->run_prop.boot_mode,
+ CMPI_uint16);
+ }
+
+ if ((piface->eth_type != ETH_TYPE_ETHER_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);
+
+ vlantype = 1;
+ }
+ CMSetProperty(instance, "VLANType",
+ (CMPIValue *)&vlantype, CMPI_uint16);
+
+out:
+ CU_FREE(str);
+ return 1;
+}
+
+static CMPIStatus add_conn_properties(const CMPIBroker *broker,
+ struct 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);
+ CU_FREE(easd_name);
+ CU_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,
+ struct 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,
+ struct 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,
+ struct 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_DEBUG("failed to find any bridge for the port %s.",
+ piface->name);
+ }
+
+ /* building the EA instance */
+ if (!(req_type&EASD_TYPE_EA)) {
+ goto ea_build_end;
+ }
+ if ((vsname == NULL) || (br1_name == 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:
+ CU_FREE(br1_name);
+ CU_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;
+ struct 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);
+ CU_FREE(eth_name);
+ CU_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:
+ CU_FREE(prefix);
+ CU_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};
+ struct 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..f9d13ec
--- /dev/null
+++ b/src/Virt_EASD.h
@@ -0,0 +1,59 @@
+/*
+ * 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
+
+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.1
12 years, 9 months