]> xenbits.xensource.com Git - people/hx242/xen.git/commitdiff
xl: Allow shutdown wait for domain death
authorJason Andryuk <jandryuk@gmail.com>
Wed, 17 Jun 2020 02:36:42 +0000 (03:36 +0100)
committerIan Jackson <ian.jackson@eu.citrix.com>
Thu, 18 Jun 2020 15:58:56 +0000 (16:58 +0100)
`xl shutdown -w` waits for the first of either domain shutdown or death.
Shutdown is the halting of the guest operating system, and death is the
freeing of domain resources.

Allow specifying -w multiple times to wait for only domain death.  This
is useful in scripts so that all resources are free before the script
continues.

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
Reviewed-by: Ian Jackson <ian.jackson@eu.citrix.com>
Release-acked-by: Paul Durrant <paul@xen.org>
docs/man/xl.1.pod.in
tools/xl/xl_vmcontrol.c

index 09339282e6bd6809fe135d7200197e90432024af..52a47a6fbd3d18bcb3873c115200f08c052049ca 100644 (file)
@@ -743,7 +743,9 @@ of a Xen system.
 
 =item B<-w>, B<--wait>
 
-Wait for the domain to complete shutdown before returning.
+Wait for the domain to complete shutdown before returning.  If given once,
+the wait is for domain shutdown or domain death.  If given multiple times,
+the wait is for domain death only.
 
 =item B<-F>
 
index 17b4514c94301038c7178ce25a595304cb8de82e..435155a03396b4c75d3c48a0c02d49c2505c759d 100644 (file)
@@ -162,7 +162,8 @@ static void shutdown_domain(uint32_t domid,
     }
 }
 
-static void wait_for_domain_deaths(libxl_evgen_domain_death **deathws, int nr)
+static void wait_for_domain_deaths(libxl_evgen_domain_death **deathws, int nr,
+                                   int wait_for_shutdown_or_death)
 {
     int rc, count = 0;
     LOG("Waiting for %d domains", nr);
@@ -183,8 +184,12 @@ static void wait_for_domain_deaths(libxl_evgen_domain_death **deathws, int nr)
         case LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN:
             LOG("Domain %d has been shut down, reason code %d",
                 event->domid, event->u.domain_shutdown.shutdown_reason);
-            libxl_evdisable_domain_death(ctx, deathws[event->for_user]);
-            count++;
+            if (wait_for_shutdown_or_death) {
+                libxl_evdisable_domain_death(ctx, deathws[event->for_user]);
+                count++;
+            } else {
+                LOG("Domain %d continue waiting for death", event->domid);
+            }
             break;
         default:
             LOG("Unexpected event type %d", event->type);
@@ -214,7 +219,7 @@ static int main_shutdown_or_reboot(int do_reboot, int argc, char **argv)
         all = 1;
         break;
     case 'w':
-        wait_for_it = 1;
+        wait_for_it++;
         break;
     case 'F':
         fallback_trigger = 1;
@@ -246,7 +251,7 @@ static int main_shutdown_or_reboot(int do_reboot, int argc, char **argv)
         }
 
         if (deathws) {
-            wait_for_domain_deaths(deathws, nrdeathws);
+            wait_for_domain_deaths(deathws, nrdeathws, wait_for_it == 1);
             free(deathws);
         }
 
@@ -258,7 +263,7 @@ static int main_shutdown_or_reboot(int do_reboot, int argc, char **argv)
         fn(domid, wait_for_it ? &deathw : NULL, 0, fallback_trigger);
 
         if (wait_for_it)
-            wait_for_domain_deaths(&deathw, 1);
+            wait_for_domain_deaths(&deathw, 1, wait_for_it == 1);
     }