On Mon, Jan 23, 2006 at 03:30:04PM -0500, C. Scott Ananian wrote: > On Tue, 24 Jan 2006, Hamish Moffatt wrote: > > >Scott's latest patch needs a minor adjustment for recent suspend2 > >patches, which use /proc/suspend2 instead of /proc/software_suspend. > > When was this change made to suspend2? The code might want to try using > /proc/software_suspend if /proc/suspend2 doesn't exist, in order to > support older versions of suspend2 (unless this change was ancient).
Good idea. It looks like it changed in 2.2-rc8; 2.2 was just released last night. I've attached a new patch although I haven't actually tested the revision yet (but it is trivial). > Also, if you've tested it, I'd appreciate if your patch would remove the > "# XXX: untested!" comment I had to write. ;-) Good point :-) One issue is that it can't work out where to resume from itself; this has to come as a resume2= parameter or hard-coded in the kernel. It doesn't seem to be possible to poke it into /proc somewhere as the patch does for swsusp. thanks Hamish --- 1000_resume.patch.orig 2006-01-24 09:23:05.000000000 +1300 +++ 1000_resume.patch 2006-01-24 14:36:25.000000000 +1300 @@ -151,7 +151,7 @@ ! ydebug) ! INIT_DEBUG=yes ! esac -@@ -368,6 +384,40 @@ TEMPLATE SET +@@ -368,6 +384,43 @@ TEMPLATE SET # @@ -163,8 +163,11 @@ + BEGIN + !if [ -z "$noresume" ] + !then -+ ! # for suspend2 -+ ! # XXX: untested! ++ ! # for suspend2 (>= 2.2-rc8) ++ ! if [ -w /proc/suspend2/do_resume ]; then ++ ! echo > /proc/suspend2/do_resume ++ ! fi ++ ! # for suspend2 (< 2.2rc8) + ! if [ -w /proc/software_suspend/do_resume ]; then + ! echo > /proc/software_suspend/do_resume + ! fi @@ -234,7 +237,7 @@ ! ydebug) ! INIT_DEBUG=yes ! esac -@@ -379,6 +395,40 @@ TEMPLATE SET +@@ -379,6 +395,43 @@ TEMPLATE SET # @@ -246,8 +249,11 @@ + BEGIN + !if [ -z "$noresume" ] + !then -+ ! # for suspend2 -+ ! # XXX: untested! ++ ! # for suspend2 (>= 2.2-rc8) ++ ! if [ -w /proc/suspend2/do_resume ]; then ++ ! echo > /proc/suspend2/do_resume ++ ! fi ++ ! # for suspend2 (< 2.2rc8) + ! if [ -w /proc/software_suspend/do_resume ]; then + ! echo > /proc/software_suspend/do_resume + ! fi -- Hamish Moffatt VK3SB <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
diff -ruHp yaird-0.0.11-debpat/perl/Parser.pm yaird-0.0.11-mod2/perl/Parser.pm --- yaird-0.0.11-debpat/perl/Parser.pm 2005-12-09 13:58:20.000000000 -0500 +++ yaird-0.0.11-mod2/perl/Parser.pm 2005-12-09 17:20:51.000000000 -0500 @@ -311,6 +311,7 @@ goal_directive : | network_directive[fileName => $arg{fileName}] | module_directive[fileName => $arg{fileName}] | optional_module_directive[fileName => $arg{fileName}] + | resume_directive[fileName => $arg{fileName}] | mountdir_directive[fileName => $arg{fileName}] | mountdev_directive[fileName => $arg{fileName}] | <error> @@ -377,6 +378,19 @@ optional_module_directive: 'OPTIONAL' 'M } # + # Load modules for swap device, and attempt to resume from it + # +resume_directive : 'RESUME' <commit> pathname(?) + { + $return = { + type => 'resume', + value => @{$item{'pathname(?)'}}[0], + origin => "$arg{fileName}:$prevline", + }; + } + | <error: Invalid argument to resume directive> + + # # Mount the fs that fstab lists for pathname # mountdir_directive: 'MOUNTDIR' <commit> pathname mount_point diff -ruHp yaird-0.0.11-debpat/perl/Plan.pm yaird-0.0.11-mod2/perl/Plan.pm --- yaird-0.0.11-debpat/perl/Plan.pm 2005-12-09 13:58:20.000000000 -0500 +++ yaird-0.0.11-mod2/perl/Plan.pm 2005-12-09 17:35:31.000000000 -0500 @@ -623,6 +623,42 @@ sub addFsTabMount ($$$) { addBlockDevMount ($actions, $blockDevName, $mountPoint); } +# +# addResumePlan -- add list of actions to load modules necessary to +# access swap device (either given, or found from /etc/fstab), then +# (if a resume device was found or given) add a short script which +# will effect the resume-from-swap from the given device. +# +sub addResumePlan ($$) { + my ($actions, $swapDevName) = @_; + # treat optional parameter uniformly: '' is equivalent to undef. + $swapDevName=undef if $swapDevName eq '' || $swapDevName eq '--'; + if (! defined ($swapDevName)) { + # find resume-from-swap device in fstab; it will be the + # entry with <type>='swap' and <options> including 'resume' + for my $entry (@{FsTab::all()}) { + if ($entry->type eq 'swap' && + $entry->opts->exists('resume')) { + if (defined ($swapDevName)) { + Base::fatal("duplicate resume-swap entries in fstab."); + } + $swapDevName = $entry->dev; + } + } + } + if (defined ($swapDevName)) { + # device must be in /dev, to determine whether + # it's raid, lvm, scsi or whatever. + my $abd = ActiveBlockDevTab::findByPath($swapDevName); + if (! defined ($abd)) { + Base::fatal ("swap block device '$swapDevName' unavailable"); + } + addDevicePlan ($actions, $abd, []); + # now add script which will do the resume from this device. + $actions->add ("resume", $swapDevName, + devno => $abd->devno); + } +} # # makePlan -- given list of goals read from config file, @@ -652,6 +688,9 @@ sub makePlan ($) { elsif ($type eq 'network') { addNetworkPlan ($actions); } + elsif ($type eq 'resume') { + addResumePlan ($actions, $value); + } elsif ($type eq 'mountdir') { my $mountPoint = $goal->{mountPoint}; Base::assert (defined ($mountPoint)); diff -ruHp yaird-0.0.11-debpat/templates/Default.cfg.in yaird-0.0.11-mod2/templates/Default.cfg.in --- yaird-0.0.11-debpat/templates/Default.cfg.in 2005-12-09 13:58:20.000000000 -0500 +++ yaird-0.0.11-mod2/templates/Default.cfg.in 2005-12-09 14:13:27.000000000 -0500 @@ -129,6 +129,20 @@ CONFIG # TEMPLATE nfsstart # + # RESUME -- handle resume-from-swap (swsusp or suspend2). + # + # This will ensure that all modules required to access the + # resume device (a swap device with the 'resume' option + # specified in /etc/fstab) are loaded, and then will attempt + # to perform a resume. This does nothing if we didn't + # just perform a suspend-to-disk. + # + # You can override the swap partition to resume from by + # providing an optional parameter, ie: + # RESUME "/dev/hda5" + RESUME + + # # MOUNTDIR -- Given a directory name that occurs in # fstab, eg "/", insert all modules needed to access # the underlying block device and file system type, diff -ruHp yaird-0.0.12/templates.old/Debian.cfg yaird-0.0.12/templates/Debian.cfg --- yaird-0.0.12/templates.old/Debian.cfg 2006-01-19 21:41:03.000000000 -0500 +++ yaird-0.0.12/templates/Debian.cfg 2006-01-19 21:46:42.000000000 -0500 @@ -167,7 +167,11 @@ TEMPLATE SET !# ro,rw - mount root read-only or read-write. !# This is like a mount -r; it overrules !# a -o rw. - !# noresume, resume - to be done + !# noresume, resume= - should we resume from a + !# suspend-to-disk? The resume parameter + !# is optional, but overrides automatic + !# detection of the resume partition if present. + !# noresume prevents us from attempting to resume. !# ide - options for module ide_core. !# need a way to append these to proper !# module. do a check on module name @@ -177,6 +181,9 @@ TEMPLATE SET !ro=-r !ip= !nfsroot= + !noresume= + !resume= + !resume2= !init=/sbin/init !for i in $(cat /proc/cmdline) !do @@ -196,6 +203,15 @@ TEMPLATE SET ! nfsroot=*) ! nfsroot="$i" ! ;; + ! noresume) + ! noresume=1 + ! ;; + ! resume=*) + ! resume=${i#resume=} + ! ;; + ! resume2=*) + ! resume2=${i#resume2=} + ! ;; ! ydebug) ! INIT_DEBUG=yes ! esac @@ -368,6 +384,43 @@ TEMPLATE SET # + # Do a resume from swap, unless 'noresume' is on the command-line. + # + TEMPLATE resume + BEGIN + SCRIPT "/init" + BEGIN + !if [ -z "$noresume" ] + !then + ! # for suspend2 (>= 2.2-rc8) + ! if [ -w /proc/suspend2/do_resume ]; then + ! echo > /proc/suspend2/do_resume + ! fi + ! # for suspend2 (< 2.2rc8) + ! if [ -w /proc/software_suspend/do_resume ]; then + ! echo > /proc/software_suspend/do_resume + ! fi + ! # for swsusp + ! if [ -n "$resume" ] + ! then + ! case "$resume" in + ! [0-9]*:[0-9]*) + ! echo "$resume" > /sys/power/resume + ! ;; + ! *[a-z]*[0-9]) + ! cat /sys/block/*/${resume#/dev/}/dev > \ + ! /sys/power/resume + ! ;; + ! esac + ! else + ! echo <TMPL_VAR NAME=devno> > /sys/power/resume + ! fi + !fi + END SCRIPT + END TEMPLATE + + + # # NOTE: honouring the kernel cmdline option ro,rw # is very nice, but... If you have an ext3 in a # file loopback-mounted from vfat, it's unlikely diff -ruHp yaird-0.0.12/templates.old/Fedora.cfg yaird-0.0.12/templates/Fedora.cfg --- yaird-0.0.12/templates.old/Fedora.cfg 2006-01-19 21:41:03.000000000 -0500 +++ yaird-0.0.12/templates/Fedora.cfg 2006-01-19 21:46:23.000000000 -0500 @@ -182,7 +182,11 @@ TEMPLATE SET !# ro,rw - mount root read-only or read-write. !# This is like a mount -r; it overrules !# a -o rw. - !# noresume, resume - to be done + !# noresume, resume= - should we resume from a + !# suspend-to-disk? The resume parameter + !# is optional, but overrides automatic + !# detection of the resume partition if present. + !# noresume prevents us from attempting to resume. !# ide - options for module ide_core. !# need a way to append these to proper !# module. do a check on module name @@ -192,6 +196,9 @@ TEMPLATE SET !ro=-r !ip= !nfsroot= + !noresume= + !resume= + !resume2= !init=/sbin/init !for i in $(cat /proc/cmdline) !do @@ -211,6 +218,15 @@ TEMPLATE SET ! nfsroot=*) ! nfsroot="$i" ! ;; + ! noresume) + ! noresume=1 + ! ;; + ! resume=*) + ! resume=${i#resume=} + ! ;; + ! resume2=*) + ! resume2=${i#resume2=} + ! ;; ! ydebug) ! INIT_DEBUG=yes ! esac @@ -379,6 +395,43 @@ TEMPLATE SET # + # Do a resume from swap, unless 'noresume' is on the command-line. + # + TEMPLATE resume + BEGIN + SCRIPT "/init" + BEGIN + !if [ -z "$noresume" ] + !then + ! # for suspend2 (>= 2.2-rc8) + ! if [ -w /proc/suspend2/do_resume ]; then + ! echo > /proc/suspend2/do_resume + ! fi + ! # for suspend2 (< 2.2rc8) + ! if [ -w /proc/software_suspend/do_resume ]; then + ! echo > /proc/software_suspend/do_resume + ! fi + ! # for swsusp + ! if [ -n "$resume" ] + ! then + ! case "$resume" in + ! [0-9]*:[0-9]*) + ! echo "$resume" > /sys/power/resume + ! ;; + ! *[a-z]*[0-9]) + ! cat /sys/block/*/${resume#/dev/}/dev > \ + ! /sys/power/resume + ! ;; + ! esac + ! else + ! echo <TMPL_VAR NAME=devno> > /sys/power/resume + ! fi + !fi + END SCRIPT + END TEMPLATE + + + # # NOTE: honouring the kernel cmdline option ro,rw # is very nice, but... If you have an ext3 in a # file loopback-mounted from vfat, it's unlikely