[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [UNIKRAFT PATCH v2 3/7] lib/uklibparam: Add support for passing array



Hi Sharan, this patch looks good.

-- Felipe

Reviewed-by: Felipe Huici <felipe.huici@xxxxxxxxx>

On 13.08.19, 14:38, "Minios-devel on behalf of Sharan Santhanam" 
<minios-devel-bounces@xxxxxxxxxxxxxxxxxxxx on behalf of 
Sharan.Santhanam@xxxxxxxxx> wrote:

    This patch implements a way to pass array parameters to the library.
    The array parameters are delimited by a ' '.
    
    Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
    ---
     lib/uklibparam/include/uk/libparam.h | 20 +++++++++++++++
     lib/uklibparam/param.c               | 38 +++++++++++++++++++++++++++-
     2 files changed, 57 insertions(+), 1 deletion(-)
    
    diff --git a/lib/uklibparam/include/uk/libparam.h 
b/lib/uklibparam/include/uk/libparam.h
    index 1022bf7e..2a271ed3 100644
    --- a/lib/uklibparam/include/uk/libparam.h
    +++ b/lib/uklibparam/include/uk/libparam.h
    @@ -115,6 +115,14 @@ extern C {
      */
     #define UK_LIB_PARAM_STR(name)
     
    +/**
    + * Declare an array of primitive.
    + * @param name
    + * The name of the parameter.
    + * @param type
    + * The type of the parameter.
    + */
    +#define UK_LIB_PARAM_ARR(name, type)
     
     #else /* !CONFIG_LIBUKLIBPARAM */
     /**
    @@ -413,6 +421,18 @@ void _uk_libparam_lib_add(struct uk_lib_section 
*lib_sec);
                                                    name));             \
        _LIB_UK_PARAM_SET(name, type, 1)
     
    +/**
    + * Declare an array of primitive.
    + * @param name
    + * The name of the parameter.
    + * @param type
    + * The type of the parameter.
    + */
    +#define UK_LIB_PARAM_ARR(name, type)                                       
\
    +   _LIB_PARAM_NAME_SET(name, _LIB_PARAM_STRING(UK_LIBPARAM_PREFIX, \
    +                                               name));             \
    +   _LIB_UK_PARAM_SET(name, type, sizeof(name)/sizeof(type))        \
    +
     /**
      * Declare a string library param.
      * @param name
    diff --git a/lib/uklibparam/param.c b/lib/uklibparam/param.c
    index d11acd3f..8b84d9a0 100644
    --- a/lib/uklibparam/param.c
    +++ b/lib/uklibparam/param.c
    @@ -42,6 +42,7 @@
     #include <uk/libparam.h>
     #include <uk/version.h>
     
    +#define ARRAY_SEP   ' '
     #define LIB_ARG_SEP         "--"
     #define NUMBER_SET(fn, type, value, addr, max, min, errcode, result_type, 
fmt)\
        do {                                                            \
    @@ -372,6 +373,8 @@ static int kernel_args_set(struct param_args *pargs,
                           struct uk_param *param)
     {
        int rc = 0;
    +   int i  = 0;
    +   char *start, *value;
        int sign = (param->param_type >> PARAM_SIGN_SHIFT) & PARAM_SIGN_MASK;
        int scopy = (param->param_type >> PARAM_SCOPY_SHIFT) & PARAM_SCOPY_MASK;
        int param_type = (param->param_type >> PARAM_SIZE_SHIFT)
    @@ -383,7 +386,40 @@ static int kernel_args_set(struct param_args *pargs,
                /* Reference the pointer instead of copying the value */
                *((__uptr *)param->addr) = (__uptr) pargs->value;
        else {
    -           if (param->param_size == 1) {
    +           if (param->param_size > 1) {
    +                   /* Adding support for array */
    +                   i = 0;
    +                   value = &pargs->value[i];
    +                   uk_pr_debug("Value:%s length: %d\n", value,
    +                                pargs->value_len);
    +                   while (value && i < param->param_size) {
    +                           start = value;
    +                           value = strchr(value, ARRAY_SEP);
    +                           if (value) {
    +                                   uk_pr_debug("Delimiter: %p\n", value);
    +                                   *value = '\0';
    +                                   /* Search from the next index */
    +                                   value++;
    +                           }
    +                           uk_pr_debug("Array index: %d contains %s\n",
    +                                       i, start);
    +                           rc = kernel_arg_set((void *)(param->addr +
    +                                               (i * param_type)),
    +                                               start, param_type, sign);
    +                           if (rc < 0)
    +                                   break;
    +                           i++;
    +                   }
    +                   if (rc < 0)
    +                           uk_pr_err("Failed to read element at index: 
%d\n",
    +                                      i);
    +                   else if (value && i == param->param_size)
    +                           uk_pr_warn("Overflow detected! Max array 
size:%d\n",
    +                                      param->param_size);
    +                   else
    +                           uk_pr_debug("Converted value: %s into an array 
containing %d elements\n",
    +                                       pargs->value, i);
    +           } else if (param->param_size == 1) {
                        rc = kernel_arg_set((void *)param->addr,
                                            pargs->value, param_type, sign);
                } else {
    -- 
    2.20.1
    
    
    _______________________________________________
    Minios-devel mailing list
    Minios-devel@xxxxxxxxxxxxxxxxxxxx
    https://lists.xenproject.org/mailman/listinfo/minios-devel

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.