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

Re: [Xen-devel] [PATCH v2 3/3] xl: new "loglvl" command



On Fri, Mar 04, 2016 at 09:48:16AM -0700, Jan Beulich wrote:
> This is pretty simplistic for now, but I'd rather have someone better
> friends with the tools improve it (if desired).
> 
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> 
> --- a/tools/libxl/libxl.c
> +++ b/tools/libxl/libxl.c
> @@ -5958,6 +5958,26 @@ int libxl_send_debug_keys(libxl_ctx *ctx
>      return 0;
>  }
>  
> +int libxl_log_level(libxl_ctx *ctx, bool set, bool guest,
> +                    int *lower_thresh, int *upper_thresh)
> +{
> +    int ret;
> +    GC_INIT(ctx);
> +    if (set) {
> +        ret = xc_set_log_level(ctx->xch, guest, *lower_thresh, 
> *upper_thresh);
> +    } else {
> +        ret = xc_get_log_level(ctx->xch, guest, lower_thresh, upper_thresh);
> +    }
> +    if ( ret < 0 ) {
> +        LOGE(ERROR, "%s %slog level",
> +             set ? "setting" : "getting", guest ? "guest " : "");
> +        GC_FREE;
> +        return ERROR_FAIL;
> +    }
> +    GC_FREE;
> +    return 0;
> +}
> +

As Dario said, libxl tends to have getter and setter pair.

>  libxl_xen_console_reader *
>      libxl_xen_console_read_start(libxl_ctx *ctx, int clear)
>  {
[...]
>  
>  /*
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -6469,6 +6469,84 @@ int main_debug_keys(int argc, char **arg
>      return 0;
>  }
>  
> +static const struct {
> +    int level;
> +    char string[8];
> +} loglvls[] = {
> +    { 0, "none" },
> +    { 1, "error" },
> +    { 2, "warning" },
> +    { 3, "info" },
> +    { 4, "all" },
> +    { 4, "debug" },

The semantics of the numbers should go into libxl_types.idl. Maybe
something like

# Keep in sync with Xen log level.
libxl_xen_log_level = Enumeration (...);

Then in here

    static const struct {
        int level;
        char string[8];
    } loglvls[] = {
        { LIBXL_XEN_LOG_LEVEL_NONE, "none" },
        { ..., "error" },
        { ..., "warning" },
        { ..., "info" },
        { ..., "all" },
        { ..., "debug" },

Please also note that after the introduction of this API, Xen log level
will become part of the stable API and subject to some compatibility
constraints. Is this what you wanted?


> +};
> +
> +static int parse_loglvl(char **parg)
> +{
> +    unsigned int i;
> +
> +    for (i = 0; i < ARRAY_SIZE(loglvls); ++i) {
> +        size_t l = strlen(loglvls[i].string);
> +
> +        if (!strncmp(*parg, loglvls[i].string, l)) {
> +            *parg += l;
> +            return loglvls[i].level;
> +        }
> +    }
> +
> +    return -1;
> +}
> +
> +static const char *format_loglvl(int loglvl)
> +{
> +    unsigned int i;
> +
> +    for (i = 0; i < ARRAY_SIZE(loglvls); ++i) {
> +        if (loglvl == loglvls[i].level)
> +            return loglvls[i].string;
> +    }
> +
> +    return "<unknown>";
> +}
> +
> +int main_loglvl(int argc, char **argv)
> +{
> +    static const struct option opts[] = {
> +        {"guest", 0, 0, 'g'},
> +        {"set", 0, 0, 's'},
> +        COMMON_LONG_OPTS
> +    };
> +    int opt, lower_thresh = -1, upper_thresh = -1;
> +    bool guest = false, set = false;
> +
> +    SWITCH_FOREACH_OPT(opt, "gs:", opts, "loglvl", 0) {
> +    case 'g':
> +        guest = true;
> +        break;
> +    case 's':
> +        if (*optarg != '/')
> +            lower_thresh = parse_loglvl(&optarg);
> +        if (*optarg == '/') {
> +            ++optarg;
> +            upper_thresh = parse_loglvl(&optarg);
> +        }
> +        set = true;
> +        break;
> +    }
> +
> +    if (libxl_log_level(ctx, set, guest, &lower_thresh, &upper_thresh)) {
> +        fprintf(stderr, "cannot %s %s log level\n",
> +                set ? "set" : "get", guest ? "guest" : "host");
> +        return 1;
> +    }
> +
> +    if (!set)
> +        printf("%s log levels: %s/%s\n", guest ? "guest" : "host",
> +               format_loglvl(lower_thresh), format_loglvl(upper_thresh));
> +
> +    return 0;
> +}
> +

You also need to patch xl manpage.

Wei.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

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