From patchwork Mon Dec 12 16:18:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 9470929 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 288CD60573 for ; Mon, 12 Dec 2016 16:24:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F52A284D4 for ; Mon, 12 Dec 2016 16:24:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14330284D9; Mon, 12 Dec 2016 16:24:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 8696D284D4 for ; Mon, 12 Dec 2016 16:24:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGTMi-0002Jy-0J; Mon, 12 Dec 2016 16:22:12 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGTMf-0002EH-QR for xen-devel@lists.xen.org; Mon, 12 Dec 2016 16:22:09 +0000 Received: from [85.158.139.211] by server-15.bemta-5.messagelabs.com id 85/32-13537-1BECE485; Mon, 12 Dec 2016 16:22:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrohUnfDOb8 Ig0+HlC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1own2++zFJyyrdi29Qh7A+MBzS5GTg4JAX+J 1w+OsoPYbAIGErcufWcGsUUEZCVWd80BinNxMAusYJS4930nSxcjB4ewgLnEv7UGIDUsAqoSh /6fAavnFfCUWDb/HiPETDmJm+c6weKcAl4St7e0g80XAqnp/MQKYatJvF1+hgWiV1Di5MwnYD azgITEwRcvmCcw8s5CkpqFJLWAkWkVo0ZxalFZapGuoYVeUlFmekZJbmJmjq6hgalebmpxcWJ 6ak5iUrFecn7uJkZg8DAAwQ7Gpu2ehxglOZiURHm/HPCLEOJLyk+pzEgszogvKs1JLT7EKMPB oSTBe/EMUE6wKDU9tSItMwcYxjBpCQ4eJRFe5bNAad7igsTc4sx0iNQpRkUpcd6TIH0CIImM0 jy4NljsXGKUlRLmZQQ6RIinILUoN7MEVf4VozgHo5Iw72yQ8TyZeSVw018BLWYCWvx8nzfI4p JEhJRUA2Nrlt6Kx4KzXPV6mjOvJszKyP5oo39rqsvWIM0jfkxZN2/eOveVwWwTY/CJ3cE5Uaw T/azaeL5Nuad07PXeq5Jufw74GxTYPV/mvGKhltnV5Dp5y+uTZ2iEz5PYLlFhJyphU2Wi0C9s v/XQpW0/n8bX6bk7vNzIty5thuh5GeGcrHjrC0dOXFViKc5INNRiLipOBABh7GYamAIAAA== X-Env-Sender: prvs=147044df7=ross.lagerwall@citrix.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1481559725!59140962!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 38888 invoked from network); 12 Dec 2016 16:22:06 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-16.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 12 Dec 2016 16:22:06 -0000 X-IronPort-AV: E=Sophos;i="5.33,337,1477958400"; d="scan'208";a="394308075" From: Ross Lagerwall To: Date: Mon, 12 Dec 2016 16:18:06 +0000 Message-ID: <1481559490-13844-4-git-send-email-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481559490-13844-1-git-send-email-ross.lagerwall@citrix.com> References: <1481559490-13844-1-git-send-email-ross.lagerwall@citrix.com> MIME-Version: 1.0 Cc: Ross Lagerwall , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v1 3/7] tools/livepatch: Improve output 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-Virus-Scanned: ClamAV using ClamSMTP Improving the output of xen-livepatch, which is currently hard to read, especially when an error occurs. Some examples of the changes: Before: $ xen-livepatch apply test Performing apply:. completed After: $ xen-livepatch apply test Applying test:. completed Before: $ xen-livepatch apply test2 test2 failed with 22(Invalid argument) Performing apply: (no newline) After: $ xen-livepatch apply test2 Applying test2: failed Error 22: Invalid argument Signed-off-by: Ross Lagerwall Acked-by: Wei Liu --- tools/misc/xen-livepatch.c | 75 +++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/tools/misc/xen-livepatch.c b/tools/misc/xen-livepatch.c index 2f6721b..afd8c48 100644 --- a/tools/misc/xen-livepatch.c +++ b/tools/misc/xen-livepatch.c @@ -100,7 +100,8 @@ static int list_func(int argc, char *argv[]) rc = xc_livepatch_list(xch, MAX_LEN, idx, info, name, len, &done, &left); if ( rc ) { - fprintf(stderr, "Failed to list %d/%d: %d(%s)!\n", + fprintf(stderr, "Failed to list %d/%d.\n" + "Error %d: %s\n", idx, left, errno, strerror(errno)); break; } @@ -140,7 +141,8 @@ static int get_name(int argc, char *argv[], char *name) ssize_t len = strlen(argv[0]); if ( len > XEN_LIVEPATCH_NAME_SIZE ) { - fprintf(stderr, "ID MUST be %d characters!\n", XEN_LIVEPATCH_NAME_SIZE); + fprintf(stderr, "ID must be no more than %d characters.\n", + XEN_LIVEPATCH_NAME_SIZE); errno = EINVAL; return errno; } @@ -172,13 +174,15 @@ static int upload_func(int argc, char *argv[]) fd = open(filename, O_RDONLY); if ( fd < 0 ) { - fprintf(stderr, "Could not open %s, error: %d(%s)\n", + fprintf(stderr, "Could not open %s.\n" + "Error %d: %s\n", filename, errno, strerror(errno)); return errno; } if ( stat(filename, &buf) != 0 ) { - fprintf(stderr, "Could not get right size %s, error: %d(%s)\n", + fprintf(stderr, "Could not get size of %s.\n" + "Error %d: %s\n", filename, errno, strerror(errno)); close(fd); return errno; @@ -188,21 +192,29 @@ static int upload_func(int argc, char *argv[]) fbuf = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0); if ( fbuf == MAP_FAILED ) { - fprintf(stderr,"Could not map: %s, error: %d(%s)\n", + fprintf(stderr, "Could not map %s.\n" + "Error %d: %s\n", filename, errno, strerror(errno)); close (fd); return errno; } - printf("Uploading %s (%zu bytes)\n", filename, len); + printf("Uploading %s... ", filename); rc = xc_livepatch_upload(xch, name, fbuf, len); if ( rc ) - fprintf(stderr, "Upload failed: %s, error: %d(%s)!\n", - filename, errno, strerror(errno)); + { + printf("failed\n"); + fprintf(stderr, "Error %d: %s\n", + errno, strerror(errno)); + } + else + printf("completed\n"); + if ( munmap( fbuf, len) ) { - fprintf(stderr, "Could not unmap!? error: %d(%s)!\n", - errno, strerror(errno)); + fprintf(stderr, "Could not unmap %s.\n" + "Error %d: %s\n", + filename, errno, strerror(errno)); if ( !rc ) rc = errno; } @@ -223,27 +235,32 @@ struct { int allow; /* State it must be in to call function. */ int expected; /* The state to be in after the function. */ const char *name; + const char *verb; int (*function)(xc_interface *xch, char *name, uint32_t timeout); unsigned int executed; /* Has the function been called?. */ } action_options[] = { { .allow = LIVEPATCH_STATE_CHECKED, .expected = LIVEPATCH_STATE_APPLIED, .name = "apply", + .verb = "Applying", .function = xc_livepatch_apply, }, { .allow = LIVEPATCH_STATE_APPLIED, .expected = LIVEPATCH_STATE_CHECKED, .name = "revert", + .verb = "Reverting", .function = xc_livepatch_revert, }, { .allow = LIVEPATCH_STATE_CHECKED, .expected = -XEN_ENOENT, .name = "unload", + .verb = "Unloading", .function = xc_livepatch_unload, }, { .allow = LIVEPATCH_STATE_CHECKED, .expected = LIVEPATCH_STATE_APPLIED, .name = "replace", + .verb = "Replacing all live patches with", .function = xc_livepatch_replace, }, }; @@ -276,39 +293,44 @@ int action_func(int argc, char *argv[], unsigned int idx) rc = xc_livepatch_get(xch, name, &status); if ( rc ) { - fprintf(stderr, "%s failed to get status %d(%s)!\n", + fprintf(stderr, "Failed to get status of %s.\n" + "Error %d: %s\n", name, errno, strerror(errno)); return -1; } if ( status.rc == -XEN_EAGAIN ) { - fprintf(stderr, "%s failed. Operation already in progress\n", name); + fprintf(stderr, + "Cannot execute %s.\n" + "Operation already in progress.\n", action_options[idx].name); return -1; } if ( status.state == action_options[idx].expected ) { - printf("No action needed\n"); + printf("No action needed.\n"); return 0; } /* Perform action. */ if ( action_options[idx].allow & status.state ) { - printf("Performing %s:", action_options[idx].name); + printf("%s %s:", action_options[idx].verb, name); rc = action_options[idx].function(xch, name, 0); if ( rc ) { - fprintf(stderr, "%s failed with %d(%s)\n", name, errno, - strerror(errno)); + printf(" failed\n"); + fprintf(stderr, "Error %d: %s\n", errno, strerror(errno)); return -1; } } else { - printf("%s: in wrong state (%s), expected (%s)\n", - name, state2str(status.state), - state2str(action_options[idx].allow)); + fprintf(stderr, "%s is in the wrong state.\n" + "Current state: %s\n" + "Expected state: %s\n", + name, state2str(status.state), + state2str(action_options[idx].allow)); return -1; } @@ -335,7 +357,8 @@ int action_func(int argc, char *argv[], unsigned int idx) if ( retry >= RETRIES ) { - fprintf(stderr, "%s: Operation didn't complete after 30 seconds.\n", name); + printf(" failed\n"); + fprintf(stderr, "Operation didn't complete after 30 seconds.\n"); return -1; } else @@ -347,14 +370,18 @@ int action_func(int argc, char *argv[], unsigned int idx) printf(" completed\n"); else if ( rc < 0 ) { - fprintf(stderr, "%s failed with %d(%s)\n", name, -rc, strerror(-rc)); + printf(" failed\n"); + fprintf(stderr, "Error %d: %s\n", -rc, strerror(-rc)); return -1; } else { - fprintf(stderr, "%s: in wrong state (%s), expected (%s)\n", - name, state2str(rc), - state2str(action_options[idx].expected)); + printf(" failed\n"); + fprintf(stderr, "%s is in the wrong state.\n" + "Current state: %s\n" + "Expected state: %s\n", + name, state2str(rc), + state2str(action_options[idx].expected)); return -1; } }