diff mbox

[v2,1/2] power/hibernate: Make passing hibernate offsets more friendly

Message ID 1522184333-27582-1-git-send-email-mario.limonciello@dell.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Limonciello, Mario March 27, 2018, 8:58 p.m. UTC
Currently the only way to specify a hibernate offset for a
swap file is on the kernel command line.

Add a new /sys/power/resume_offset that lets userspace
specify the offset and disk to use when initiating a hibernate
cycle.

Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
---
 Documentation/ABI/testing/sysfs-power | 14 ++++++++++++++
 Documentation/power/swsusp.txt        | 10 +++++++++-
 kernel/power/hibernate.c              | 21 +++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)

Comments

kernel test robot March 28, 2018, 2:01 p.m. UTC | #1
Hi Mario,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.16-rc7 next-20180328]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Mario-Limonciello/power-hibernate-Make-passing-hibernate-offsets-more-friendly/20180328-212230
config: i386-randconfig-x006-201812 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   kernel/power/hibernate.c: In function 'resume_offset_show':
   kernel/power/hibernate.c:1067:25: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'sector_t {aka long long unsigned int}' [-Wformat=]
     return sprintf(buf, "%lu\n", swsusp_resume_block);
                          ~~^
                          %llu
   kernel/power/hibernate.c: In function 'resume_offset_store':
>> kernel/power/hibernate.c:1074:28: error: passing argument 3 of 'kstrtoul' from incompatible pointer type [-Werror=incompatible-pointer-types]
     int rc = kstrtoul(buf, 0, &swsusp_resume_block);
                               ^
   In file included from include/linux/list.h:9:0,
                    from include/linux/preempt.h:11,
                    from include/linux/spinlock.h:51,
                    from include/linux/swap.h:5,
                    from include/linux/suspend.h:5,
                    from kernel/power/hibernate.c:16:
   include/linux/kernel.h:332:32: note: expected 'long unsigned int *' but argument is of type 'sector_t * {aka long long unsigned int *}'
    static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
                                   ^~~~~~~~
   cc1: some warnings being treated as errors

vim +/kstrtoul +1074 kernel/power/hibernate.c

  1063	
  1064	static ssize_t resume_offset_show(struct kobject *kobj,
  1065					  struct kobj_attribute *attr, char *buf)
  1066	{
> 1067		return sprintf(buf, "%lu\n", swsusp_resume_block);
  1068	}
  1069	
  1070	static ssize_t resume_offset_store(struct kobject *kobj,
  1071					   struct kobj_attribute *attr, const char *buf,
  1072					   size_t n)
  1073	{
> 1074		int rc = kstrtoul(buf, 0, &swsusp_resume_block);
  1075	
  1076		if (rc)
  1077			return rc;
  1078	
  1079		return n;
  1080	}
  1081	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/Documentation/ABI/testing/sysfs-power b/Documentation/ABI/testing/sysfs-power
index 1e0d1da..2f813d6 100644
--- a/Documentation/ABI/testing/sysfs-power
+++ b/Documentation/ABI/testing/sysfs-power
@@ -287,3 +287,17 @@  Description:
 		Writing a "1" to this file enables the debug messages and
 		writing a "0" (default) to it disables them.  Reads from
 		this file return the current value.
+
+What:		/sys/power/resume_offset
+Date:		April 2018
+Contact:	Mario Limonciello <mario.limonciello@dell.com>
+Description:
+		This file is used for telling the kernel an offset into a disk
+		to use when hibernating the system such as with a swap file.
+
+		Reads from this file will display the current offset
+		the kernel will be using on the next hibernation
+		attempt.
+
+		Using this sysfs file will override any values that were
+		set using the kernel command line for disk offset.
\ No newline at end of file
diff --git a/Documentation/power/swsusp.txt b/Documentation/power/swsusp.txt
index 9f2f942..cc87adf 100644
--- a/Documentation/power/swsusp.txt
+++ b/Documentation/power/swsusp.txt
@@ -24,8 +24,16 @@  Some warnings, first.
  * see the FAQ below for details.  (This is not true for more traditional
  * power states like "standby", which normally don't turn USB off.)
 
+Swap partition:
 You need to append resume=/dev/your_swap_partition to kernel command
-line. Then you suspend by
+line or specify it using /sys/power/resume.
+
+Swap file:
+If using a swapfile you can also specify a resume offset using
+resume_offset=<number> on the kernel command line or specify it
+in /sys/power/resume_offset.
+
+After preparing then you suspend by
 
 echo shutdown > /sys/power/disk; echo disk > /sys/power/state
 
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index a5c36e9..16e8645 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -1061,6 +1061,26 @@  static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
 
 power_attr(resume);
 
+static ssize_t resume_offset_show(struct kobject *kobj,
+				  struct kobj_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%lu\n", swsusp_resume_block);
+}
+
+static ssize_t resume_offset_store(struct kobject *kobj,
+				   struct kobj_attribute *attr, const char *buf,
+				   size_t n)
+{
+	int rc = kstrtoul(buf, 0, &swsusp_resume_block);
+
+	if (rc)
+		return rc;
+
+	return n;
+}
+
+power_attr(resume_offset);
+
 static ssize_t image_size_show(struct kobject *kobj, struct kobj_attribute *attr,
 			       char *buf)
 {
@@ -1106,6 +1126,7 @@  power_attr(reserved_size);
 
 static struct attribute * g[] = {
 	&disk_attr.attr,
+	&resume_offset_attr.attr,
 	&resume_attr.attr,
 	&image_size_attr.attr,
 	&reserved_size_attr.attr,