From patchwork Tue Mar 8 19:02:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harmandeep Kaur X-Patchwork-Id: 8536831 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 91E77C0553 for ; Tue, 8 Mar 2016 19:05:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7BE8720155 for ; Tue, 8 Mar 2016 19:05:40 +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 46C732017D for ; Tue, 8 Mar 2016 19:05:39 +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 1adMu9-0000q8-HI; Tue, 08 Mar 2016 19:02:49 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1adMu7-0000pK-C5 for xen-devel@lists.xenproject.org; Tue, 08 Mar 2016 19:02:47 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 3C/5E-07120-6D12FD65; Tue, 08 Mar 2016 19:02:46 +0000 X-Env-Sender: write.harmandeep@gmail.com X-Msg-Ref: server-14.tower-21.messagelabs.com!1457463765!4814369!1 X-Originating-IP: [74.125.82.65] X-SpamReason: No, hits=3.0 required=7.0 tests=ML_RADAR_551,spamassassin: X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 14168 invoked from network); 8 Mar 2016 19:02:45 -0000 Received: from mail-wm0-f65.google.com (HELO mail-wm0-f65.google.com) (74.125.82.65) by server-14.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 8 Mar 2016 19:02:45 -0000 Received: by mail-wm0-f65.google.com with SMTP id l68so5892069wml.3 for ; Tue, 08 Mar 2016 11:02:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=C2qm5/rmPIruvMlE0vB913/m2f3FWz4gHgdqCrP7SGk=; b=hkuHx7zNuVKO++rKK4gvfGHpkiG0OVSw+1/FxNlc6cbN2u2MCpYwBvomsbFk0y8qPZ YeWB7c+RegApd1Q4Bt7AzJFqpsTxxmR/Yyjv/+fj9/jWOrproUScHQOHtbEhEl4JuhvV 13gNyqe6c8k6RvbUlQDpL5N0AMBiZhPFWF8oAxNRjw5HacHTMurzOQeb2n29OGhRO8NH ce+Vpw7syqciCUVKD66aJij5edXnktiNLudmtEEuemX7d2AVnP+aDKQTYUuvkkbgbm/k jC711jjpujyPTsqGLGTZZmdUfLPfZ7reRRmRBvj+PGj0p+9M86kOMZe2ul9rDrUQQEvj nTuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=C2qm5/rmPIruvMlE0vB913/m2f3FWz4gHgdqCrP7SGk=; b=QLrOQVpYXrK8Jbnkaj3Fzx45iQfZmN3mkAfrAAmD5ZYCsINy4EZcFRQIxmmNFxQrl+ r3CHZSGZJJaaxsWbX0HiQ8zzHLiYIdp6Iou8+EkqbCAv109mYnyIfc5TDzmW2hNCsTlX ks9Mmi9/2wsoYuK7slX0pAygcIEsvn9un/8PjGGJxCIOrFS/MuVyDT3rcFvCZFFfk9lo q8l1n+WcgB7SwM/50gwFHN5/kT2l1LS/2ijPaXKHz5NU343oRK5XGcA3KFBmKvjzxPPN PQ1+nsS3YUs682mZLFMAAbLNBpfVCWjg8NeE5J1kU5BrbDaaN++c0j7Lr3Y4M1lrFHkt 3Zvw== X-Gm-Message-State: AD7BkJJ13bcUrL2Lfh8Xj7tY81PShw41EzZC6DXuoYerGpcBYPbhzWT6q//vbRnUr9Bteg== X-Received: by 10.194.248.200 with SMTP id yo8mr30794615wjc.38.1457463765629; Tue, 08 Mar 2016 11:02:45 -0800 (PST) Received: from localhost.localdomain ([124.253.57.150]) by smtp.googlemail.com with ESMTPSA id hu1sm4310795wjb.36.2016.03.08.11.02.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Mar 2016 11:02:45 -0800 (PST) From: Harmandeep Kaur To: xen-devel@lists.xenproject.org Date: Wed, 9 Mar 2016 00:32:04 +0530 Message-Id: <1457463730-4712-4-git-send-email-write.harmandeep@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1457463730-4712-1-git-send-email-write.harmandeep@gmail.com> References: <1457463730-4712-1-git-send-email-write.harmandeep@gmail.com> Cc: wei.liu2@citrix.com, ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com, dario.faggioli@citrix.com, ian.jackson@eu.citrix.com, Harmandeep Kaur Subject: [Xen-devel] [PATCH 3/9 v2] xl: Improve return and exit codes of migrate related functions. 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no 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 Micros CHK_ERRNOVAL, CHK_SYSCALL, MUST are fixed. xvasprintf(), save_domain_core_begin(), create_migration_child(), migrate_read_fixedmessage(), migrate_do_preamble(), migrate_domain(), migrate_receive(), main_migrate_receive() and main_migrate() in the file xl_cmdimpl are fixed. Signed-off-by: Harmandeep Kaur --- v2: Add CHK_SYSCALL, MUST micros. Add xvasprintf(). --- tools/libxl/xl_cmdimpl.c | 58 ++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 690eb91..9ec3b2a 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -50,7 +50,7 @@ else if (chk_errnoval > 0) { \ fprintf(stderr,"xl: fatal error: %s:%d: %s: %s\n", \ __FILE__,__LINE__, strerror(chk_errnoval), #call); \ - exit(-ERROR_FAIL); \ + exit(EXIT_FAILURE); \ } \ }) @@ -59,7 +59,7 @@ if ((call) == -1) { \ fprintf(stderr,"xl: fatal error: %s:%d: %s: %s\n", \ __FILE__,__LINE__, strerror(errno), #call); \ - exit(-ERROR_FAIL); \ + exit(EXIT_FAILURE); \ } \ }) @@ -68,7 +68,7 @@ if (must_rc < 0) { \ fprintf(stderr,"xl: fatal error: %s:%d, rc=%d: %s\n", \ __FILE__,__LINE__, must_rc, #call); \ - exit(-must_rc); \ + exit(EXIT_FAILURE); \ } \ }) @@ -374,7 +374,7 @@ static void xvasprintf(char **strp, const char *fmt, va_list ap) int r = vasprintf(strp, fmt, ap); if (r == -1) { perror("asprintf failed"); - exit(-ERROR_FAIL); + exit(EXIT_FAILURE); } } @@ -4045,7 +4045,7 @@ static void save_domain_core_begin(uint32_t domid, &config_v, config_len_r); if (rc) { fprintf(stderr, "unable to read overridden config file\n"); - exit(2); + exit(EXIT_FAILURE); } parse_config_data(override_config_file, config_v, *config_len_r, &d_config); @@ -4054,14 +4054,14 @@ static void save_domain_core_begin(uint32_t domid, rc = libxl_retrieve_domain_configuration(ctx, domid, &d_config); if (rc) { fprintf(stderr, "unable to retrieve domain configuration\n"); - exit(2); + exit(EXIT_FAILURE); } } config_c = libxl_domain_config_to_json(ctx, &d_config); if (!config_c) { fprintf(stderr, "unable to convert config file to JSON\n"); - exit(2); + exit(EXIT_FAILURE); } *config_data_r = (uint8_t *)config_c; *config_len_r = strlen(config_c) + 1; /* including trailing '\0' */ @@ -4175,7 +4175,7 @@ static pid_t create_migration_child(const char *rune, int *send_fd, close(recvpipe[0]); close(recvpipe[1]); execlp("sh","sh","-c",rune,(char*)0); perror("failed to exec sh"); - exit(-1); + exit(EXIT_FAILURE); } close(sendpipe[0]); @@ -4198,14 +4198,14 @@ static int migrate_read_fixedmessage(int fd, const void *msg, int msgsz, stream = rune ? "migration receiver stream" : "migration stream"; rc = libxl_read_exactly(ctx, fd, buf, msgsz, stream, what); - if (rc) return ERROR_FAIL; + if (rc) return 1; if (memcmp(buf, msg, msgsz)) { fprintf(stderr, "%s contained unexpected data instead of %s\n", stream, what); if (rune) fprintf(stderr, "(command run was: %s )\n", rune); - return ERROR_FAIL; + return 1; } return 0; } @@ -4281,7 +4281,7 @@ static void migrate_do_preamble(int send_fd, int recv_fd, pid_t child, if (send_fd < 0 || recv_fd < 0) { fprintf(stderr, "migrate_do_preamble: invalid file descriptors\n"); - exit(1); + exit(EXIT_FAILURE); } rc = migrate_read_fixedmessage(recv_fd, migrate_receiver_banner, @@ -4290,7 +4290,7 @@ static void migrate_do_preamble(int send_fd, int recv_fd, pid_t child, if (rc) { close(send_fd); migration_child_report(recv_fd); - exit(-rc); + exit(EXIT_FAILURE); } save_domain_core_writeconfig(send_fd, "migration stream", @@ -4315,7 +4315,7 @@ static void migrate_domain(uint32_t domid, const char *rune, int debug, if (!config_len) { fprintf(stderr, "No config file stored for running domain and " "none supplied - cannot migrate.\n"); - exit(1); + exit(EXIT_FAILURE); } child = create_migration_child(rune, &send_fd, &recv_fd); @@ -4402,26 +4402,26 @@ static void migrate_domain(uint32_t domid, const char *rune, int debug, if (!rc) fprintf(stderr, "migration sender: Resumed OK.\n"); fprintf(stderr, "Migration failed due to problems at target.\n"); - exit(-ERROR_FAIL); + exit(EXIT_FAILURE); } fprintf(stderr, "migration sender: Target reports successful startup.\n"); libxl_domain_destroy(ctx, domid, 0); /* bang! */ fprintf(stderr, "Migration successful.\n"); - exit(0); + exit(EXIT_SUCCESS); failed_suspend: close(send_fd); migration_child_report(recv_fd); fprintf(stderr, "Migration failed, failed to suspend at sender.\n"); - exit(-ERROR_FAIL); + exit(EXIT_FAILURE); failed_resume: close(send_fd); migration_child_report(recv_fd); fprintf(stderr, "Migration failed, resuming at sender.\n"); libxl_domain_resume(ctx, domid, 1, 0); - exit(-ERROR_FAIL); + exit(EXIT_FAILURE); failed_badly: fprintf(stderr, @@ -4434,7 +4434,7 @@ static void migrate_domain(uint32_t domid, const char *rune, int debug, close(send_fd); migration_child_report(recv_fd); - exit(-ERROR_BADFAIL); + exit(EXIT_FAILURE); } static void migrate_receive(int debug, int daemonize, int monitor, @@ -4470,7 +4470,7 @@ static void migrate_receive(int debug, int daemonize, int monitor, if (rc < 0) { fprintf(stderr, "migration target: Domain creation failed" " (code %d).\n", rc); - exit(-rc); + exit(EXIT_FAILURE); } domid = rc; @@ -4508,7 +4508,7 @@ static void migrate_receive(int debug, int daemonize, int monitor, "Failed to unpause domain %s (id: %u):%d\n", common_domname, domid, rc); - exit(rc ? -ERROR_FAIL: 0); + exit(rc ? EXIT_FAILURE : EXIT_SUCCESS); default: /* do nothing */ break; @@ -4521,7 +4521,7 @@ static void migrate_receive(int debug, int daemonize, int monitor, migrate_receiver_ready, sizeof(migrate_receiver_ready), "migration ack stream", "ready message"); - if (rc) exit(-rc); + if (rc) exit(EXIT_FAILURE); rc = migrate_read_fixedmessage(recv_fd, migrate_permission_to_go, sizeof(migrate_permission_to_go), @@ -4546,14 +4546,14 @@ static void migrate_receive(int debug, int daemonize, int monitor, migrate_report, sizeof(migrate_report), "migration ack stream", "success/failure report"); - if (rc2) exit(-ERROR_BADFAIL); + if (rc2) exit(EXIT_FAILURE); rc_buf = -rc; assert(!!rc_buf == !!rc); rc2 = libxl_write_exactly(ctx, send_fd, &rc_buf, 1, "migration ack stream", "success/failure code"); - if (rc2) exit(-ERROR_BADFAIL); + if (rc2) exit(EXIT_FAILURE); if (rc) { fprintf(stderr, "migration target: Failure, destroying our copy.\n"); @@ -4562,7 +4562,7 @@ static void migrate_receive(int debug, int daemonize, int monitor, if (rc2) { fprintf(stderr, "migration target: Failed to destroy our copy" " (code %d).\n", rc2); - exit(-ERROR_BADFAIL); + exit(EXIT_FAILURE); } fprintf(stderr, "migration target: Cleanup OK, granting sender" @@ -4573,10 +4573,10 @@ static void migrate_receive(int debug, int daemonize, int monitor, sizeof(migrate_permission_to_go), "migration ack stream", "permission to sender to have domain back"); - if (rc2) exit(-ERROR_BADFAIL); + if (rc2) exit(EXIT_FAILURE); } - exit(0); + exit(EXIT_SUCCESS); } int main_restore(int argc, char **argv) @@ -4671,13 +4671,13 @@ int main_migrate_receive(int argc, char **argv) if (argc-optind != 0) { help("migrate-receive"); - return 2; + return EXIT_FAILURE; } migrate_receive(debug, daemonize, monitor, STDOUT_FILENO, STDIN_FILENO, checkpointed); - return 0; + return EXIT_SUCCESS; } int main_save(int argc, char **argv) @@ -4776,7 +4776,7 @@ int main_migrate(int argc, char **argv) } migrate_domain(domid, rune, debug, config_filename); - return 0; + return EXIT_SUCCESS; } #endif