From: Tobias Geerinckx-Rice via Guix-patches via <guix-patches@gnu.org>
To: 40927@debbugs.gnu.org
Subject: [bug#40927] [PATCH] Allow resume from swap device during boot
Date: Sun, 03 May 2020 13:05:52 +0200 [thread overview]
Message-ID: <874ksxnurk.fsf@nckx> (raw)
In-Reply-To: <87o8r7ehpr.fsf@nckx>
[-- Attachment #1.1: Type: text/plain, Size: 691 bytes --]
Hullo again,
Tobias Geerinckx-Rice 写道:
> This is what the last iteration of my patch does.
I managed to find it! Long live dusty back-ups.
It uses native procedures to divine the device number, instead of
— clever! — /sys/blockery that supports only a subset of specs
(and reminds me too much of ‘look what I found lying around’ shell
scripting). If any are missing we can add them to
CANONICALIZE-DEVICE-SPEC to the benefit of all.
Tested with both built-in & modular ATA drivers × mainline swsusp
& TuxOnIce. More welcome.
These copyright dates are downright embarrassing. Let's Get
(something like) This Merged!
Kind regards,
T G-R
[-- Attachment #1.2: 0001-linux-boot-Resume-from-hibernation.patch --]
[-- Type: text/x-patch, Size: 4652 bytes --]
From 46c4c1010d9257f3d1d1ddb201dc7f7519d42ba0 Mon Sep 17 00:00:00 2001
From: Tobias Geerinckx-Rice <me@tobias.gr>
Date: Fri, 26 Feb 2016 17:57:07 +0100
Subject: [PATCH] linux-boot: Resume from hibernation.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* gnu/build/linux-boot.scm (resume-if-hibernated): New procedure.
(boot-system): Call it unless ‘noresume’ was specified.
---
gnu/build/linux-boot.scm | 52 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm
index 05e833c0c6..74e76b6a31 100644
--- a/gnu/build/linux-boot.scm
+++ b/gnu/build/linux-boot.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2016, 2017, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2019 Guillaume Le Vaillant <glv@posteo.net>
;;;
@@ -110,6 +111,51 @@ OPTION doesn't appear in ARGUMENTS."
(substring arg (+ 1 (string-index arg #\=)))))
arguments)))
+(define (resume-if-hibernated device)
+ "Resume from hibernation if possible. This is safe ONLY if no on-disk file
+systems have been mounted; calling it later risks severe file system corruption!
+See <Documentation/swsusp.txt> in the kernel source directory. This is the
+caller's responsibility, as is catching exceptions if resumption was supposed to
+happen but didn't.
+
+Resume only from DEVICE if it's a string. If it's #f, use the kernel's default
+hibernation device (CONFIG_PM_STD_PARTITION). Never return if resumption
+succeeds. Return nothing otherwise. The kernel logs any details to dmesg."
+
+ (define (string->major:minor string)
+ "Return a string with MAJOR:MINOR numbers of the device specified by STRING"
+
+ ;; The "resume=" kernel command-line option always provides a string, which
+ ;; can represent a device, a UUID, or a label. Check for all three.
+ (let* ((spec (cond ((string-prefix? "/" string) string)
+ ((uuid string) => identity)
+ (else (file-system-label string))))
+ ;; XXX kernel's swsusp_resume_can_resume() waits if ‘resumewait’ is
+ ;; found on the command line; our canonicalize-device-spec gives up
+ ;; after 20 seconds. We could loop (ew!) if someone relies on it…
+ (device (canonicalize-device-spec spec))
+ (rdev (stat:rdev (stat device)))
+ (minor (modulo rdev 256))
+ (major (/ (- rdev minor) 256)))
+ (format #f "~a:~a" major minor)))
+
+ ;; Write the MAJOR:MINOR numbers of the specified or default resume DEVICE to
+ ;; this magic file. The kernel will immediately try to resume from it.
+ (let ((resume "/sys/power/resume"))
+ (when (file-exists? resume) ; this kernel supports hibernation
+ ;; Honour the kernel's default device (only) if none other was given.
+ (let ((major:minor (if device
+ (string->major:minor device)
+ (let ((default (call-with-input-file resume
+ read-line)))
+ ;; Don't waste time echoing ‘nothing’ to /sys.
+ (if (string=? "0:0" default)
+ #f
+ default)))))
+ (when major:minor
+ (call-with-output-file resume ; may throw an ‘Invalid argument’
+ (cut display major:minor <>))))))) ; may never return
+
(define* (make-disk-device-nodes base major #:optional (minor 0))
"Make the block device nodes around BASE (something like \"/root/dev/sda\")
with the given MAJOR number, starting with MINOR."
@@ -504,6 +550,12 @@ upon error."
(load-linux-modules-from-directory linux-modules
linux-module-directory)
+ (unless (member "noresume" args)
+ ;; Try to resume immediately after loading (storage) modules
+ ;; but before any on-disk file systems have been mounted.
+ (false-if-exception ; failure is not fatal
+ (resume-if-hibernated (find-long-option "resume" args))))
+
(when keymap-file
(let ((status (system* "loadkeys" keymap-file)))
(unless (zero? status)
--
2.25.2
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]
next prev parent reply other threads:[~2020-05-03 11:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-28 7:26 [bug#40927] [PATCH] Allow resume from swap device during boot Jean-Baptiste Note
2020-05-01 14:50 ` Danny Milosavljevic
2020-05-05 18:07 ` Jean-Baptiste Note
2020-05-05 19:29 ` Jean-Baptiste Note
2020-05-01 16:35 ` Tobias Geerinckx-Rice via Guix-patches via
2020-05-03 11:05 ` Tobias Geerinckx-Rice via Guix-patches via [this message]
2020-05-07 20:58 ` [bug#40927] Subject=[bug#40927] " Jean-Baptiste Note
2021-05-09 19:34 ` bug#40927: Close hibernation bugs Tobias Geerinckx-Rice via Guix-patches via
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=874ksxnurk.fsf@nckx \
--to=guix-patches@gnu.org \
--cc=40927@debbugs.gnu.org \
--cc=me@tobias.gr \
/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).