xl: Introduce shutdown xm compatibility option -a to shutdown all domains
PATCH 1/1 xl: Introduce shutdown xm compatibility option -a to shutdown all domains
docs/man/xl.pod.1 | 6 +++++- tools/libxl/xl_cmdimpl.c | 39 ++++++++++++++++++++++++++++++++++++--- tools/libxl/xl_cmdtable.c | 3 ++- 3 files changed, 43 insertions(+), 5 deletions(-)
xl: Introduce shutdown xm compatibility option -a to shutdown all domains
docs/man/xl.pod.1 +5 -1
@@ -527,7 +527,7 @@ List specifically for that domain. Other =back -=item B<shutdown> [I<OPTIONS>] I<domain-id> +=item B<shutdown> [I<OPTIONS>] [I<domain-id>] Gracefully shuts down a domain. This coordinates with the domain OS to perform graceful shutdown, so there is no guarantee that it will
@@ -550,6 +550,10 @@ B<OPTIONS> =over 4 +=item B<-a> + +-a Shutdown all domains. Often used when doing a complete shutdown of a Xen system. + =item B<-w> Wait for the domain to complete shutdown before returning.
tools/libxl/xl_cmdimpl.c +36 -3
@@ -3670,14 +3670,20 @@ int main_destroy(int argc, char **argv)int main_shutdown (int argc,char **argv) { -int opt; +libxl_dominfo *dominfo; +char *domname; +int opt, i, nb_domain; +int all =0 ;int wait =0 ;int fallback_trigger =0 ; -while ((opt =def_getopt (argc, argv,"wF" ,"shutdown" ,1 )) !=-1 ) { +while ((opt =def_getopt (argc, argv,"awF" ,"shutdown" ,0 )) !=-1 ) {switch (opt) {case 0 :case 2 :return opt; +case 'a' : + all =1 ; +break ;case 'w' : wait =1 ;break ;
@@ -3687,7 +3693,34 @@ int main_shutdown(int argc, char **argv) } } -shutdown_domain (argv[optind], wait, fallback_trigger); +if (!argv[optind] && !all) { +fprintf (stderr,"You must specify -a or a domain id.\n\n" ); +return opt; + } + +if (all) { +if (!(dominfo =libxl_list_domain (ctx, &nb_domain))) { +fprintf (stderr,"libxl_list_domain failed.\n" ); + goto main_shutdown_out; + } + +for (i =0 ; i<nb_domain; i++) { +if (dominfo[i].domid ==0 ) +continue ; + + domname =libxl_domid_to_name (ctx, dominfo[i].domid); +if (domname) +shutdown_domain (domname, wait, fallback_trigger); + +free (domname); + } + +libxl_dominfo_list_free (dominfo, nb_domain); + }else { +shutdown_domain (argv[optind], wait, fallback_trigger); + } + +main_shutdown_out:return 0 ; }
tools/libxl/xl_cmdtable.c +2 -1
@@ -60,7 +60,8 @@ struct cmd_spec cmd_table[] = { {"shutdown" , &main_shutdown,0 ,1 ,"Issue a shutdown signal to a domain" , -"[options] <Domain>" , +"[options] [Domain]" , +"-a Shutdown all domains.\n" "-h Print this help.\n" "-F Fallback to ACPI power event for HVM guests with\n" " no PV drivers.\n"
Quoted 9 lines · Sander Eikelenboom
docs/man/xl.pod.1 | 6 +++++-
tools/libxl/xl_cmdimpl.c | 39 ++++++++++++++++++++++++++++++++++++--- tools/libxl/xl_cmdtable.c | 3 ++- 3 files changed, 43 insertions(+), 5 deletions(-)xl: Introduce shutdown xm compatibility option -a to shutdown all domains
Signed-off-by Sander Eikelenboom <[email protected]>
Thanks Sander, however I'm afraid this comes too late for 4.2.0 (it was always going to be tight). We should take it for 4.2.1 though.
docs/man/xl.pod.1 List specifically for that domain. Other · line 530
Quoted 9 lines
diff -r
9dc729b75595-r67f9ef649937docs/man/xl.pod.1docs/man/xl.pod.1 +1
-1@@ -527,7 +527,7 @@ List specifically for that domain. Other =back -=item B<shutdown> [I<OPTIONS>] I<domain-id> +=item B<shutdown> [I<OPTIONS>] [I<domain-id>]
Perhaps write this as "I<-a|domain-id>" to make it clear one or the other is needed?
Quoted 43 lines
docs/man/xl.pod.1 +4
-0Gracefully shuts down a domain. This coordinates with the domain OS to perform graceful shutdown, so there is no guarantee that it will@@ -550,6 +550,10 @@ B<OPTIONS> =over 4 +=item B<-a> + +-a Shutdown all domains. Often used when doing a complete shutdown of a Xen system. + =item B<-w> Wait for the domain to complete shutdown before returning.diff -r
9dc729b75595-r67f9ef649937tools/libxl/xl_cmdimpl.ctools/libxl/xl_cmdimpl.c +8
-2@@ -3670,14 +3670,20 @@ int main_destroy(int argc, char **argv)int main_shutdown (int argc,char **argv) { -int opt; +libxl_dominfo *dominfo; +char *domname; +int opt, i, nb_domain; +int all =0 ;int wait =0 ;int fallback_trigger =0 ; -while ((opt =def_getopt (argc, argv,"wF" ,"shutdown" ,1 )) !=-1 ) { +while ((opt =def_getopt (argc, argv,"awF" ,"shutdown" ,0 )) !=-1 ) {switch (opt) {case 0 :case 2 :return opt; +case 'a' : + all =1 ; +break ;case 'w' : wait =1 ;break ;@@ -3687,7 +3693,34 @@ int main_shutdown(int argc, char **argv) } }
tools/libxl/xl_cmdimpl.c int main_shutdown(int argc, char **argv) · line 3704
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +9
-1-shutdown_domain (argv[optind], wait, fallback_trigger); +if (!argv[optind] && !all) { +fprintf (stderr,"You must specify -a or a domain id.\n\n" ); +return opt; + } + +if (all) { +if (!(dominfo =libxl_list_domain (ctx, &nb_domain))) { +fprintf (stderr,"libxl_list_domain failed.\n" ); + goto main_shutdown_out;
return -1 here, main_shutdown_out reurns 0 AKA success.
Quoted 7 lines
tools/libxl/xl_cmdimpl.c +7
-0+ } + +for (i =0 ; i<nb_domain; i++) { +if (dominfo[i].domid ==0 ) +continue ; + + domname =libxl_domid_to_name (ctx, dominfo[i].domid);
tools/libxl/xl_cmdimpl.c int main_shutdown(int argc, char **argv) · line 3721
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10
-0+if (domname) +shutdown_domain (domname, wait, fallback_trigger); + +free (domname); + } + +libxl_dominfo_list_free (dominfo, nb_domain); + }else { +shutdown_domain (argv[optind], wait, fallback_trigger); + }
Can you make shutdown_domain take a domid instead, which avoids the needless libxl_domid_to_name->libxl_name_to_domid laundering in the -a case.
Otherwise the patch looks good, thanks!
Thanks,
Ian.
Quoted 7 lines · you
Quoted 6 lines · Sander Eikelenboom
docs/man/xl.pod.1 | 6 +++++-
tools/libxl/xl_cmdimpl.c | 39 ++++++++++++++++++++++++++++++++++++--- tools/libxl/xl_cmdtable.c | 3 ++- 3 files changed, 43 insertions(+), 5 deletions(-)
Quoted 6 lines
Quoted 3 lines
xl: Introduce shutdown xm compatibility option -a to shutdown all domains
Signed-off-by Sander Eikelenboom <[email protected]>Thanks Sander, however I'm afraid this comes too late for 4.2.0 (it was always going to be tight). We should take it for 4.2.1 though.
Ok, although init.d/xendomains in combination with the default sysconfig-xendomains scripts use this (needs another patch to use the short -a instead of --all Will respin with the changes below !
Quoted 95 lines
docs/man/xl.pod.1 Thu Sep 06 12:04:12 2012 +0200 List specifically for that domain. Other · line 530
Quoted 9 lines
diff -r
9dc729b75595-r67f9ef649937docs/man/xl.pod.1docs/man/xl.pod.1 Thu Sep 06 12:04:12 2012 +0200 renamed from docs/man/xl.pod.1 Mon Sep 03 11:22:02 2012 +0100 +1
-1@@ -527,7 +527,7 @@ List specifically for that domain. Other =back -=item B<shutdown> [I<OPTIONS>] I<domain-id> +=item B<shutdown> [I<OPTIONS>] [I<domain-id>]Perhaps write this as "I<-a|domain-id>" to make it clear one or the other is needed?
Quoted 43 lines
docs/man/xl.pod.1 Thu Sep 06 12:04:12 2012 +0200 renamed from docs/man/xl.pod.1 Mon Sep 03 11:22:02 2012 +0100 +4
-0Gracefully shuts down a domain. This coordinates with the domain OS to perform graceful shutdown, so there is no guarantee that it will@@ -550,6 +550,10 @@ B<OPTIONS> =over 4 +=item B<-a> + +-a Shutdown all domains. Often used when doing a complete shutdown of a Xen system. + =item B<-w> Wait for the domain to complete shutdown before returning.diff -r
9dc729b75595-r67f9ef649937tools/libxl/xl_cmdimpl.ctools/libxl/xl_cmdimpl.c Thu Sep 06 12:04:12 2012 +0200 renamed from tools/libxl/xl_cmdimpl.c Mon Sep 03 11:22:02 2012 +0100 +8
-2@@ -3670,14 +3670,20 @@ int main_destroy(int argc, char **argv) int main_shutdown(int argc, char **argv) { - int opt; + libxl_dominfo *dominfo; + char *domname; + int opt, i, nb_domain; + int all = 0; int wait = 0; int fallback_trigger = 0; - while ((opt = def_getopt(argc, argv, "wF", "shutdown", 1)) != -1) { + while ((opt = def_getopt(argc, argv, "awF", "shutdown", 0)) != -1) { switch (opt) { case 0: case 2: return opt; + case 'a': + all = 1; + break; case 'w': wait = 1; break;@@ -3687,7 +3693,34 @@ int main_shutdown(int argc, char **argv) } }tools/libxl/xl_cmdimpl.c Thu Sep 06 12:04:12 2012 +0200 int main_shutdown(int argc, char **argv) · line 3704
Quoted 10 lines
tools/libxl/xl_cmdimpl.c Thu Sep 06 12:04:12 2012 +0200 renamed from tools/libxl/xl_cmdimpl.c Mon Sep 03 11:22:02 2012 +0100 +9
-1- shutdown_domain(argv[optind], wait, fallback_trigger); + if (!argv[optind] && !all) { + fprintf(stderr, "You must specify -a or a domain id.\n\n"); + return opt; + } + + if (all) { + if (!(dominfo = libxl_list_domain(ctx, &nb_domain))) { + fprintf(stderr, "libxl_list_domain failed.\n"); + goto main_shutdown_out;return -1 here,
main_shutdown_outreurns 0 AKA success.Quoted 7 lines
tools/libxl/xl_cmdimpl.c Thu Sep 06 12:04:12 2012 +0200 renamed from tools/libxl/xl_cmdimpl.c Mon Sep 03 11:22:02 2012 +0100 +7
-0+ } + + for (i = 0; i<nb_domain; i++) { + if (dominfo[i].domid == 0) + continue; + + domname = libxl_domid_to_name(ctx, dominfo[i].domid);tools/libxl/xl_cmdimpl.c Thu Sep 06 12:04:12 2012 +0200 int main_shutdown(int argc, char **argv) · line 3721
Quoted 10 lines
tools/libxl/xl_cmdimpl.c Thu Sep 06 12:04:12 2012 +0200 renamed from tools/libxl/xl_cmdimpl.c Mon Sep 03 11:22:02 2012 +0100 +10
-0+ if (domname) + shutdown_domain(domname, wait, fallback_trigger); + + free(domname); + } + + libxl_dominfo_list_free(dominfo, nb_domain); + } else { + shutdown_domain(argv[optind], wait, fallback_trigger); + }Can you make
shutdown_domaintake a domid instead, which avoids the needlesslibxl_domid_to_name->libxl_name_to_domidlaundering in the -a case.Otherwise the patch looks good, thanks!
Thanks,
Ian.