Re: [PATCH/RFC] Add support to resume swsusp from initrd

From: Matthew Garrett
Date: Mon Dec 06 2004 - 18:26:26 EST


Ok, how does this one look? (applies on top of the __init patch from
last time)

resume_device has been renamed to swsusp_resume_device to avoid
confusion with the resume_device function in drivers/power. If a resume
device has been set, it's assumed that userspace has been started. If
not, it behaves as before. name_to_dev_t is only called if userspace
hasn't been started - otherwise, we depend on the values provided by
userspace being correct. If userspace has been started, we freeze tasks
and free memory before starting the resume. If this looks ok, I'll merge
it to your changes after 2.6.10.


diff -ur kernel.bak/power/disk.c kernel/power/disk.c
--- kernel.bak/power/disk.c 2004-12-05 16:11:19.000000000 +0000
+++ kernel/power/disk.c 2004-12-06 22:29:34.000000000 +0000
@@ -1,3 +1,4 @@
+
/*
* kernel/power/disk.c - Suspend-to-disk support.
*
@@ -28,7 +29,7 @@
extern int swsusp_read(void);
extern int swsusp_resume(void);
extern int swsusp_free(void);
-
+extern dev_t swsusp_resume_device;

static int noresume = 0;
char resume_file[256] = CONFIG_PM_STD_PARTITION;
@@ -223,6 +224,18 @@

pr_debug("PM: Reading pmdisk image.\n");

+ if (swsusp_resume_device) {
+ /* We want to be really sure that userspace isn't touching
+ anything at this point... */
+ if (freeze_processes()) {
+ goto Done;
+ }
+
+ /* And then make sure that we have enough memory to do the
+ resume */
+ free_some_memory();
+ }
+
if ((error = swsusp_read()))
goto Done;

@@ -327,8 +340,42 @@

power_attr(disk);

+static ssize_t resume_show(struct subsystem * subsys, char * buf) {
+ return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device),
+ MINOR(swsusp_resume_device));
+}
+
+static ssize_t resume_store(struct subsystem * s, const char * buf, size_t n)
+{
+ int error = 0;
+ int len;
+ char *p;
+ unsigned maj, min;
+ dev_t (res);
+
+ p = memchr(buf, '\n', n);
+ len = p ? p - buf : n;
+
+ if (sscanf(buf, "%u:%u", &maj, &min) == 2) {
+ res = MKDEV(maj, min);
+ if (maj == MAJOR(res) && min == MINOR(res)) {
+ swsusp_resume_device = res;
+ error = software_resume();
+ } else {
+ error = -EINVAL;
+ }
+ } else {
+ error = -EINVAL;
+ }
+
+ return error ? error : n;
+}
+
+power_attr(resume);
+
static struct attribute * g[] = {
&disk_attr.attr,
+ &resume_attr.attr,
NULL,
};

diff -ur kernel.bak/power/swsusp.c kernel/power/swsusp.c
--- kernel.bak/power/swsusp.c 2004-12-05 18:31:40.000000000 +0000
+++ kernel/power/swsusp.c 2004-12-06 23:02:21.000000000 +0000
@@ -81,7 +81,7 @@
int nr_copy_pages_check;

extern char resume_file[];
-static dev_t resume_device;
+dev_t swsusp_resume_device = 0;
/* Local variables that should not be affected by save */
unsigned int nr_copy_pages __nosavedata = 0;

@@ -171,7 +171,7 @@
struct inode *inode = file->f_dentry->d_inode;

return S_ISBLK(inode->i_mode) &&
- resume_device == MKDEV(imajor(inode), iminor(inode));
+ swsusp_resume_device == MKDEV(imajor(inode), iminor(inode));
}

int swsusp_swap_check(void) /* This is called before saving image */
@@ -740,7 +740,7 @@
* space avaiable.
*
* FIXME: si_swapinfo(&i) returns all swap devices information.
- * We should only consider resume_device.
+ * We should only consider swsusp_resume_device.
*/

static int enough_swap(void)
@@ -1220,13 +1220,16 @@
{
int error;

- if (!strlen(resume_file))
- return -ENOENT;
+ if (!swsusp_resume_device) {
+ if (!strlen(resume_file))
+ return -ENOENT;

- resume_device = name_to_dev_t(resume_file);
- pr_debug("swsusp: Resume From Partition: %s\n", resume_file);
+ swsusp_resume_device = name_to_dev_t(resume_file);
+ pr_debug("swsusp: Resume From Partition: %s\n", resume_file);
+ }
+
+ resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_READ);

- resume_bdev = open_by_devnum(resume_device, FMODE_READ);
if (!IS_ERR(resume_bdev)) {
set_blocksize(resume_bdev, PAGE_SIZE);
error = read_suspend_image();

--
Matthew Garrett | mjg59@xxxxxxxxxxxxx

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/