Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Hibernation: Correct definitions of some ioctls (rev. 2)

Three ioctl numbers belonging to the hibernation userland interface,
SNAPSHOT_ATOMIC_SNAPSHOT, SNAPSHOT_AVAIL_SWAP, SNAPSHOT_GET_SWAP_PAGE,
are defined in a wrong way (eg. not portable). Provide new ioctl numbers for
these ioctls and mark the existing ones as deprecated.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Len Brown <len.brown@intel.com>

authored by

Rafael J. Wysocki and committed by
Len Brown
cc5d207c 96f73749

+34 -20
+13 -13
Documentation/power/userland-swsusp.txt
··· 27 27 The ioctl() commands recognized by the device are: 28 28 29 29 SNAPSHOT_FREEZE - freeze user space processes (the current process is 30 - not frozen); this is required for SNAPSHOT_ATOMIC_SNAPSHOT 30 + not frozen); this is required for SNAPSHOT_CREATE_IMAGE 31 31 and SNAPSHOT_ATOMIC_RESTORE to succeed 32 32 33 33 SNAPSHOT_UNFREEZE - thaw user space processes frozen by SNAPSHOT_FREEZE 34 34 35 - SNAPSHOT_ATOMIC_SNAPSHOT - create a snapshot of the system memory; the 35 + SNAPSHOT_CREATE_IMAGE - create a snapshot of the system memory; the 36 36 last argument of ioctl() should be a pointer to an int variable, 37 37 the value of which will indicate whether the call returned after 38 38 creating the snapshot (1) or after restoring the system memory state 39 39 from it (0) (after resume the system finds itself finishing the 40 - SNAPSHOT_ATOMIC_SNAPSHOT ioctl() again); after the snapshot 40 + SNAPSHOT_CREATE_IMAGE ioctl() again); after the snapshot 41 41 has been created the read() operation can be used to transfer 42 42 it out of the kernel 43 43 ··· 49 49 50 50 SNAPSHOT_FREE - free memory allocated for the snapshot image 51 51 52 - SNAPSHOT_SET_IMAGE_SIZE - set the preferred maximum size of the image 52 + SNAPSHOT_PREF_IMAGE_SIZE - set the preferred maximum size of the image 53 53 (the kernel will do its best to ensure the image size will not exceed 54 54 this number, but if it turns out to be impossible, the kernel will 55 55 create the smallest image possible) 56 56 57 57 SNAPSHOT_GET_IMAGE_SIZE - return the actual size of the hibernation image 58 58 59 - SNAPSHOT_AVAIL_SWAP - return the amount of available swap in bytes (the last 60 - argument should be a pointer to an unsigned int variable that will 59 + SNAPSHOT_AVAIL_SWAP_SIZE - return the amount of available swap in bytes (the 60 + last argument should be a pointer to an unsigned int variable that will 61 61 contain the result if the call is successful). 62 62 63 - SNAPSHOT_GET_SWAP_PAGE - allocate a swap page from the resume partition 63 + SNAPSHOT_ALLOC_SWAP_PAGE - allocate a swap page from the resume partition 64 64 (the last argument should be a pointer to a loff_t variable that 65 65 will contain the swap page offset if the call is successful) 66 66 67 - SNAPSHOT_FREE_SWAP_PAGES - free all swap pages allocated with 68 - SNAPSHOT_GET_SWAP_PAGE 67 + SNAPSHOT_FREE_SWAP_PAGES - free all swap pages allocated by 68 + SNAPSHOT_ALLOC_SWAP_PAGE 69 69 70 70 SNAPSHOT_SET_SWAP_AREA - set the resume partition and the offset (in <PAGE_SIZE> 71 71 units) from the beginning of the partition at which the swap header is ··· 102 102 into the kernel. It has the same limitations as the read() operation. 103 103 104 104 The release() operation frees all memory allocated for the snapshot image 105 - and all swap pages allocated with SNAPSHOT_GET_SWAP_PAGE (if any). 105 + and all swap pages allocated with SNAPSHOT_ALLOC_SWAP_PAGE (if any). 106 106 Thus it is not necessary to use either SNAPSHOT_FREE or 107 107 SNAPSHOT_FREE_SWAP_PAGES before closing the device (in fact it will also 108 108 unfreeze user space processes frozen by SNAPSHOT_UNFREEZE if they are ··· 113 113 partition, or a swap file as storage space (if a swap file is used, the resume 114 114 partition is the partition that holds this file). However, this is not really 115 115 required, as they can use, for example, a special (blank) suspend partition or 116 - a file on a partition that is unmounted before SNAPSHOT_ATOMIC_SNAPSHOT and 116 + a file on a partition that is unmounted before SNAPSHOT_CREATE_IMAGE and 117 117 mounted afterwards. 118 118 119 119 These utilities MUST NOT make any assumptions regarding the ordering of ··· 135 135 The suspending and resuming utilities MUST lock themselves in memory, 136 136 preferrably using mlockall(), before calling SNAPSHOT_FREEZE. 137 137 138 - The suspending utility MUST check the value stored by SNAPSHOT_ATOMIC_SNAPSHOT 138 + The suspending utility MUST check the value stored by SNAPSHOT_CREATE_IMAGE 139 139 in the memory location pointed to by the last argument of ioctl() and proceed 140 140 in accordance with it: 141 141 1. If the value is 1 (ie. the system memory snapshot has just been ··· 149 149 image has been saved. 150 150 (b) The suspending utility SHOULD NOT attempt to perform any 151 151 file system operations (including reads) on the file systems 152 - that were mounted before SNAPSHOT_ATOMIC_SNAPSHOT has been 152 + that were mounted before SNAPSHOT_CREATE_IMAGE has been 153 153 called. However, it MAY mount a file system that was not 154 154 mounted at that time and perform some operations on it (eg. 155 155 use it for saving the image).
+5 -5
kernel/power/power.h
··· 147 147 #define SNAPSHOT_IOC_MAGIC '3' 148 148 #define SNAPSHOT_FREEZE _IO(SNAPSHOT_IOC_MAGIC, 1) 149 149 #define SNAPSHOT_UNFREEZE _IO(SNAPSHOT_IOC_MAGIC, 2) 150 - #define SNAPSHOT_ATOMIC_SNAPSHOT _IOW(SNAPSHOT_IOC_MAGIC, 3, void *) 151 150 #define SNAPSHOT_ATOMIC_RESTORE _IO(SNAPSHOT_IOC_MAGIC, 4) 152 151 #define SNAPSHOT_FREE _IO(SNAPSHOT_IOC_MAGIC, 5) 153 - #define SNAPSHOT_SET_IMAGE_SIZE _IOW(SNAPSHOT_IOC_MAGIC, 6, unsigned long) 154 - #define SNAPSHOT_AVAIL_SWAP _IOR(SNAPSHOT_IOC_MAGIC, 7, void *) 155 - #define SNAPSHOT_GET_SWAP_PAGE _IOR(SNAPSHOT_IOC_MAGIC, 8, void *) 156 152 #define SNAPSHOT_FREE_SWAP_PAGES _IO(SNAPSHOT_IOC_MAGIC, 9) 157 153 #define SNAPSHOT_S2RAM _IO(SNAPSHOT_IOC_MAGIC, 11) 158 154 #define SNAPSHOT_SET_SWAP_AREA _IOW(SNAPSHOT_IOC_MAGIC, 13, \ ··· 156 160 #define SNAPSHOT_GET_IMAGE_SIZE _IOR(SNAPSHOT_IOC_MAGIC, 14, loff_t) 157 161 #define SNAPSHOT_PLATFORM_SUPPORT _IO(SNAPSHOT_IOC_MAGIC, 15) 158 162 #define SNAPSHOT_POWER_OFF _IO(SNAPSHOT_IOC_MAGIC, 16) 159 - #define SNAPSHOT_IOC_MAXNR 16 163 + #define SNAPSHOT_CREATE_IMAGE _IOW(SNAPSHOT_IOC_MAGIC, 17, int) 164 + #define SNAPSHOT_PREF_IMAGE_SIZE _IO(SNAPSHOT_IOC_MAGIC, 18) 165 + #define SNAPSHOT_AVAIL_SWAP_SIZE _IOR(SNAPSHOT_IOC_MAGIC, 19, loff_t) 166 + #define SNAPSHOT_ALLOC_SWAP_PAGE _IOR(SNAPSHOT_IOC_MAGIC, 20, loff_t) 167 + #define SNAPSHOT_IOC_MAXNR 20 160 168 161 169 /* If unset, the snapshot device cannot be open. */ 162 170 extern atomic_t snapshot_device_available;
+16 -2
kernel/power/user.c
··· 40 40 #define PMOPS_ENTER 2 41 41 #define PMOPS_FINISH 3 42 42 43 + /* 44 + * NOTE: The following ioctl definitions are wrong and have been replaced with 45 + * correct ones. They are only preserved here for compatibility with existing 46 + * userland utilities and will be removed in the future. 47 + */ 48 + #define SNAPSHOT_ATOMIC_SNAPSHOT _IOW(SNAPSHOT_IOC_MAGIC, 3, void *) 49 + #define SNAPSHOT_SET_IMAGE_SIZE _IOW(SNAPSHOT_IOC_MAGIC, 6, unsigned long) 50 + #define SNAPSHOT_AVAIL_SWAP _IOR(SNAPSHOT_IOC_MAGIC, 7, void *) 51 + #define SNAPSHOT_GET_SWAP_PAGE _IOR(SNAPSHOT_IOC_MAGIC, 8, void *) 52 + 43 53 44 54 #define SNAPSHOT_MINOR 231 45 55 ··· 201 191 data->frozen = 0; 202 192 break; 203 193 194 + case SNAPSHOT_CREATE_IMAGE: 204 195 case SNAPSHOT_ATOMIC_SNAPSHOT: 205 196 if (data->mode != O_RDONLY || !data->frozen || data->ready) { 206 197 error = -EPERM; ··· 209 198 } 210 199 error = hibernation_snapshot(data->platform_support); 211 200 if (!error) 212 - error = put_user(in_suspend, (unsigned int __user *)arg); 201 + error = put_user(in_suspend, (int __user *)arg); 213 202 if (!error) 214 203 data->ready = 1; 215 204 break; ··· 230 219 data->ready = 0; 231 220 break; 232 221 222 + case SNAPSHOT_PREF_IMAGE_SIZE: 233 223 case SNAPSHOT_SET_IMAGE_SIZE: 234 224 image_size = arg; 235 225 break; ··· 245 233 error = put_user(size, (loff_t __user *)arg); 246 234 break; 247 235 236 + case SNAPSHOT_AVAIL_SWAP_SIZE: 248 237 case SNAPSHOT_AVAIL_SWAP: 249 238 size = count_swap_pages(data->swap, 1); 250 239 size <<= PAGE_SHIFT; 251 240 error = put_user(size, (loff_t __user *)arg); 252 241 break; 253 242 243 + case SNAPSHOT_ALLOC_SWAP_PAGE: 254 244 case SNAPSHOT_GET_SWAP_PAGE: 255 245 if (data->swap < 0 || data->swap >= MAX_SWAPFILES) { 256 246 error = -ENODEV; ··· 261 247 offset = alloc_swapdev_block(data->swap); 262 248 if (offset) { 263 249 offset <<= PAGE_SHIFT; 264 - error = put_user(offset, (sector_t __user *)arg); 250 + error = put_user(offset, (loff_t __user *)arg); 265 251 } else { 266 252 error = -ENOSPC; 267 253 }