From patchwork Wed Dec 14 07:51:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 9473773 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 CFC4E60571 for ; Wed, 14 Dec 2016 07:54:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C4D3A28681 for ; Wed, 14 Dec 2016 07:54:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9B98286D5; Wed, 14 Dec 2016 07:54:42 +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 3705E28681 for ; Wed, 14 Dec 2016 07:54:42 +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 1cH4MF-0001ZB-SY; Wed, 14 Dec 2016 07:52:11 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cH4ME-0001Ys-Rk for xen-devel@lists.xen.org; Wed, 14 Dec 2016 07:52:10 +0000 Received: from [85.158.143.35] by server-11.bemta-6.messagelabs.com id 92/99-25337-A2AF0585; Wed, 14 Dec 2016 07:52:10 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrohUlfzV0C EwdpXmhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8a+lUfZCj7ZVqzu38vcwPhEs4uRk0NCwF9i ws9NTCA2m4CBxK1L35lBbBEBWYnVXXPYuxi5OJgFVjBK3Pu+kwUkISxgLrFl6TugIg4OFgFVi acTBUDCvAKeErvnbWaEmCkncfNcJ9gcTgEvieZH99hAbCGgmvPL97BC2GoSb5efYYHoFZQ4Of MJmM0sICFx8MUL5gmMvLOQpGYhSS1gZFrFqFGcWlSWWqRrZKiXVJSZnlGSm5iZo2toYKaXm1p cnJiempOYVKyXnJ+7iREYPAxAsIPxz7KAQ4ySHExKorxcVwMihPiS8lMqMxKLM+KLSnNSiw8x ynBwKEnwmvwEygkWpaanVqRl5gDDGCYtwcGjJMLbBZLmLS5IzC3OTIdInWJUlBLnNQBJCIAkM krz4NpgsXOJUVZKmJcR6BAhnoLUotzMElT5V4ziHIxKwrzTQabwZOaVwE1/BbSYCWix6BJ/kM UliQgpqQbGmkVnjztUe3BffeBzqrK8N1K2KYb79ekJksynKpe3vPj+KIjfePF/zsq19vw5S++ sjZn+5FKivEePjJwZl6fa08jy9z7p/z4ser0x2sE49N2hztt3i9VK9S5HNj2LtfzWsCrT+4WJ dtSmEGeTRSKz01mntsqKrA4488lAMv1zeu1JLafmpcuVWIozEg21mIuKEwErsqKvmAIAAA== X-Env-Sender: prvs=149da8861=ross.lagerwall@citrix.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1481701927!25115382!2 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 39325 invoked from network); 14 Dec 2016 07:52:09 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-6.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 14 Dec 2016 07:52:09 -0000 X-IronPort-AV: E=Sophos;i="5.33,345,1477958400"; d="scan'208";a="394683832" From: Ross Lagerwall To: Date: Wed, 14 Dec 2016 07:51:55 +0000 Message-ID: <1481701920-13758-4-git-send-email-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481701920-13758-1-git-send-email-ross.lagerwall@citrix.com> References: <1481701920-13758-1-git-send-email-ross.lagerwall@citrix.com> MIME-Version: 1.0 Cc: Ross Lagerwall , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v2 3/8] 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 56ae5aa..6e3fcf2 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; } }