public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matthew Garrett <mjg59@srcf.ucam.org>
To: Pavel Machek <pavel@suse.cz>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH/RFC] Add support to resume swsusp from initrd
Date: Mon, 06 Dec 2004 23:15:24 +0000	[thread overview]
Message-ID: <1102374924.13483.9.camel@tyrosine> (raw)
In-Reply-To: <20041205211823.GD1012@elf.ucw.cz>

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@srcf.ucam.org


  reply	other threads:[~2004-12-06 23:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-05 20:48 [PATCH/RFC] Add support to resume swsusp from initrd Matthew Garrett
2004-12-05 21:12 ` Pavel Machek
2004-12-05 21:21   ` Matthew Garrett
2004-12-05 21:29     ` Pavel Machek
2004-12-05 21:42       ` Matthew Garrett
2004-12-05 21:49         ` Pavel Machek
2004-12-06 10:02   ` Stefan Seyfried
2004-12-05 21:18 ` Pavel Machek
2004-12-06 23:15   ` Matthew Garrett [this message]
2004-12-07  9:44     ` Pavel Machek
2004-12-07 11:39       ` Matthew Garrett
2004-12-07 11:46         ` Pavel Machek

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=1102374924.13483.9.camel@tyrosine \
    --to=mjg59@srcf.ucam.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@suse.cz \
    /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