[PATCH] swsusp: add ioctl for swap files support
authorRafael J. Wysocki <rjw@sisk.pl>
Thu, 7 Dec 2006 04:34:15 +0000 (20:34 -0800)
committerLinus Torvalds <torvalds@woody.osdl.org>
Thu, 7 Dec 2006 16:39:27 +0000 (08:39 -0800)
To be able to use swap files as suspend storage from the userland suspend
tools we need an additional ioctl() that will allow us to provide the kernel
with both the swap header's offset and the identification of the resume
partition.

The new ioctl() should be regarded as a replacement for the
SNAPSHOT_SET_SWAP_FILE ioctl() that from now on will be considered as
obsolete, but has to stay for backwards compatibility of the interface.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
kernel/power/power.h
kernel/power/user.c

index adaf7d4fbdaf468f6b99131572ec5c95904384a3..7dbfd9f67e1cabf35c3562fb507a2b17d14e6b85 100644 (file)
@@ -106,6 +106,16 @@ extern int snapshot_write_next(struct snapshot_handle *handle, size_t count);
 extern int snapshot_image_loaded(struct snapshot_handle *handle);
 extern void snapshot_free_unused_memory(struct snapshot_handle *handle);
 
+/*
+ * This structure is used to pass the values needed for the identification
+ * of the resume swap area from a user space to the kernel via the
+ * SNAPSHOT_SET_SWAP_AREA ioctl
+ */
+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)
@@ -119,7 +129,9 @@ extern void snapshot_free_unused_memory(struct snapshot_handle *handle);
 #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
index f0b7ef8bdd7493bb416acb79bc81197acef997b2..05c58a2c0dd4c51ddd5756af9990250b48a19d37 100644 (file)
@@ -343,6 +343,37 @@ OutS3:
                }
                break;
 
+       case SNAPSHOT_SET_SWAP_AREA:
+               if (data->bitmap) {
+                       error = -EPERM;
+               } else {
+                       struct resume_swap_area swap_area;
+                       dev_t swdev;
+
+                       error = copy_from_user(&swap_area, (void __user *)arg,
+                                       sizeof(struct resume_swap_area));
+                       if (error) {
+                               error = -EFAULT;
+                               break;
+                       }
+
+                       /*
+                        * User space encodes device types as two-byte values,
+                        * so we need to recode them
+                        */
+                       swdev = old_decode_dev(swap_area.dev);
+                       if (swdev) {
+                               offset = swap_area.offset;
+                               data->swap = swap_type_of(swdev, offset);
+                               if (data->swap < 0)
+                                       error = -ENODEV;
+                       } else {
+                               data->swap = -1;
+                               error = -EINVAL;
+                       }
+               }
+               break;
+
        default:
                error = -ENOTTY;