All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH]xl: Add "xl shutdown" command
@ 2010-05-18  7:03 Yang Hongyang
  2010-05-18  8:22 ` Yang Hongyang
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Hongyang @ 2010-05-18  7:03 UTC (permalink / raw)
  To: xen-devel@lists.xensource.com

Add "xl shutdown" command.

Signed-off-by: Yang Hongyang<yanghy@cn.fujitsu.com> 

diff -r baccadfd9418 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri May 14 08:05:05 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Tue May 18 22:47:32 2010 +0800
@@ -3667,3 +3667,66 @@
 
     exit(0);
 }
+
+int main_shutdown(int argc, char **argv)
+{
+    int all = 0, reboot = 0, halt = 0, action = 0/*default action is poweroff*/;
+    struct libxl_vminfo *info;
+    char *dom = NULL;
+    int nb_vm = 0;
+    int opt, i;
+
+    while ((opt = getopt(argc, argv, "haRH")) != -1) {
+        switch (opt) {
+        case 'a':
+            all = 1;
+            break;
+        case 'R':
+            reboot = 1;
+            break;
+        case 'H':
+            halt = 1;
+            break;
+        case 'h':
+            help("shutdown");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    if (reboot && halt) {
+        fprintf(stderr, "Reboot and Halt can not be specified together.\n\n");
+        help("shutdown");
+        exit(1);
+    }
+
+    dom = argv[optind];
+    if (!dom && all == 0) {
+        fprintf(stderr, "You must specify -a or a domain id.\n\n");
+        help("shutdown");
+        exit(1);
+    }
+
+    if (reboot)
+        action = 1;
+    else if (halt)
+        action = 4;
+
+    if (all) {
+        info = libxl_list_vm(&ctx, &nb_vm);
+        for (i = 0; i < nb_vm; i++)
+            libxl_domain_shutdown(&ctx, info[i].domid, action);
+    } else {
+        find_domain(dom);
+        if (domid == 0) {
+            fprintf(stderr, "Domain 0 cannot be shutdown.\n\n");
+            exit(1);
+        }
+        libxl_domain_shutdown(&ctx, domid, action);
+    }
+
+    exit(0);
+}
+
diff -r baccadfd9418 tools/libxl/xl_cmdimpl.h
--- a/tools/libxl/xl_cmdimpl.h	Fri May 14 08:05:05 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.h	Tue May 18 22:47:32 2010 +0800
@@ -52,6 +52,7 @@
 int main_blocklist(int argc, char **argv);
 int main_blockdetach(int argc, char **argv);
 int main_uptime(int argc, char **argv);
+int main_shutdown(int argc, char **argv);
 
 void help(char *command);
 
diff -r baccadfd9418 tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c	Fri May 14 08:05:05 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c	Tue May 18 22:47:32 2010 +0800
@@ -224,6 +224,14 @@
       "Print uptime for all/some domains",
       "[-s] [Domain]",
     },
+    { "shutdown",
+      &main_shutdown,
+      "Shutdown a domain",
+      "<Domain> [-aRH]",
+      "-a  Shutdown all VMs.\n"
+      "-R  Shutdown and reboot.\n"
+      "-H  Shutdown without reboot(halt).\n"
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);

-- 
Regards
Yang Hongyang

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH]xl: Add "xl shutdown" command
  2010-05-18  7:03 [PATCH]xl: Add "xl shutdown" command Yang Hongyang
@ 2010-05-18  8:22 ` Yang Hongyang
  0 siblings, 0 replies; 2+ messages in thread
From: Yang Hongyang @ 2010-05-18  8:22 UTC (permalink / raw)
  To: xen-devel@lists.xensource.com

I notice that someone else has already implenmentd the command,

Please ingnore this patch.

