[PATCH 9/9] PM: suspend_block: Add timeout support to user-space suspend_blockers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This also allows a grace period to be set where suspend is blocked for a whileif a user-space suspend_blocker is destroyed while it was active.
Signed-off-by: Arve Hjønnevåg <arve@xxxxxxxxxxx>--- Documentation/power/suspend-blockers.txt |    7 +++++++ include/linux/suspend_block_dev.h        |    1 + kernel/power/user_suspend_blocker.c      |   23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/Documentation/power/suspend-blockers.txt b/Documentation/power/suspend-blockers.txtindex fd9f932..747c163 100644--- a/Documentation/power/suspend-blockers.txt+++ b/Documentation/power/suspend-blockers.txt@@ -113,6 +113,8 @@ then call:  To activate a suspend_blocker call:     ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK);+or+    ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK_TIMEOUT, &timespec_timeout);  To unblock call:     ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK);@@ -120,3 +122,8 @@ To unblock call: To destroy the suspend_blocker, close the device:     close(fd); +A module parameter, unclean_exit_grace_period, can be set to allow servers+some time to restart if they crash with an active suspend_blocker. If the+process dies or the device is closed while the suspend_blocker is active, a+suspend_blocker will be held for the number of seconds specified.+diff --git a/include/linux/suspend_block_dev.h b/include/linux/suspend_block_dev.hindex a7c0bf9..cff4943 100644--- a/include/linux/suspend_block_dev.h+++ b/include/linux/suspend_block_dev.h@@ -20,6 +20,7 @@  #define SUSPEND_BLOCKER_IOCTL_INIT(len)		_IOC(_IOC_WRITE, 's', 0, len) #define SUSPEND_BLOCKER_IOCTL_BLOCK		_IO('s', 1)+#define SUSPEND_BLOCKER_IOCTL_BLOCK_TIMEOUT	_IOW('s', 2, struct timespec) #define SUSPEND_BLOCKER_IOCTL_UNBLOCK		_IO('s', 3)  #endifdiff --git a/kernel/power/user_suspend_blocker.c b/kernel/power/user_suspend_blocker.cindex 69b3ddb..b853f66 100644--- a/kernel/power/user_suspend_blocker.c+++ b/kernel/power/user_suspend_blocker.c@@ -26,7 +26,12 @@ enum { static int debug_mask = DEBUG_FAILURE; module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP); +static int unclean_exit_grace_period;+module_param_named(unclean_exit_grace_period, unclean_exit_grace_period, int,+						S_IRUGO | S_IWUSR | S_IWGRP);+ static DEFINE_MUTEX(ioctl_lock);+static struct suspend_blocker unclean_exit_suspend_blocker;  struct user_suspend_blocker { 	struct suspend_blocker	blocker;@@ -58,6 +63,8 @@ static long user_suspend_blocker_ioctl(struct file *file, unsigned int cmd, { 	void __user *arg = (void __user *)_arg; 	struct user_suspend_blocker *bl;+	struct timespec ts;+	unsigned long timeout; 	long ret;  	mutex_lock(&ioctl_lock);@@ -75,6 +82,15 @@ static long user_suspend_blocker_ioctl(struct file *file, unsigned int cmd, 		suspend_block(&bl->blocker); 		ret = 0; 		break;+	case SUSPEND_BLOCKER_IOCTL_BLOCK_TIMEOUT:+		if (copy_from_user(&ts, arg, sizeof(ts))) {+			ret = -EFAULT;+			goto done;+		}+		timeout  = timespec_to_jiffies(&ts);+		suspend_block_timeout(&bl->blocker, timeout);+		ret = 0;+		break; 	case SUSPEND_BLOCKER_IOCTL_UNBLOCK: 		suspend_unblock(&bl->blocker); 		ret = 0;@@ -95,6 +111,10 @@ static int user_suspend_blocker_release(struct inode *inode, struct file *file) 	struct user_suspend_blocker *bl = file->private_data; 	if (!bl) 		return 0;+	if (suspend_blocker_is_active(&bl->blocker) &&+	    unclean_exit_grace_period)+		suspend_block_timeout(&unclean_exit_suspend_blocker,+					unclean_exit_grace_period * HZ); 	suspend_blocker_destroy(&bl->blocker); 	kfree(bl); 	return 0;@@ -113,12 +133,15 @@ struct miscdevice user_suspend_blocker_device = {  static int __init user_suspend_blocker_init(void) {+	suspend_blocker_init(&unclean_exit_suspend_blocker,+				"user-unclean-exit"); 	return misc_register(&user_suspend_blocker_device); }  static void __exit user_suspend_blocker_exit(void) { 	misc_deregister(&user_suspend_blocker_device);+	suspend_blocker_destroy(&unclean_exit_suspend_blocker); }  module_init(user_suspend_blocker_init);-- 1.6.1
_______________________________________________linux-pm mailing listlinux-pm@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx://lists.linux-foundation.org/mailman/listinfo/linux-pm


[Index of Archives]     [Linux ACPI]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [CPU Freq]     [Kernel Newbies]     [Fedora Kernel]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux