From nobody@FreeBSD.org  Mon Aug 27 14:06:51 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id A78591065673
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Aug 2012 14:06:51 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 9251F8FC17
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Aug 2012 14:06:51 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q7RE6pCq089123
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Aug 2012 14:06:51 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q7RE6pSa089122;
	Mon, 27 Aug 2012 14:06:51 GMT
	(envelope-from nobody)
Message-Id: <201208271406.q7RE6pSa089122@red.freebsd.org>
Date: Mon, 27 Aug 2012 14:06:51 GMT
From: Mark Felder <feld@feld.me>
To: freebsd-gnats-submit@FreeBSD.org
Subject: FreeBSD XENHVM guest doesn't shutdown cleanly
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         171118
>Category:       kern
>Synopsis:       [xen] FreeBSD XENHVM guest doesn't shutdown cleanly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-xen
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 27 14:10:03 UTC 2012
>Closed-Date:    Thu Mar 06 13:13:23 UTC 2014
>Last-Modified:  Thu Mar 06 13:13:23 UTC 2014
>Originator:     Mark Felder
>Release:        9.0-RELEASE
>Organization:
>Environment:
>Description:
If you install FreeBSD as a guest on XenServer or XCP and utilize both sysutils/xen-tools and my Xen scripts (https://github.com/felderado/freebsd-xen-tools-scripts) the hypervisor will recognize the guest and give you additional features such as the ability to make the guest cleanly shutdown. When you do this to FreeBSD, it doesn't shutdown completely. It appears it is doing the equivalent of a "shutdown -h now" and halting instead of doing the complete poweroff. If you manually run "shutdown -p now" from the console it does cleanly poweroff the VM, indicating the capability exists; it just doesn't use the right shutdown method when the signal comes through XEN.
>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-xen 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Aug 31 08:06:10 UTC 2012 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171118 

From: Mark Felder <feld@feld.me>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: kern/171118: [xen] FreeBSD XENHVM guest doesn&#39;t shutdown
 cleanly
Date: Mon, 8 Oct 2012 16:35:26 -0500

 NetBSD's documentation mentions a similar issue and their workaround is to  
 enable the NetBSD powerd daemon in rc.conf. Perhaps we can figure out what  
 their powerd daemon is doing so we can have a workaround? We can't run  
 powerd as a domU because it's looking for cpufreq settings that aren't in  
 sysctl.
 
 http://www.netbsd.org/ports/xen/howto.html
 
 > It is also desirable to add
 >      powerd=YES
 >
 > in rc.conf. This way, the domain will be properly shut down if xm  
 > shutdown -Ror xm shutdown -H is used on the domain0.

From: Mark Felder <feld@feld.me>
To: shidj <shidj@arraynetworks.com.cn>,
 "bug-followup" <bug-followup@FreeBSD.org>
Cc:  
Subject: Re: kern/171118: [xen] FreeBSD XENHVM guest doesn
Date: Mon, 21 Oct 2013 08:00:43 -0500

 On Tue, Aug 13, 2013, at 21:01, Jason Shi wrote:
 > 
 > Though you may not get exactly what you expect when you really want your
 > VMs to "halt".
 > 
 
 I'm struggling to think of a scenario where I want a VM to halt and not
 shutdown.

From: Mark Felder <feld@feld.me>
To: "bug-followup" <bug-followup@FreeBSD.org>
Cc:  
Subject: Re: kern/171118: [xen] FreeBSD XENHVM guest doesn
Date: Mon, 21 Oct 2013 08:25:47 -0500

 Quoting this in a reply to the PR -- it seems Jason's message was
 rejected by spam perhaps and didn't make it into GNATS?
 
 On Tue, Aug 13, 2013, at 21:01, Jason Shi wrote:
 > After we lanuch a "shutdown" operation in Xen Center, Xen Server issues a
 > clean_shutdown operation. 
 > And actually the signal sended to VM is "halt". We can see that from the
 > xen source log on dom0. e.g.:
 > Aug 13 15:03:48 xenserver-lxpwbbml xenopsd:
 > [debug|xenserver-lxpwbbml|7|Async.VM.clean_shutdown
 > R:832f756cad74|xenops] VM =
 > dc401e38-9        7af-5972-7150-d067d701fa88; domid = 115; Requesting
 > domain
 > halt
 > 
 > FreeBSD VM receives the signal and do shutdown_nice(RB_HALT). This is a
 > halt action which will not lead to
 >  a poweroff ending. So the VM domain will not be destroyed.
 > Xen Server expected the target domain to be destroyed until it times out.
 > Then Xen Center gets a timeout and 
 > it logs "shutdown failed" then.
 > 
 > I think this a xen bug. 
 > But as a workaround, you can modify the xctrl_halt function from:
 > shutdown_nice(RB_HALT); 
 > to
 > shutdown_nice(RB_POWEROFF|RB_HALT);
 > 
 > Though you may not get exactly what you expect when you really want your
 > VMs to "halt".
 > 
 > 
 > 
 > 
 > Jason Shi

From: =?ISO-8859-1?Q?Roger_Pau_Monn=E9?= <roger.pau@citrix.com>
To: <bug-followup@FreeBSD.org>, <feld@feld.me>
Cc:  
Subject: Re: kern/171118: [xen] FreeBSD XENHVM guest doesn&#39;t shutdown
 cleanly
Date: Mon, 21 Oct 2013 16:18:34 +0100

 When using libxl the event sent is a "poweroff", but I guess XenServer 
 toolstack is sending a "halt" event instead (which libxl doesn't use 
 for anything). The following patch wires the "halt" event handler to 
 the "poweroff" handler and removes the now unused "halt" handler.
 
 I'm currently on a trip, so I haven't been able to test the patch 
 (not even compile tested).
 
 ---
 diff --git a/sys/dev/xen/control/control.c b/sys/dev/xen/control/control.c
 index 35c923d..78894ba 100644
 --- a/sys/dev/xen/control/control.c
 +++ b/sys/dev/xen/control/control.c
 @@ -158,7 +158,6 @@ static xctrl_shutdown_handler_t xctrl_poweroff;
  static xctrl_shutdown_handler_t xctrl_reboot;
  static xctrl_shutdown_handler_t xctrl_suspend;
  static xctrl_shutdown_handler_t xctrl_crash;
 -static xctrl_shutdown_handler_t xctrl_halt;
  
  /*-------------------------- Private Data Structures -------------------------*/
  /** Element type for lookup table of event name to handler. */
 @@ -173,7 +172,7 @@ static const struct xctrl_shutdown_reason xctrl_shutdown_reasons[] = {
  	{ "reboot",   xctrl_reboot   },
  	{ "suspend",  xctrl_suspend  },
  	{ "crash",    xctrl_crash    },
 -	{ "halt",     xctrl_halt     },
 +	{ "halt",     xctrl_poweroff },
  };
  
  struct xctrl_softc {
 @@ -427,12 +426,6 @@ xctrl_crash()
  }
  
  static void
 -xctrl_halt()
 -{
 -	shutdown_nice(RB_HALT);
 -}
 -
 -static void
  xen_pv_shutdown_final(void *arg, int howto)
  {
  	/*

From: Mark Felder <feld@feld.me>
To: =?ISO-8859-1?Q?Roger=20Pau=20Monn=E9?= <roger.pau@citrix.com>,
 bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/171118: [xen] FreeBSD XENHVM guest doesn&#39;t shutdown cleanly
Date: Thu, 31 Oct 2013 09:59:18 -0500

 Your patch works. It would be appreciated if this could make its way
 into 10.0-RELEASE.
State-Changed-From-To: open->closed 
State-Changed-By: feld 
State-Changed-When: Thu Mar 6 13:13:23 UTC 2014 
State-Changed-Why:  
Confirmed that this made it into 10.0-RELEASE 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171118 
>Unformatted:
