From: Harmandeep Kaur <write.harmandeep@gmail.com>
To: xen-devel@lists.xenproject.org
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 <write.harmandeep@gmail.com>
Subject: [PATCH 1/9 v2] xl: Improve return and exit codes of memory related functions.
Date: Wed, 9 Mar 2016 00:32:02 +0530 [thread overview]
Message-ID: <1457463730-4712-2-git-send-email-write.harmandeep@gmail.com> (raw)
In-Reply-To: <1457463730-4712-1-git-send-email-write.harmandeep@gmail.com>
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 <write.harmandeep@gmail.com>
---
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,
--
2.5.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-03-08 19:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-08 19:02 [PATCH 0/9 v2] xl: convert exit codes related to domain subcommands to EXIT_[SUCCESS|FAILURE] Harmandeep Kaur
2016-03-08 19:02 ` Harmandeep Kaur [this message]
2016-03-08 19:02 ` [PATCH 2/9 v2] xl: Improve return and exit codes of restore and save related functions Harmandeep Kaur
2016-03-08 19:02 ` [PATCH 3/9 v2] xl: Improve return and exit codes of migrate " Harmandeep Kaur
2016-03-08 19:02 ` [PATCH 4/9 v2] xl: Improve return and exit codes of console, vnc and core dump " Harmandeep Kaur
2016-03-08 19:02 ` [PATCH 5/9 v2] xl: Improve return and exit codes of pause, destroy and shutdown " Harmandeep Kaur
2016-03-08 19:02 ` [PATCH 6/9 v2] xl: Improve return and exit codes of list " Harmandeep Kaur
2016-03-08 19:02 ` [PATCH 7/9 v2] xl: Improve return and exit codes of create, config_update and rename " Harmandeep Kaur
2016-03-08 19:02 ` [PATCH 8/9 v2] xl : Improve return and exit codes debugging, special keys and triggering " Harmandeep Kaur
2016-03-08 19:02 ` [PATCH 9/9 v2] xl: Improve return and exit codes of domain id and name " Harmandeep Kaur
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457463730-4712-2-git-send-email-write.harmandeep@gmail.com \
--to=write.harmandeep@gmail.com \
--cc=dario.faggioli@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).