Package: yaird
Version: 0.0.11-12.3
Followup-For: Bug #329319

Attached is a patch to provide swsusp support for yaird.  It may also
provide suspend2 support; I've included the code fragment given by the
original submitter, but I do not have a suspend2 kernel installed, so it
is untested.  It shouldn't do anything too evil, in any case.

The patch identifies the partition to suspend/resume from by looking for
a 'resume' option on a swap partition in /etc/fstab.  This seems best to
me, as it avoids unnecessary bootloader dependencies, and one may assume
that a future Debian installer might automatically add this option to
the largest swap partition created.

We also support specification of the suspend/resume partition via the
'resume=' kernel command-line option; this will always override the
detected partition.  We support suppression of resume via the "noresume"
kernel command-line option as well.

This patch allows users to configure software suspend using stock Debian
kernels.  Without this, one would have to build a custom non-initrd kernel
with the appropriate modules necessary to access one's swap partition
statically linked in -- and even then it is likely not to work correctly,
as the "late_init" binding of the software_resume() call is (on my machine
at least) still earlier than IDE initialization.

If this patch is accepted upstream, I plan to also submit a patch to the
Linux kernel documentation explaining how to (easily) set up software
suspend/resume on a system with yaird.  The existing kernel documentation
does not adequately treat initrd issues (and resume doesn't actually
currently work on non-initrd kernels).

This patch is against the latest debian version of yaird (0.0.11-12).
It should be sufficient to place this in
  yaird-0.0.11/debian/patches/1099_add_resume_rule.patch
and add '1099_add_resume_rule.patch' to the end of
  yaird-0.0.11/debian/patches/series
 --scott

-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'stable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.15-rc5
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)

Versions of packages yaird depends on:
ii  cpio                         2.6-9       GNU cpio -- a program to manage ar
ii  dash                         0.5.3-1     The Debian Almquist Shell
ii  libc6                        2.3.5-8.1   GNU C Library: Shared libraries an
ii  libhtml-template-perl        2.7-1       HTML::Template : A module for usin
ii  libparse-recdescent-perl     1.94.free-1 Generates recursive-descent parser
ii  perl                         5.8.7-8     Larry Wall's Practical Extraction 

yaird recommends no packages.

-- no debconf information
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
Only in yaird-0.0.11-mod2/perl: Parser.pm~
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));
Only in yaird-0.0.11-mod2/perl: Plan.pm~
diff -ruHp yaird-0.0.11-debpat/templates/Debian.cfg 
yaird-0.0.11-mod2/templates/Debian.cfg
--- yaird-0.0.11-debpat/templates/Debian.cfg    2005-12-09 13:58:20.000000000 
-0500
+++ yaird-0.0.11-mod2/templates/Debian.cfg      2005-12-09 14:14:43.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
@@ -340,6 +356,33 @@ 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/software_suspend/do_resume ]; then
+                       !    echo > /proc/software_suspend/do_resume
+                       !  fi
+                       !  # for swsusp
+                       !  if [ -n "$resume" ]
+                       !  then
+                       !    cat /sys/block/*/${resume#/dev/}/dev > \
+                       !        /sys/power/resume
+                       !  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.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,
Only in yaird-0.0.11-mod2/templates: Default.cfg.in~
diff -ruHp yaird-0.0.11-debpat/templates/Fedora.cfg 
yaird-0.0.11-mod2/templates/Fedora.cfg
--- yaird-0.0.11-debpat/templates/Fedora.cfg    2005-12-09 13:58:20.000000000 
-0500
+++ yaird-0.0.11-mod2/templates/Fedora.cfg      2005-12-09 14:15:49.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
@@ -360,6 +376,33 @@ 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/software_suspend/do_resume ]; then
+                       !    echo > /proc/software_suspend/do_resume
+                       !  fi
+                       !  # for swsusp
+                       !  if [ -n "$resume" ]
+                       !  then
+                       !    cat /sys/block/*/${resume#/dev/}/dev > \
+                       !        /sys/power/resume
+                       !  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
Only in yaird-0.0.11-mod2/templates: Fedora.cfg.orig
Only in yaird-0.0.11-mod2: xyz
Only in yaird-0.0.11-mod2: xyz~

Reply via email to