* [PATCH v1] shepherd: add support for kexec
@ 2024-10-02 17:01 Jakob Kirsch
2024-10-23 16:45 ` Ludovic Courtès
0 siblings, 1 reply; 2+ messages in thread
From: Jakob Kirsch @ 2024-10-02 17:01 UTC (permalink / raw)
To: guix-devel; +Cc: Jakob Kirsch
This patch adds preliminary support for rebooting into kexec using `reboot -k` or `reboot --do-kexec`.
---
configure.ac | 2 ++
modules/shepherd/scripts/reboot.scm | 12 ++++++++++--
modules/shepherd/service.scm | 9 +++++++++
modules/shepherd/system.scm.in | 6 ++++++
4 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index f98024d..cfbd938 100644
--- a/configure.ac
+++ b/configure.ac
@@ -104,6 +104,7 @@ case "$host_os" in
AC_COMPUTE_INT([RB_DISABLE_CAD], [RB_DISABLE_CAD], [#include <sys/reboot.h>])
AC_COMPUTE_INT([RB_POWER_OFF], [RB_POWER_OFF], [#include <sys/reboot.h>])
AC_COMPUTE_INT([RB_SW_SUSPEND], [RB_SW_SUSPEND], [#include <sys/reboot.h>])
+ AC_COMPUTE_INT([RB_KEXEC], [RB_KEXEC], [#include <sys/reboot.h>])
;;
gnu*)
# On GNU/Hurd, the Mach-derived reboot.h uses different names, and
@@ -125,6 +126,7 @@ AC_SUBST([RB_DISABLE_CAD])
AC_SUBST([RB_AUTOBOOT])
AC_SUBST([RB_HALT_SYSTEM])
AC_SUBST([RB_POWER_OFF])
+AC_SUBST([RB_KEXEC])
AC_MSG_RESULT([done])
AC_MSG_CHECKING([<sys/prctl.h> constants])
diff --git a/modules/shepherd/scripts/reboot.scm b/modules/shepherd/scripts/reboot.scm
index 6be5414..f7f6647 100644
--- a/modules/shepherd/scripts/reboot.scm
+++ b/modules/shepherd/scripts/reboot.scm
@@ -30,6 +30,8 @@
(define (main . args)
(initialize-cli)
+ (define reboot-action 'stop)
+
(parameterize ((program-name "reboot"))
(let ((socket-file %system-socket-file)
(command-args '()))
@@ -44,13 +46,19 @@
#:argument-name "FILE"
#:description "send commands to FILE"
#:action (lambda (file)
- (set! socket-file file))))
+ (set! socket-file file)))
+ (option
+ #:long-name "do-kexec" #:short-name #\k
+ #:takes-argument? #f
+ #:description "reboot using kexec"
+ #:action (lambda () (set! reboot-action 'reboot-kexec))
+ ))
(set! command-args (reverse command-args))
(with-system-error-handling
(let ((sock (open-connection socket-file)))
;; Send the command without further ado.
- (write-command (shepherd-command 'stop 'root) sock)
+ (write-command (shepherd-command reboot-action 'root) sock)
;; Receive output if we're not already dead.
(match (read sock)
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 0a52b7a..f076277 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -2849,6 +2849,15 @@ Clients such as 'herd' can read it and format it in a human-readable way."
(lambda (key)
(local-output (l10n "Shutting down..."))
(power-off)))))
+
+ (reboot-kexec
+ "Reboot the system and run kexec."
+ (lambda (running)
+ (catch 'quit
+ (cut stop root-service)
+ (lambda (key)
+ (local-output (l10n "Rebooting with kexec..."))
+ (reboot-kexec)))))
;; Evaluate arbitrary code.
(load
"Load the Scheme code from FILE into shepherd. This is potentially
diff --git a/modules/shepherd/system.scm.in b/modules/shepherd/system.scm.in
index 9929f38..bb95455 100644
--- a/modules/shepherd/system.scm.in
+++ b/modules/shepherd/system.scm.in
@@ -26,6 +26,7 @@
#:use-module (srfi srfi-26)
#:export (disable-reboot-on-ctrl-alt-del
reboot
+ reboot-kexec
halt
power-off
max-file-descriptors
@@ -49,6 +50,7 @@
(define RB_HALT_SYSTEM @RB_HALT_SYSTEM@)
(define RB_POWER_OFF @RB_POWER_OFF@)
(define RB_DISABLE_CAD @RB_DISABLE_CAD@) ; integer | #f
+(define RB_KEXEC @RB_KEXEC@)
(define (syscall->procedure return-type name argument-types)
"Return a procedure that wraps the C function NAME using the dynamic FFI,
@@ -93,6 +95,10 @@ ctrlaltdel(8) and see kernel/reboot.c in Linux."
"Perform a hard reset of the system now. Return #f on failure."
(%libc-reboot RB_AUTOBOOT))
+(define (reboot-kexec)
+ "Execute kernel loaded with 'kexec -l' now. Return #f on failure."
+ (%libc-reboot RB_KEXEC))
+
(define (halt)
"Halt the system. Return #f on failure."
(%libc-reboot RB_HALT_SYSTEM))
--
2.46.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] shepherd: add support for kexec
2024-10-02 17:01 [PATCH v1] shepherd: add support for kexec Jakob Kirsch
@ 2024-10-23 16:45 ` Ludovic Courtès
0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2024-10-23 16:45 UTC (permalink / raw)
To: Jakob Kirsch; +Cc: guix-devel
Hi Jakob,
Jakob Kirsch <jakob.kirsch@web.de> skribis:
> This patch adds preliminary support for rebooting into kexec using `reboot -k` or `reboot --do-kexec`.
Nice! That sounds useful.
Some comments inline below. In the future, could you send patches to
guix-patches@gnu.org, with “Shepherd” in the subject?
> --- a/configure.ac
> +++ b/configure.ac
> @@ -104,6 +104,7 @@ case "$host_os" in
> AC_COMPUTE_INT([RB_DISABLE_CAD], [RB_DISABLE_CAD], [#include <sys/reboot.h>])
> AC_COMPUTE_INT([RB_POWER_OFF], [RB_POWER_OFF], [#include <sys/reboot.h>])
> AC_COMPUTE_INT([RB_SW_SUSPEND], [RB_SW_SUSPEND], [#include <sys/reboot.h>])
> + AC_COMPUTE_INT([RB_KEXEC], [RB_KEXEC], [#include <sys/reboot.h>])
> ;;
> gnu*)
> # On GNU/Hurd, the Mach-derived reboot.h uses different names, and
Please also handle the Hurd case, similar to how ‘RB_DISABLE_CAD’ is
handled.
> +++ b/modules/shepherd/scripts/reboot.scm
> @@ -30,6 +30,8 @@
> (define (main . args)
> (initialize-cli)
>
> + (define reboot-action 'stop)
Or just ‘action’?
> + #:action (lambda () (set! reboot-action 'reboot-kexec))
… and just ‘kexec’?
> + (reboot-kexec
> + "Reboot the system and run kexec."
Likewise, I’d call it just ‘kexec’.
Could you expand the docstring a bit to give an overview of what “kexec”
does for users not familiar with it?
> +(define (reboot-kexec)
> + "Execute kernel loaded with 'kexec -l' now. Return #f on failure."
“Execute the Linux kernel previously loaded with 'kexec -l'. Throw an
exception on failure.”
> + (%libc-reboot RB_KEXEC))
Please address the case where RB_KEXEC is #f by doing something like:
(throw 'system-error 'kexec "~A" (list (strerror ENOSYS))
(list ENOSYS))
Could you also update ‘doc/shepherd.texi’, specifically the reference of
the ‘reboot’ command and the list of actions of the ‘root’ service?
Thanks for this work!
Ludo’.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-23 16:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-02 17:01 [PATCH v1] shepherd: add support for kexec Jakob Kirsch
2024-10-23 16:45 ` Ludovic Courtès
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.