From patchwork Fri Apr 8 02:23:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 8779691 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 435EC9F39A for ; Fri, 8 Apr 2016 02:25:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0B27B20263 for ; Fri, 8 Apr 2016 02:25:43 +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 A8F2D2025B for ; Fri, 8 Apr 2016 02:25:41 +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 1aoM5M-00055W-H9; Fri, 08 Apr 2016 02:23:48 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aoM5L-00055F-Ge for xen-devel@lists.xenproject.org; Fri, 08 Apr 2016 02:23:47 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id B4/BB-16378-23617075; Fri, 08 Apr 2016 02:23:46 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrIIsWRWlGSWpSXmKPExsXiVRvkomsoxh5 u8OWoucX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmtG1NaBgZUrFhTV7GRsYO1y6GLk4hASmM0rs PrmOHcRhEVjDKnFt9RpGEEdC4BKrxNFVl9m6GDmBnBiJZ0cPQdnlEg8WNrGC2EICKhI3t69ig hi1mEli1vcfLCAJYQE9iSNHf7BD2OESE7oPMILYbAIGEm927AVrFhFQkri3ajITiM0sUCmxvv EvWD2LgKrEgZVzwOK8AnYSbU8ng/VyCthLXP97j7mLkQNomZ3E1QdyIGFRATmJlZdbWCHKBSV OznzCAlLCLKApsX6XPsR0eYntb+cwT2AUmYWkahZC1SwkVQsYmVcxahSnFpWlFukaGuglFWWm Z5TkJmbmAHmmermpxcWJ6ak5iUnFesn5uZsYgcHPAAQ7GNdMdT7EKMnBpCTK68PHHi7El5SfU pmRWJwRX1Sak1p8iFGGg0NJgveXCFBOsCg1PbUiLTMHGIcwaQkOHiURXkFRoDRvcUFibnFmOk TqFKMux5ap99YyCbHk5eelSonzioMUCYAUZZTmwY2ApYRLjLJSwryMQEcJ8RSkFuVmlqDKv2I U52BUEub9CnIJT2ZeCdymV0BHMAEdcYGfDeSIkkSElFQDY9uuTo5V+7+znOWt+6TOM4flkOn6 zk6FtmYDN68lTDxGS6fqFsgvEnBtyi+SPvMoW5Y5P/B5kYL3fv3rSlNnP/tR0LX8jLKmcUBp/ uflYgJlrfJdLhtvb1vWKG/PFnaNccli61Pc12KnLm295MEonb5ngvJa0aUhN/Z4/5kuKz5x0a wDRqmnlViKMxINtZiLihMBsnH/cgQDAAA= X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-12.tower-206.messagelabs.com!1460082225!33635343!1 X-Originating-IP: [74.125.82.68] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.28; banners=-,-,- X-VirusChecked: Checked Received: (qmail 24947 invoked from network); 8 Apr 2016 02:23:45 -0000 Received: from mail-wm0-f68.google.com (HELO mail-wm0-f68.google.com) (74.125.82.68) by server-12.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 8 Apr 2016 02:23:45 -0000 Received: by mail-wm0-f68.google.com with SMTP id a140so946847wma.2 for ; Thu, 07 Apr 2016 19:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=hVsXMckpainn9rZ65UzvXiLjJ+qyUzOfAqEyBpE94Jc=; b=ko1D3AUkVsEm7DZmQavqYtyauzjdKEwvJRYkSRj2L7YWZla3ulzA7yiKCp7hCdWGYB NBAPZYFleGJSkyKRsJcK1E2t3NCjaVR+hVdy1C2BVnw+dmMnqVIG517rTFYMA0hQNXXA +rjnWordQ44A30f2CwxfW4K+Eb0QPwVjd2nZtA749105lCG1dml9QJkeBtB6agUN2SVr 3L6plGoE4lUfoe6/YetJkrOoR9N/zEsSQNxsCnkn7W9wY8NcXWO22jWF1hWD9lzS40b7 ZyFCfNg6M8IJiEXeAwpwgRQE9piWAHmXpa8dQ1TaSEk2moNdHRvTJTARdDdxq6YaSao1 4DiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=hVsXMckpainn9rZ65UzvXiLjJ+qyUzOfAqEyBpE94Jc=; b=gmnqEgIg8EgYM9wVR6hWdMAT+zyJX4t0BD+99HI5PHEr584yNSS5b4k9B8aGuDWIEx ZBoMqfAqvB+Ed8sj358rWzksPieSbvAS/6nLDx49rd+xm0bsTUrMnzhJzI0XGhFZkpTw Odni2HYFUbnhdClRe/RVIu7ApOk4MP8GX95UcNWuqVjzWUjuEknxcHUv1DTbtOHuKZSL 3BuNe5h2GfO9mQmjTvzpCvVXCEuBT/1oCVM/OA+3i2ITCeaks8VOCOZ/DBHuV5znxDCL FgKsubE9fLoya6t7G8phQMjRu82oq5KDdCVFH36wabjwiXdo+248H51BURfBBSg9fo8w TW/A== X-Gm-Message-State: AD7BkJLRludRFWQ0gDwlLO7PjbEwcQvEo2LmY07viRPFLy9eOY7UyHKAptJYRnFqRcA8Cg== X-Received: by 10.28.54.208 with SMTP id y77mr725333wmh.17.1460082225585; Thu, 07 Apr 2016 19:23:45 -0700 (PDT) Received: from Solace.fritz.box (net-37-116-155-252.cust.vodafonedsl.it. [37.116.155.252]) by smtp.gmail.com with ESMTPSA id k139sm703571wmg.24.2016.04.07.19.23.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Apr 2016 19:23:44 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 08 Apr 2016 04:23:39 +0200 Message-ID: <20160408022339.9058.13804.stgit@Solace.fritz.box> In-Reply-To: <20160408022241.9058.86808.stgit@Solace.fritz.box> References: <20160408022241.9058.86808.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Wei Liu , Ian Jackson , Harmandeep Kaur Subject: [Xen-devel] [PATCH v3 2/6] xl: improve exit codes of save/restore and migration 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, 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 From: Harmandeep Kaur by making them more consistent with other examples in xl. Macros CHK_ERRNOVAL, CHK_SYSCALL, MUST are also updated. Signed-off-by: Harmandeep Kaur Signed-off-by: Dario Faggioli Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Wei Liu --- v3: This is patches 2 and 3 squashed together. Shorten changelog. v2: Add main_remus(). Remove create_domain(). --- tools/libxl/xl_cmdimpl.c | 80 +++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 9612b00..9cd3144 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); \ } \ }) @@ -376,7 +376,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); } } @@ -4350,7 +4350,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); @@ -4359,14 +4359,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' */ @@ -4436,7 +4436,7 @@ static int save_domain(uint32_t domid, const char *filename, int checkpoint, fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644); if (fd < 0) { fprintf(stderr, "Failed to open temp file %s for writing\n", filename); - exit(2); + exit(EXIT_FAILURE); } save_domain_core_writeconfig(fd, filename, config_data, config_len); @@ -4456,7 +4456,7 @@ static int save_domain(uint32_t domid, const char *filename, int checkpoint, else libxl_domain_destroy(ctx, domid, 0); - exit(rc < 0 ? 1 : 0); + exit(rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS); } static pid_t create_migration_child(const char *rune, int *send_fd, @@ -4480,7 +4480,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]); @@ -4503,14 +4503,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; } @@ -4586,7 +4586,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, @@ -4595,7 +4595,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", @@ -4620,7 +4620,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); @@ -4707,26 +4707,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, @@ -4739,7 +4739,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, @@ -4780,7 +4780,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; @@ -4823,7 +4823,7 @@ static void migrate_receive(int debug, int daemonize, int monitor, "Failed to unpause domain %s (id: %u):%d\n", ha, common_domname, domid, rc); - exit(rc ? -ERROR_FAIL: 0); + exit(rc ? EXIT_FAILURE : EXIT_SUCCESS); default: /* do nothing */ break; @@ -4836,7 +4836,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), @@ -4861,14 +4861,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"); @@ -4877,7 +4877,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" @@ -4888,10 +4888,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) @@ -4940,7 +4940,7 @@ int main_restore(int argc, char **argv) checkpoint_file = argv[optind + 1]; } else { help("restore"); - return 2; + return EXIT_FAILURE; } memset(&dom_info, 0, sizeof(dom_info)); @@ -4958,9 +4958,9 @@ int main_restore(int argc, char **argv) rc = create_domain(&dom_info); if (rc < 0) - return -rc; + return EXIT_FAILURE; - return 0; + return EXIT_SUCCESS; } int main_migrate_receive(int argc, char **argv) @@ -5000,13 +5000,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, script); - return 0; + return EXIT_SUCCESS; } int main_save(int argc, char **argv) @@ -5029,7 +5029,7 @@ int main_save(int argc, char **argv) if (argc-optind > 3) { help("save"); - return 2; + return EXIT_FAILURE; } domid = find_domain(argv[optind]); @@ -5038,7 +5038,7 @@ int main_save(int argc, char **argv) config_filename = argv[optind + 2]; save_domain(domid, filename, checkpoint, leavepaused, config_filename); - return 0; + return EXIT_SUCCESS; } int main_migrate(int argc, char **argv) @@ -5105,7 +5105,7 @@ int main_migrate(int argc, char **argv) } migrate_domain(domid, rune, debug, config_filename); - return 0; + return EXIT_SUCCESS; } #endif @@ -8756,7 +8756,7 @@ int main_remus(int argc, char **argv) send_fd = open("/dev/null", O_RDWR, 0644); if (send_fd < 0) { perror("failed to open /dev/null"); - exit(-1); + exit(EXIT_FAILURE); } } else { @@ -8783,7 +8783,7 @@ int main_remus(int argc, char **argv) if (!config_len) { fprintf(stderr, "No config file stored for running domain and " "none supplied - cannot start remus.\n"); - exit(1); + exit(EXIT_FAILURE); } child = create_migration_child(rune, &send_fd, &recv_fd); @@ -8805,7 +8805,7 @@ int main_remus(int argc, char **argv) fprintf(stderr, "%s: Primary domain has been destroyed.\n", libxl_defbool_val(r_info.colo) ? "COLO" : "Remus"); close(send_fd); - return 0; + return EXIT_SUCCESS; } /* If we are here, it means remus setup/domain suspend/backup has @@ -8821,7 +8821,7 @@ int main_remus(int argc, char **argv) } close(send_fd); - return -ERROR_FAIL; + return EXIT_FAILURE; } #endif