From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id cPCvA5qlrl4WYAAA0tVLHw (envelope-from ) for ; Sun, 03 May 2020 11:06:02 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id YEjjMqOlrl6feQAA1q6Kng (envelope-from ) for ; Sun, 03 May 2020 11:06:11 +0000 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 455AD941310 for ; Sun, 3 May 2020 11:06:10 +0000 (UTC) Received: from localhost ([::1]:56866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jVCRl-0006VE-33 for larch@yhetil.org; Sun, 03 May 2020 07:06:09 -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 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" Reply-to: Tobias Geerinckx-Rice , Tobias Geerinckx-Rice via Guix-patches From: Tobias Geerinckx-Rice via Guix-patches via X-Scanner: scn0 X-Spam-Score: -1.61 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=tobias.gr header.s=2018 header.b=pmGQjf56; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 2001:470:142::17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Scan-Result: default: False [-1.61 / 13.00]; HAS_REPLYTO(0.00)[me@tobias.gr]; GENERIC_REPUTATION(0.00)[-0.49363401365217]; DWL_DNSWL_FAIL(0.00)[2001:470:142::17:server fail]; R_SPF_ALLOW(-0.20)[+ip6:2001:470:142::/48:c]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.15), country: US(-0.00), ip: 2001:470:142::17(-0.49)]; TO_DN_NONE(0.00)[]; R_DKIM_REJECT(1.00)[tobias.gr:s=2018]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; DKIM_TRACE(0.00)[tobias.gr:-]; MAILLIST(-0.20)[mailman]; SIGNED_PGP(-2.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_IN_DNSWL_FAIL(0.00)[2001:470:142::17:server fail]; MIME_TRACE(0.00)[0:+,1:+,2:+,3:+,4:~]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:22989, ipnet:2001:470:142::/48, country:US]; TAGGED_FROM(0.00)[larch=yhetil.org]; FROM_NEQ_ENVFROM(0.00)[guix-patches@gnu.org,guix-patches-bounces@gnu.org]; ARC_NA(0.00)[]; URIBL_BLOCKED(0.00)[posteo.net:email,gnu.org:email,tobias.gr:email]; FROM_HAS_DN(0.00)[]; MIME_GOOD(-0.20)[multipart/signed,multipart/mixed,text/plain,text/x-patch]; REPLYTO_DOM_NEQ_FROM_DOM(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[40927@debbugs.gnu.org]; HAS_LIST_UNSUB(-0.01)[]; RCPT_COUNT_ONE(0.00)[1]; DMARC_NA(0.00)[gnu.org]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_COUNT_SEVEN(0.00)[7]; FORGED_SENDER_MAILLIST(0.00)[] X-TUID: n8PlD2U2xwXP --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Hullo again, Tobias Geerinckx-Rice =E5=86=99=E9=81=93=EF=BC=9A > 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=20 =E2=80=94 clever! =E2=80=94 /sys/blockery that supports only a subset of sp= ecs=20 (and reminds me too much of =E2=80=98look what I found lying around=E2=80= =99 shell=20 scripting). If any are missing we can add them to=20 CANONICALIZE-DEVICE-SPEC to the benefit of all. Tested with both built-in & modular ATA drivers =C3=97 mainline swsusp=20 & TuxOnIce. More welcome. These copyright dates are downright embarrassing. Let's Get=20 (something like) This Merged! Kind regards, T G-R --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-linux-boot-Resume-from-hibernation.patch Content-Transfer-Encoding: quoted-printable From=2046c4c1010d9257f3d1d1ddb201dc7f7519d42ba0 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=3DUTF-8 Content-Transfer-Encoding: 8bit * gnu/build/linux-boot.scm (resume-if-hibernated): New procedure. (boot-system): Call it unless =E2=80=98noresume=E2=80=99 was specified. =2D-- 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 =2D-- a/gnu/build/linux-boot.scm +++ b/gnu/build/linux-boot.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Cour= t=C3=A8s +;;; Copyright =C2=A9 2016, 2017, 2019 Tobias Geerinckx-Rice ;;; Copyright =C2=A9 2017 Mathieu Othacehe ;;; Copyright =C2=A9 2019 Guillaume Le Vaillant ;;; @@ -110,6 +111,51 @@ OPTION doesn't appear in ARGUMENTS." (substring arg (+ 1 (string-index arg #\=3D))))) arguments))) =20 +(define (resume-if-hibernated device) + "Resume from hibernation if possible. This is safe ONLY if no on-disk f= ile +systems have been mounted; calling it later risks severe file system corru= ption! +See in the kernel source directory. This is the +caller's responsibility, as is catching exceptions if resumption was suppo= sed to +happen but didn't. + +Resume only from DEVICE if it's a string. If it's #f, use the kernel's de= fault +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 S= TRING" + + ;; The "resume=3D" 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) =3D> identity) + (else (file-system-label string)))) + ;; XXX kernel's swsusp_resume_can_resume() waits if =E2=80=98re= sumewait=E2=80=99 is + ;; found on the command line; our canonicalize-device-spec give= s up + ;; after 20 seconds. We could loop (ew!) if someone relies on = it=E2=80=A6 + (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 DEVI= CE 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 =E2=80=98nothin= g=E2=80=99 to /sys. + (if (string=3D? "0:0" default) + #f + default))))) + (when major:minor + (call-with-output-file resume ; may throw an =E2=80=98Invalid ar= gument=E2=80=99 + (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) =20 + (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) =2D-=20 2.25.2 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEARYKAB0WIQT12iAyS4c9C3o4dnINsP+IT1VteQUCXq6lkAAKCRANsP+IT1Vt ee7FAQCNQZKsTJRLSao1EPowujl4UuFGwfr1+Fmi4ZHY9TufmAEAspCjwJTFCj7b FyN4w91UguXucRUo/pzAEb6jQ9MEegE= =gREP -----END PGP SIGNATURE----- --==-=-=--