Hi,

This is an updated version of the patch that adds support for swap files.
I'd like to apply it soon as the necessary ioctl is in the latest -mm, so
please speak up if you have any objections.

Greetings,
Rafael


---
 HOWTO     |   51 +++++++++++++++++++++++++++++++++++----------------
 resume.c  |    8 +++++++-
 suspend.c |   31 +++++++++++++++++++++++++------
 swsusp.h  |   11 +++++++++--
 4 files changed, 76 insertions(+), 25 deletions(-)

Index: suspend/suspend.c
===================================================================
--- suspend.orig/suspend.c
+++ suspend/suspend.c
@@ -45,6 +45,7 @@
 
 static char snapshot_dev_name[MAX_STR_LEN] = SNAPSHOT_DEVICE;
 static char resume_dev_name[MAX_STR_LEN] = RESUME_DEVICE;
+static loff_t resume_offset;
 static unsigned long pref_image_size = IMAGE_SIZE;
 static int suspend_loglevel = SUSPEND_LOGLEVEL;
 static char compute_checksum;
@@ -89,6 +90,11 @@ static struct config_par parameters[PARA
                .len = MAX_STR_LEN
        },
        {
+               .name = "resume offset",
+               .fmt = "%llu",
+               .ptr = &resume_offset,
+       },
+       {
                .name = "image size",
                .fmt = "%lu",
                .ptr = &pref_image_size,
@@ -185,9 +191,18 @@ static inline int free_swap_pages(int de
        return ioctl(dev, SNAPSHOT_FREE_SWAP_PAGES, 0);
 }
 
-static inline int set_swap_file(int dev, dev_t blkdev)
+static inline int set_swap_file(int dev, dev_t blkdev, loff_t offset)
 {
-       return ioctl(dev, SNAPSHOT_SET_SWAP_FILE, blkdev);
+       struct resume_swap_area swap;
+       int error;
+
+       swap.dev = blkdev;
+       swap.offset = offset;
+       error = ioctl(dev, SNAPSHOT_SET_SWAP_AREA, &swap);
+       if (error && !offset)
+               error = ioctl(dev, SNAPSHOT_SET_SWAP_FILE, blkdev);
+
+       return error;
 }
 
 /**
@@ -236,7 +251,8 @@ struct swap_map_handle {
 #endif
 };
 
-static int init_swap_writer(struct swap_map_handle *handle, int dev, int fd, 
void *buf)
+static int
+init_swap_writer(struct swap_map_handle *handle, int dev, int fd, void *buf)
 {
        if (!buf)
                return -EINVAL;
@@ -477,12 +493,14 @@ static int mark_swap(int fd, loff_t star
 {
        int error = 0;
        unsigned int size = sizeof(struct swsusp_header);
-       unsigned int shift = page_size - size;
+       unsigned int shift = (resume_offset + 1) * page_size - size;
 
        if (lseek(fd, shift, SEEK_SET) != shift)
                return -EIO;
+
        if (read(fd, &swsusp_header, size) < size)
                return -EIO;
+
        if (!memcmp("SWAP-SPACE", swsusp_header.sig, 10) ||
            !memcmp("SWAPSPACE2", swsusp_header.sig, 10)) {
                memcpy(swsusp_header.orig_sig, swsusp_header.sig, 10);
@@ -490,6 +508,7 @@ static int mark_swap(int fd, loff_t star
                swsusp_header.image = start;
                if (lseek(fd, shift, SEEK_SET) != shift)
                        return -EIO;
+
                if (write(fd, &swsusp_header, size) < size)
                        error = -EIO;
        } else {
@@ -620,7 +639,7 @@ static int reset_signature(int fd)
 {
        int ret, error = 0;
        unsigned int size = sizeof(struct swsusp_header);
-       unsigned int shift = page_size - size;
+       unsigned int shift = (resume_offset + 1) * page_size - size;
 
        if (lseek(fd, shift, SEEK_SET) != shift)
                return -EIO;
@@ -1244,7 +1263,7 @@ int main(int argc, char *argv[])
                goto Close_resume_fd;
        }
 
-       if (set_swap_file(snapshot_fd, resume_dev)) {
+       if (set_swap_file(snapshot_fd, resume_dev, resume_offset)) {
                ret = errno;
                fprintf(stderr, "suspend: Could not use the resume device "
                        "(try swapon -a)\n");
Index: suspend/swsusp.h
===================================================================
--- suspend.orig/swsusp.h
+++ suspend/swsusp.h
@@ -14,6 +14,11 @@
 
 #include "encrypt.h"
 
+struct resume_swap_area {
+       loff_t offset;
+       u_int32_t dev;
+} __attribute__((packed));
+
 #define SNAPSHOT_IOC_MAGIC     '3'
 #define SNAPSHOT_FREEZE                        _IO(SNAPSHOT_IOC_MAGIC, 1)
 #define SNAPSHOT_UNFREEZE              _IO(SNAPSHOT_IOC_MAGIC, 2)
@@ -27,7 +32,9 @@
 #define SNAPSHOT_SET_SWAP_FILE         _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned 
int)
 #define SNAPSHOT_S2RAM                 _IO(SNAPSHOT_IOC_MAGIC, 11)
 #define SNAPSHOT_PMOPS                 _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned 
int)
-#define SNAPSHOT_IOC_MAXNR     12
+#define SNAPSHOT_SET_SWAP_AREA         _IOW(SNAPSHOT_IOC_MAGIC, 13, \
+                                                       struct resume_swap_area)
+#define SNAPSHOT_IOC_MAXNR     13
 
 #define PMOPS_PREPARE  1
 #define PMOPS_ENTER    2
@@ -190,7 +197,7 @@ struct buf_block {
 
 #define SUSPEND_SWAPPINESS     100
 
-#define GEN_PARAM      9
+#define GEN_PARAM      10
 
 #ifdef CONFIG_COMPRESS
 #define COMPRESS_PARAM 1
Index: suspend/resume.c
===================================================================
--- suspend.orig/resume.c
+++ suspend/resume.c
@@ -37,6 +37,7 @@
 
 static char snapshot_dev_name[MAX_STR_LEN] = SNAPSHOT_DEVICE;
 static char resume_dev_name[MAX_STR_LEN] = RESUME_DEVICE;
+static loff_t resume_offset;
 static int suspend_loglevel = SUSPEND_LOGLEVEL;
 static int max_loglevel = MAX_LOGLEVEL;
 static char verify_checksum;
@@ -68,6 +69,11 @@ static struct config_par parameters[PARA
                .len = MAX_STR_LEN
        },
        {
+               .name = "resume offset",
+               .fmt = "%llu",
+               .ptr = &resume_offset,
+       },
+       {
                .name = "suspend loglevel",
                .fmt = "%d",
                .ptr = &suspend_loglevel,
@@ -532,7 +538,7 @@ static int read_image(int dev, char *res
        char *buffer = (char *)mem_pool + page_size;
        unsigned int nr_pages;
        unsigned int size = sizeof(struct swsusp_header);
-       unsigned int shift = page_size - size;
+       unsigned int shift = (resume_offset + 1) * page_size - size;
        char c;
 
        fd = open(resume_dev_name, O_RDWR);
Index: suspend/HOWTO
===================================================================
--- suspend.orig/HOWTO
+++ suspend/HOWTO
@@ -10,7 +10,7 @@ I. Quick start
 
 (a) This package
 (b) Linux kernel supporting the swsusp userland interface (2.6.17 or above)
-(c) Swap partition, approximately as big as 1/2 of RAM
+(c) Swap partition or a swap file, approximately as big as 1/2 of RAM
 (d) Special device file for the snapshot device (character, 10, 231), e.g.
 
 crw-r--r--  1 root root 10, 231 Jan 13 21:21 /dev/snapshot
@@ -93,7 +93,12 @@ full path of a swap partition device fil
 [There should be just one resume partition, for now. You'll need at most 1/2
 of your RAM of free space on it, but in some cases it may be smaller, too.
 The s2disk tool may be configured to create quite small snapshot images but
-then some contents of the RAM will have to be swapped out before suspend.]
+then some contents of the RAM will have to be swapped out before suspend.
+
+It also is possible to use a swap file for suspending, but this only works with
+the 2.6.18-mm3 kernel (or later).  In such a case the resume partition is the
+partition that holds the swap file, and there is an additional configuration
+parameter "resume offset" that has to be set, as described below.]
 
 - Build the suspend tools in the usual way:
 
@@ -238,7 +243,9 @@ snapshot device = /dev/snapshot
 
 and the following parameters:
 
+resume offset = <offset_of_the_swap_header>
 image size = <preferred_suspend_image_size_in_bytes>
+shutdown method = <reboot, platform>
 suspend loglevel = <kernel_console_loglevel_during_suspend>
 compute checksum = <y/n>
 compress = <y/n>
@@ -247,7 +254,13 @@ RSA key file = <path>
 max loglevel = <ignored>
 early writeout = <y/n>
 splash = <y/n>
-shutdown method = <reboot, platform>
+
+The "resume offset" parameter is necessary if a swap file is used for
+suspending.  In such a case the device identified by the "resume device"
+parameter is regarded as the partition that contains the swap file, and
+"resume offset" must be equal to the offset from the beginning of this
+partition at which the swap file's header is located, in <PAGE_SIZE> units.
+[For this feature to work, you will need an -mm kernel, 2.6.18-mm3 or newer.]
 
 The "image size" parameter may be used to limit the size of the system
 snapshot image created by the s2disk tool, but it's not mandatory. Namely,
@@ -256,6 +269,17 @@ this parameter, but if that's not possib
 with a bigger image. If "image size" is set to 0, the snapshot image will be
 as small as possible.
 
+The "shutdown method" parameter defines the operation that will be carried out
+after the suspend image has been created and the machine is ready to be powered
+off.  If it is set to "reboot", the machine will be rebooted immediately.
+If it is set to "platform", the machine will be shut down using special
+power management operations available from the kernel that may be necessary
+for the hardware to be properly reinitialized after the resume, and may cause
+the system to resume faster (this is the recommended shutdown method on the
+majority of systems).  For any other value the machine will be powered off.
+The default is to use the "platform" method.  [For this feature to work,
+you will need an -mm kernel, 2.6.18-mm3 or newer.]
+
 If the "compute checksum" parameter is set to 'y', the s2disk and resume
 tools will use the MD5 algorithm to verify the image integrity.
 
@@ -276,12 +300,6 @@ utility will start syncing the resume de
 the image to it.  [This has been reported to speed up the suspend on some
 boxes and eliminates the "fast progress meter and long fsync wait" effect.]
 
-If the "shutdown method" parameter is set to "reboot", the s2disk utility will
-reboot the machine rather than powering down. This is useful when testing
-repeated benchmarks, such as when checking whether "early writeout" produces a
-speedup or not for your combination of hardware, image size, and s2disk
-parameters.
-
 The "splash" parameter is used to make s2disk and/or resume use a splash system
 (when set to 'y').  Currently the bootsplash.org and splashy splash systems
 are supported. Note that for both systems your initrd or initramfs will
@@ -290,15 +308,16 @@ more information.
 
 The resume tool can use the same configuration file that is used by the
 s2disk tool, but it will ignore most of the above parameters.  It will use the
-value of "suspend loglevel" as the kernel console loglevel during resume. 
Additionally
-it will use the value of "max loglevel" as the kernel console loglevel to 
switch to in
-case the resume fails (this parameter is ignored by the s2disk tool).
+value of "suspend loglevel" as the kernel console loglevel during resume.
+Additionally it will use the value of "max loglevel" as the kernel console
+loglevel to switch to in case the resume fails (this parameter is ignored by
+the s2disk tool).
 
 It is not necessary to set "compute checksum = y" and/or "compress = y",
-and/or "encrypt = y" for the resume tool.  The appropriate information related 
to
-these options will be passed to it in the image header by the s2disk tool.
-However, the resume tool will only use the splash system if "splash = y" is 
set for it
-explicitly.
+and/or "encrypt = y" for the resume tool.  The appropriate information related
+to these options will be passed to it in the image header by the s2disk tool.
+However, the resume tool will only use the splash system if "splash = y" is set
+for it explicitly.
 
 In order to create the configuration file for s2disk and/or resume, it is
 recommended to edit the file suspend.conf in the conf/ subdirectory of the

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Suspend-devel mailing list
Suspend-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/suspend-devel

Reply via email to