[klibc] [PATCH] resume: Use the kernel API from 4.17 for setting resume offset

Mario Limonciello mario.limonciello at dell.com
Fri Mar 30 07:22:15 PDT 2018


The previous API for setting resume offset didn't actually work
in the kernel.  It silently ignored this part of the string.

A new API was introduced under /sys/power/resume_offset specifically
for setting this value.
https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id=648464076160ee7a4112d05eea13621790ab9d04

Signed-off-by: Mario Limonciello <mario.limonciello at dell.com>
---
 usr/kinit/resume/resumelib.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/usr/kinit/resume/resumelib.c b/usr/kinit/resume/resumelib.c
index e557b05..5fc2019 100644
--- a/usr/kinit/resume/resumelib.c
+++ b/usr/kinit/resume/resumelib.c
@@ -45,7 +45,9 @@ int resume(const char *resume_file, unsigned long long resume_offset)
 {
 	dev_t resume_device;
 	int powerfd = -1;
+	int offsetfd = -1;
 	char device_string[64];
+	char offset_string[64];
 	int len;
 
 	resume_device = name_to_dev_t(resume_file);
@@ -55,13 +57,23 @@ int resume(const char *resume_file, unsigned long long resume_offset)
 		goto failure;
 	}
 
+	/* Write the offset, this won't work on less than 4.17 */
+	offsetfd = open("/sys/power/resume_offset", O_WRONLY);
+	if (offsetfd > 0) {
+		len = snprintf(offset_string, sizeof offset_string, "%llu",
+			       resume_offset);
+		if (len >= sizeof offset_string)
+			goto fail_r;
+		if (write(offsetfd, offset_string, len) != len)
+			goto fail_r;
+	}
+
 	if ((powerfd = open("/sys/power/resume", O_WRONLY)) < 0)
 		goto fail_r;
 
 	len = snprintf(device_string, sizeof device_string,
-		       "%u:%u:%llu",
-		       major(resume_device), minor(resume_device),
-		       resume_offset);
+		       "%u:%u",
+		       major(resume_device), minor(resume_device));
 
 	/* This should never happen */
 	if (len >= sizeof device_string)
-- 
2.7.4



More information about the klibc mailing list