xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Fabio Fantoni <fabio.fantoni@m2r.biz>
To: Jan Beulich <JBeulich@suse.com>,
	xen-devel <xen-devel@lists.xenproject.org>
Cc: Wei Liu <wei.liu2@citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: Re: [PATCH v2 3/3] xl: new "loglvl" command
Date: Mon, 7 Mar 2016 14:20:56 +0100	[thread overview]
Message-ID: <56DD8038.2000104@m2r.biz> (raw)
In-Reply-To: <56D9CA6002000078000D9935@prv-mh.provo.novell.com>

Il 04/03/2016 17:48, Jan Beulich ha scritto:
> 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@suse.com>
>
> --- 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;
> +}
> +
>   libxl_xen_console_reader *
>       libxl_xen_console_read_start(libxl_ctx *ctx, int clear)
>   {
> --- a/tools/libxl/libxl.h
> +++ b/tools/libxl/libxl.h
> @@ -1765,6 +1765,8 @@ int libxl_send_trigger(libxl_ctx *ctx, u
>                          libxl_trigger trigger, uint32_t vcpuid);
>   int libxl_send_sysrq(libxl_ctx *ctx, uint32_t domid, char sysrq);
>   int libxl_send_debug_keys(libxl_ctx *ctx, char *keys);
> +int libxl_log_level(libxl_ctx *ctx, bool set, bool guest,
> +                    int *lower_thresh, int *upper_thresh);
>   
>   typedef struct libxl__xen_console_reader libxl_xen_console_reader;
>   
> --- a/tools/libxl/xl.h
> +++ b/tools/libxl/xl.h
> @@ -81,6 +81,7 @@ int main_trigger(int argc, char **argv);
>   int main_sysrq(int argc, char **argv);
>   int main_debug_keys(int argc, char **argv);
>   int main_dmesg(int argc, char **argv);
> +int main_loglvl(int argc, char **argv);
>   int main_top(int argc, char **argv);
>   int main_networkattach(int argc, char **argv);
>   int main_networklist(int argc, char **argv);
> @@ -209,6 +210,8 @@ extern void printf_info_sexp(int domid,
>   #define XL_GLOBAL_CONFIG XEN_CONFIG_DIR "/xl.conf"
>   #define XL_LOCK_FILE XEN_LOCK_DIR "/xl"
>   
> +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
> +
>   #endif /* XL_H */
>   
>   /*
> --- 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" },
> +};

double "4" for both all and debug seems strange to me, is it right?

> +
> +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;
> +}
> +
>   int main_dmesg(int argc, char **argv)
>   {
>       unsigned int clear = 0;
> --- a/tools/libxl/xl_cmdtable.c
> +++ b/tools/libxl/xl_cmdtable.c
> @@ -309,6 +309,13 @@ struct cmd_spec cmd_table[] = {
>         "[-c]",
>         "  -c                        Clear dmesg buffer as well as printing it",
>       },
> +    { "loglvl",
> +      &main_loglvl, 0, 1,
> +      "Manage Xen log levels",
> +      "[-g] [-s=[LOWER][/UPPER]]",
> +      "-g,                 --guest                 act on guest log level\n"
> +      "-s [LOWER][/UPPER], --set=[LOWER][/UPPER]   set new log level\n"
> +    },
>       { "top",
>         &main_top, 0, 0,
>         "Monitor a host and the domains in real time",
>
>
>


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

  parent reply	other threads:[~2016-03-07 13:19 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-04 16:38 [PATCH v2 0/3] allow runtime log level threshold adjustments Jan Beulich
2016-03-04 16:46 ` [PATCH v2 1/3] console: allow " Jan Beulich
2016-03-04 20:55   ` Konrad Rzeszutek Wilk
2016-03-07 10:44     ` Jan Beulich
2016-03-07 14:41       ` Konrad Rzeszutek Wilk
2016-03-07 15:19         ` Jan Beulich
2016-03-04 16:47 ` [PATCH v2 2/3] libxc: wrapper for log level sysctl Jan Beulich
2016-03-05 16:00   ` Dario Faggioli
2016-03-08 16:20   ` Wei Liu
2016-03-04 16:48 ` [PATCH v2 3/3] xl: new "loglvl" command Jan Beulich
2016-03-04 18:45   ` Dario Faggioli
2016-03-07 11:46     ` Jan Beulich
2016-03-07 18:07       ` Dario Faggioli
2016-03-08  8:08         ` Jan Beulich
2016-03-08 14:05           ` George Dunlap
2016-03-08 16:09             ` Wei Liu
2016-03-08 18:05             ` Dario Faggioli
2016-03-05 15:36   ` Dario Faggioli
2016-03-07 13:20   ` Fabio Fantoni [this message]
2016-03-07 13:26     ` Jan Beulich
2016-03-08 16:20   ` Wei Liu
2016-03-14 15:23     ` Jan Beulich
2016-03-14 15:36       ` Wei Liu
2016-03-14 15:49         ` Jan Beulich
2016-03-14 16:01           ` Wei Liu
2016-03-14 17:00             ` Jan Beulich
2016-03-14 17:07               ` Ian Jackson
2016-03-15  7:37                 ` Jan Beulich
2016-03-15 13:58                   ` Wei Liu
2016-03-15 14:07                     ` Jan Beulich
2016-03-15 14:51                       ` Wei Liu
2016-03-15 15:03                         ` Jan Beulich
2016-03-15 15:38                       ` Ian Jackson
2016-03-16 11:22                         ` Jan Beulich
2016-04-28 15:33                           ` Wei Liu
2016-04-29  7:20                             ` Jan Beulich
2016-05-02 11:14                               ` Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56DD8038.2000104@m2r.biz \
    --to=fabio.fantoni@m2r.biz \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=JBeulich@suse.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).