On Fri, Oct 06, 2006 at 10:01:19AM +0200, Tim Dijkstra wrote:
> On Fri, 6 Oct 2006 07:56:11 +0200
> Stefan Seyfried <[EMAIL PROTECTED]> wrote:
> 
> > Ok. I am going to try to move all our powersaved scripts to pm-utils,
> > and making it work with uswsusp (which is our default now) would have
> > been one of the tasks anyway :-)
> 
> Very good. Takes something from my todo list;)

how about this:

Index: functions
===================================================================
RCS file: /cvs/pm-utils/pm-utils/pm/functions,v
retrieving revision 1.20
diff -u -p -r1.20 functions
--- functions   28 Sep 2006 21:25:36 -0000      1.20
+++ functions   6 Oct 2006 09:27:49 -0000
@@ -96,14 +102,32 @@ pm_main()
        run_hooks "$1"
        sync ; sync ; sync
 
+       [ -e /etc/pm/config.d/$1 ] && . /etc/pm/config.d/$1
+
        case "$1" in
                suspend)
                        pm-pmu --suspend || echo -n "mem" > /sys/power/state
                        run_hooks resume reverse
                        ;;
                hibernate)
-                       echo -n "platform" > /sys/power/disk
-                       echo -n "disk" > /sys/power/state
+                       if [ -z "$HIBERNATE" ]; then
+                               if [ -x /usr/sbin/s2disk -a -c /dev/snapshot ]; 
then
+                                       HIBERNATE="userspace"
+                               else
+                                       HIBERNATE="kernel"
+                               fi
+                       fi
+                       if checkhibernate; then
+                               case $HIBERNATE in
+                                       userspace)
+                                               /usr/sbin/s2disk -f 
/var/lib/s2disk.conf
+                                               ;;
+                                       kernel)
+                                               echo -n "platform" > 
/sys/power/disk
+                                               echo -n "disk" > 
/sys/power/state
+                                               ;;
+                               esac
+                       fi
                        run_hooks thaw reverse
                        ;;
        esac
@@ -155,3 +213,52 @@ restorestate()
 {
        eval echo \$${1}_STATE
 }
+
+# sanity check the environment if resume will be possible after hibernate
+checkhibernate()
+{
+       if [ "$HIBERNATE" = "kernel" ]; then
+               read RDEV < /sys/power/resume
+               if [ "$RDEV" = "0:0" ]; then
+                       # DEBUG "no resume partition set"
+                       # maybe "resume=..." was given, but initrd did not set 
up
+                       # /sys/power/resume correctly.
+                       return 1
+               fi
+               if [ -n "$IMAGE_SIZE" -a -w /sys/power/image_size ]; then
+                       echo "$IMAGE_SIZE" > /sys/power/image_size 2>/dev/null
+               fi
+       fi
+       RDEV=""
+       read CMDLINE < /proc/cmdline
+       for CMD in $CMDLINE; do
+               case $CMD in
+                       resume=*) RDEV=${CMD#*=}
+                       break ;;
+               esac
+       done
+       if [ -z "$RDEV" ]; then
+               # DEBUG "no resume parameter"
+               return 1
+       fi
+       while read SDEV STYPE DUMMY; do
+               [ "$STYPE" != "partition" ] && continue
+               [ "$SDEV" = "$RDEV" ] && break
+               SDEV=""
+       done < /proc/swaps
+       if [ -z "$SDEV" ]; then
+               # DEBUG "resume partition '$RDEV' not swapon'ed"
+               return 1
+       fi
+       if [ "$HIBERNATE" = "userspace" ]; then
+               rm -f /var/lib/s2disk.conf
+               echo "resume device = $RDEV" >> /var/lib/s2disk.conf
+               if [ -n "$IMAGE_SIZE" ]; then
+                       echo "image size = $IMAGE_SIZE" >> /var/lib/s2disk.conf
+               # add the parameters from /etc/suspend.conf to 
/var/lib/s2disk.conf
+               if [ -e /etc/suspend.conf ]; then
+                       sed '/^[[:space:]]*\(#\|$\)/d;' /etc/suspend.conf >> 
/var/lib/s2disk.conf
+               fi
+       fi
+       return 0
+}


This is basically how i did it until now in powersaved.
Precondition:
- your initrd does invoke resume with the device from "resume=". I think it
  is a good idea to use the well known resume parameter also for userspace
  suspend. Generally, the user should not need to care about which method he
  uses.
  Right now i do not even copy /etc/suspend.conf into the initrd anymore
  since it is not needed for resume.

Then i generate a temporary suspend config file in /var/lib/s2disk.conf from
the resume= parameter (read from /proc/cmdline) and from IMAGE_SIZE (which
might be set in /etc/pm/config.d/hibernate or calculated intelligently from
the free swap space and the total amount of system memory, this is not yet
in this patch).
I append any options from /etc/suspend.conf to this temporary config file.
Since s2disk just takes the latest incarnation of an option, the settings
from /etc/suspend.conf override our automatic determined setting.
I ship an empty (all options commented out) config file, and it just works
out of the box, if the resume= parameter is correctly set (done by the
installer).

What do you think about that?

-- 
Stefan Seyfried
QA / R&D Team Mobile Devices        |              "Any ideas, John?"
SUSE LINUX Products GmbH, Nürnberg  | "Well, surrounding them's out." 
_______________________________________________
Pm-utils mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pm-utils

Reply via email to