Skip to contentSkip to conversation

PM / Sleep: Freeze filesystems during system suspend/hibernation

RFC PATCH In review Rafael J. Wysocki 12 participants 37 messages Jan 28, 2012 – Dec 23, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 PM / Sleep: Freeze filesystems during system suspend/hibernation

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

---
 fs/super.c               |   73 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h       |    3 +
 kernel/power/hibernate.c |   11 +++++--
 kernel/power/power.h     |   23 --------------
 kernel/power/suspend.c   |   42 +++++++++++++++++++++++++++
 5 files changed, 128 insertions(+), 24 deletions(-)
include/linux/fs.h +3 -0
Index: linux/include/linux/fs.h
===================================================================
@@ -210,6 +210,7 @@ struct inodes_stat_t {
 #define MS_KERNMOUNT	(1<<22) /* this is a kern_mount call */
 #define MS_I_VERSION	(1<<23) /* Update inode I_version field */
 #define MS_STRICTATIME	(1<<24) /* Always perform atime updates */
+#define MS_FROZEN	(1<<25) /* Frozen filesystem */
 #define MS_NOSEC	(1<<28)
 #define MS_BORN		(1<<29)
 #define MS_ACTIVE	(1<<30)
@@ -2501,6 +2502,8 @@ extern void drop_super(struct super_bloc
 extern void iterate_supers(void (*)(struct super_block *, void *), void *);
 extern void iterate_supers_type(struct file_system_type *,
 			        void (*)(struct super_block *, void *), void *);
+extern int freeze_supers(void);
+extern void thaw_supers(void);
 
 extern int dcache_dir_open(struct inode *, struct file *);
 extern int dcache_dir_close(struct inode *, struct file *);
fs/super.c +73 -0

79 lines not on this page · raw message

kernel/power/power.h +1 -22
Index: linux/kernel/power/power.h
===================================================================
@@ -1,3 +1,4 @@
+#include <linux/fs.h>
 #include <linux/suspend.h>
 #include <linux/suspend_ioctls.h>
 #include <linux/utsname.h>
@@ -227,25 +228,3 @@ enum {
 #define TEST_MAX	(__TEST_AFTER_LAST - 1)
 
 extern int pm_test_level;
-
-#ifdef CONFIG_SUSPEND_FREEZER
-static inline int suspend_freeze_processes(void)
-{
-	int error = freeze_processes();
-	return error ? : freeze_kernel_threads();
-}
-
-static inline void suspend_thaw_processes(void)
-{
-	thaw_processes();
-}
-#else
-static inline int suspend_freeze_processes(void)
-{
-	return 0;
-}
-
-static inline void suspend_thaw_processes(void)
-{
-}
-#endif
kernel/power/suspend.c +42 -0

48 lines not on this page · raw message

kernel/power/hibernate.c +9 -2
Index: linux/kernel/power/hibernate.c
===================================================================
@@ -626,12 +626,17 @@ int hibernate(void)
 	if (error)
 		goto Finish;
 
-	error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
+	error = freeze_supers();
 	if (error)
 		goto Thaw;
+
+	error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
+	if (error)
+		goto Thaw_fs;
+
 	if (freezer_test_done) {
 		freezer_test_done = false;
-		goto Thaw;
+		goto Thaw_fs;
 	}
 
 	if (in_suspend) {
@@ -655,6 +660,8 @@ int hibernate(void)
 		pr_debug("PM: Image restored successfully.\n");
 	}
 
+ Thaw_fs:
+	thaw_supers();
  Thaw:
 	thaw_processes();
  Finish:
#1 lore raw

Hi.

Quoted 76 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

---
 fs/super.c               |   73 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h       |    3 +
 kernel/power/hibernate.c |   11 +++++--
 kernel/power/power.h     |   23 --------------
 kernel/power/suspend.c   |   42 +++++++++++++++++++++++++++
 5 files changed, 128 insertions(+), 24 deletions(-)

Index: linux/include/linux/fs.h
===================================================================

include/linux/fs.h +3 -0
@@ -210,6 +210,7 @@ struct inodes_stat_t {
 #define MS_KERNMOUNT	(1<<22) /* this is a kern_mount call */
 #define MS_I_VERSION	(1<<23) /* Update inode I_version field */
 #define MS_STRICTATIME	(1<<24) /* Always perform atime updates */
+#define MS_FROZEN	(1<<25) /* Frozen filesystem */
 #define MS_NOSEC	(1<<28)
 #define MS_BORN		(1<<29)
 #define MS_ACTIVE	(1<<30)
@@ -2501,6 +2502,8 @@ extern void drop_super(struct super_bloc
 extern void iterate_supers(void (*)(struct super_block *, void *), void *);
 extern void iterate_supers_type(struct file_system_type *,
 			        void (*)(struct super_block *, void *), void *);
+extern int freeze_supers(void);
+extern void thaw_supers(void);
 
 extern int dcache_dir_open(struct inode *, struct file *);
 extern int dcache_dir_close(struct inode *, struct file *);

Index: linux/fs/super.c
===================================================================

fs/super.c +17 -0
@@ -594,6 +594,79 @@ void iterate_supers_type(struct file_sys
 EXPORT_SYMBOL(iterate_supers_type);
 
 /**
+ *	thaw_supers - call thaw_super() for all superblocks
+ */
+void thaw_supers(void)
+{
+	struct super_block *sb, *p = NULL;
+
+	spin_lock(&sb_lock);
+	list_for_each_entry(sb, &super_blocks, s_list) {
+		if (list_empty(&sb->s_instances))
+			continue;
+		sb->s_count++;
+		spin_unlock(&sb_lock);
+
+		if (sb->s_flags & MS_FROZEN) {
+			thaw_super(sb);
+			sb->s_flags &= ~MS_FROZEN;
+		}

fs/super.c void iterate_supers_type(struct file_sys · line 623

Quoted 10 lines
fs/super.c +10 -0
+
+		spin_lock(&sb_lock);
+		if (p)
+			__put_super(p);
+		p = sb;
+	}
+	if (p)
+		__put_super(p);
+	spin_unlock(&sb_lock);
+}

It might be helpful to explain why you delay calling __put_super (I can't see why, though I realise that fs/super.c does it this way too), and perhaps also where the balancing get is (it's not obvious that s->count++ is the open coded get).

Quoted 13 lines
fs/super.c +13 -0
+
+/**
+ *	freeze_supers - call freeze_super() for all superblocks
+ */
+int freeze_supers(void)
+{
+	struct super_block *sb, *p = NULL;
+	int error = 0;
+
+	spin_lock(&sb_lock);
+	/*
+	 * Freeze in reverse order so filesystems depending on others are
+	 * frozen in the right order (eg. loopback on ext3).

fs/super.c void iterate_supers_type(struct file_sys · line 646

Quoted 10 lines
fs/super.c +10 -0
+	 */
+	list_for_each_entry_reverse(sb, &super_blocks, s_list) {
+		if (list_empty(&sb->s_instances))
+			continue;
+		sb->s_count++;
+		spin_unlock(&sb_lock);
+
+		if (sb->s_root && sb->s_frozen != SB_FREEZE_TRANS
+		    && !(sb->s_flags & MS_RDONLY)) {
+			error = freeze_super(sb);

No chance of a race against another caller of freeze_super, right? (Userspace is already frozen and kernel threads aren't going to invoke this without pushing). Might be good to document that there's no locking in freeze_super anyway?

Quoted 78 lines
fs/super.c +23 -0
+			if (!error)
+				sb->s_flags |= MS_FROZEN;
+		}
+
+		spin_lock(&sb_lock);
+		if (error)
+			break;
+		if (p)
+			__put_super(p);
+		p = sb;
+	}
+	if (p)
+		__put_super(p);
+	spin_unlock(&sb_lock);
+
+	if (error)
+		thaw_supers();
+
+	return error;
+}
+
+
+/**
  *	get_super - get the superblock of a device
  *	@bdev: device to get the superblock for
  *	

Index: linux/kernel/power/power.h
===================================================================

kernel/power/power.h +1 -22
@@ -1,3 +1,4 @@
+#include <linux/fs.h>
 #include <linux/suspend.h>
 #include <linux/suspend_ioctls.h>
 #include <linux/utsname.h>
@@ -227,25 +228,3 @@ enum {
 #define TEST_MAX	(__TEST_AFTER_LAST - 1)
 
 extern int pm_test_level;
-
-#ifdef CONFIG_SUSPEND_FREEZER
-static inline int suspend_freeze_processes(void)
-{
-	int error = freeze_processes();
-	return error ? : freeze_kernel_threads();
-}
-
-static inline void suspend_thaw_processes(void)
-{
-	thaw_processes();
-}
-#else
-static inline int suspend_freeze_processes(void)
-{
-	return 0;
-}
-
-static inline void suspend_thaw_processes(void)
-{
-}
-#endif

Index: linux/kernel/power/suspend.c
===================================================================

kernel/power/suspend.c +9 -0
@@ -29,6 +29,48 @@
 
 #include "power.h"
 
+#ifdef CONFIG_SUSPEND_FREEZER
+
+static inline int suspend_freeze_processes(void)
+{
+	int error;
+
+	error = freeze_processes();
+	if (error)
+		return error;

kernel/power/suspend.c line 50

Quoted 10 lines
kernel/power/suspend.c +10 -0
+
+	error = freeze_supers();
+	if (error) {
+		thaw_processes();
+		return error;
+	}
+
+	error = freeze_kernel_threads();
+	if (error)
+		thaw_supers();

Comment why there's no matching thaw_processes() as well?

That's all from me.

Regards,

Nigel

Quoted 60 lines
kernel/power/suspend.c +23 -0
+
+	return error;
+}
+
+static inline void suspend_thaw_processes(void)
+{
+	thaw_supers();
+	thaw_processes();
+}
+
+#else /* !CONFIG_SUSPEND_FREEZER */
+
+static inline int suspend_freeze_processes(void)
+{
+	return 0;
+}
+
+static inline void suspend_thaw_processes(void)
+{
+}
+
+#endif /* !CONFIG_SUSPEND_FREEZER */
+
 const char *const pm_states[PM_SUSPEND_MAX] = {
 	[PM_SUSPEND_STANDBY]	= "standby",
 	[PM_SUSPEND_MEM]	= "mem",

Index: linux/kernel/power/hibernate.c
===================================================================

kernel/power/hibernate.c +9 -2
@@ -626,12 +626,17 @@ int hibernate(void)
 	if (error)
 		goto Finish;
 
-	error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
+	error = freeze_supers();
 	if (error)
 		goto Thaw;
+
+	error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
+	if (error)
+		goto Thaw_fs;
+
 	if (freezer_test_done) {
 		freezer_test_done = false;
-		goto Thaw;
+		goto Thaw_fs;
 	}
 
 	if (in_suspend) {
@@ -655,6 +660,8 @@ int hibernate(void)
 		pr_debug("PM: Image restored successfully.\n");
 	}
 
+ Thaw_fs:
+	thaw_supers();
  Thaw:
 	thaw_processes();
  Finish:
Signature · 3 lines
Evolution (n): A hypothetical process whereby improbable
events occur with alarming frequency, order arises from chaos, and
no one is given credit.
#2 lore raw
In reply to Rafael J. Wysocki

Am Samstag, 28. Januar 2012 schrieb Rafael J. Wysocki:

Quoted 6 lines

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

Quoted 6 lines

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image

replied => replayed

Quoted 2 lines

and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

Thanks,

Signature · 2 lines
Martin 'Helios' Steigerwald - http://www.Lichtvoll.de
GPG: 03B0 0D6C 0040 0710 4AFA  B82F 991B EAAC A599 84C7
#4 lore raw
In reply to Rafael J. Wysocki
Quoted 32 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image

and/or initrd causing it to become inconsistent with the information

stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

---
 fs/super.c               |   73 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h       |    3 +
 kernel/power/hibernate.c |   11 +++++--
 kernel/power/power.h     |   23 --------------
 kernel/power/suspend.c   |   42 +++++++++++++++++++++++++++
 5 files changed, 128 insertions(+), 24 deletions(-)

...

Quoted 18 lines

Index: linux/kernel/power/suspend.c
===================================================================

kernel/power/suspend.c +10 -0
@@ -29,6 +29,48 @@
 
 #include "power.h"
 
+#ifdef CONFIG_SUSPEND_FREEZER
+
+static inline int suspend_freeze_processes(void)
+{
+	int error;
+
+	error = freeze_processes();
+	if (error)
+		return error;
+

kernel/power/suspend.c line 51

Quoted 10 lines
kernel/power/suspend.c +10 -0
+	error = freeze_supers();
+	if (error) {
+		thaw_processes();
+		return error;
+	}
+
+	error = freeze_kernel_threads();
+	if (error)
+		thaw_supers();
+

If freezing of kernel threads fails, freeze_kernel_threads() calls thaw_processes(), which means, even userspace processes get thawed. So, there would be a time-window in which userspace is thawed but the filesystems are still frozen. That is not very desirable right?

If that is right, then modifying freeze_kernel_threads() to call thaw_kernel_threads() instead of thaw_processes() would fix it (and of course, we would need to explicitly call thaw_processes above).

BTW, after your patch posted at https://lkml.org/lkml/2012/1/27/501,
I very much wanted to write a patch to convert the semantics of freeze/thaw to something like:

freeze_processes() calls thaw_processes on error.
//Both touch only userspace processes.

freeze_kernel_threads() calls thaw_kernel_threads() on error. //Both touch only kernel threads.

Of course, such a patch would need to do a lot of fixing up at several places, but IMHO, it would really help make the overall code more logical and easier to understand.

I can write it up and post it soon, but then you'll have to rebase your patch (this one) on top of that. What do you say?

Regards,
Srivatsa S. Bhat

Quoted 59 lines
kernel/power/suspend.c +22 -0
+	return error;
+}
+
+static inline void suspend_thaw_processes(void)
+{
+	thaw_supers();
+	thaw_processes();
+}
+
+#else /* !CONFIG_SUSPEND_FREEZER */
+
+static inline int suspend_freeze_processes(void)
+{
+	return 0;
+}
+
+static inline void suspend_thaw_processes(void)
+{
+}
+
+#endif /* !CONFIG_SUSPEND_FREEZER */
+
 const char *const pm_states[PM_SUSPEND_MAX] = {
 	[PM_SUSPEND_STANDBY]	= "standby",
 	[PM_SUSPEND_MEM]	= "mem",

Index: linux/kernel/power/hibernate.c
===================================================================

kernel/power/hibernate.c +9 -2
@@ -626,12 +626,17 @@ int hibernate(void)
 	if (error)
 		goto Finish;
 
-	error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
+	error = freeze_supers();
 	if (error)
 		goto Thaw;
+
+	error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
+	if (error)
+		goto Thaw_fs;
+
 	if (freezer_test_done) {
 		freezer_test_done = false;
-		goto Thaw;
+		goto Thaw_fs;
 	}
 
 	if (in_suspend) {
@@ -655,6 +660,8 @@ int hibernate(void)
 		pr_debug("PM: Image restored successfully.\n");
 	}
 
+ Thaw_fs:
+	thaw_supers();
  Thaw:
 	thaw_processes();
  Finish:
#5 lore raw
Quoted 63 lines · Srivatsa S. Bhat
Quoted 32 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image

and/or initrd causing it to become inconsistent with the information

stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

---
 fs/super.c               |   73 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h       |    3 +
 kernel/power/hibernate.c |   11 +++++--
 kernel/power/power.h     |   23 --------------
 kernel/power/suspend.c   |   42 +++++++++++++++++++++++++++
 5 files changed, 128 insertions(+), 24 deletions(-)

...

Quoted 26 lines

Index: linux/kernel/power/suspend.c
===================================================================

kernel/power/suspend.c +18 -0
@@ -29,6 +29,48 @@
 
 #include "power.h"
 
+#ifdef CONFIG_SUSPEND_FREEZER
+
+static inline int suspend_freeze_processes(void)
+{
+	int error;
+
+	error = freeze_processes();
+	if (error)
+		return error;
+
+	error = freeze_supers();
+	if (error) {
+		thaw_processes();
+		return error;
+	}
+
+	error = freeze_kernel_threads();
+	if (error)
Quoted 8 lines

kernel/power/suspend.c line 51

Quoted 2 lines
kernel/power/suspend.c +2 -0
+		thaw_supers();
+

If freezing of kernel threads fails, freeze_kernel_threads() calls thaw_processes(), which means, even userspace processes get thawed. So, there would be a time-window in which userspace is thawed but the filesystems are still frozen. That is not very desirable right?

No, it is not. I overlooked that, thanks!

Quoted 15 lines

If that is right, then modifying freeze_kernel_threads() to call thaw_kernel_threads() instead of thaw_processes() would fix it (and of course, we would need to explicitly call thaw_processes above).

BTW, after your patch posted at https://lkml.org/lkml/2012/1/27/501,
I very much wanted to write a patch to convert the semantics of freeze/thaw to something like:

freeze_processes() calls thaw_processes on error.
//Both touch only userspace processes.

freeze_kernel_threads() calls thaw_kernel_threads() on error. //Both touch only kernel threads.

Quoted 6 lines

Of course, such a patch would need to do a lot of fixing up at several places, but IMHO, it would really help make the overall code more logical and easier to understand.

I can write it up and post it soon, but then you'll have to rebase your patch (this one) on top of that. What do you say?

Please do that, it wouldn't be any problem for me to rebase the $subject patch.

Thanks,
Rafael

Quoted 66 lines
Quoted 51 lines
kernel/power/suspend.c +22 -0
+	return error;
+}
+
+static inline void suspend_thaw_processes(void)
+{
+	thaw_supers();
+	thaw_processes();
+}
+
+#else /* !CONFIG_SUSPEND_FREEZER */
+
+static inline int suspend_freeze_processes(void)
+{
+	return 0;
+}
+
+static inline void suspend_thaw_processes(void)
+{
+}
+
+#endif /* !CONFIG_SUSPEND_FREEZER */
+
 const char *const pm_states[PM_SUSPEND_MAX] = {
 	[PM_SUSPEND_STANDBY]	= "standby",
 	[PM_SUSPEND_MEM]	= "mem",

Index: linux/kernel/power/hibernate.c
===================================================================

kernel/power/hibernate.c +7 -2
@@ -626,12 +626,17 @@ int hibernate(void)
 	if (error)
 		goto Finish;
 
-	error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
+	error = freeze_supers();
 	if (error)
 		goto Thaw;
+
+	error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
+	if (error)
+		goto Thaw_fs;
+
 	if (freezer_test_done) {
 		freezer_test_done = false;
-		goto Thaw;
+		goto Thaw_fs;
 	}
 
 	if (in_suspend) {

kernel/power/hibernate.c int hibernate(void) · line 667

Quoted 8 lines
kernel/power/hibernate.c +2 -0
@@ -655,6 +660,8 @@ int hibernate(void)
 		pr_debug("PM: Image restored successfully.\n");
 	}
 
+ Thaw_fs:
+	thaw_supers();
  Thaw:
 	thaw_processes();
  Finish:

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Martin Steigerwald
Quoted 7 lines · Martin Steigerwald

Am Samstag, 28. Januar 2012 schrieb Rafael J. Wysocki:

Quoted 6 lines

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

Quoted 8 lines
Quoted 6 lines

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image

replied => replayed

Right, thanks!

Rafael

reviewer
#7 lore raw
In reply to Rafael J. Wysocki
Quoted 55 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

---
 fs/super.c               |   73 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h       |    3 +
 kernel/power/hibernate.c |   11 +++++--
 kernel/power/power.h     |   23 --------------
 kernel/power/suspend.c   |   42 +++++++++++++++++++++++++++
 5 files changed, 128 insertions(+), 24 deletions(-)

Index: linux/fs/super.c
===================================================================

fs/super.c +17 -0
@@ -594,6 +594,79 @@ void iterate_supers_type(struct file_sys
 EXPORT_SYMBOL(iterate_supers_type);
 
 /**
+ *	thaw_supers - call thaw_super() for all superblocks
+ */
+void thaw_supers(void)
+{
+	struct super_block *sb, *p = NULL;
+
+	spin_lock(&sb_lock);
+	list_for_each_entry(sb, &super_blocks, s_list) {
+		if (list_empty(&sb->s_instances))
+			continue;
+		sb->s_count++;
+		spin_unlock(&sb_lock);
+
+		if (sb->s_flags & MS_FROZEN) {
+			thaw_super(sb);
+			sb->s_flags &= ~MS_FROZEN;
+		}

fs/super.c void iterate_supers_type(struct file_sys · line 623

Quoted 10 lines
fs/super.c +10 -0
+
+		spin_lock(&sb_lock);
+		if (p)
+			__put_super(p);
+		p = sb;
+	}
+	if (p)
+		__put_super(p);
+	spin_unlock(&sb_lock);
+}

At least for thawing you can use iterate_supers() helper.

fs/super.c void iterate_supers_type(struct file_sys · line 637

Quoted 13 lines
fs/super.c +13 -0
+/**
+ *	freeze_supers - call freeze_super() for all superblocks
+ */
+int freeze_supers(void)
+{
+	struct super_block *sb, *p = NULL;
+	int error = 0;
+
+	spin_lock(&sb_lock);
+	/*
+	 * Freeze in reverse order so filesystems depending on others are
+	 * frozen in the right order (eg. loopback on ext3).
+	 */

Ho, hum, are you sure the order in super_blocks list is the one you need?
Maybe it is but I'm not sure you are guaranteed it is. I've added Al to CC, he'll likely have opinion on this...

Quoted 25 lines
fs/super.c +25 -0
+	list_for_each_entry_reverse(sb, &super_blocks, s_list) {
+		if (list_empty(&sb->s_instances))
+			continue;
+		sb->s_count++;
+		spin_unlock(&sb_lock);
+
+		if (sb->s_root && sb->s_frozen != SB_FREEZE_TRANS
+		    && !(sb->s_flags & MS_RDONLY)) {
+			error = freeze_super(sb);
+			if (!error)
+				sb->s_flags |= MS_FROZEN;
+		}
+
+		spin_lock(&sb_lock);
+		if (error)
+			break;
+		if (p)
+			__put_super(p);
+		p = sb;
+	}
+	if (p)
+		__put_super(p);
+	spin_unlock(&sb_lock);
+
+	if (error)

fs/super.c void iterate_supers_type(struct file_sys · line 672

Quoted 10 lines
fs/super.c +7 -0
+		thaw_supers();
+
+	return error;
+}
+
+
+/**
  *	get_super - get the superblock of a device
  *	@bdev: device to get the superblock for
  *	

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#8 lore raw
Quoted 59 lines · Jan Kara
Quoted 58 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

---
 fs/super.c               |   73 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h       |    3 +
 kernel/power/hibernate.c |   11 +++++--
 kernel/power/power.h     |   23 --------------
 kernel/power/suspend.c   |   42 +++++++++++++++++++++++++++
 5 files changed, 128 insertions(+), 24 deletions(-)

Index: linux/fs/super.c
===================================================================

fs/super.c +20 -0
@@ -594,6 +594,79 @@ void iterate_supers_type(struct file_sys
 EXPORT_SYMBOL(iterate_supers_type);
 
 /**
+ *	thaw_supers - call thaw_super() for all superblocks
+ */
+void thaw_supers(void)
+{
+	struct super_block *sb, *p = NULL;
+
+	spin_lock(&sb_lock);
+	list_for_each_entry(sb, &super_blocks, s_list) {
+		if (list_empty(&sb->s_instances))
+			continue;
+		sb->s_count++;
+		spin_unlock(&sb_lock);
+
+		if (sb->s_flags & MS_FROZEN) {
+			thaw_super(sb);
+			sb->s_flags &= ~MS_FROZEN;
+		}
+
+		spin_lock(&sb_lock);
+		if (p)
Quoted 8 lines

fs/super.c void iterate_supers_type(struct file_sys · line 623

Quoted 7 lines
fs/super.c +7 -0
+			__put_super(p);
+		p = sb;
+	}
+	if (p)
+		__put_super(p);
+	spin_unlock(&sb_lock);
+}

At least for thawing you can use iterate_supers() helper.

OK

Quoted 7 lines
Quoted 7 lines
fs/super.c +7 -0
+/**
+ *	freeze_supers - call freeze_super() for all superblocks
+ */
+int freeze_supers(void)
+{
+	struct super_block *sb, *p = NULL;
+	int error = 0;
Quoted 8 lines

fs/super.c void iterate_supers_type(struct file_sys · line 637

Quoted 6 lines
fs/super.c +6 -0
+
+	spin_lock(&sb_lock);
+	/*
+	 * Freeze in reverse order so filesystems depending on others are
+	 * frozen in the right order (eg. loopback on ext3).
+	 */

Ho, hum, are you sure the order in super_blocks list is the one you need?
Maybe it is but I'm not sure you are guaranteed it is.

Well, is there any way I can get the right order?

Quoted 30 lines

I've added Al to CC,
he'll likely have opinion on this...

Quoted 27 lines
fs/super.c +27 -0
+	list_for_each_entry_reverse(sb, &super_blocks, s_list) {
+		if (list_empty(&sb->s_instances))
+			continue;
+		sb->s_count++;
+		spin_unlock(&sb_lock);
+
+		if (sb->s_root && sb->s_frozen != SB_FREEZE_TRANS
+		    && !(sb->s_flags & MS_RDONLY)) {
+			error = freeze_super(sb);
+			if (!error)
+				sb->s_flags |= MS_FROZEN;
+		}
+
+		spin_lock(&sb_lock);
+		if (error)
+			break;
+		if (p)
+			__put_super(p);
+		p = sb;
+	}
+	if (p)
+		__put_super(p);
+	spin_unlock(&sb_lock);
+
+	if (error)
+		thaw_supers();
+
Quoted 8 lines

fs/super.c void iterate_supers_type(struct file_sys · line 672

Quoted 8 lines
fs/super.c +5 -0
+	return error;
+}
+
+
+/**
  *	get_super - get the superblock of a device
  *	@bdev: device to get the superblock for
  *	

Thanks,
Rafael

#9 lore raw

Hi.

Quoted 10 lines · Rafael J. Wysocki
Quoted 7 lines · Jan Kara

fs/super.c void iterate_supers_type(struct file_sys · line 637

Quoted 4 lines · Rafael J. Wysocki
fs/super.c +4 -0
+	/*
+	 * Freeze in reverse order so filesystems depending on others are
+	 * frozen in the right order (eg. loopback on ext3).
+	 */

Ho, hum, are you sure the order in super_blocks list is the one you need?
Maybe it is but I'm not sure you are guaranteed it is.

Well, is there any way I can get the right order?

Jan, what's the case where the reverse of mount order might be the wrong order?

Regards,

Nigel

Signature · 3 lines
Evolution (n): A hypothetical process whereby improbable
events occur with alarming frequency, order arises from chaos, and
no one is given credit.
#6 lore raw
In reply to Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki

On Sunday, January 29, 2012, Srivatsa S. Bhat wrote:

[...]

Quoted 56 lines
Quoted 26 lines
Quoted 26 lines

Index: linux/kernel/power/suspend.c
===================================================================

kernel/power/suspend.c +18 -0
@@ -29,6 +29,48 @@
 
 #include "power.h"
 
+#ifdef CONFIG_SUSPEND_FREEZER
+
+static inline int suspend_freeze_processes(void)
+{
+	int error;
+
+	error = freeze_processes();
+	if (error)
+		return error;
+
+	error = freeze_supers();
+	if (error) {
+		thaw_processes();
+		return error;
+	}
+
+	error = freeze_kernel_threads();
+	if (error)
Quoted 8 lines

kernel/power/suspend.c line 51

Quoted 2 lines
kernel/power/suspend.c +2 -0
+		thaw_supers();
+

If freezing of kernel threads fails, freeze_kernel_threads() calls thaw_processes(), which means, even userspace processes get thawed. So, there would be a time-window in which userspace is thawed but the filesystems are still frozen. That is not very desirable right?

No, it is not. I overlooked that, thanks!

Quoted 19 lines

If that is right, then modifying freeze_kernel_threads() to call thaw_kernel_threads() instead of thaw_processes() would fix it (and of course, we would need to explicitly call thaw_processes above).

BTW, after your patch posted at https://lkml.org/lkml/2012/1/27/501,
I very much wanted to write a patch to convert the semantics of freeze/thaw to something like:

freeze_processes() calls thaw_processes on error.
//Both touch only userspace processes.

freeze_kernel_threads() calls thaw_kernel_threads() on error. //Both touch only kernel threads.

Of course, such a patch would need to do a lot of fixing up at several places, but IMHO, it would really help make the overall code more logical and easier to understand.

Quoted 6 lines
Quoted 2 lines

I can write it up and post it soon, but then you'll have to rebase your patch (this one) on top of that. What do you say?

Please do that, it wouldn't be any problem for me to rebase the $subject patch.

Hi Rafael,
I have posted the patchset (v2) at https://lkml.org/lkml/2012/1/30/530

Regards,
Srivatsa S. Bhat

reviewer
#11 lore raw
In reply to Rafael J. Wysocki
Quoted 18 lines · Rafael J. Wysocki
Quoted 16 lines · Jan Kara

fs/super.c void iterate_supers_type(struct file_sys · line 637

Quoted 13 lines · Rafael J. Wysocki
fs/super.c +13 -0
+/**
+ *	freeze_supers - call freeze_super() for all superblocks
+ */
+int freeze_supers(void)
+{
+	struct super_block *sb, *p = NULL;
+	int error = 0;
+
+	spin_lock(&sb_lock);
+	/*
+	 * Freeze in reverse order so filesystems depending on others are
+	 * frozen in the right order (eg. loopback on ext3).
+	 */

Ho, hum, are you sure the order in super_blocks list is the one you need?
Maybe it is but I'm not sure you are guaranteed it is.

Quoted 1 line

Well, is there any way I can get the right order?

None I'm aware of :( I think your reverse order scanning is the best you
can do now as we don't track the "freeze dependency" in any way. I was just warning that noone really guarantees this is the right order. So we should probably at least document somewhere that super_blocks list order matters for freeze_supers().

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
fs/super.c +27 -0
+	list_for_each_entry_reverse(sb, &super_blocks, s_list) {
+		if (list_empty(&sb->s_instances))
+			continue;
+		sb->s_count++;
+		spin_unlock(&sb_lock);
+
+		if (sb->s_root && sb->s_frozen != SB_FREEZE_TRANS
+		    && !(sb->s_flags & MS_RDONLY)) {
+			error = freeze_super(sb);
+			if (!error)
+				sb->s_flags |= MS_FROZEN;
+		}
+
+		spin_lock(&sb_lock);
+		if (error)
+			break;
+		if (p)
+			__put_super(p);
+		p = sb;
+	}
+	if (p)
+		__put_super(p);
+	spin_unlock(&sb_lock);
+
+	if (error)
+		thaw_supers();
+
Quoted 8 lines
Quoted 8 lines

fs/super.c void iterate_supers_type(struct file_sys · line 672

Quoted 8 lines
fs/super.c +5 -0
+	return error;
+}
+
+
+/**
  *	get_super - get the superblock of a device
  *	@bdev: device to get the superblock for
  *	

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
reviewer
#10 lore raw
In reply to Nigel Cunningham
Quoted 12 lines · Nigel Cunningham

Hi.

Quoted 9 lines · Rafael J. Wysocki
Quoted 7 lines · Jan Kara

fs/super.c void iterate_supers_type(struct file_sys · line 637

Quoted 4 lines · Rafael J. Wysocki
fs/super.c +4 -0
+	/*
+	 * Freeze in reverse order so filesystems depending on others are
+	 * frozen in the right order (eg. loopback on ext3).
+	 */

Ho, hum, are you sure the order in super_blocks list is the one you need?
Maybe it is but I'm not sure you are guaranteed it is.

Quoted 4 lines
Quoted 1 line

Well, is there any way I can get the right order?

Jan, what's the case where the reverse of mount order might be the wrong order?

After some though, I'm not able to come up with a counterexample. As I
wrote to Rafael, let's at least document that we rely on some ordering of super_blocks list.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#12 lore raw
In reply to Rafael J. Wysocki

Hi!

Quoted 9 lines

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In

Good.

Quoted 5 lines

particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

Ungood. Why is bootloader/initrd doing that? If it mounts filesystem read/write, what is the guarantee that it will not change data on the filesystem, breaking stuff?

Bootloaders should just not replay journals.

Quoted 3 lines

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

...so bootloaders need to be fixed, anyway.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#13 lore raw
Quoted 10 lines · Pavel Machek
Quoted 5 lines

particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

Ungood. Why is bootloader/initrd doing that? If it mounts filesystem read/write, what is the guarantee that it will not change data on the filesystem, breaking stuff?

Quoted 7 lines

Bootloaders should just not replay journals.

Quoted 3 lines

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

...so bootloaders need to be fixed, anyway.

I don't know about bootloaders, but from what I've heard, Linux fs drivers (including those inside initrds) always replay the journal, even if the filesystem is mounted read-only. This could be considered a bug in the filesystem code.

Alan Stern

Acked-by on v1 1/1
#16 lore raw
In reply to Rafael J. Wysocki

Hi.

Quoted 15 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

Quoted 7 lines

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

(Or reviewed by or whatever :> I'm out of the loop too much, and don't remember what the right one is!)

Signature · 3 lines
Evolution (n): A hypothetical process whereby improbable
events occur with alarming frequency, order arises from chaos, and
no one is given credit.
#14 lore raw
In reply to Alan Stern
Quoted 18 lines · Alan Stern
Quoted 16 lines · Pavel Machek
Quoted 5 lines

particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

Ungood. Why is bootloader/initrd doing that? If it mounts filesystem read/write, what is the guarantee that it will not change data on the filesystem, breaking stuff?

Bootloaders should just not replay journals.

Quoted 3 lines

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

Quoted 6 lines
Quoted 1 line

...so bootloaders need to be fixed, anyway.

I don't know about bootloaders, but from what I've heard, Linux fs drivers (including those inside initrds) always replay the journal, even if the filesystem is mounted read-only. This could be considered a bug in the filesystem code.

Theoretically a filesystem might need replay for the bootloader to see a non-corrupt image, even for just the files it uses.

For example if the last state was in the middle of updating the root directory, the /boot entry in the root directory might not be reliably found without replaying the journal.

However replaying a journal when mounted read-only should probably track journalled blocks in memory only, not commit back to the storage.

All the best,
-- Jamie

reviewer
#15 lore raw
Quoted 29 lines · Jamie Lokier
Quoted 18 lines · Alan Stern
Quoted 16 lines · Pavel Machek
Quoted 5 lines

particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

Ungood. Why is bootloader/initrd doing that? If it mounts filesystem read/write, what is the guarantee that it will not change data on the filesystem, breaking stuff?

Bootloaders should just not replay journals.

Quoted 3 lines

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

Quoted 6 lines
Quoted 1 line

...so bootloaders need to be fixed, anyway.

I don't know about bootloaders, but from what I've heard, Linux fs drivers (including those inside initrds) always replay the journal, even if the filesystem is mounted read-only. This could be considered a bug in the filesystem code.

Theoretically a filesystem might need replay for the bootloader to see a non-corrupt image, even for just the files it uses.

Quoted 6 lines

For example if the last state was in the middle of updating the root directory, the /boot entry in the root directory might not be reliably found without replaying the journal.

However replaying a journal when mounted read-only should probably track journalled blocks in memory only, not commit back to the storage.

Yes, that would be nice. Although memory constraints of the bootloader
might make it tricky.

The reason why we don't have the functionality in kernel is not so much
about memory demands but more about the complexities of implementing the caching - we'd have to create an equivalent of dm-snapshot of the device from the mount code to trick generic code in pagecache to loading proper replayed data).

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#17 lore raw
In reply to Rafael J. Wysocki
Quoted 15 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases).  In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

Quoted 7 lines

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

Do you happen to have a version of this patch that has been rebased to the latest 3.3 git tree? I looked in the various archives and haven't found one yet. I'd like to get this into Fedora rawhide to see if some of the hibernate issues we've been seeing clear up.

josh
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#18 lore raw
Quoted 20 lines · Josh Boyer
Quoted 19 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases).  In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

Quoted 8 lines
Quoted 3 lines

This change is based on earlier work by Nigel Cunningham.

Do you happen to have a version of this patch that has been rebased to the latest 3.3 git tree?  I looked in the various archives and haven't found one yet.  I'd like to get this into Fedora rawhide to see if some of the hibernate issues we've been seeing clear up.

I got impatient and decided to tackle this myself. If others would like to look at the forward port below, I'd appreciate it.

josh

commit b94887bbc0621e1e8402e7f0ec4bc3adf46c9a6e

Author: Rafael J. Wysocki <[email protected]>
Date:   Fri Feb 17 12:42:08 2012 -0500

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

Rebased to 3.3-rc3 by Josh Boyer <[email protected]>

fs/super.c +73 -0
index 6015c02..c8057fa 100644
@@ -594,6 +594,79 @@ void iterate_supers_type(struct file_system_type *type,
 EXPORT_SYMBOL(iterate_supers_type);
 
 /**
+ *	thaw_supers - call thaw_super() for all superblocks
+ */
+void thaw_supers(void)
+{
+	struct super_block *sb, *p = NULL;
+
+	spin_lock(&sb_lock);
+	list_for_each_entry(sb, &super_blocks, s_list) {
+		if (hlist_unhashed(&sb->s_instances))
+			continue;
+		sb->s_count++;
+		spin_unlock(&sb_lock);
+
+		if (sb->s_flags & MS_FROZEN) {
+			thaw_super(sb);
+			sb->s_flags &= ~MS_FROZEN;
+		}
+
+		spin_lock(&sb_lock);
+		if (p)
+			__put_super(p);
+		p = sb;
+	}
+	if (p)
+		__put_super(p);
+	spin_unlock(&sb_lock);
+}
+
+/**
+ *	freeze_supers - call freeze_super() for all superblocks
+ */
+int freeze_supers(void)
+{
+	struct super_block *sb, *p = NULL;
+	int error = 0;
+
+	spin_lock(&sb_lock);
+	/*
+	 * Freeze in reverse order so filesystems depending on others are
+	 * frozen in the right order (eg. loopback on ext3).
+	 */
+	list_for_each_entry_reverse(sb, &super_blocks, s_list) {
+		if (hlist_unhashed(&sb->s_instances))
+			continue;
+		sb->s_count++;
+		spin_unlock(&sb_lock);
+
+		if (sb->s_root && sb->s_frozen != SB_FREEZE_TRANS
+		    && !(sb->s_flags & MS_RDONLY)) {
+			error = freeze_super(sb);
+			if (!error)
+				sb->s_flags |= MS_FROZEN;
+		}
+
+		spin_lock(&sb_lock);
+		if (error)
+			break;
+		if (p)
+			__put_super(p);
+		p = sb;
+	}
+	if (p)
+		__put_super(p);
+	spin_unlock(&sb_lock);
+
+	if (error)
+		thaw_supers();
+
+	return error;
+}
+
+
+/**
  *	get_super - get the superblock of a device
  *	@bdev: device to get the superblock for
  *	
include/linux/fs.h +3 -0
index 386da09..a164f4a 100644
@@ -210,6 +210,7 @@ struct inodes_stat_t {
 #define MS_KERNMOUNT	(1<<22) /* this is a kern_mount call */
 #define MS_I_VERSION	(1<<23) /* Update inode I_version field */
 #define MS_STRICTATIME	(1<<24) /* Always perform atime updates */
+#define MS_FROZEN	(1<<25) /* Frozen filesystem */
 #define MS_NOSEC	(1<<28)
 #define MS_BORN		(1<<29)
 #define MS_ACTIVE	(1<<30)
@@ -2501,6 +2502,8 @@ extern void drop_super(struct super_block *sb);
 extern void iterate_supers(void (*)(struct super_block *, void *), void *);
 extern void iterate_supers_type(struct file_system_type *,
 			        void (*)(struct super_block *, void *), void *);
+extern int freeze_supers(void);
+extern void thaw_supers(void);
 
 extern int dcache_dir_open(struct inode *, struct file *);
 extern int dcache_dir_close(struct inode *, struct file *);
kernel/power/hibernate.c +9 -2
index 6d6d288..492fc62 100644
@@ -626,12 +626,17 @@ int hibernate(void)
 	if (error)
 		goto Finish;
 
-	error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
+	error = freeze_supers();
 	if (error)
 		goto Thaw;
+
+	error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
+	if (error)
+		goto Thaw_fs;
+
 	if (freezer_test_done) {
 		freezer_test_done = false;
-		goto Thaw;
+		goto Thaw_fs;
 	}
 
 	if (in_suspend) {
@@ -655,6 +660,8 @@ int hibernate(void)
 		pr_debug("PM: Image restored successfully.\n");
 	}
 
+ Thaw_fs:
+	thaw_supers();
  Thaw:
 	thaw_processes();
  Finish:
kernel/power/power.h +1 -42

49 lines not on this page · raw message

kernel/power/suspend.c +56 -0

62 lines not on this page · raw message

#19 lore raw
Quoted 25 lines · Josh Boyer
Quoted 24 lines · Josh Boyer
Quoted 22 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

Quoted 7 lines
Quoted 4 lines

Do you happen to have a version of this patch that has been rebased to the latest 3.3 git tree? I looked in the various archives and haven't found one yet. I'd like to get this into Fedora rawhide to see if some of the hibernate issues we've been seeing clear up.

I got impatient and decided to tackle this myself. If others would like to look at the forward port below, I'd appreciate it.

It looks good at first sight, thanks for rebasing!

Rafael

Quoted 289 lines

commit b94887bbc0621e1e8402e7f0ec4bc3adf46c9a6e

Author: Rafael J. Wysocki <[email protected]>
Date:   Fri Feb 17 12:42:08 2012 -0500

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

Rebased to 3.3-rc3 by Josh Boyer <[email protected]>

fs/super.c +73 -0
index 6015c02..c8057fa 100644
@@ -594,6 +594,79 @@ void iterate_supers_type(struct file_system_type *type,
 EXPORT_SYMBOL(iterate_supers_type);
 
 /**
+ *	thaw_supers - call thaw_super() for all superblocks
+ */
+void thaw_supers(void)
+{
+	struct super_block *sb, *p = NULL;
+
+	spin_lock(&sb_lock);
+	list_for_each_entry(sb, &super_blocks, s_list) {
+		if (hlist_unhashed(&sb->s_instances))
+			continue;
+		sb->s_count++;
+		spin_unlock(&sb_lock);
+
+		if (sb->s_flags & MS_FROZEN) {
+			thaw_super(sb);
+			sb->s_flags &= ~MS_FROZEN;
+		}
+
+		spin_lock(&sb_lock);
+		if (p)
+			__put_super(p);
+		p = sb;
+	}
+	if (p)
+		__put_super(p);
+	spin_unlock(&sb_lock);
+}
+
+/**
+ *	freeze_supers - call freeze_super() for all superblocks
+ */
+int freeze_supers(void)
+{
+	struct super_block *sb, *p = NULL;
+	int error = 0;
+
+	spin_lock(&sb_lock);
+	/*
+	 * Freeze in reverse order so filesystems depending on others are
+	 * frozen in the right order (eg. loopback on ext3).
+	 */
+	list_for_each_entry_reverse(sb, &super_blocks, s_list) {
+		if (hlist_unhashed(&sb->s_instances))
+			continue;
+		sb->s_count++;
+		spin_unlock(&sb_lock);
+
+		if (sb->s_root && sb->s_frozen != SB_FREEZE_TRANS
+		    && !(sb->s_flags & MS_RDONLY)) {
+			error = freeze_super(sb);
+			if (!error)
+				sb->s_flags |= MS_FROZEN;
+		}
+
+		spin_lock(&sb_lock);
+		if (error)
+			break;
+		if (p)
+			__put_super(p);
+		p = sb;
+	}
+	if (p)
+		__put_super(p);
+	spin_unlock(&sb_lock);
+
+	if (error)
+		thaw_supers();
+
+	return error;
+}
+
+
+/**
  *	get_super - get the superblock of a device
  *	@bdev: device to get the superblock for
  *	
include/linux/fs.h +3 -0
index 386da09..a164f4a 100644
@@ -210,6 +210,7 @@ struct inodes_stat_t {
 #define MS_KERNMOUNT	(1<<22) /* this is a kern_mount call */
 #define MS_I_VERSION	(1<<23) /* Update inode I_version field */
 #define MS_STRICTATIME	(1<<24) /* Always perform atime updates */
+#define MS_FROZEN	(1<<25) /* Frozen filesystem */
 #define MS_NOSEC	(1<<28)
 #define MS_BORN		(1<<29)
 #define MS_ACTIVE	(1<<30)
@@ -2501,6 +2502,8 @@ extern void drop_super(struct super_block *sb);
 extern void iterate_supers(void (*)(struct super_block *, void *), void *);
 extern void iterate_supers_type(struct file_system_type *,
 			        void (*)(struct super_block *, void *), void *);
+extern int freeze_supers(void);
+extern void thaw_supers(void);
 
 extern int dcache_dir_open(struct inode *, struct file *);
 extern int dcache_dir_close(struct inode *, struct file *);
kernel/power/hibernate.c +9 -2
index 6d6d288..492fc62 100644
@@ -626,12 +626,17 @@ int hibernate(void)
 	if (error)
 		goto Finish;
 
-	error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
+	error = freeze_supers();
 	if (error)
 		goto Thaw;
+
+	error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
+	if (error)
+		goto Thaw_fs;
+
 	if (freezer_test_done) {
 		freezer_test_done = false;
-		goto Thaw;
+		goto Thaw_fs;
 	}
 
 	if (in_suspend) {
@@ -655,6 +660,8 @@ int hibernate(void)
 		pr_debug("PM: Image restored successfully.\n");
 	}
 
+ Thaw_fs:
+	thaw_supers();
  Thaw:
 	thaw_processes();
  Finish:
kernel/power/power.h +1 -42
index 21724ee..40d6f64 100644
@@ -1,3 +1,4 @@
+#include <linux/fs.h>
 #include <linux/suspend.h>
 #include <linux/suspend_ioctls.h>
 #include <linux/utsname.h>
@@ -227,45 +228,3 @@ enum {
 #define TEST_MAX	(__TEST_AFTER_LAST - 1)
 
 extern int pm_test_level;
-
-#ifdef CONFIG_SUSPEND_FREEZER
-static inline int suspend_freeze_processes(void)
-{
-	int error;
-
-	error = freeze_processes();
-
-	/*
-	 * freeze_processes() automatically thaws every task if freezing
-	 * fails. So we need not do anything extra upon error.
-	 */
-	if (error)
-		goto Finish;
-
-	error = freeze_kernel_threads();
-
-	/*
-	 * freeze_kernel_threads() thaws only kernel threads upon freezing
-	 * failure. So we have to thaw the userspace tasks ourselves.
-	 */
-	if (error)
-		thaw_processes();
-
- Finish:
-	return error;
-}
-
-static inline void suspend_thaw_processes(void)
-{
-	thaw_processes();
-}
-#else
-static inline int suspend_freeze_processes(void)
-{
-	return 0;
-}
-
-static inline void suspend_thaw_processes(void)
-{
-}
-#endif
kernel/power/suspend.c +56 -0
index 4fd51be..5f51fc7 100644
@@ -29,6 +29,62 @@
 
 #include "power.h"
 
+#ifdef CONFIG_SUSPEND_FREEZER
+
+static inline int suspend_freeze_processes(void)
+{
+	int error;
+
+	error = freeze_processes();
+
+	/*
+	 * freeze_processes() automatically thaws every task if freezing
+	 * fails. So we need not do anything extra upon error.
+	 */
+
+	if (error)
+		goto Finish;
+
+	error = freeze_supers();
+	if (error) {
+		thaw_processes();
+		goto Finish;
+	}
+
+	error = freeze_kernel_threads();
+
+	/*
+	 * freeze_kernel_threads() thaws only kernel threads upon freezing
+	 * failure. So we have to thaw the userspace tasks ourselves.
+	 */
+	if (error) {
+		thaw_supers();
+		thaw_processes();
+	}
+
+Finish:
+	return error;
+}
+
+static inline void suspend_thaw_processes(void)
+{
+	thaw_supers();
+	thaw_processes();
+}
+
+#else /* !CONFIG_SUSPEND_FREEZER */
+
+static inline int suspend_freeze_processes(void)
+{
+	return 0;
+}
+
+static inline void suspend_thaw_processes(void)
+{
+}
+
+#endif /* !CONFIG_SUSPEND_FREEZER */
+
 const char *const pm_states[PM_SUSPEND_MAX] = {
 	[PM_SUSPEND_STANDBY]	= "standby",
 	[PM_SUSPEND_MEM]	= "mem",
#20 lore raw
Quoted 21 lines · Rafael J. Wysocki
Quoted 21 lines

commit b94887bbc0621e1e8402e7f0ec4bc3adf46c9a6e
Author: Rafael J. Wysocki <[email protected]>
Date:   Fri Feb 17 12:42:08 2012 -0500

    Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

    This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases).  In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

    The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

Quoted 5 lines
Quoted 5 lines

    This change is based on earlier work by Nigel Cunningham.

    Rebased to 3.3-rc3 by Josh Boyer <[email protected]>

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Did if fall through the cracks or was it NAKed somewhere?

josh
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#21 lore raw
Quoted 26 lines · Josh Boyer
Quoted 25 lines · Rafael J. Wysocki
Quoted 25 lines

commit b94887bbc0621e1e8402e7f0ec4bc3adf46c9a6e

Author: Rafael J. Wysocki <[email protected]>
Date:   Fri Feb 17 12:42:08 2012 -0500

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Rebased to 3.3-rc3 by Josh Boyer <[email protected]>

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Did if fall through the cracks or was it NAKed somewhere?

No, it wasn't in principle. There were some comments I haven't addressed yet.

Thanks,
Rafael

#22 lore raw
Quoted 29 lines · Rafael J. Wysocki
Quoted 28 lines · Josh Boyer
Quoted 26 lines · Rafael J. Wysocki
Quoted 26 lines

commit b94887bbc0621e1e8402e7f0ec4bc3adf46c9a6e

Author: Rafael J. Wysocki <[email protected]>
Date:   Fri Feb 17 12:42:08 2012 -0500

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

Rebased to 3.3-rc3 by Josh Boyer <[email protected]>

Quoted 7 lines
Quoted 5 lines

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Did if fall through the cracks or was it NAKed somewhere?

No, it wasn't in principle. There were some comments I haven't addressed yet.

Dredging up a really old thread, sorry.

We're still carrying this patch along in Fedora. Should we drop it at this point, or is it still eventually going to head upstream?

josh

#23 lore raw
Quoted 34 lines · Josh Boyer
Quoted 33 lines · Rafael J. Wysocki
Quoted 32 lines · Josh Boyer
Quoted 21 lines · Rafael J. Wysocki
Quoted 21 lines

commit b94887bbc0621e1e8402e7f0ec4bc3adf46c9a6e

Author: Rafael J. Wysocki <[email protected]>
Date:   Fri Feb 17 12:42:08 2012 -0500

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

Quoted 5 lines
Quoted 5 lines

This change is based on earlier work by Nigel Cunningham.

Rebased to 3.3-rc3 by Josh Boyer <[email protected]>

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Did if fall through the cracks or was it NAKed somewhere?

No, it wasn't in principle. There were some comments I haven't addressed yet.

Dredging up a really old thread, sorry.

We're still carrying this patch along in Fedora. Should we drop it at this point, or is it still eventually going to head upstream?

Fixed Rafael's email address. (Double sorry.)

josh

#24 lore raw

Hi!

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Did if fall through the cracks or was it NAKed somewhere?

No, it wasn't in principle. There were some comments I haven't addressed yet.

Dredging up a really old thread, sorry.

We're still carrying this patch along in Fedora. Should we drop it at this point, or is it still eventually going to head upstream?

I'd say drop.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#25 lore raw
Quoted 8 lines · Pavel Machek

Hi!

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Did if fall through the cracks or was it NAKed somewhere?

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

No, it wasn't in principle. There were some comments I haven't addressed yet.

Dredging up a really old thread, sorry.

We're still carrying this patch along in Fedora. Should we drop it at this point, or is it still eventually going to head upstream?

I'd say drop.

I disagree - given the problem it is resolving leads to silent filesystem corruption, this patch should be considered somewhat of a priority to push...

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#26 lore raw
Quoted 13 lines · Dave Chinner
Quoted 12 lines · Pavel Machek

Hi!

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Did if fall through the cracks or was it NAKed somewhere?

No, it wasn't in principle. There were some comments I haven't addressed yet.

Dredging up a really old thread, sorry.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

We're still carrying this patch along in Fedora. Should we drop it at this point, or is it still eventually going to head upstream?

I'd say drop.

I disagree - given the problem it is resolving leads to silent filesystem corruption, this patch should be considered somewhat of a priority to push...

Umm. Ok, I forgot what it does, really.

So... for few years now suspend corrupts data on XFS? And Fedora has the fix but it is not in mainline? That does not sound right...

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#32 lore raw
In reply to Josh Boyer
Quoted 37 lines · Josh Boyer
Quoted 36 lines · Josh Boyer
Quoted 35 lines · Rafael J. Wysocki
Quoted 33 lines · Josh Boyer
Quoted 21 lines · Rafael J. Wysocki
Quoted 21 lines

commit b94887bbc0621e1e8402e7f0ec4bc3adf46c9a6e

Author: Rafael J. Wysocki <[email protected]>
Date:   Fri Feb 17 12:42:08 2012 -0500

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

Quoted 5 lines
Quoted 5 lines

This change is based on earlier work by Nigel Cunningham.

Rebased to 3.3-rc3 by Josh Boyer <[email protected]>

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Did if fall through the cracks or was it NAKed somewhere?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

No, it wasn't in principle. There were some comments I haven't addressed yet.

Dredging up a really old thread, sorry.

We're still carrying this patch along in Fedora. Should we drop it at this point, or is it still eventually going to head upstream?

Fixed Rafael's email address. (Double sorry.)

No biggie.

I just hadn't got sufficient response for that patch at the time it was submitted, so I guess it would be good to resubmit it. Please feel free to do that if you want.

Thanks!

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#33 lore raw
Quoted 45 lines · Rafael J. Wysocki
Quoted 44 lines · Josh Boyer
Quoted 42 lines · Josh Boyer
Quoted 29 lines · Rafael J. Wysocki
Quoted 28 lines · Josh Boyer
Quoted 26 lines · Rafael J. Wysocki
Quoted 26 lines

commit b94887bbc0621e1e8402e7f0ec4bc3adf46c9a6e

Author: Rafael J. Wysocki <[email protected]>
Date:   Fri Feb 17 12:42:08 2012 -0500

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

This change is based on earlier work by Nigel Cunningham.

Rebased to 3.3-rc3 by Josh Boyer <[email protected]>

Quoted 7 lines
Quoted 5 lines

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Did if fall through the cracks or was it NAKed somewhere?

No, it wasn't in principle. There were some comments I haven't addressed yet.

Dredging up a really old thread, sorry.

We're still carrying this patch along in Fedora. Should we drop it at this point, or is it still eventually going to head upstream?

Quoted 7 lines
Quoted 1 line

Fixed Rafael's email address. (Double sorry.)

No biggie.

I just hadn't got sufficient response for that patch at the time it was submitted, so I guess it would be good to resubmit it. Please feel free to do that if you want.

You want me to resend a patch you authored back to you? I mean, I can do that but it seems a bit strange. All I did was rebase what you wrote to a newer kernel version.

josh

#34 lore raw
Quoted 50 lines · Josh Boyer
Quoted 49 lines · Rafael J. Wysocki
Quoted 37 lines · Josh Boyer
Quoted 36 lines · Josh Boyer
Quoted 35 lines · Rafael J. Wysocki
Quoted 33 lines · Josh Boyer
Quoted 21 lines · Rafael J. Wysocki
Quoted 21 lines

commit b94887bbc0621e1e8402e7f0ec4bc3adf46c9a6e

Author: Rafael J. Wysocki <[email protected]>
Date:   Fri Feb 17 12:42:08 2012 -0500

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

Quoted 5 lines
Quoted 5 lines

This change is based on earlier work by Nigel Cunningham.

Rebased to 3.3-rc3 by Josh Boyer <[email protected]>

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Did if fall through the cracks or was it NAKed somewhere?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

No, it wasn't in principle. There were some comments I haven't addressed yet.

Dredging up a really old thread, sorry.

We're still carrying this patch along in Fedora. Should we drop it at this point, or is it still eventually going to head upstream?

Fixed Rafael's email address. (Double sorry.)

No biggie.

Quoted 7 lines
Quoted 3 lines

I just hadn't got sufficient response for that patch at the time it was submitted, so I guess it would be good to resubmit it. Please feel free to do that if you want.

You want me to resend a patch you authored back to you? I mean, I can do that but it seems a bit strange. All I did was rebase what you wrote to a newer kernel version.

Well, you can send it to me in private then and I'll resubmit. :-)

I just don't have any recent version of it handy.

Thanks,
Rafael

#35 lore raw
Quoted 55 lines · Rafael J. Wysocki
Quoted 54 lines · Josh Boyer
Quoted 52 lines · Rafael J. Wysocki
Quoted 37 lines · Josh Boyer
Quoted 36 lines · Josh Boyer
Quoted 35 lines · Rafael J. Wysocki
Quoted 33 lines · Josh Boyer
Quoted 21 lines · Rafael J. Wysocki
Quoted 21 lines

commit b94887bbc0621e1e8402e7f0ec4bc3adf46c9a6e

Author: Rafael J. Wysocki <[email protected]>
Date:   Fri Feb 17 12:42:08 2012 -0500

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

Quoted 5 lines
Quoted 5 lines

This change is based on earlier work by Nigel Cunningham.

Rebased to 3.3-rc3 by Josh Boyer <[email protected]>

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Did if fall through the cracks or was it NAKed somewhere?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

No, it wasn't in principle. There were some comments I haven't addressed yet.

Dredging up a really old thread, sorry.

We're still carrying this patch along in Fedora. Should we drop it at this point, or is it still eventually going to head upstream?

Fixed Rafael's email address. (Double sorry.)

No biggie.

I just hadn't got sufficient response for that patch at the time it was submitted, so I guess it would be good to resubmit it. Please feel free to do that if you want.

Quoted 5 lines
Quoted 3 lines

You want me to resend a patch you authored back to you? I mean, I can do that but it seems a bit strange. All I did was rebase what you wrote to a newer kernel version.

Well, you can send it to me in private then and I'll resubmit. :-)

Done. Thanks.

josh

#27 lore raw
In reply to Pavel Machek
Quoted 17 lines · Pavel Machek
Quoted 16 lines · Dave Chinner
Quoted 15 lines · Pavel Machek

Hi!

Quoted 12 lines
Quoted 12 lines
Quoted 7 lines
Quoted 5 lines

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Did if fall through the cracks or was it NAKed somewhere?

No, it wasn't in principle. There were some comments I haven't addressed yet.

Dredging up a really old thread, sorry.

We're still carrying this patch along in Fedora. Should we drop it at this point, or is it still eventually going to head upstream?

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I'd say drop.

I disagree - given the problem it is resolving leads to silent filesystem corruption, this patch should be considered somewhat of a priority to push...

Umm. Ok, I forgot what it does, really.

It ensures that the filesystem is in an quiescent state both in memory and on disk, and it cannot be modified in memory or on disk whilst the suspend image is being generated, or by log recovery after a resume before the suspended image has been restored.

Quoted 2 lines

So... for few years now suspend corrupts data on XFS? And Fedora has the fix but it is not in mainline? That does not sound right...

The issues freezing the filesystem before the suspend image is created affect every journalled filesystem linux supports, be it XFS, ext4, reiser, btrfs, etc.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#28 lore raw
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

I disagree - given the problem it is resolving leads to silent filesystem corruption, this patch should be considered somewhat of a priority to push...

Umm. Ok, I forgot what it does, really.

It ensures that the filesystem is in an quiescent state both in memory and on disk, and it cannot be modified in memory or on disk whilst the suspend image is being generated, or by log recovery after a resume before the suspended image has been restored.

If someone attempts to run log recovery before resume, that's a bug and yes, it will corrupt filesystems. (Including ext3). Don't do that.

Documentation/power/swsusp.txt:

* BIG FAT WARNING
*********************************************************
*
* If you touch anything on disk between suspend and resume...
* ...kiss your data goodbye.

Quoted 6 lines
Quoted 2 lines

So... for few years now suspend corrupts data on XFS? And Fedora has the fix but it is not in mainline? That does not sound right...

The issues freezing the filesystem before the suspend image is created affect every journalled filesystem linux supports, be it XFS, ext4, reiser, btrfs, etc.

Did not it have some problems with ext3?

Regards,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#36 lore raw
In reply to Josh Boyer
Quoted 56 lines · Josh Boyer
Quoted 55 lines · Rafael J. Wysocki
Quoted 54 lines · Josh Boyer
Quoted 52 lines · Rafael J. Wysocki
Quoted 37 lines · Josh Boyer
Quoted 36 lines · Josh Boyer
Quoted 35 lines · Rafael J. Wysocki
Quoted 33 lines · Josh Boyer
Quoted 21 lines · Rafael J. Wysocki
Quoted 21 lines

commit b94887bbc0621e1e8402e7f0ec4bc3adf46c9a6e

Author: Rafael J. Wysocki <[email protected]>
Date:   Fri Feb 17 12:42:08 2012 -0500

Freeze all filesystems during system suspend and (kernel-driven) hibernation by calling freeze_supers() for all superblocks and thaw them during the subsequent resume with the help of thaw_supers().

This makes filesystems stay in a consistent state in case something goes wrong between system suspend (or hibernation) and the subsequent resume (e.g. journal replays won't be necessary in those cases). In particular, this should help to solve a long-standing issue that, in some cases, during resume from hibernation the boot loader causes the journal to be replied for the filesystem containing the kernel image and/or initrd causing it to become inconsistent with the information stored in the hibernation image.

The user-space-driven hibernation (s2disk) is not covered by this change, because the freezing of filesystems prevents s2disk from accessing device special files it needs to do its job.

Quoted 5 lines
Quoted 5 lines

This change is based on earlier work by Nigel Cunningham.

Rebased to 3.3-rc3 by Josh Boyer <[email protected]>

Did this patch ever wind up going anywhere? Fedora has it sitting in our tree with a comment that says "rebase" and I don't see it in the linux-next tree at all.

Did if fall through the cracks or was it NAKed somewhere?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

No, it wasn't in principle. There were some comments I haven't addressed yet.

Dredging up a really old thread, sorry.

We're still carrying this patch along in Fedora. Should we drop it at this point, or is it still eventually going to head upstream?

Fixed Rafael's email address. (Double sorry.)

No biggie.

I just hadn't got sufficient response for that patch at the time it was submitted, so I guess it would be good to resubmit it. Please feel free to do that if you want.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

You want me to resend a patch you authored back to you? I mean, I can do that but it seems a bit strange. All I did was rebase what you wrote to a newer kernel version.

Well, you can send it to me in private then and I'll resubmit. :-)

Done. Thanks.

OK, thanks!

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#29 lore raw
In reply to Pavel Machek
Quoted 6 lines · Pavel Machek
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

I disagree - given the problem it is resolving leads to silent filesystem corruption, this patch should be considered somewhat of a priority to push...

Umm. Ok, I forgot what it does, really.

Quoted 7 lines
Quoted 4 lines

It ensures that the filesystem is in an quiescent state both in memory and on disk, and it cannot be modified in memory or on disk whilst the suspend image is being generated, or by log recovery after a resume before the suspended image has been restored.

If someone attempts to run log recovery before resume, that's a bug and yes, it will corrupt filesystems. (Including ext3). Don't do that.

Freezing the filesystem prevents that accidental mount of the filesystem from being an issue. It fixes a bug that:

Quoted 7 lines

Documentation/power/swsusp.txt:

* BIG FAT WARNING
*********************************************************
*
* If you touch anything on disk between suspend and resume...
* ...kiss your data goodbye.

Makes this a whole lot less dangerous.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

So... for few years now suspend corrupts data on XFS? And Fedora has the fix but it is not in mainline? That does not sound right...

The issues freezing the filesystem before the suspend image is created affect every journalled filesystem linux supports, be it XFS, ext4, reiser, btrfs, etc.

Did not it have some problems with ext3?

Please read more carefully: "affect every journalled filesystem linux supports". So, ext3 is affected because it's a journalling filesystem. I didn't list every journalled filesystem Linux supports - "etc" means there are more examples that aren't explicitly listed.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#30 lore raw

Hi!

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

I disagree - given the problem it is resolving leads to silent filesystem corruption, this patch should be considered somewhat of a priority to push...

Umm. Ok, I forgot what it does, really.

It ensures that the filesystem is in an quiescent state both in memory and on disk, and it cannot be modified in memory or on disk whilst the suspend image is being generated, or by log recovery after a resume before the suspended image has been restored.

Quoted 5 lines
Quoted 2 lines

If someone attempts to run log recovery before resume, that's a bug and yes, it will corrupt filesystems. (Including ext3). Don't do that.

Freezing the filesystem prevents that accidental mount of the filesystem from being an issue. It fixes a bug that:

Can you elaborate on that?

If you do read-write mount of that filesystem, surely filesystem metadata will differ from what the filesystem expects. You'll still get data corruption AFAICT.

Read-only mount... maybe that will get slightly better -- there'll be no journal to play back. But what happens to superblock information such as "last mount time"? Mount counts?

Quoted 9 lines
Quoted 7 lines

Documentation/power/swsusp.txt:

* BIG FAT WARNING
*********************************************************
*
* If you touch anything on disk between suspend and resume...
* ...kiss your data goodbye.

Makes this a whole lot less dangerous.

Do you claim that it is now safe to mount (rw) and access filesystem between suspend and resume?

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

So... for few years now suspend corrupts data on XFS? And Fedora has the fix but it is not in mainline? That does not sound right...

The issues freezing the filesystem before the suspend image is created affect every journalled filesystem linux supports, be it XFS, ext4, reiser, btrfs, etc.

Quoted 7 lines
Quoted 1 line

Did not it have some problems with ext3?

Please read more carefully: "affect every journalled filesystem linux supports". So, ext3 is affected because it's a journalling filesystem. I didn't list every journalled filesystem Linux supports - "etc" means there are more examples that aren't explicitly listed.

Sorry for being unclear. My memory says this patch caused some regression with ext3. Is my memory wrong? Or was the regression fixed in the meantime?

(Clearly, ext3 has the same issues with journal replays as btrfs. But note that mounting filesystem between suspend and resume is not safe even on simple filesystems such as ext2).

Thanks,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#31 lore raw
Quoted 16 lines · Pavel Machek

Hi!

Quoted 14 lines
Quoted 13 lines
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

I disagree - given the problem it is resolving leads to silent filesystem corruption, this patch should be considered somewhat of a priority to push...

Umm. Ok, I forgot what it does, really.

It ensures that the filesystem is in an quiescent state both in memory and on disk, and it cannot be modified in memory or on disk whilst the suspend image is being generated, or by log recovery after a resume before the suspended image has been restored.

If someone attempts to run log recovery before resume, that's a bug and yes, it will corrupt filesystems. (Including ext3). Don't do that.

Quoted 8 lines
Quoted 2 lines

Freezing the filesystem prevents that accidental mount of the filesystem from being an issue. It fixes a bug that:

Can you elaborate on that?

If you do read-write mount of that filesystem, surely filesystem metadata will differ from what the filesystem expects. You'll still get data corruption AFAICT.

Only if you modify stuff. That's not what we are protecting against, it's avoiding the automatic journal replay that you can't avoid if you accidentally mount the filesystem.

Quoted 3 lines

Read-only mount... maybe that will get slightly better -- there'll be no journal to play back. But what happens to superblock information such as "last mount time"? Mount counts?

If metadata is being modified on a read only mount outside of journal replay, then the filesystem needs fixing.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

Documentation/power/swsusp.txt:

* BIG FAT WARNING
*********************************************************
*
* If you touch anything on disk between suspend and resume...
* ...kiss your data goodbye.

Quoted 4 lines
Quoted 1 line

Makes this a whole lot less dangerous.

Do you claim that it is now safe to mount (rw) and access filesystem between suspend and resume?

No, I didn't claim that. "less dangerous" is still dangerous, just less so than it was before.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]