git: 9dd5105f22a2 - main - xen: expose support for poweroff/reboot/suspend on xenbus

From: Roger Pau Monné <royger_at_FreeBSD.org>
Date: Mon, 07 Oct 2024 17:00:00 UTC
The branch main has been updated by royger:

URL: https://cgit.FreeBSD.org/src/commit/?id=9dd5105f22a2276cf099f0e10e318294fcc4f6a7

commit 9dd5105f22a2276cf099f0e10e318294fcc4f6a7
Author:     Roger Pau Monné <royger@FreeBSD.org>
AuthorDate: 2024-09-30 17:27:56 +0000
Commit:     Roger Pau Monné <royger@FreeBSD.org>
CommitDate: 2024-10-07 16:59:45 +0000

    xen: expose support for poweroff/reboot/suspend on xenbus
    
    Some toolstacks won't attempt the signal power actions on xenbus unless the VM
    explicitly exposes support for them.  FreeBSD supports all power actions, hence
    signal on xenbus such support by setting the nodes to the value of "1".
    
    Sponsored by: Cloud Software Group
    Reviewed by: markj
    Differential review: https://reviews.freebsd.org/D46859
---
 sys/dev/xen/control/control.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/sys/dev/xen/control/control.c b/sys/dev/xen/control/control.c
index 1dc1df935b84..4601db70ef16 100644
--- a/sys/dev/xen/control/control.c
+++ b/sys/dev/xen/control/control.c
@@ -394,6 +394,20 @@ xctrl_on_watch_event(struct xs_watch *watch, const char **vec, unsigned int len)
 }
 
 /*------------------ Private Device Attachment Functions  --------------------*/
+
+static void
+notify_support(void)
+{
+	/*
+	 * Notify kernel is ready to handle "control/shutdown" events.  Ignore
+	 * errors if the nodes haven't been created by the toolstack, as the
+	 * parent "control" directory should be read-only for the guest.
+	 */
+	xs_write(XST_NIL, "control", "feature-poweroff", "1");
+	xs_write(XST_NIL, "control", "feature-reboot", "1");
+	xs_write(XST_NIL, "control", "feature-suspend", "1");
+}
+
 /**
  * \brief Identify instances of this device type in the system.
  *
@@ -455,6 +469,8 @@ xctrl_attach(device_t dev)
 	EVENTHANDLER_REGISTER(shutdown_final, xctrl_shutdown_final, NULL,
 	    SHUTDOWN_PRI_LAST);
 
+	notify_support();
+
 	return (0);
 }
 
@@ -479,6 +495,14 @@ xctrl_detach(device_t dev)
 	return (0);
 }
 
+static int
+xctrl_resume(device_t dev)
+{
+	notify_support();
+
+	return (0);
+}
+
 /*-------------------- Private Device Attachment Data  -----------------------*/
 static device_method_t xctrl_methods[] = { 
 	/* Device interface */ 
@@ -486,6 +510,7 @@ static device_method_t xctrl_methods[] = {
 	DEVMETHOD(device_probe,         xctrl_probe), 
 	DEVMETHOD(device_attach,        xctrl_attach), 
 	DEVMETHOD(device_detach,        xctrl_detach), 
+	DEVMETHOD(device_resume,        xctrl_resume),
 
 	DEVMETHOD_END
 };