From: Jakob Kirsch <jakob.kirsch@web.de>
To: guix-devel@gnu.org
Cc: Jakob Kirsch <jakob.kirsch@web.de>
Subject: [PATCH v1] shepherd: add support for kexec
Date: Wed, 2 Oct 2024 19:01:12 +0200 [thread overview]
Message-ID: <20241002170111.17526-2-jakob.kirsch@web.de> (raw)
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
next reply other threads:[~2024-10-02 20:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-02 17:01 Jakob Kirsch [this message]
2024-10-23 16:45 ` [PATCH v1] shepherd: add support for kexec Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241002170111.17526-2-jakob.kirsch@web.de \
--to=jakob.kirsch@web.de \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).