Skip to contentSkip to conversation

fix emergency unfreezing

PATCH New Mateusz Guzik 1 participant 3 messages Oct 3, 2017 VFS

lore
Share & tools
lore
#0 lore raw

cover fix emergency unfreezing

Filesystems frozen with fsfreeze --freeze are not getting thawed with sysrq j (or echo j > /proc/sysrq-trigger). Thawing only deals with bdev part, does not do anything about fsfreeze.

I went for the easiest fix possible: just thaw the super block. Doing it requires a little bit of refactoring in order to keep the sb locked the whole time.

The first patch moves sb iteration found in emergency remount to a dedicated func for code reuse. This patch patch is a no-op.

The second employs factored out code to do both bdev and sb thaws.

Mateusz Guzik (2):
vfs: factor sb iteration out of do_emergency_remount buffer.c: call thaw_super during emergency thaw

 fs/buffer.c        |  25 +------------
 fs/super.c         | 105 +++++++++++++++++++++++++++++++++++++++--------------
 include/linux/fs.h |   1 +
 3 files changed, 80 insertions(+), 51 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 vfs: factor sb iteration out of do_emergency_remount

The intent is to reduce code duplication with other code iterating the list.

No functional changes.

---
 fs/super.c | 61 ++++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 36 insertions(+), 25 deletions(-)
fs/super.c +36 -25
index 166c4ee..fd9c02f 100644
@@ -574,6 +574,28 @@ void drop_super_exclusive(struct super_block *sb)
 }
 EXPORT_SYMBOL(drop_super_exclusive);
 
+static void __iterate_supers(void (*f)(struct super_block *))
+{
+	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);
+
+		f(sb);
+
+		spin_lock(&sb_lock);
+		if (p)
+			__put_super(p);
+		p = sb;
+	}
+	if (p)
+		__put_super(p);
+	spin_unlock(&sb_lock);
+}
 /**
  *	iterate_supers - call function for all active superblocks
  *	@f: function to call
@@ -881,33 +903,22 @@ int do_remount_sb(struct super_block *sb, int sb_flags, void *data, int force)
 	return retval;
 }
 
-static void do_emergency_remount(struct work_struct *work)
+static void do_emergency_remount_callback(struct super_block *sb)
 {
-	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);
-		down_write(&sb->s_umount);
-		if (sb->s_root && sb->s_bdev && (sb->s_flags & SB_BORN) &&
-		    !sb_rdonly(sb)) {
-			/*
-			 * What lock protects sb->s_flags??
-			 */
-			do_remount_sb(sb, SB_RDONLY, NULL, 1);
-		}
-		up_write(&sb->s_umount);
-		spin_lock(&sb_lock);
-		if (p)
-			__put_super(p);
-		p = sb;
+	down_write(&sb->s_umount);
+	if (sb->s_root && sb->s_bdev && (sb->s_flags & SB_BORN) &&
+	    !sb_rdonly(sb)) {
+		/*
+		 * What lock protects sb->s_flags??
+		 */
+		do_remount_sb(sb, SB_RDONLY, NULL, 1);
 	}
-	if (p)
-		__put_super(p);
-	spin_unlock(&sb_lock);
+	up_write(&sb->s_umount);
+}
+
+static void do_emergency_remount(struct work_struct *work)
+{
+	__iterate_supers(do_emergency_remount_callback);
 	kfree(work);
 	printk("Emergency Remount complete\n");
 }
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/2 buffer.c: call thaw_super during emergency thaw

In reply to Mateusz Guzik

There are 2 distinct freezing mechanisms - one operates on block devices and another one directly on super blocks. Both end up with the same result, but thaw of only one of these does not thaw the other.

In particular fsfreeze --freeze uses the ioctl variant going to the super block. Since prior to this patch emergency thaw was not doing a relevant thaw, filesystems frozen with this method remained unaffected.

The patch is a hack which adds blind unfreezing.

In order to keep the super block write-locked the whole time the code is shuffled around and the newly introduced __iterate_supers is employed.

---
 fs/buffer.c        | 25 +------------------------
 fs/super.c         | 44 ++++++++++++++++++++++++++++++++++++++++++--
 include/linux/fs.h |  1 +
 3 files changed, 44 insertions(+), 26 deletions(-)
fs/buffer.c +1 -24
index 170df85..37ea00b 100644
@@ -523,35 +523,12 @@ static int osync_buffers_list(spinlock_t *lock, struct list_head *list)
 	return err;
 }
 
-static void do_thaw_one(struct super_block *sb, void *unused)
+void emergency_thaw_bdev(struct super_block *sb)
 {
 	while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb))
 		printk(KERN_WARNING "Emergency Thaw on %pg\n", sb->s_bdev);
 }
 
-static void do_thaw_all(struct work_struct *work)
-{
-	iterate_supers(do_thaw_one, NULL);
-	kfree(work);
-	printk(KERN_WARNING "Emergency Thaw complete\n");
-}
-
-/**
- * emergency_thaw_all -- forcibly thaw every frozen filesystem
- *
- * Used for emergency unfreeze of all filesystems via SysRq
- */
-void emergency_thaw_all(void)
-{
-	struct work_struct *work;
-
-	work = kmalloc(sizeof(*work), GFP_ATOMIC);
-	if (work) {
-		INIT_WORK(work, do_thaw_all);
-		schedule_work(work);
-	}
-}
-
 /**
  * sync_mapping_buffers - write out & wait upon a mapping's "associated" buffers
  * @mapping: the mapping which wants those buffers written
fs/super.c +42 -2

69 lines not on this page · raw message

include/linux/fs.h +1 -0
index 339e737..e3f1b13 100644
@@ -2428,6 +2428,7 @@ extern int finish_open(struct file *file, struct dentry *dentry,
 extern void kill_bdev(struct block_device *);
 extern struct super_block *freeze_bdev(struct block_device *);
 extern void emergency_thaw_all(void);
+extern void emergency_thaw_bdev(struct super_block *sb);
 extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
 extern int fsync_bdev(struct block_device *);
 
Signature · 1 line
1.8.3.1