From patchwork Thu Oct 24 18:04:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Kirsch X-Patchwork-Id: 32463 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 958BB27BBEA; Thu, 24 Oct 2024 19:06:15 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 95B0527BBE2 for ; Thu, 24 Oct 2024 19:06:11 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t42DG-0007rp-20; Thu, 24 Oct 2024 14:05:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t42DD-0007rG-T3 for guix-patches@gnu.org; Thu, 24 Oct 2024 14:05:31 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t42DD-0004Fn-KN for guix-patches@gnu.org; Thu, 24 Oct 2024 14:05:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:From:Date:To:Subject; bh=fw7naxm5lCTQud8bUOz3EfhdKsVvkSzCkQWqfOj1ZoM=; b=HREYroNK5Ycg8eDQLy7Sy+pXklmtxLZAvMaQPGM6Ml4uySg+8cq27+3U5EGg3Rptv8W4qR/AdpeQyKmQgVk6zUT9Mu+m0A9XQDoOyhoJ7kH3epHvf7pjXy1IlGAVf5js1WEDmjP5KS9fBqTVEajRRcc3oREBlUPrFG8DX9MjdSZ9bLzspaB/Wisply137XWkoFYy13fwxjTBtd2K3kgT0NeITeN+9+A2+DgCZJhxstuSH3XzqWlOGAAqCgNdD4B27B/EPiW5duRzxbZety9x7jHekGujn+ZoL2SVjSqZPVLwtDThZOCqPdxfA/PBEgX4cCXTaU2uuS/uWY4DPpFTkw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t42Di-0000JE-4x for guix-patches@gnu.org; Thu, 24 Oct 2024 14:06:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73992] [Shepherd PATCH] shepherd: Add support for rebooting using kexec Resent-From: Jakob Kirsch Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 24 Oct 2024 18:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73992 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 73992@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.1729793106705 (code B ref -1); Thu, 24 Oct 2024 18:06:01 +0000 Received: (at submit) by debbugs.gnu.org; 24 Oct 2024 18:05:06 +0000 Received: from localhost ([127.0.0.1]:36111 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t42Ck-0000BD-Kg for submit@debbugs.gnu.org; Thu, 24 Oct 2024 14:05:06 -0400 Received: from lists.gnu.org ([209.51.188.17]:35202) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t42Cg-0000Ad-6A for submit@debbugs.gnu.org; Thu, 24 Oct 2024 14:05:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t42CA-0007jA-1M for guix-patches@gnu.org; Thu, 24 Oct 2024 14:04:26 -0400 Received: from mout.web.de ([212.227.17.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t42C4-0003zu-V8 for guix-patches@gnu.org; Thu, 24 Oct 2024 14:04:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1729793054; x=1730397854; i=jakob.kirsch@web.de; bh=fw7naxm5lCTQud8bUOz3EfhdKsVvkSzCkQWqfOj1ZoM=; h=X-UI-Sender-Class:Date:From:To:Subject:Message-ID:MIME-Version: Content-Type:cc:content-transfer-encoding:content-type:date:from: message-id:mime-version:reply-to:subject:to; b=hm1zbEqhoPoiJNFo3m5bLFG9dCFHTadUL7/QLP6b+abiKqDwEWi1fAstP/xRURIj cU5mmU9KrYbxAdnYNed23+4rKPWkPpfnIuNNEVZgbOxlEjKIbscjn+zlPiO7KIjeq hLZh1FsR/PsvEed7cSUBk+2QBikVm081HU1guV8KCeNNizw7p61wzxZKBNqfquUdv ahWfV11Je8MIm1LDy1vHJnpRwPXghivUwn8WJJQp0VbPLNeZQ23NEYEr39OeeyAp1 KzrDTT+n933oyzY/0h/7pWX7ueB/QLHgt3jN1FeCyjKAuQmXVcT5Oldeii92vZqcP VqhD3k/gzP58O4WAWw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from kernelpanicroom ([134.19.29.168]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MHmm4-1t928e150g-000uY1 for ; Thu, 24 Oct 2024 20:04:14 +0200 Date: Thu, 24 Oct 2024 20:04:14 +0200 Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Provags-ID: V03:K1:D8YrL0BgZpLiYkPd5PoBKFPczW3QjV98lWyAAJMS0L1UoSqXXcm Mgj1KRkn8RaiB1dUxEGwNf0C77BAmi8gLiEKJQ1PXmZNadnzwmCpawW5ysJivjqmTZcEhG+ lOsPpJIp4OR4HzHY/5bstgRp3WJL+ZeMYsYgdSsNOmUGQsF4Xh13tDK59W29Z3FkgGkcI7F 5lJtXO+Mo8oO1OeXWrikA== UI-OutboundReport: notjunk:1;M01:P0:5w71WscdXic=;RL4IOSJfzGRH2egHyWzQux4xiza yQjYrCTQ/RxaRjF8vdEwftPIcmDV0p12Ax89uepZoWQj33pio+lDvlEgM6xulwW3WGA6p/mVp mWXvqw06RYk3D+PytJdVjgnYc/dTf8jMMb++bL5FLn9B4eTr1bMm3zSRd1wC+fJVtOkf87y09 AddVZ1BVuGa23NR7qvTiWNxoN4hAq7mn/p7lIg50Zn0B8TrNNLUp7h7zy8Ofn30Y9p58lHq0G bWPZK+3c8Wd2svC7gsXPIlpNdWLnrWo8lNCZPHPyaZCqkzJgkXRfl3RpOT9oiG0wVXXtBJcGz xhXz9OC1iLFjsr5txBg5yR+SQg2XPtT6GMIrKnXZx3RN/5YtsGUWw9ZDi4F556i/tXnqDJQM+ ufL7lMcykazhatX8DHice0xupbDYFk7tRezF+bDzUeA/jqEXSuanD7ygyNhLHpUXqNu1vXWu0 HcZTKx6UOmjXm3hX0AhidMgQr6NinexH4dECXRzFaw8nVJj/I0ojN0mQeDx6wcLeTqvhus1RM pkGv5CgMMNuUtniC6QQU+UPM6KI1lqi3HxpFhggfcyI5WXsOGRbfuItrtfGwB+QdSWfhtvxi+ p8Wz68/U055nzWvi29IyLotjjJV2CoP31ZVkcRLwq7PMGqe/YG1gHuyx7+/0AC346jOAOEsQJ rKZpc6ypGtDyVInzeQoNcLHVPBIVU8pfokxnQtzW7zHyT1OlhQQI7MLtciAt6NfDY2jpoZ4/c hO1xcEeR9UcBSNLPoUI7WSG2+HbQ5u7viaEFB+DOXP27DQMOCVBTsfCYML9lrJuaGPD5EuLo5 7CZqkwX0s8Iuqz9wXgcdd4Yw== Received-SPF: pass client-ip=212.227.17.12; envelope-from=jakob.kirsch@web.de; helo=mout.web.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jakob Kirsch X-ACL-Warn: , Jakob Kirsch via Guix-patches X-Patchwork-Original-From: Jakob Kirsch via Guix-patches via From: Jakob Kirsch Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches This is my improved patch for using kexec with shepherd as I sent the last one to the wrong address (someone should update the description of the shepherd project to link to the correct patch submission list). From 762fbee53fb890a7cf5e26abcc2dcfad03b1bab4 Mon Sep 17 00:00:00 2001 From: Jakob Kirsch Date: Thu, 24 Oct 2024 19:45:31 +0200 Subject: [PATCH v3] shepherd: Add support for rebooting using kexec --- AUTHORS | 1 + configure.ac | 4 ++++ doc/shepherd.texi | 9 +++++++++ modules/shepherd/scripts/reboot.scm | 12 ++++++++++-- modules/shepherd/service.scm | 9 +++++++++ modules/shepherd/system.scm.in | 10 ++++++++++ tests/status-sexp.sh | 2 +- 7 files changed, 44 insertions(+), 3 deletions(-) -- 2.46.0 diff --git a/AUTHORS b/AUTHORS index 19132a7..6642bdc 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,3 +10,4 @@ when it was known as GNU dmd. Others have since contributed: Alex Sassmannshausen David Thompson Andy Wingo + Jakob Kirsch diff --git a/configure.ac b/configure.ac index bcfef13..db1dc95 100644 --- a/configure.ac +++ b/configure.ac @@ -124,6 +124,7 @@ case "$host_os" in AC_COMPUTE_INT([RB_DISABLE_CAD], [RB_DISABLE_CAD], [#include ]) AC_COMPUTE_INT([RB_POWER_OFF], [RB_POWER_OFF], [#include ]) AC_COMPUTE_INT([RB_SW_SUSPEND], [RB_SW_SUSPEND], [#include ]) + AC_COMPUTE_INT([RB_KEXEC], [RB_KEXEC], [#include ]) ;; gnu*) # On GNU/Hurd, the Mach-derived reboot.h uses different names, and @@ -131,6 +132,7 @@ case "$host_os" in AC_COMPUTE_INT([RB_HALT_SYSTEM], [RB_HALT], [#include ]) AC_COMPUTE_INT([RB_POWER_OFF], [RB_HALT], [#include ]) RB_DISABLE_CAD="#f" + RB_KEXEC="#f" ;; *) # What is this? GNU/kFreeBSD? @@ -138,6 +140,7 @@ case "$host_os" in AC_COMPUTE_INT([RB_HALT_SYSTEM], [RB_HALT_SYSTEM], [#include ]) AC_COMPUTE_INT([RB_POWER_OFF], [RB_HALT_SYSTEM], [#include ]) RB_DISABLE_CAD="#f" + RB_KEXEC="#f" ;; esac @@ -145,6 +148,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([ constants]) diff --git a/doc/shepherd.texi b/doc/shepherd.texi index 0e627b3..921bf40 100644 --- a/doc/shepherd.texi +++ b/doc/shepherd.texi @@ -14,6 +14,7 @@ Copyright @copyright{} @value{NEW-YEARS} Ludovic Courtès@* Copyright @copyright{} 2020 Brice Waegeneire@* Copyright @copyright{} 2020 Oleg Pykhalov@* Copyright @copyright{} 2020, 2023 Jan (janneke) Nieuwenhuizen@* +Copyright @copyright{} 2024 Jakob Kirsch@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -600,6 +601,14 @@ It is equivalent to running @command{herd stop shepherd}. The Send commands to the socket special file @var{file}. If this option is not specified, @file{@var{localstatedir}/run/shepherd/socket} is taken. +@item -k +@itemx --do-kexec +Reboot the system using kexec. The kernel that was previously loaded +using @command{kexec -l @var{file}} is executed instead of rebooting +into the BIOS in order to keep the down time to a minimum or to chainload +another kernel. This feature is only available on Linux-based systems and will +throw an exception on GNU/Hurd. This is also equivalent to running @command{herd kexec shepherd}. + @end table @c @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ diff --git a/modules/shepherd/scripts/reboot.scm b/modules/shepherd/scripts/reboot.scm index 6be5414..4c2448e 100644 --- a/modules/shepherd/scripts/reboot.scm +++ b/modules/shepherd/scripts/reboot.scm @@ -30,6 +30,8 @@ (define (main . args) (initialize-cli) + (define 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! action '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 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 5942b0a..6a5e112 100644 --- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -2707,6 +2707,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))))) + + (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 4c83175..1168c15 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 @@ -51,6 +52,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@) ; integer | #f (define (syscall->procedure return-type name argument-types) "Return a procedure that wraps the C function NAME using the dynamic FFI, @@ -95,6 +97,14 @@ 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. Kexec is a feature of the +Linux kernel that allows you to instantly reboot into a new kernel while skipping +the BIOS phase. Return #f on failure or throw an exception on non-Linux systems." + (if RB_KEXEC + (%libc-reboot RB_KEXEC) + (throw 'system-error 'kexec "~A" (list (strerror ENOSYS)) (list ENOSYS)))) + (define (halt) "Halt the system. Return #f on failure." (%libc-reboot RB_HALT_SYSTEM)) diff --git a/tests/status-sexp.sh b/tests/status-sexp.sh index 14b1e72..3fa0283 100644 --- a/tests/status-sexp.sh +++ b/tests/status-sexp.sh @@ -91,7 +91,7 @@ root_service_sexp=" (transient? #f) (respawn-limit (5 . 7)) (respawn-delay 0.1) - (actions (help status halt power-off load eval unload reload daemonize restart)) + (actions (help status halt power-off kexec load eval unload reload daemonize restart)) (exit-statuses ()) (recent-messages ()) (log-files (\"$PWD/$log\"))