From: Harmandeep Kaur <write.harmandeep@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: lars.kurth@citrix.com, wei.liu2@citrix.com,
ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com,
dario.faggioli@citrix.com, ian.jackson@eu.citrix.com,
george.dunlap@citrix.com,
Harmandeep Kaur <write.harmandeep@gmail.com>
Subject: [PATCH v2 5/5] xl: improve return and exit codes of parse related functions
Date: Sat, 24 Oct 2015 11:01:36 +0530 [thread overview]
Message-ID: <1445664696-14258-6-git-send-email-write.harmandeep@gmail.com> (raw)
In-Reply-To: <1445664696-14258-1-git-send-email-write.harmandeep@gmail.com>
turning parsing related functions xl exit codes towards using the
EXIT_[SUCCESS|FAILURE] macros, instead of instead of arbitrary numbers
or libxl return codes.
it doesn't include parse_config_data() which is big enough to deserve its
own patch
Signed-off-by: Harmandeep Kaur <write.harmandeep@gmail.com>
---
tools/libxl/xl_cmdimpl.c | 71 ++++++++++++++++++++++--------------------------
1 file changed, 32 insertions(+), 39 deletions(-)
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 07b2bcd..f176689 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -578,10 +578,10 @@ static void parse_disk_config_multistring(XLU_Config **config,
}
e = xlu_disk_parse(*config, nspecs, specs, disk);
- if (e == EINVAL) exit(-1);
+ if (e == EINVAL) exit(EXIT_FAILURE);
if (e) {
fprintf(stderr,"xlu_disk_parse failed: %s\n",strerror(errno));
- exit(-1);
+ exit(EXIT_FAILURE);
}
}
@@ -600,7 +600,7 @@ static void parse_vif_rate(XLU_Config **config, const char *rate,
if (e == EINVAL || e == EOVERFLOW) exit(-1);
if (e) {
fprintf(stderr,"xlu_vif_parse_rate failed: %s\n",strerror(errno));
- exit(-1);
+ exit(EXIT_FAILURE);
}
}
@@ -741,19 +741,19 @@ static int parse_range(const char *str, unsigned long *a, unsigned long *b)
*a = *b = strtoul(str, &endptr, 10);
if (endptr == str || *a == ULONG_MAX)
- return ERROR_INVAL;
+ return 1;
if (*endptr == '-') {
nstr = endptr + 1;
*b = strtoul(nstr, &endptr, 10);
if (endptr == nstr || *b == ULONG_MAX || *b < *a)
- return ERROR_INVAL;
+ return 1;
}
/* Valid value or range so far, but we also don't want junk after that */
if (*endptr != '\0')
- return ERROR_INVAL;
+ return 1;
return 0;
}
@@ -841,17 +841,15 @@ static int update_cpumap_range(const char *str, libxl_bitmap *cpumap)
static int cpurange_parse(const char *cpu, libxl_bitmap *cpumap)
{
char *ptr, *saveptr = NULL, *buf = strdup(cpu);
- int rc = 0;
for (ptr = strtok_r(buf, ",", &saveptr); ptr;
ptr = strtok_r(NULL, ",", &saveptr)) {
- rc = update_cpumap_range(ptr, cpumap);
- if (rc)
+ if (update_cpumap_range(ptr, cpumap))
break;
}
free(buf);
- return rc;
+ return 0;
}
static void parse_top_level_vnc_options(XLU_Config *config,
@@ -902,7 +900,7 @@ static char *parse_cmdline(XLU_Config *config)
if ((buf || root || extra) && !cmdline) {
fprintf(stderr, "Failed to allocate memory for cmdline\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
return cmdline;
@@ -946,11 +944,11 @@ static void parse_vcpu_affinity(libxl_domain_build_info *b_info,
libxl_bitmap_init(&vcpu_affinity_array[j]);
if (libxl_cpu_bitmap_alloc(ctx, &vcpu_affinity_array[j], 0)) {
fprintf(stderr, "Unable to allocate cpumap for vcpu %d\n", j);
- exit(1);
+ exit(EXIT_FAILURE);
}
if (cpurange_parse(buf, &vcpu_affinity_array[j]))
- exit(1);
+ exit(EXIT_FAILURE);
j++;
}
@@ -963,17 +961,17 @@ static void parse_vcpu_affinity(libxl_domain_build_info *b_info,
libxl_bitmap_init(&vcpu_affinity_array[0]);
if (libxl_cpu_bitmap_alloc(ctx, &vcpu_affinity_array[0], 0)) {
fprintf(stderr, "Unable to allocate cpumap for vcpu 0\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
if (cpurange_parse(buf, &vcpu_affinity_array[0]))
- exit(1);
+ exit(EXIT_FAILURE);
for (i = 1; i < b_info->max_vcpus; i++) {
libxl_bitmap_init(&vcpu_affinity_array[i]);
if (libxl_cpu_bitmap_alloc(ctx, &vcpu_affinity_array[i], 0)) {
fprintf(stderr, "Unable to allocate cpumap for vcpu %d\n", i);
- exit(1);
+ exit(EXIT_FAILURE);
}
libxl_bitmap_copy(ctx, &vcpu_affinity_array[i],
&vcpu_affinity_array[0]);
@@ -1064,7 +1062,7 @@ static unsigned long parse_ulong(const char *str)
val = strtoul(str, &endptr, 10);
if (endptr == str || val == ULONG_MAX) {
fprintf(stderr, "xl: failed to convert \"%s\" to number\n", str);
- exit(1);
+ exit(EXIT_FAILURE);
}
return val;
}
@@ -1086,7 +1084,7 @@ static void parse_vnuma_config(const XLU_Config *config,
if (libxl_get_physinfo(ctx, &physinfo) != 0) {
libxl_physinfo_dispose(&physinfo);
fprintf(stderr, "libxl_get_physinfo failed\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
nr_nodes = physinfo.nr_nodes;
@@ -1105,7 +1103,7 @@ static void parse_vnuma_config(const XLU_Config *config,
libxl_bitmap_init(&vcpu_parsed[i]);
if (libxl_cpu_bitmap_alloc(ctx, &vcpu_parsed[i], b_info->max_vcpus)) {
fprintf(stderr, "libxl_node_bitmap_alloc failed.\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
}
@@ -1130,7 +1128,7 @@ static void parse_vnuma_config(const XLU_Config *config,
xlu_cfg_value_get_list(config, vnode_spec, &vnode_config_list, 0);
if (!vnode_config_list) {
fprintf(stderr, "xl: cannot get vnode config option list\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
for (conf_count = 0;
@@ -1152,7 +1150,7 @@ static void parse_vnuma_config(const XLU_Config *config,
&value_untrimmed)) {
fprintf(stderr, "xl: failed to split \"%s\" into pair\n",
buf);
- exit(1);
+ exit(EXIT_FAILURE);
}
trim(isspace, option_untrimmed, &option);
trim(isspace, value_untrimmed, &value);
@@ -1162,7 +1160,7 @@ static void parse_vnuma_config(const XLU_Config *config,
if (val >= nr_nodes) {
fprintf(stderr,
"xl: invalid pnode number: %lu\n", val);
- exit(1);
+ exit(EXIT_FAILURE);
}
p->pnode = val;
libxl_defbool_set(&b_info->numa_placement, false);
@@ -1218,20 +1216,20 @@ static void parse_vnuma_config(const XLU_Config *config,
if (b_info->max_vcpus != 0) {
if (b_info->max_vcpus != max_vcpus) {
fprintf(stderr, "xl: vnuma vcpus and maxvcpus= mismatch\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
} else {
int host_cpus = libxl_get_online_cpus(ctx);
if (host_cpus < 0) {
fprintf(stderr, "Failed to get online cpus\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
if (host_cpus < max_vcpus) {
fprintf(stderr, "xl: vnuma specifies more vcpus than pcpus, "\
"use maxvcpus= to override this check.\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
b_info->max_vcpus = max_vcpus;
@@ -1241,7 +1239,7 @@ static void parse_vnuma_config(const XLU_Config *config,
if (b_info->max_memkb != LIBXL_MEMKB_DEFAULT &&
b_info->max_memkb != max_memkb) {
fprintf(stderr, "xl: maxmem and vnuma memory size mismatch\n");
- exit(1);
+ exit(EXIT_FAILURE);
} else
b_info->max_memkb = max_memkb;
@@ -3126,7 +3124,7 @@ static int64_t parse_mem_size_kb(const char *mem)
kbytes = strtoll(mem, &endptr, 10);
if (strlen(endptr) > 1)
- return -1;
+ return 1;
switch (tolower((uint8_t)*endptr)) {
case 't':
@@ -3145,7 +3143,7 @@ static int64_t parse_mem_size_kb(const char *mem)
kbytes >>= 10;
break;
default:
- return -1;
+ return 1;
}
return kbytes;
@@ -3259,17 +3257,14 @@ 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) {
+ if (memorykb == 1) {
fprintf(stderr, "invalid memory size: %s\n", mem);
- exit(3);
+ exit(EXIT_FAILURE);
}
- rc = libxl_domain_setmaxmem(ctx, domid, memorykb);
-
- return rc;
+ return libxl_domain_setmaxmem(ctx, domid, memorykb);
}
int main_memmax(int argc, char **argv)
@@ -3277,7 +3272,6 @@ int main_memmax(int argc, char **argv)
uint32_t domid;
int opt = 0;
char *mem;
- int rc;
SWITCH_FOREACH_OPT(opt, "", NULL, "mem-max", 2) {
/* No options */
@@ -3286,8 +3280,7 @@ int main_memmax(int argc, char **argv)
domid = find_domain(argv[optind]);
mem = argv[optind + 1];
- rc = set_memory_max(domid, mem);
- if (rc) {
+ if (set_memory_max(domid, mem)){
fprintf(stderr, "cannot set domid %d static max memory to : %s\n", domid, mem);
return 1;
}
@@ -3300,9 +3293,9 @@ static void set_memory_target(uint32_t domid, const char *mem)
long long int memorykb;
memorykb = parse_mem_size_kb(mem);
- if (memorykb == -1) {
+ 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);
--
1.9.1
next prev parent reply other threads:[~2015-10-24 5:33 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-24 5:31 [PATCH v2 0/5] xl: convert exit codes to EXIT_[SUCCESS|FAILURE] Harmandeep Kaur
2015-10-24 5:31 ` [PATCH v2 1/5] " Harmandeep Kaur
2015-10-26 9:32 ` Dario Faggioli
2015-10-26 17:39 ` Wei Liu
2015-10-24 5:31 ` [PATCH v2 2/5] xl: improve return and exit codes of scheduling related functions Harmandeep Kaur
2015-10-26 9:56 ` Dario Faggioli
2015-10-24 5:31 ` [PATCH v2 3/5] xl: improve return and exit codes of vcpu " Harmandeep Kaur
2015-10-26 10:03 ` Dario Faggioli
2015-10-24 5:31 ` [PATCH v2 4/5] xl: improve return and exit codes of cpupool " Harmandeep Kaur
2015-10-26 10:06 ` Dario Faggioli
2015-10-24 5:31 ` Harmandeep Kaur [this message]
2015-10-26 10:34 ` [PATCH v2 5/5] xl: improve return and exit codes of parse " Dario Faggioli
2015-10-26 10:40 ` Dario Faggioli
2015-10-26 17:54 ` Wei Liu
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=1445664696-14258-6-git-send-email-write.harmandeep@gmail.com \
--to=write.harmandeep@gmail.com \
--cc=dario.faggioli@citrix.com \
--cc=george.dunlap@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=lars.kurth@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).