From patchwork Tue Apr 28 07:26:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Note X-Patchwork-Id: 21700 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 4E88427BBE4; Tue, 28 Apr 2020 10:30:53 +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 [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id C918B27BBE1 for ; Tue, 28 Apr 2020 10:30:52 +0100 (BST) Received: from localhost ([::1]:49208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTMZn-0007oW-Sd for patchwork@mira.cbaines.net; Tue, 28 Apr 2020 05:30:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33576) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTMXH-0005GP-0J for guix-patches@gnu.org; Tue, 28 Apr 2020 05:30:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTMUC-0005xY-IA for guix-patches@gnu.org; Tue, 28 Apr 2020 05:28:14 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55637) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jTMUC-0005xS-2j for guix-patches@gnu.org; Tue, 28 Apr 2020 05:25:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jTMUA-0000uo-VR for guix-patches@gnu.org; Tue, 28 Apr 2020 05:25:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40927] [PATCH] Allow resume from swap device during boot Resent-From: Jean-Baptiste Note Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 28 Apr 2020 09:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 40927 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 40927@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.15880658693417 (code B ref -1); Tue, 28 Apr 2020 09:25:02 +0000 Received: (at submit) by debbugs.gnu.org; 28 Apr 2020 09:24:29 +0000 Received: from localhost ([127.0.0.1]:38929 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jTMTc-0000sy-LQ for submit@debbugs.gnu.org; Tue, 28 Apr 2020 05:24:29 -0400 Received: from lists.gnu.org ([209.51.188.17]:55461) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jTM4M-0000B7-82 for submit@debbugs.gnu.org; Tue, 28 Apr 2020 04:58:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55174) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTM1t-0007yp-7C for guix-patches@gnu.org; Tue, 28 Apr 2020 04:58:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTLvs-0005Cn-Ey for guix-patches@gnu.org; Tue, 28 Apr 2020 04:50:48 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:50268) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jTKdR-0000Wm-Ul for guix-patches@gnu.org; Tue, 28 Apr 2020 03:26:30 -0400 Received: by mail-wm1-x342.google.com with SMTP id x25so1527991wmc.0 for ; Tue, 28 Apr 2020 00:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:user-agent:mime-version; bh=v7ZhvYbvUTYrgj0wxY+58SvXoPamvvXAQnWz/NML49E=; b=UxTHj0ZwqOq7MoB4GL/yFYz2oV+sY0kXqLxpol9mTFsNvNJ37jLAUkdYVywtDtZQuS 0AXH3SYiAG9qwVdVxJbPYoQSkSWD4JHS10Jk7TzUHwjgHv/rEWEn4l81eYkBaZtKztgj 5pJUVCTgHCGqzvkK7b5qo1ihmbHJtR4hYuZl4Eqpng2WMDQ9bXhJtSxVp6CDOKySI48k qrQZ60jxkxSvqBpEsX/M72r/Hk9sSJJsdrjeixszfBrixYXyvN3IqJAZJmNjb5K1C213 n57ge1WZmwhfkDHKPSBx7jfLVE2h6Sj+ogyWVUAUJvesJD6v5N4URZdLLZeRbxWrLfCi HzMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :user-agent:mime-version; bh=v7ZhvYbvUTYrgj0wxY+58SvXoPamvvXAQnWz/NML49E=; b=AGJWJ8RsJqNRg4WuMV21tN5G03gfzydsABLW648fW5qHYOH8Q05N7oQ8CZkmQ6hwSJ /XmceC41bJ9y9bPheFPCenBY0GElS5R8XI6Jnw2sxMgXBWoY7nWKy5qjTG6NORznr3id OxnmiaFHjdAuZMkE1JfH21XY8rZ56cNFBl/sZcYgvIUSgtYTOiz4zTQQdbOf2jDgIqD9 QhnypkHWs9ZQrXLn99fHU8cnYy74wRkAvEY67UyBQJWBx0S+d9UGhH4DOBkkfG7WvqSO 3rrGbuH9s92ESjGIBz1GE6+rw3p5/LAHfCyZiiD1iVTLiTQ2EkHpa1kSDvrsT57KQmZu 4aow== X-Gm-Message-State: AGi0PubNSZ9M92onaNNlHprQkENmKNqT0K7QnqEFb84qbiLXkT9sE/Lj Z5nhc+ybr1X6qIDmz8tj1jq6Dq1lffI= X-Google-Smtp-Source: APiQypLO0zjXLFfarh9qEL23cCm3oBDnzDvz3nq6zGfKBCDEN2hIa7YuMMIVKNFfQF5fvhlKCGe3BA== X-Received: by 2002:a1c:668a:: with SMTP id a132mr3142826wmc.46.1588058787882; Tue, 28 Apr 2020 00:26:27 -0700 (PDT) Received: from guixrules ([2a01:e35:2e0b:a6b0:e2ce:c3ff:fe74:cec8]) by smtp.gmail.com with ESMTPSA id t20sm2716706wmi.2.2020.04.28.00.26.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 00:26:26 -0700 (PDT) From: Jean-Baptiste Note Date: Tue, 28 Apr 2020 07:26:15 +0000 Message-ID: <87zhawax60.fsf@m4x.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::342; envelope-from=jbnote@gmail.com; helo=mail-wm1-x342.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Mailman-Approved-At: Tue, 28 Apr 2020 05:24:24 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 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" X-getmail-retrieved-from-mailbox: Patches Dear GUIX maintainers, Current the GUIX SD boot process does not allow resuming from sleep, even thought sleep options are available through loginctl, eg: loginctl hybrid-sleep loginctl hibernate This is a very important feature for people like me using GUIX SD on a laptop (yes, it is possible, mine is a corebooted X230 running linux-libre!) This patch is based on a patch floating around. The core functionality has been isolated, the resume function isolated, the patch rebased and tested. I'm not taking credit for it, even though tracing the exact origin is hard. The resume hook is called if the resume= kernel argument is provided, which one can do during system configuration. My scheme level is zero, so please bear with me. In particular, some conditionals could maybe be moved within the function, or the function itself called within some already-available hooks. Also it is not clear if the commit log is adequate for such a change. Please let me know how to improve this and get this merged; I can also write some documentation (probably once the mechanism is in place) to explain how the feature can be used. Kind regards, Jean-Baptiste From 2531d1d08dabb53ff15020aedcec2ad5d8e6c600 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Note Date: Mon, 27 Apr 2020 20:42:03 +0000 Subject: [PATCH] linux-boot: Add support for resuming from swap device. * gnu/build/linux-boot.scm (resume-from-device): Add function. * gnu/build/linux-boot.scm (boot-system): Add hook calling resume-from-device if specified on commandline, before mounting any actual disk filesystems. --- gnu/build/linux-boot.scm | 43 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm index 4fb711b8f2..907c84276f 100644 --- a/gnu/build/linux-boot.scm +++ b/gnu/build/linux-boot.scm @@ -357,6 +357,37 @@ the last argument of `mknod'." (compose (cut string=? program <>) basename)))) (filter-map string->number (scandir "/proc"))))) +(define (resume-from-device resume-device) + "Resume from hibernation state on device DEVICE. This *must* happen before +we mount any filesystems on disk. See +linux-libre/Documentation/swsusp.txt. Please note that this function will not +return if resume happens successfully, and will return if swap device does not +contain a valid resume signature." + (false-if-exception + (let* ((device-base-name + ;; The base name of the device file, after resolving + ;; symlinks. + (let loop ((file resume-device)) + (match (stat:type (lstat file)) + ('symlink + (let ((target (readlink file))) + (if (string-prefix? "/" target) + (loop target) + (loop (string-append (dirname file) "/" target))))) + (_ (basename file))))) + (major+minor + ;; The major:minor string (e.g. "8:2") corresponding + ;; to the resume device. + (call-with-input-file (string-append "/sys/class/block/" + device-base-name + "/dev") + read-line))) + ;; Write the major:minor string to /sys/power/resume + ;; to attempt resume from hibernation. + (when major+minor + (call-with-output-file "/sys/power/resume" + (cut display major+minor <>)))))) + (define* (mount-root-file-system root type #:key volatile-root? (flags 0) options) "Mount the root file system of type TYPE at device ROOT. If VOLATILE-ROOT? is @@ -493,9 +524,10 @@ upon error." (call-with-error-handling (lambda () (mount-essential-file-systems) - (let* ((args (linux-command-line)) - (to-load (find-long-option "--load" args)) - (root (find-long-option "--root" args))) + (let* ((args (linux-command-line)) + (to-load (find-long-option "--load" args)) + (root (find-long-option "--root" args)) + (resume-device (find-long-option "resume" args))) (when (member "--repl" args) (start-repl)) @@ -528,6 +560,11 @@ upon error." (unless (pre-mount) (error "pre-mount actions failed"))) + (when (and resume-device + (file-exists? resume-device) + (file-exists? "/sys/power/resume")) + (resume-from-device resume-device)) + (setenv "EXT2FS_NO_MTAB_OK" "1") (if root -- 2.26.1