# HG changeset patch # User Tim Deegan # Date 1275473721 -3600 # Node ID ba22297b00514325fef3673f3184eca466bd6990 # Parent a3bdee5a20daf590ae7a440dad4e3b104b99c620 Allow domains to set a shutdown code without actually shutting down. Useful for Windows guests, since the PV drivers are notified that the domain is about to crash just before the crash dump gets written. Signed-off-by: Tim Deegan diff -r a3bdee5a20da -r ba22297b0051 xen/common/domain.c --- a/xen/common/domain.c Wed Jun 02 10:54:32 2010 +0100 +++ b/xen/common/domain.c Wed Jun 02 11:15:21 2010 +0100 @@ -485,10 +485,21 @@ { struct vcpu *v; + spin_lock(&d->shutdown_lock); + if ( !d->has_shutdown_code ) + { + d->shutdown_code = reason; + d->has_shutdown_code = 1; + } + else + reason = d->shutdown_code; + if ( d->domain_id == 0 ) + { + spin_unlock(&d->shutdown_lock); dom0_shutdown(reason); - - spin_lock(&d->shutdown_lock); + spin_lock(&d->shutdown_lock); + } if ( d->is_shutting_down ) { @@ -497,7 +508,6 @@ } d->is_shutting_down = 1; - d->shutdown_code = reason; smp_mb(); /* set shutdown status /then/ check for per-cpu deferrals */ @@ -529,6 +539,7 @@ spin_lock(&d->shutdown_lock); d->is_shutting_down = d->is_shut_down = 0; + d->shutdown_code = d->has_shutdown_code = 0; for_each_vcpu ( d, v ) { diff -r a3bdee5a20da -r ba22297b0051 xen/common/schedule.c --- a/xen/common/schedule.c Wed Jun 02 10:54:32 2010 +0100 +++ b/xen/common/schedule.c Wed Jun 02 11:15:21 2010 +0100 @@ -716,6 +716,29 @@ break; } + case SCHEDOP_shutdown_code: + { + struct sched_shutdown sched_shutdown; + + ret = -EFAULT; + if ( copy_from_guest(&sched_shutdown, arg, 1) ) + break; + + ret = 0; + TRACE_3D(TRC_SCHED_SHUTDOWN_CODE, + current->domain->domain_id, current->vcpu_id, + sched_shutdown.reason); + spin_lock(¤t->domain->shutdown_lock); + if ( !current->domain->has_shutdown_code ) + { + current->domain->shutdown_code = (u8)sched_shutdown.reason; + current->domain->has_shutdown_code = 1; + } + spin_unlock(¤t->domain->shutdown_lock); + + break; + } + case SCHEDOP_poll: { struct sched_poll sched_poll; diff -r a3bdee5a20da -r ba22297b0051 xen/include/public/sched.h --- a/xen/include/public/sched.h Wed Jun 02 10:54:32 2010 +0100 +++ b/xen/include/public/sched.h Wed Jun 02 11:15:21 2010 +0100 @@ -99,6 +99,13 @@ DEFINE_XEN_GUEST_HANDLE(sched_remote_shutdown_t); /* + * Latch a shutdown code, so that when the domain later shuts down it + * reports this code to the control tools. + * @arg == as for SCHEDOP_shutdown. + */ +#define SCHEDOP_shutdown_code 5 + +/* * Reason codes for SCHEDOP_shutdown. These may be interpreted by control * software to determine the appropriate action. For the most part, Xen does * not care about the shutdown code. diff -r a3bdee5a20da -r ba22297b0051 xen/include/public/trace.h --- a/xen/include/public/trace.h Wed Jun 02 10:54:32 2010 +0100 +++ b/xen/include/public/trace.h Wed Jun 02 11:15:21 2010 +0100 @@ -79,6 +79,7 @@ #define TRC_SCHED_DOM_TIMER_FN (TRC_SCHED_VERBOSE + 13) #define TRC_SCHED_SWITCH_INFPREV (TRC_SCHED_VERBOSE + 14) #define TRC_SCHED_SWITCH_INFNEXT (TRC_SCHED_VERBOSE + 15) +#define TRC_SCHED_SHUTDOWN_CODE (TRC_SCHED_VERBOSE + 16) #define TRC_MEM_PAGE_GRANT_MAP (TRC_MEM + 1) #define TRC_MEM_PAGE_GRANT_UNMAP (TRC_MEM + 2) diff -r a3bdee5a20da -r ba22297b0051 xen/include/xen/sched.h --- a/xen/include/xen/sched.h Wed Jun 02 10:54:32 2010 +0100 +++ b/xen/include/xen/sched.h Wed Jun 02 11:15:21 2010 +0100 @@ -269,6 +269,7 @@ spinlock_t shutdown_lock; bool_t is_shutting_down; /* in process of shutting down? */ bool_t is_shut_down; /* fully shut down? */ + bool_t has_shutdown_code; /* shutdown_code has been set? */ int shutdown_code; /* If this is not 0, send suspend notification here instead of