From: Xu Wang <cngesaint(a)outlook.com>
If lldptool command or vsi support output updates, user can update items in
the libvirt-cim.conf file. The config option could support maximum 8 items.
Signed-off-by: Xu Wang <cngesaint(a)outlook.com>
---
libvirt-cim.conf | 16 +++++++++++
libxkutil/misc_util.c | 18 ++++++++++++
libxkutil/misc_util.h | 2 +
src/Virt_SwitchService.c | 66 ++++++++++++++++++++++++++++++++++++++-------
4 files changed, 91 insertions(+), 11 deletions(-)
diff --git a/libvirt-cim.conf b/libvirt-cim.conf
index f6464c3..d268169 100644
--- a/libvirt-cim.conf
+++ b/libvirt-cim.conf
@@ -39,3 +39,19 @@
# Default value: false
#
# disable_kvm = false;
+
+# lldptool_query_options (string)
+# Defines the command used in SwitchService to query VEPA support, will be
+# used as "lldptool -i [INTERFACE] [OPTIONS]"
+#
+# lldptool_query_options = "-t -g ncb -V evbcfg";
+
+# vsi_support_key_string (string)
+# Defines the string used in SwitchService to search in lldptool's output
+# When lldptool updates its output, please set this value and update the
+# output set, maximum 8 items. use comma to devide items. If there is
+# no need to change the output set, please do not leave it void. Because
+# this value has higher level than default.
+#
+# vsi_support_key_string = "{ supported forwarding mode: (0x40) reflective
relay,"
+# " supported capabilities: (0x7) RTE ECP VDP}";
diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c
index 921604c..d4515e6 100644
--- a/libxkutil/misc_util.c
+++ b/libxkutil/misc_util.c
@@ -244,6 +244,24 @@ const char *get_mig_ssh_tmp_key(void)
return prop.value_string;
}
+const char *get_lldptool_query_options(void)
+{
+ static LibvirtcimConfigProperty prop = {
+ "lldptool_query_options", CONFIG_STRING, {0}, 0};
+
+ libvirt_cim_config_get(&prop);
+ return prop.value_string;
+}
+
+const char *get_vsi_support_key_string(void)
+{
+ static LibvirtcimConfigProperty prop = {
+ "vsi_support_key_string", CONFIG_STRING, {0}, 0};;
+
+ libvirt_cim_config_get(&prop);
+ return prop.value_string;
+}
+
virConnectPtr connect_by_classname(const CMPIBroker *broker,
const char *classname,
CMPIStatus *s)
diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h
index 8493005..3279b09 100644
--- a/libxkutil/misc_util.h
+++ b/libxkutil/misc_util.h
@@ -155,6 +155,8 @@ int virt_set_status(const CMPIBroker *broker,
/* get libvirt-cim config */
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);
/*
* Local Variables:
diff --git a/src/Virt_SwitchService.c b/src/Virt_SwitchService.c
index 8991426..983ebc0 100644
--- a/src/Virt_SwitchService.c
+++ b/src/Virt_SwitchService.c
@@ -46,12 +46,29 @@ static CMPIStatus check_vsi_support(char *command)
CMPIStatus s = {CMPI_RC_OK, NULL};
char buff[MAX_LEN];
FILE *stream = NULL;
- const char *searchStr[] = {" supported forwarding mode: "
- "(0x40) reflective relay",
- " supported capabilities: "
- "(0x07) RTE ECP VDP",
- NULL};
- int matched = 0;
+ char *searchStr[8]; /* maximum items of vsi support output */
+ int count = 0;
+ const char *user_settings = get_vsi_support_key_string();
+ char *vsi_support_key_string = NULL;
+ char *delim = "{},";
+ int matched = 0;
+ char *temp = NULL;
+
+ if (!user_settings) {
+ /* default supported output set, 8 maximum */
+ user_settings = "{ supported forwarding mode: "
+ "(0x40) reflective relay,"
+ " supported capabilities: "
+ "(0x7) RTE ECP VDP}";
+ }
+
+ vsi_support_key_string = strdup(user_settings);
+ if (vsi_support_key_string == NULL) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Strdup vsi_support_key_string failed!");
+ goto out;
+ }
// Run lldptool command to find vsi support.
stream = popen(command, "r");
@@ -63,6 +80,25 @@ static CMPIStatus check_vsi_support(char *command)
goto out;
}
+ /* Slice vsi_support_key_string into items */
+ searchStr[count] = strtok_r(vsi_support_key_string, delim, &temp);
+ if (searchStr[count] == NULL) {
+ CU_DEBUG("searchStr fetch failed when calling strtok_r!");
+ } else {
+ CU_DEBUG("searchStr[%d]: %s", count, searchStr[count]);
+ count++;
+ }
+
+ while ((searchStr[count] = strtok_r(NULL, delim, &temp))) {
+ if (count >= 7) {
+ CU_DEBUG("WARN: searchStr is full, left aborted!");
+ break;
+ } else {
+ CU_DEBUG("searchStr[%d]: %s", count,
searchStr[count]);
+ count++;
+ }
+ }
+
// Read the output of the command.
while (fgets(buff, MAX_LEN, stream) != NULL) {
int i = 0;
@@ -81,16 +117,18 @@ static CMPIStatus check_vsi_support(char *command)
}
/* All the search strings were found in the output of this
command. */
- if (matched == 2) {
+ if (matched == count) {
cu_statusf(_BROKER, &s, CMPI_RC_OK, "VSI
supported");
- goto out;;
+ goto out;
}
}
+
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_NOT_FOUND,
"No VSI Support found");
- out:
+ out:
+ free(vsi_support_key_string);
if (stream != NULL)
pclose(stream);
return s;
@@ -214,6 +252,7 @@ static CMPIStatus get_switchservice(const CMPIObjectPath *reference,
int i;
char **if_list;
char cmd[MAX_LEN];
+ const char *lldptool_query_options = NULL;
*_inst = NULL;
conn = connect_by_classname(broker, CLASSNAME(reference), &s);
@@ -257,10 +296,15 @@ static CMPIStatus get_switchservice(const CMPIObjectPath
*reference,
CU_DEBUG("Found %d interfaces", count);
+ lldptool_query_options = get_lldptool_query_options();
+ if (!lldptool_query_options) {
+ lldptool_query_options = "-t -g ncb -V evbcfg";
+ }
for (i=0; i<count; i++) {
- sprintf(cmd, "lldptool -i %s -t -V evbcfg", if_list[i]);
- CU_DEBUG("running command %s ...", cmd);
+ sprintf(cmd, "lldptool -i %s %s",
+ if_list[i], lldptool_query_options);
+ CU_DEBUG("running command [%s]", cmd);
s = check_vsi_support(cmd);
if (s.rc == CMPI_RC_OK) {
vsi = true;
--
1.7.1