From patchwork Sun May 3 11:05:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "vasilii.smirnov--- via Guix-patches\" via" X-Patchwork-Id: 21869 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 748E427BBE1; Sun, 3 May 2020 12:06:09 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::17]) by mira.cbaines.net (Postfix) with ESMTP id AA31627BBE4 for ; Sun, 3 May 2020 12:06:08 +0100 (BST) Received: from localhost ([::1]:56866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jVCRk-0006VE-4H for patchwork@mira.cbaines.net; Sun, 03 May 2020 07:06:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVCRe-0006Un-As for guix-patches@gnu.org; Sun, 03 May 2020 07:06:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:43233) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jVCRe-00057w-1k for guix-patches@gnu.org; Sun, 03 May 2020 07:06:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jVCRd-0000hK-R9 for guix-patches@gnu.org; Sun, 03 May 2020 07:06:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40927] [PATCH] Allow resume from swap device during boot Resent-From: Tobias Geerinckx-Rice Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 03 May 2020 11:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40927 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 40927@debbugs.gnu.org Received: via spool by 40927-submit@debbugs.gnu.org id=B40927.15885039452657 (code B ref 40927); Sun, 03 May 2020 11:06:01 +0000 Received: (at 40927) by debbugs.gnu.org; 3 May 2020 11:05:45 +0000 Received: from localhost ([127.0.0.1]:54779 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jVCRN-0000gm-4A for submit@debbugs.gnu.org; Sun, 03 May 2020 07:05:45 -0400 Received: from tobias.gr ([80.241.217.52]:50256) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jVCRK-0000gb-GD for 40927@debbugs.gnu.org; Sun, 03 May 2020 07:05:43 -0400 Received: by tobias.gr (OpenSMTPD) with ESMTP id cb671759 for <40927@debbugs.gnu.org>; Sun, 3 May 2020 11:05:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=tobias.gr; h=from:to :subject:message-id:references:in-reply-to:date:mime-version :content-type; s=2018; i=me@tobias.gr; bh=p9Lka5/WbunurGAh7EVl3D 4UlNJPHNze5FPUqSUqo9k=; b=pmGQjf566Op6HcGe5SUWd5Dzm4PrIflQslgq2c LPTFpuQSWmwVEx7DCJba4e9freychDOfvEgQwh03Tmv2kEUV9hFgWY1DPLfaXglh VP9OkUHZiQOBgJDpIzGuMEwoiE/LAv1d2hP1XZBShLfJkPJL9RBSqPkaMajgUoRU mwUExuF+vUCIIhikt9HMLbKtMHiHaa+aF81xW4kEBLZwKbaxqnAtmltb1l2OPvon y8Qxhm5wILvJlzHsSHOCJZWb0OjXfd8lM8Veai8gAT9ZA4hhDr3rv8rbRK5zO2d1 EK4LUK0TZXisKakwSkt2eIjGF1rh+ifrfPlsQ/iu8KyL+d5A== Received: by submission.tobias.gr (OpenSMTPD) with ESMTPSA id f99687bf (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO) for <40927@debbugs.gnu.org>; Sun, 3 May 2020 11:05:39 +0000 (UTC) Message-ID: <874ksxnurk.fsf@nckx> References: <87zhawax60.fsf@m4x.org> <87o8r7ehpr.fsf@nckx> In-reply-to: <87o8r7ehpr.fsf@nckx> Date: Sun, 03 May 2020 13:05:52 +0200 MIME-Version: 1.0 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: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: Tobias Geerinckx-Rice , Tobias Geerinckx-Rice via Guix-patches X-Patchwork-Original-From: Tobias Geerinckx-Rice via Guix-patches via From: "vasilii.smirnov--- via Guix-patches\" via" X-getmail-retrieved-from-mailbox: Patches 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 From 46c4c1010d9257f3d1d1ddb201dc7f7519d42ba0 Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice 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 +;;; Copyright © 2016, 2017, 2019 Tobias Geerinckx-Rice ;;; Copyright © 2017 Mathieu Othacehe ;;; Copyright © 2019 Guillaume Le Vaillant ;;; @@ -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 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