From patchwork Tue Mar 8 19:02:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harmandeep Kaur X-Patchwork-Id: 8536801 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 9EBB99F372 for ; Tue, 8 Mar 2016 19:05:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B1DE22017D for ; Tue, 8 Mar 2016 19:05:32 +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 CCEFB20155 for ; Tue, 8 Mar 2016 19:05:30 +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 1adMtx-0000ma-Tq; Tue, 08 Mar 2016 19:02:37 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1adMtw-0000mS-QW for xen-devel@lists.xenproject.org; Tue, 08 Mar 2016 19:02:36 +0000 Received: from [85.158.137.68] by server-17.bemta-3.messagelabs.com id 2C/00-03109-CC12FD65; Tue, 08 Mar 2016 19:02:36 +0000 X-Env-Sender: write.harmandeep@gmail.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1457463755!18158231!1 X-Originating-IP: [74.125.82.67] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 47452 invoked from network); 8 Mar 2016 19:02:35 -0000 Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by server-4.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 8 Mar 2016 19:02:35 -0000 Received: by mail-wm0-f67.google.com with SMTP id 1so5907092wmg.2 for ; Tue, 08 Mar 2016 11:02:35 -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=kHIoegm+IWA6iWE7R/L8HG2xm9FzNaVawPxNvfo+PJY=; b=Fo7ncAM78jgkQuRLa4qPYC6mPN6gdOjFrQ6OunC45bBpB95WGpnp4ox5MpwAulE6Hr TUSj4JuvST9lKdyXi7J9okqFchi3577pGP1N6n62lUwpVyJyOHJXGog7FGNJDGS55KkC pCslcDM0oyktuBbXyBThgK+GR2SMPBjDVPZedq/JH9Ay/j9YKzp6sg0Ndajt03Me4/NT dhTBQF3KQ445oSMge/AOz1vtXWQd/dTehUNvvaY9ulrnV8wX+XaWUoG685Smds1Um25y eLgSEkfbpkDMdjYc9Q3ZiASsUAmibYHaBEg6MFktg1QQzl0/sHkUnp8HC2MBoyyjZqiE NFjA== 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=kHIoegm+IWA6iWE7R/L8HG2xm9FzNaVawPxNvfo+PJY=; b=AvrJdgAEyT0x6YUlVUZl3leL0V7pjvuBZoYF4vtJO2/ryeA21GXuPI+Qj2U4lzaL4B AbdkfvF7rJ2GUsH2yTUWMw0sYJEbZ8MoO3eBSfwhYwAv/gcsZGXP9/2yPUvPvkaJjE0C eNGTuXm/iDJ1aMc8/+/boCHVrCKw76sP2+4E2/bjI5q+jUS4O/itwFdGbbLgAuy7JpJM FQsDIRU7Dvjg99+otRAfN8qd8rwyZ9UHy+GW3Dak/7eBO1eRhmcbZcYGQMe1nmHoGfe9 V56USNAA9Ft7L6a7prZm6/jvURWHkGCkfkRPnpYjC2e8TlPSK0vVMsjFruTbtj7n0ZLC ByEg== X-Gm-Message-State: AD7BkJJU5u88hNYPfVyxLMOFhswUAxPTYAZXmAs8zc08Ldt4ImdmXqcXG72DNPeFhEffng== X-Received: by 10.28.148.8 with SMTP id w8mr5003867wmd.90.1457463755279; Tue, 08 Mar 2016 11:02:35 -0800 (PST) Received: from localhost.localdomain ([124.253.57.150]) by smtp.googlemail.com with ESMTPSA id hu1sm4310795wjb.36.2016.03.08.11.02.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Mar 2016 11:02:34 -0800 (PST) From: Harmandeep Kaur To: xen-devel@lists.xenproject.org Date: Wed, 9 Mar 2016 00:32:02 +0530 Message-Id: <1457463730-4712-2-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 1/9 v2] xl: Improve return and exit codes of memory 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 Return and exit codes of freemem(), set_memory_max(), main_memmax(), set_memory_target(), main_memset() and main_sharing() in the file xl_cmdimpl are fixed. Add comment to explain return vaule of parse_mem_size_kb(). Signed-off-by: Harmandeep Kaur --- v2: Add comment to explain return vaule of parse_mem_size_kb(). Add freemem() and main_sharing(). Remove find_domain(). --- tools/libxl/xl_cmdimpl.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 990d3c9..088971e 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -2581,30 +2581,30 @@ static int freemem(uint32_t domid, libxl_domain_build_info *b_info) rc = libxl_domain_need_memory(ctx, b_info, &need_memkb); if (rc < 0) - return rc; + return -1; do { rc = libxl_get_free_memory(ctx, &free_memkb); if (rc < 0) - return rc; + return -1; if (free_memkb >= need_memkb) return 0; rc = libxl_set_memory_target(ctx, 0, free_memkb - need_memkb, 1, 0); if (rc < 0) - return rc; + return -1; /* wait until dom0 reaches its target, as long as we are making * progress */ rc = libxl_wait_for_memory_target(ctx, 0, 10); if (rc < 0) - return rc; + return -1; retries--; } while (retries > 0); - return ERROR_NOMEM; + return -1; } static void autoconnect_console(libxl_ctx *ctx_ignored, @@ -3133,6 +3133,10 @@ void help(const char *command) } } +/* + * parse_mem_size_kb() returns -1 on failure, or the amount of memory, + * on success. + */ static int64_t parse_mem_size_kb(const char *mem) { char *endptr; @@ -3275,17 +3279,17 @@ static int def_getopt(int argc, char * const argv[], static int set_memory_max(uint32_t domid, const char *mem) { int64_t memorykb; - int rc; memorykb = parse_mem_size_kb(mem); if (memorykb == -1) { fprintf(stderr, "invalid memory size: %s\n", mem); - exit(3); + exit(EXIT_FAILURE); } - rc = libxl_domain_setmaxmem(ctx, domid, memorykb); + if (libxl_domain_setmaxmem(ctx, domid, memorykb)) + return 1; - return rc; + return 0; } int main_memmax(int argc, char **argv) @@ -3305,10 +3309,10 @@ int main_memmax(int argc, char **argv) rc = set_memory_max(domid, mem); if (rc) { fprintf(stderr, "cannot set domid %d static max memory to : %s\n", domid, mem); - return 1; + return EXIT_FAILURE; } - return 0; + return EXIT_SUCCESS; } static void set_memory_target(uint32_t domid, const char *mem) @@ -3318,7 +3322,7 @@ static void set_memory_target(uint32_t domid, const char *mem) memorykb = parse_mem_size_kb(mem); if (memorykb == -1) { fprintf(stderr, "invalid memory size: %s\n", mem); - exit(3); + exit(EXIT_FAILURE); } libxl_set_memory_target(ctx, domid, memorykb, 0, /* enforce */ 1); @@ -3338,7 +3342,7 @@ int main_memset(int argc, char **argv) mem = argv[optind + 1]; set_memory_target(domid, mem); - return 0; + return EXIT_SUCCESS; } static int cd_insert(uint32_t domid, const char *virtdev, char *phys) @@ -5783,7 +5787,7 @@ int main_sharing(int argc, char **argv) info = libxl_list_domain(ctx, &nb_domain); if (!info) { fprintf(stderr, "libxl_list_domain failed.\n"); - return 1; + return EXIT_FAILURE; } info_free = info; } else if (optind == argc-1) { @@ -5792,17 +5796,17 @@ int main_sharing(int argc, char **argv) if (rc == ERROR_DOMAIN_NOTFOUND) { fprintf(stderr, "Error: Domain \'%s\' does not exist.\n", argv[optind]); - return -rc; + return EXIT_FAILURE; } if (rc) { fprintf(stderr, "libxl_domain_info failed (code %d).\n", rc); - return -rc; + return EXIT_FAILURE; } info = &info_buf; nb_domain = 1; } else { help("sharing"); - return 2; + return EXIT_FAILURE; } sharing(info, nb_domain); @@ -5812,7 +5816,7 @@ int main_sharing(int argc, char **argv) else libxl_dominfo_dispose(info); - return 0; + return EXIT_SUCCESS; } static int sched_domain_get(libxl_scheduler sched, int domid,