aboutsummaryrefslogtreecommitdiffstats
path: root/tools/misc/xen-hptool.c
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2010-05-19 14:18:56 +0100
committerKeir Fraser <keir.fraser@citrix.com>2010-05-19 14:18:56 +0100
commit785effb80af31f3e23985abd2e70efe6fbb4c4b8 (patch)
treecc512dfc5c47d79c80ae7df9f390c4408c6ed534 /tools/misc/xen-hptool.c
parent000026edbf0f117efaaa722ed6c3912aacfa30cc (diff)
downloadxen-785effb80af31f3e23985abd2e70efe6fbb4c4b8.tar.gz
xen-785effb80af31f3e23985abd2e70efe6fbb4c4b8.tar.bz2
xen-785effb80af31f3e23985abd2e70efe6fbb4c4b8.zip
xen-hptool: A few usage cleanups.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
Diffstat (limited to 'tools/misc/xen-hptool.c')
-rw-r--r--tools/misc/xen-hptool.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/tools/misc/xen-hptool.c b/tools/misc/xen-hptool.c
index a9d6780016..7c2bf4acc6 100644
--- a/tools/misc/xen-hptool.c
+++ b/tools/misc/xen-hptool.c
@@ -1,23 +1,24 @@
#include <xenctrl.h>
#include <xc_private.h>
#include <xc_core.h>
+#include <errno.h>
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
static int xc_fd;
-/* help message */
void show_help(void)
{
fprintf(stderr,
- "\nxen cpu memory hotplug tool\n\n"
- "usage: xen-hptool <command> [args]\n\n"
- "xen-hptool command list:\n\n"
- "cpu-online <cpuid> online CPU <cpuid>\n"
- "cpu-offline <cpuid> offline CPU <cpuid>\n"
- "mem-online <mfn> online MEMORY <mfn>\n"
- "mem-offline <mfn> offline MEMORY <mfn>\n"
- "mem-status <mfn> query Memory status<mfn>\n"
+ "xen-hptool: Xen CPU/memory hotplug tool\n"
+ "Usage: xen-hptool <command> [args]\n"
+ "Commands:\n"
+ " help display this help\n"
+ " cpu-online <cpuid> online CPU <cpuid>\n"
+ " cpu-offline <cpuid> offline CPU <cpuid>\n"
+ " mem-online <mfn> online MEMORY <mfn>\n"
+ " mem-offline <mfn> offline MEMORY <mfn>\n"
+ " mem-status <mfn> query Memory status<mfn>\n"
);
}
@@ -244,7 +245,7 @@ static int hp_cpu_online_func(int argc, char *argv[])
{
int cpu, ret;
- if (argc != 1)
+ if ( argc != 1 )
{
show_help();
return -1;
@@ -254,7 +255,8 @@ static int hp_cpu_online_func(int argc, char *argv[])
printf("Prepare to online CPU %d\n", cpu);
ret = xc_cpu_online(xc_fd, cpu);
if (ret < 0)
- fprintf(stderr, "CPU %d onlined failed\n", cpu);
+ fprintf(stderr, "CPU %d online failed (error %d: %s)\n",
+ cpu, errno, strerror(errno));
else
printf("CPU %d onlined successfully\n", cpu);
@@ -265,7 +267,7 @@ static int hp_cpu_offline_func(int argc, char *argv[])
{
int cpu, ret;
- if (argc !=1)
+ if (argc != 1 )
{
show_help();
return -1;
@@ -274,7 +276,8 @@ static int hp_cpu_offline_func(int argc, char *argv[])
printf("Prepare to offline CPU %d\n", cpu);
ret = xc_cpu_offline(xc_fd, cpu);
if (ret < 0)
- fprintf(stderr, "CPU %d offlined failed\n", cpu);
+ fprintf(stderr, "CPU %d offline failed (error %d: %s)\n",
+ cpu, errno, strerror(errno));
else
printf("CPU %d offlined successfully\n", cpu);
@@ -297,6 +300,7 @@ struct {
int main(int argc, char *argv[])
{
int i, ret;
+
if (argc < 2)
{
show_help();
@@ -310,20 +314,19 @@ int main(int argc, char *argv[])
return 0;
}
- for (i = 0; i < ARRAY_SIZE(main_options); i++)
- {
+ for ( i = 0; i < ARRAY_SIZE(main_options); i++ )
if (!strncmp(main_options[i].name, argv[1], strlen(argv[1])))
- {
- ret = main_options[i].function(argc -2, argv + 2);
break;
- }
+ if ( i == ARRAY_SIZE(main_options) )
+ {
+ fprintf(stderr, "Unrecognised command '%s' -- try "
+ "'xen-hptool help'\n", argv[1]);
+ return 1;
}
- if (i >= ARRAY_SIZE(main_options))
- show_help();
- else if (ret < 0)
- fprintf(stderr, "Required Ops failed\n");
+
+ ret = main_options[i].function(argc -2, argv + 2);
xc_interface_close(xc_fd);
- return 0;
+ return !!ret;
}