On 05/18/2010 03:03 PM, Yang Hongyang wrote:
> Add "xl shutdown" command.
> 
> Signed-off-by: Yang Hongyang<yanghy@cn.fujitsu.com> 
> 
> diff -r baccadfd9418 tools/libxl/xl_cmdimpl.c
> --- a/tools/libxl/xl_cmdimpl.c	Fri May 14 08:05:05 2010 +0100
> +++ b/tools/libxl/xl_cmdimpl.c	Tue May 18 22:47:32 2010 +0800
> @@ -3667,3 +3667,66 @@
>  
>      exit(0);
>  }
> +
> +int main_shutdown(int argc, char **argv)
> +{
> +    int all = 0, reboot = 0, halt = 0, action = 0/*default action is poweroff*/;
> +    struct libxl_vminfo *info;
> +    char *dom = NULL;
> +    int nb_vm = 0;
> +    int opt, i;
> +
> +    while ((opt = getopt(argc, argv, "haRH")) != -1) {
> +        switch (opt) {
> +        case 'a':
> +            all = 1;
> +            break;
> +        case 'R':
> +            reboot = 1;
> +            break;
> +        case 'H':
> +            halt = 1;
> +            break;
> +        case 'h':
> +            help("shutdown");
> +            exit(0);
> +        default:
> +            fprintf(stderr, "option `%c' not supported.\n", opt);
> +            break;
> +        }
> +    }
> +
> +    if (reboot && halt) {
> +        fprintf(stderr, "Reboot and Halt can not be specified together.\n\n");
> +        help("shutdown");
> +        exit(1);
> +    }
> +
> +    dom = argv[optind];
> +    if (!dom && all == 0) {
> +        fprintf(stderr, "You must specify -a or a domain id.\n\n");
> +        help("shutdown");
> +        exit(1);
> +    }
> +
> +    if (reboot)
> +        action = 1;
> +    else if (halt)
> +        action = 4;
> +
> +    if (all) {
> +        info = libxl_list_vm(&ctx, &nb_vm);
> +        for (i = 0; i < nb_vm; i++)
> +            libxl_domain_shutdown(&ctx, info[i].domid, action);
> +    } else {
> +        find_domain(dom);
> +        if (domid == 0) {
> +            fprintf(stderr, "Domain 0 cannot be shutdown.\n\n");
> +            exit(1);
> +        }
> +        libxl_domain_shutdown(&ctx, domid, action);
> +    }
> +
> +    exit(0);
> +}
> +
> diff -r baccadfd9418 tools/libxl/xl_cmdimpl.h
> --- a/tools/libxl/xl_cmdimpl.h	Fri May 14 08:05:05 2010 +0100
> +++ b/tools/libxl/xl_cmdimpl.h	Tue May 18 22:47:32 2010 +0800
> @@ -52,6 +52,7 @@
>  int main_blocklist(int argc, char **argv);
>  int main_blockdetach(int argc, char **argv);
>  int main_uptime(int argc, char **argv);
> +int main_shutdown(int argc, char **argv);
>  
>  void help(char *command);
>  
> diff -r baccadfd9418 tools/libxl/xl_cmdtable.c
> --- a/tools/libxl/xl_cmdtable.c	Fri May 14 08:05:05 2010 +0100
> +++ b/tools/libxl/xl_cmdtable.c	Tue May 18 22:47:32 2010 +0800
> @@ -224,6 +224,14 @@
>        "Print uptime for all/some domains",
>        "[-s] [Domain]",
>      },
> +    { "shutdown",
> +      &main_shutdown,
> +      "Shutdown a domain",
> +      "<Domain> [-aRH]",
> +      "-a  Shutdown all VMs.\n"
> +      "-R  Shutdown and reboot.\n"
> +      "-H  Shutdown without reboot(halt).\n"
> +    },
>  };
>  
>  int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
> 


-- 
Regards
Yang Hongyang

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-05-18  8:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-18  7:03 [PATCH]xl: Add "xl shutdown" command Yang Hongyang
2010-05-18  8:22 ` Yang Hongyang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.