From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH] PRELIMINARY: Add support for hibernation. Date: Fri, 02 Sep 2016 15:03:16 +0200 Message-ID: <8737lilai3.fsf@gnu.org> References: <87bn0u1msx.fsf@netris.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bfo7y-0007ZD-5a for guix-devel@gnu.org; Fri, 02 Sep 2016 09:03:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bfo7r-00036L-BB for guix-devel@gnu.org; Fri, 02 Sep 2016 09:03:25 -0400 In-Reply-To: <87bn0u1msx.fsf@netris.org> (Mark H. Weaver's message of "Mon, 15 Aug 2016 04:03:26 -0400") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Mark H Weaver Cc: guix-devel@gnu.org Hello! Mark H Weaver skribis: > Here's a preliminary patch to add support for hibernation. To enable > it, you'll also need to add a line like this to your 'operating-system' > definition. > > (kernel-arguments '("resume=3D/dev/sda2")) > > Where the device named is a swap partition. Awesome! I missed this. > It may be that we should add a dedicated 'resume-device' field to the > 'operating-system'. Thoughts? I think it=E2=80=99s OK this way (though we should give an example in the manual), but not strong opinion. > From ad1d583eb6f009a2dfbc284cb8368608caf27a05 Mon Sep 17 00:00:00 2001 > From: Mark H Weaver > Date: Sun, 14 Aug 2016 05:33:12 -0400 > Subject: [PATCH] PRELIMINARY: Add support for hibernation. > > * gnu/build/linux-boot.scm (boot-system): Look for a resume=3D > argument on the linux command line, and if present, attempt to resume from > hibernation. > * gnu/services/desktop.scm (): Change the default > value of the 'handle-hibernate-key' key to 'hibernate'. [...] > + (resume-device (find-long-option "resume" args))) Could you mention this argument under =E2=80=9CInitial RAM Disk=E2=80=9D? > + ;; > + ;; Attempt to resume from hibernation. > + ;; > + ;; IMPORTANT: This *must* happen before we mount any filesystems = on > + ;; disk. Quoting linux-libre/Documentation/swsusp.txt: > + ;;=20 > + ;; * BIG FAT WARNING ********************************************= ****** > + ;; * > + ;; * If you touch anything on disk between suspend and resume... > + ;; * ...kiss your data goodbye. > + ;; * > + ;; * If you do resume from initrd after your filesystems are moun= ted... > + ;; * ...bye bye root partition. > + ;; * [this is actually same case as above] > + ;; * > + (when (and resume-device > + (file-exists? resume-device) > + (file-exists? "/sys/power/resume")) > + (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) "/" tar= get))))) > + (_ (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 <>)))))) Could you turn the (false-if-exception =E2=80=A6) expression into a separate procedure? I would perhaps remove =E2=80=98false-if-exception=E2=80=99: that way, if s= omething goes wrong, we=E2=80=99ll be able to see what the error is and get a REPL. It m= ight also be useful to display a message like =E2=80=9Cresuming from device /dev= /xyz (8:2)=E2=80=A6=E2=80=9D Apart from that it seems alright! It=E2=80=99d be interesting to see if we can write a test. The existing te= sts do not use a swap partition, but adding one shouldn=E2=80=99t be too hard. Thank you, Ludo=E2=80=99.