Scott's latest patch needs a minor adjustment for recent suspend2
patches, which use /proc/suspend2 instead of /proc/software_suspend.

The diff is simply

--- 1000_resume.patch.orig      2006-01-24 09:23:05.000000000 +1300
+++ 1000_resume.patch   2006-01-24 09:23:17.000000000 +1300
@@ -165,8 +165,8 @@
 +                      !then
 +                      !  # for suspend2
 +                      !  # XXX: untested!
-+                      !  if [ -w /proc/software_suspend/do_resume ]; then
-+                      !    echo > /proc/software_suspend/do_resume
++                      !  if [ -w /proc/suspend2/do_resume ]; then
++                      !    echo > /proc/suspend2/do_resume
 +                      !  fi
 +                      !  # for swsusp
 +                      !  if [ -n "$resume" ]
@@ -248,8 +248,8 @@
 +                      !then
 +                      !  # for suspend2
 +                      !  # XXX: untested!
-+                      !  if [ -w /proc/software_suspend/do_resume ]; then
-+                      !    echo > /proc/software_suspend/do_resume
++                      !  if [ -w /proc/suspend2/do_resume ]; then
++                      !    echo > /proc/suspend2/do_resume
 +                      !  fi
 +                      !  # for swsusp
 +                      !  if [ -n "$resume" ]

Updated copy of the whole patch attached. I'm using this with yaird
0.0.12-3 and it's working perfectly. Thanks Scott.

I hope the Yaird team will consider applying this as it does reduce the
effort to get suspend going significantly. Thanks.


Hamish
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,40 @@ 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
+                       !  # XXX: untested!
+                       !  if [ -w /proc/suspend2/do_resume ]; then
+                       !    echo > /proc/suspend2/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,40 @@ 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
+                       !  # XXX: untested!
+                       !  if [ -w /proc/suspend2/do_resume ]; then
+                       !    echo > /proc/suspend2/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

Reply via email to