linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@dell.com>
To: "Rafael J . Wysocki" <rjw@rjwysocki.net>
Cc: linux-acpi@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	Mario Limonciello <mario.limonciello@dell.com>
Subject: [RFC] power/hibernate: Make passing hibernate offsets more friendly
Date: Wed, 28 Feb 2018 11:43:49 -0600	[thread overview]
Message-ID: <1519839829-2191-1-git-send-email-mario.limonciello@dell.com> (raw)

Currently the only way to specify a hibernate offset for a swap
file is on the kernel command line.

This makes some changes to improve:
1) Add a new /sys/power/disk_offset that lets userspace specify
the offset and disk to use when initiating a hibernate cycle.

2) Adjust /sys/power/resume interpretation to also read in an
offset.

Actually klibc's /bin/resume has supported passing a hibernate
offset in since 20695264e21dcbde309cd81f73cfe2cea42e779d.

The kernel was just lobbing anything after the device specified
off the string.  Instead parse that and populate hibernate offset
with it.

Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
---
An alternative to introducing a new sysfs parameter may be to document
setting these values via /sys/power/resume.  If the wrong signature is found
on the swapfile/swap partition by the kernel it does show an error
but it updates the values and they'll work when actually invoked later.

In that case it may make sense to adjust that error and make it level
info and explain the situation.

 kernel/power/hibernate.c | 59 ++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 47 insertions(+), 12 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index a5c36e9..f606ed6 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -1025,33 +1025,68 @@ static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
 
 power_attr(disk);
 
-static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr,
-			   char *buf)
-{
-	return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device),
-		       MINOR(swsusp_resume_device));
-}
-
-static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
-			    const char *buf, size_t n)
+static int parse_device_input(const char *buf, size_t n)
 {
+	unsigned long long offset;
 	dev_t res;
 	int len = n;
 	char *name;
+	char *last;
 
 	if (len && buf[len-1] == '\n')
 		len--;
 	name = kstrndup(buf, len, GFP_KERNEL);
 	if (!name)
 		return -ENOMEM;
-
+	last = strrchr(name, ':');
+	printk("%lu %s %s %d", last-name, name, last, len);
+	if (last != NULL &&
+	    (last-name) != len-1 &&
+	    sscanf(last+1, "%llu", &offset) == 1)
+                swsusp_resume_block = offset;
 	res = name_to_dev_t(name);
 	kfree(name);
 	if (!res)
 		return -EINVAL;
+	swsusp_resume_device = res;
+
+	return 1;
+}
+
+static ssize_t disk_offset_show(struct kobject *kobj, struct kobj_attribute *attr,
+				char *buf)
+{
+	return sprintf(buf,"%d:%d:%lu\n", MAJOR(swsusp_resume_device),
+		       MINOR(swsusp_resume_device), swsusp_resume_block);
+}
+
+static ssize_t disk_offset_store(struct kobject *kobj, struct kobj_attribute *attr,
+				 const char *buf, size_t n)
+{
+	ssize_t rc = parse_device_input(buf, n);
+	if (rc < 0)
+		return rc;
+
+	return n;
+}
+
+power_attr(disk_offset);
+
+static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr,
+			   char *buf)
+{
+	return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device),
+		       MINOR(swsusp_resume_device));
+}
+
+static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
+			    const char *buf, size_t n)
+{
+	ssize_t rc = parse_device_input(buf, n);
+	if (rc < 0)
+		return rc;
 
 	lock_system_sleep();
-	swsusp_resume_device = res;
 	unlock_system_sleep();
 	pr_info("Starting manual resume from disk\n");
 	noresume = 0;
@@ -1106,6 +1141,7 @@ power_attr(reserved_size);
 
 static struct attribute * g[] = {
 	&disk_attr.attr,
+	&disk_offset_attr.attr,
 	&resume_attr.attr,
 	&image_size_attr.attr,
 	&reserved_size_attr.attr,
@@ -1125,7 +1161,6 @@ static int __init pm_disk_init(void)
 
 core_initcall(pm_disk_init);
 
-
 static int __init resume_setup(char *str)
 {
 	if (noresume)
-- 
2.7.4

             reply	other threads:[~2018-02-28 17:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-28 17:43 Mario Limonciello [this message]
2018-02-28 18:11 ` [RFC] power/hibernate: Make passing hibernate offsets more friendly Andy Shevchenko
2018-02-28 20:05   ` Mario.Limonciello
2018-03-02  9:42     ` Rafael J. Wysocki
2018-03-02 13:41       ` Mario.Limonciello

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1519839829-2191-1-git-send-email-mario.limonciello@dell.com \
    --to=mario.limonciello@dell.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).