diff mbox

[RFC,6/8] xl: parse vif backend features parameters

Message ID 20171102180616.24084-7-joao.m.martins@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Joao Martins Nov. 2, 2017, 6:06 p.m. UTC
Any option name preceded by "require-" means a backend feature to be {un,}set.
This is stored in key value structure which libxl will parse and inform netback
to override the specified features.

An example would be a config containing:

...
vcpus = 8
vif = ["bridge=br0,require-multi-queue-max-queues=2"]
...

Which would set the number of queues to 2 as opposed to e.g. the global
netback defined xen_netback.max_queues parameter.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 tools/xl/xl_parse.c | 37 +++++++++++++++++++++++++++++++++++++
 tools/xl/xl_parse.h |  2 ++
 2 files changed, 39 insertions(+)
diff mbox

Patch

diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c
index 9a692d5ae6..007df694d8 100644
--- a/tools/xl/xl_parse.c
+++ b/tools/xl/xl_parse.c
@@ -401,6 +401,29 @@  void replace_string(char **str, const char *val)
     *str = xstrdup(val);
 }
 
+static void add_to_kvlist(libxl_key_value_list *sl, char *key, char *val)
+{
+    size_t count = libxl_key_value_list_length(sl);
+    libxl_key_value_list array = *sl;
+    int i;
+
+    array = xcalloc((count+1) * 2 + 1, sizeof(char*));
+
+    for (i = 0; i < count * 2; i++) {
+        if ((*sl)[i])
+            array[i] = xstrdup((*sl)[i]);
+    }
+    array[i] = NULL;
+    libxl_key_value_list_dispose(sl);
+
+    count *= 2;
+    array[count++] = xstrdup(key);
+    array[count++] = xstrdup(val);
+    array[count] = NULL;
+
+    *sl = array;
+}
+
 int match_option_size(const char *prefix, size_t len,
                       char *arg, char **argopt)
 {
@@ -559,6 +582,20 @@  int parse_nic_config(libxl_device_nic *nic, XLU_Config **config, char *token)
         fprintf(stderr, "the accel parameter for vifs is currently not supported\n");
     } else if (MATCH_OPTION("devid", token, oparg)) {
         nic->devid = parse_ulong(oparg);
+    } else if (MATCH_FEATURE("require", token, oparg)) {
+        char *key = NULL, *value = NULL;
+        int rc;
+
+        rc = split_string_into_pair(oparg, "=", &key, &value);
+        if (rc != 0) {
+            fprintf(stderr, "failed to parse vif backend feature %s", oparg);
+            return 1;
+        }
+
+        add_to_kvlist(&nic->backend_features, key, value);
+
+        free(key);
+        free(value);
     } else {
         fprintf(stderr, "unrecognized argument `%s'\n", token);
         return 1;
diff --git a/tools/xl/xl_parse.h b/tools/xl/xl_parse.h
index cc459fb43f..aea07394cc 100644
--- a/tools/xl/xl_parse.h
+++ b/tools/xl/xl_parse.h
@@ -40,6 +40,8 @@  int match_option_size(const char *prefix, size_t len,
 #define MATCH_OPTION(prefix, arg, oparg) \
     match_option_size((prefix "="), sizeof((prefix)), (arg), &(oparg))
 
+#define MATCH_FEATURE(prefix, arg, oparg) \
+    match_option_size((prefix "-"), sizeof((prefix)), (arg), &(oparg))
 
 void split_string_into_string_list(const char *str, const char *delim,
                                    libxl_string_list *psl);