From patchwork Fri Mar 4 16:48:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 8506311 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C55099F7CA for ; Fri, 4 Mar 2016 16:50:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9B20420125 for ; Fri, 4 Mar 2016 16:50:54 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 72E8E20121 for ; Fri, 4 Mar 2016 16:50:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1abstp-0003CB-AG; Fri, 04 Mar 2016 16:48:21 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1abstn-0003Bl-Dc for xen-devel@lists.xenproject.org; Fri, 04 Mar 2016 16:48:19 +0000 Received: from [193.109.254.147] by server-14.bemta-14.messagelabs.com id DC/AE-02987-25CB9D65; Fri, 04 Mar 2016 16:48:18 +0000 X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-4.tower-27.messagelabs.com!1457110095!27936728!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 40530 invoked from network); 4 Mar 2016 16:48:17 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-4.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 4 Mar 2016 16:48:17 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Fri, 04 Mar 2016 09:48:15 -0700 Message-Id: <56D9CA6002000078000D9935@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Fri, 04 Mar 2016 09:48:16 -0700 From: "Jan Beulich" To: "xen-devel" References: <56D9C80702000078000D9910@prv-mh.provo.novell.com> In-Reply-To: <56D9C80702000078000D9910@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Ian Jackson , Wei Liu , Stefano Stabellini Subject: [Xen-devel] [PATCH v2 3/3] xl: new "loglvl" command X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 xl: new "loglvl" command 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 --- 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" }, +}; + +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 ""; +} + +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", --- 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" }, +}; + +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 ""; +} + +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",