[PATCH] libcmpiutil: Fix endianness issues in embedded object parsing
by Viktor Mihajlovski
From: Thilo Boehm <tboehm(a)linux.vnet.ibm.com>
The auxiliary functions _set_int_prop/parse_int_property only
worked on little-endian archs as they performed an incorrect
reinterpretation of 64bit integers. Fixed by using the proper
CMPIValue union fields.
Signed-off-by: Thilo Boehm <tboehm(a)linux.vnet.ibm.com>
Signed-off-by: Viktor Mihajlovski <mihajlov(a)linux.vnet.ibm.com>
---
eo_parser.c | 35 ++++++++++++++++++++++-------------
eo_parser_xml.c | 49 +++++++++++++++++++++++++++++++++++++++----------
2 files changed, 61 insertions(+), 23 deletions(-)
diff --git a/eo_parser.c b/eo_parser.c
index 36106fd..4c5b0ee 100644
--- a/eo_parser.c
+++ b/eo_parser.c
@@ -113,31 +113,40 @@ static int _set_int_prop(CMPISint64 value,
CMPIInstance *inst)
{
CMPIStatus s;
- uint64_t unsigned_val = 0;
- int64_t signed_val = 0;
+ CMPIValue val;
- switch(type) {
+ switch (type) {
case CMPI_uint64:
+ val.uint64 = (uint64_t) value;
+ break;
case CMPI_uint32:
+ val.uint32 = (uint32_t) value;
+ break;
case CMPI_uint16:
+ val.uint16 = (uint16_t) value;
+ break;
case CMPI_uint8:
- unsigned_val = (uint64_t) value;
- s = CMSetProperty(inst,
- prop,
- (CMPIValue *) &(unsigned_val),
- type);
+ val.uint8 = (uint8_t) value;
break;
case CMPI_sint64:
+ val.sint64 = (int64_t) value;
+ break;
case CMPI_sint32:
+ val.sint32 = (int32_t) value;
+ break;
case CMPI_sint16:
+ val.sint16 = (int16_t) value;
+ break;
case CMPI_sint8:
+ val.sint8 = (int8_t) value;
+ break;
default:
- signed_val = (int64_t) value;
- s = CMSetProperty(inst,
- prop,
- (CMPIValue *) &(signed_val),
- type);
+ return 0;
}
+ s = CMSetProperty(inst,
+ prop,
+ &val,
+ type);
if (s.rc == CMPI_RC_OK)
return 1;
diff --git a/eo_parser_xml.c b/eo_parser_xml.c
index c8b28cc..234b04b 100644
--- a/eo_parser_xml.c
+++ b/eo_parser_xml.c
@@ -90,11 +90,48 @@ static CMPIType parse_int_property(const char *string,
if (sign) {
int64_t _val;
ret = sscanf(string, "%" SCNi64, &_val);
- val->sint64 = _val;
+ switch (size) {
+ case 8:
+ t = CMPI_sint8;
+ val->sint8 = (int8_t) _val;
+ break;
+ case 16:
+ t = CMPI_sint16;
+ val->sint16 = (int16_t) _val;
+ break;
+ case 32:
+ t = CMPI_sint32;
+ val->sint32 = (int32_t) _val;
+ break;
+ default:
+ case 64:
+ t = CMPI_sint64;
+ val->sint64 = (int64_t) _val;
+ break;
+ };
} else {
uint64_t _val;
ret = sscanf(string, "%" SCNu64, &_val);
- val->uint64 = _val;
+ switch (size) {
+ case 8:
+ t = CMPI_uint8;
+ val->uint8 = (uint8_t) _val;
+ break;
+ case 16:
+ t = CMPI_uint16;
+ val->uint16 = (uint16_t) _val;
+ break;
+ case 32:
+ t = CMPI_uint32;
+ val->uint32 = (uint32_t) _val;
+ break;
+ default:
+ case 64:
+ t = CMPI_uint64;
+ val->uint64 = (uint64_t) _val;
+ break;
+
+ };
}
if (ret != 1) {
@@ -102,14 +139,6 @@ static CMPIType parse_int_property(const char *string,
return CMPI_null;
}
- switch (size) {
- case 8: t = sign ? CMPI_sint8 : CMPI_uint8; break;
- case 16: t = sign ? CMPI_sint16 : CMPI_uint16; break;
- case 32: t = sign ? CMPI_sint32 : CMPI_uint32; break;
- default:
- case 64: t = sign ? CMPI_sint64 : CMPI_uint64; break;
- };
-
return t;
}
--
1.7.9.5
11 years, 1 month
[PATCH] get_dominfo: Use VIR_DOMAIN_XML_SECURE more wisely
by Michal Privoznik
Currently, even if we are connected RO to the libvirtd, we try to dump
domain XML with secure information (VIR_DOMAIN_XML_SECURE flag). This
is, however, forbidden in libvirt. With RO connection, we should not use
the SECURE flag at all.
---
libxkutil/device_parsing.c | 9 +++++++--
libxkutil/misc_util.c | 2 +-
libxkutil/misc_util.h | 1 +
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 7900e06..ffdf682 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -31,6 +31,7 @@
#include <libcmpiutil/libcmpiutil.h>
#include "device_parsing.h"
+#include "misc_util.h"
#include "xmlgen.h"
#include "../src/svpc_types.h"
@@ -1283,8 +1284,12 @@ int get_dominfo(virDomainPtr dom, struct domain **dominfo)
char *xml;
int ret = 0;
int start;
- xml = virDomainGetXMLDesc(dom,
- VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE);
+ int flags = VIR_DOMAIN_XML_INACTIVE;
+
+ if (!is_read_only())
+ flags |= VIR_DOMAIN_XML_SECURE;
+
+ xml = virDomainGetXMLDesc(dom, flags);
if (xml == NULL) {
CU_DEBUG("Failed to get dom xml with libvirt API.");
diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c
index 9e7e0d5..2164dd0 100644
--- a/libxkutil/misc_util.c
+++ b/libxkutil/misc_util.c
@@ -219,7 +219,7 @@ static int libvirt_cim_config_get(LibvirtcimConfigProperty *prop)
}
#endif
-static int is_read_only(void)
+int is_read_only(void)
{
static LibvirtcimConfigProperty prop = {
"readonly", CONFIG_BOOL, {0}, 0};
diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h
index fd4f191..056c327 100644
--- a/libxkutil/misc_util.h
+++ b/libxkutil/misc_util.h
@@ -153,6 +153,7 @@ int virt_set_status(const CMPIBroker *broker,
#define REF2STR(r) CMGetCharPtr(CMObjectPathToString(r, NULL))
/* get libvirt-cim config */
+int is_read_only(void);
const char *get_mig_ssh_tmp_key(void);
bool get_disable_kvm(void);
const char *get_lldptool_query_options(void);
--
1.8.1.5
11 years, 1 month
[PATCH] fix xmt-makefv.sh die() output
by Jincheng Miao
If xmt-makefv.sh failed, it will prompt FAILED: <reason>. But the reason part
is blank. It is because die() in xmt-makefv.sh use $i to show the reason. That
should be $1 rather than $i.
Signed-off-by: Jincheng Miao <jmiao(a)redhat.com>
---
suites/libvirt-cim/images/xmt-makefv.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/suites/libvirt-cim/images/xmt-makefv.sh b/suites/libvirt-cim/images/xmt-makefv.sh
index 64ca362..1cf6a0f 100755
--- a/suites/libvirt-cim/images/xmt-makefv.sh
+++ b/suites/libvirt-cim/images/xmt-makefv.sh
@@ -31,7 +31,7 @@ else
fi
die() {
- echo "FAILED: $i" >&2
+ echo "FAILED: $1" >&2
umount $TMPMOUT >/dev/null 2>&1
kpartx -d $loop >/dev/null 2>&1
--
1.8.3.1
11 years, 1 month
[PATCH V2 0/3] cimtest: Add default network device availability check
by Xu Wang
The default network device is a constant value. But if it doesn't exist in the
system some failure would occur. Hence these patches add checking existence of
them. If default network card name exists in the network info list, it will be
kept. If not, the value of it will be changed into the 1st available one in the
network info list.
Xu Wang (3):
cimtest: Add default network card name existence check to
27_definesystem_macvtap_dev.py
cimtest: Add default network existence check to
28_definesystem_with_vsi_profile.py
cimtest: Add default network existence check to 06_parent_net_pool.py
.../libvirt-cim/cimtest/RASD/06_parent_net_pool.py | 25 +++++++++++++++++--
.../27_definesystem_macvtap_dev.py | 16 ++++++++++++
.../28_definesystem_with_vsi_profile.py | 17 +++++++++++++
3 files changed, 55 insertions(+), 3 deletions(-)
11 years, 1 month
[PATCH V2] Add default network card existence checking
by Xu Wang
The default network card (used as forward device in network pool) name
was set as "eth0" in Virt_SettingDefineCapabilities.c. This patch added
check if there is such a network card exists in the network info list.
If it exists, use it. If not, the default network card would be changed
into the first one in the network devices list.
Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/misc_util.c | 39 +++++++++++++++++++++++++++++++++
libxkutil/misc_util.h | 2 +-
src/Virt_SettingsDefineCapabilities.c | 6 ++++-
3 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c
index 9e7e0d5..7541aa3 100644
--- a/libxkutil/misc_util.c
+++ b/libxkutil/misc_util.c
@@ -33,6 +33,8 @@
#include <errno.h>
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
#include "cmpidt.h"
#include "cmpift.h"
@@ -900,6 +902,43 @@ int virt_set_status(const CMPIBroker *broker,
return ret;
}
+char *get_avail_net(const char *def_name)
+{
+ int fd;
+ int interfaceNum = 0;
+ struct ifreq buf[16];
+ struct ifconf ifc;
+ char *avail_name = NULL;
+
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ CU_DEBUG("socket() failed.");
+ goto out;
+ }
+
+ ifc.ifc_len = sizeof(buf);
+ ifc.ifc_buf = (caddr_t)buf;
+ if (!ioctl(fd, SIOCGIFCONF, (char *)&ifc)) {
+ interfaceNum = ifc.ifc_len / sizeof(struct ifreq);
+ CU_DEBUG("interface num = %d", interfaceNum);
+ while (interfaceNum-- > 0) {
+ CU_DEBUG("network device name: %s", buf[interfaceNum].ifr_name);
+ if (!strcmp(def_name, buf[interfaceNum].ifr_name)) {
+ avail_name = strdup(buf[interfaceNum].ifr_name);
+ goto out;
+ }
+ }
+
+ avail_name = strdup(buf[0].ifr_name);
+ } else {
+ CU_DEBUG("ioctl: %s [%s:%d]\n", strerror(errno), __FILE__, __LINE__);
+ goto out;
+ }
+
+out:
+ close(fd);
+ return avail_name;
+}
+
/*
* Local Variables:
diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h
index fd4f191..9489a18 100644
--- a/libxkutil/misc_util.h
+++ b/libxkutil/misc_util.h
@@ -157,7 +157,7 @@ const char *get_mig_ssh_tmp_key(void);
bool get_disable_kvm(void);
const char *get_lldptool_query_options(void);
const char *get_vsi_support_key_string(void);
-
+char *get_avail_net(const char *def_name);
/*
* Local Variables:
* mode: C
diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c
index 78c128c..817980c 100644
--- a/src/Virt_SettingsDefineCapabilities.c
+++ b/src/Virt_SettingsDefineCapabilities.c
@@ -777,6 +777,7 @@ static CMPIStatus set_net_pool_props(const CMPIObjectPath *ref,
int dev_count;
int i;
char *tmp_str = NULL;
+ char *forward_device = NULL;
/* Isolated network pools don't have a forward device */
if (pool_type == NETPOOL_FORWARD_NONE)
@@ -836,14 +837,17 @@ static CMPIStatus set_net_pool_props(const CMPIObjectPath *ref,
(CMPIValue *)&pool_type, CMPI_uint16);
if (i == 1) {
+ forward_device = get_avail_net("eth0");
+
CMSetProperty(inst, "ForwardDevice",
- (CMPIValue *)"eth0", CMPI_chars);
+ (CMPIValue *)forward_device, CMPI_chars);
}
inst_list_add(list, inst);
}
out:
+ free(forward_device);
return s;
}
--
1.7.1
11 years, 1 month
[PATCH 0/2] Add default network card name existence check
by Xu Wang
Some default name of network cards is set as "eth0", "eth1" or "em1". But
when some system doesn't contain such a name, the testcase would fail.
Hence these patches added check of default network card and if it doesn't
exists in the network info list, the default name would be changed into
the first one except "lo". The second patch is updated with default network
card check in libvirt-cim.
Xu Wang (2):
cimtest: Add default network existence check to
28_definesystem_with_vsi_profile.py
cimtest: Add default network existence check to 06_parent_net_pool.py
.../libvirt-cim/cimtest/RASD/06_parent_net_pool.py | 16 +++++++++++++---
.../28_definesystem_with_vsi_profile.py | 9 +++++++++
2 files changed, 22 insertions(+), 3 deletions(-)
11 years, 1 month
[PATCH] Add default network card existence checking
by Xu Wang
From: Xu Wang <cngesaint(a)gmail.com>
The default network card (used as forward device in network pool) name
was set as "eth0" in Virt_SettingDefineCapabilities.c. This patch added
check if there is such a network card exists in the network info list.
If it exists, use it. If not, the default network card would be changed
into the first available one except lo.
Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/misc_util.c | 38 +++++++++++++++++++++++++++++++++
libxkutil/misc_util.h | 2 +-
src/Virt_SettingsDefineCapabilities.c | 8 ++++++-
3 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c
index 9e7e0d5..ada664c 100644
--- a/libxkutil/misc_util.c
+++ b/libxkutil/misc_util.c
@@ -900,6 +900,44 @@ int virt_set_status(const CMPIBroker *broker,
return ret;
}
+char *get_avai_net(char *def_name)
+{
+ char buf[512];
+ FILE *pp;
+ char *delims = ": ";
+ char *sub_str = NULL;
+ char *avai_net = NULL;
+ bool avai_found = false;
+
+ pp = popen("ip addr", "r");
+ if (!pp) {
+ CU_DEBUG("popen() error.\n");
+ return NULL;
+ }
+
+ while (fgets(buf, sizeof(buf), pp)) {
+ sub_str = strtok(buf, delims);
+ while (sub_str != NULL) {
+ if (!strncmp(sub_str, "eth", 3) || !strncmp(sub_str, "em", 2)) {
+ if (!strcmp(def_name, sub_str)) {
+ avai_net = strdup(sub_str);
+ goto out;
+ }
+
+ if (!avai_found) {
+ avai_net = strdup(sub_str);
+ avai_found = true;
+ }
+ }
+ sub_str = strtok(NULL, delims);
+ }
+ }
+ pclose(pp);
+
+out:
+ return avai_net;
+}
+
/*
* Local Variables:
diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h
index fd4f191..fc63000 100644
--- a/libxkutil/misc_util.h
+++ b/libxkutil/misc_util.h
@@ -157,7 +157,7 @@ const char *get_mig_ssh_tmp_key(void);
bool get_disable_kvm(void);
const char *get_lldptool_query_options(void);
const char *get_vsi_support_key_string(void);
-
+char *get_avai_net(char *def_name);
/*
* Local Variables:
* mode: C
diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c
index 78c128c..09ae49f 100644
--- a/src/Virt_SettingsDefineCapabilities.c
+++ b/src/Virt_SettingsDefineCapabilities.c
@@ -777,6 +777,7 @@ static CMPIStatus set_net_pool_props(const CMPIObjectPath *ref,
int dev_count;
int i;
char *tmp_str = NULL;
+ char *forward_device = "eth0";
/* Isolated network pools don't have a forward device */
if (pool_type == NETPOOL_FORWARD_NONE)
@@ -836,8 +837,13 @@ static CMPIStatus set_net_pool_props(const CMPIObjectPath *ref,
(CMPIValue *)&pool_type, CMPI_uint16);
if (i == 1) {
+ forward_device = get_avai_net(forward_device);
+ if (!forward_device) {
+ goto out;
+ }
+
CMSetProperty(inst, "ForwardDevice",
- (CMPIValue *)"eth0", CMPI_chars);
+ (CMPIValue *)forward_device, CMPI_chars);
}
inst_list_add(list, inst);
--
1.7.1
11 years, 1 month