swsusp: remove code duplication between disk.c and user.c
Currently, much of the code in kernel/power/disk.c is duplicated in kernel/power/user.c , mainly for historical reasons. By eliminating this code duplication we can reduce the size of user.c quite substantially and remove the maintenance difficulty resulting from it. [bunk@stusta.de: kernel/power/disk.c: make code static] Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Pavel Machek <pavel@ucw.cz> Cc: Nigel Cunningham <nigel@nigel.suspend2.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
Linus Torvalds
parent
127067a9c9
commit
7777fab989
@ -128,83 +128,6 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf,
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline int platform_prepare(void)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
if (hibernation_ops)
|
||||
error = hibernation_ops->prepare();
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static inline void platform_finish(void)
|
||||
{
|
||||
if (hibernation_ops)
|
||||
hibernation_ops->finish();
|
||||
}
|
||||
|
||||
static inline int snapshot_suspend(int platform_suspend)
|
||||
{
|
||||
int error;
|
||||
|
||||
mutex_lock(&pm_mutex);
|
||||
/* Free memory before shutting down devices. */
|
||||
error = swsusp_shrink_memory();
|
||||
if (error)
|
||||
goto Finish;
|
||||
|
||||
if (platform_suspend) {
|
||||
error = platform_prepare();
|
||||
if (error)
|
||||
goto Finish;
|
||||
}
|
||||
suspend_console();
|
||||
error = device_suspend(PMSG_FREEZE);
|
||||
if (error)
|
||||
goto Resume_devices;
|
||||
|
||||
error = disable_nonboot_cpus();
|
||||
if (!error) {
|
||||
in_suspend = 1;
|
||||
error = swsusp_suspend();
|
||||
}
|
||||
enable_nonboot_cpus();
|
||||
Resume_devices:
|
||||
if (platform_suspend)
|
||||
platform_finish();
|
||||
|
||||
device_resume();
|
||||
resume_console();
|
||||
Finish:
|
||||
mutex_unlock(&pm_mutex);
|
||||
return error;
|
||||
}
|
||||
|
||||
static inline int snapshot_restore(void)
|
||||
{
|
||||
int error;
|
||||
|
||||
mutex_lock(&pm_mutex);
|
||||
pm_prepare_console();
|
||||
suspend_console();
|
||||
error = device_suspend(PMSG_PRETHAW);
|
||||
if (error)
|
||||
goto Finish;
|
||||
|
||||
error = disable_nonboot_cpus();
|
||||
if (!error)
|
||||
error = swsusp_resume();
|
||||
|
||||
enable_nonboot_cpus();
|
||||
Finish:
|
||||
device_resume();
|
||||
resume_console();
|
||||
pm_restore_console();
|
||||
mutex_unlock(&pm_mutex);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int snapshot_ioctl(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
@ -251,7 +174,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
|
||||
error = -EPERM;
|
||||
break;
|
||||
}
|
||||
error = snapshot_suspend(data->platform_suspend);
|
||||
error = hibernation_snapshot(data->platform_suspend);
|
||||
if (!error)
|
||||
error = put_user(in_suspend, (unsigned int __user *)arg);
|
||||
if (!error)
|
||||
@ -265,7 +188,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
|
||||
error = -EPERM;
|
||||
break;
|
||||
}
|
||||
error = snapshot_restore();
|
||||
error = hibernation_restore();
|
||||
break;
|
||||
|
||||
case SNAPSHOT_FREE:
|
||||
@ -377,19 +300,14 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
|
||||
switch (arg) {
|
||||
|
||||
case PMOPS_PREPARE:
|
||||
if (hibernation_ops) {
|
||||
data->platform_suspend = 1;
|
||||
error = 0;
|
||||
} else {
|
||||
error = -ENOSYS;
|
||||
}
|
||||
data->platform_suspend = 1;
|
||||
error = 0;
|
||||
break;
|
||||
|
||||
case PMOPS_ENTER:
|
||||
if (data->platform_suspend) {
|
||||
kernel_shutdown_prepare(SYSTEM_SUSPEND_DISK);
|
||||
error = hibernation_ops->enter();
|
||||
}
|
||||
if (data->platform_suspend)
|
||||
error = hibernation_platform_enter();
|
||||
|
||||
break;
|
||||
|
||||
case PMOPS_FINISH:
|
||||
|
Reference in New Issue
Block a user