Skip to content

Commit 08fdc8a

Browse files
Mateusz GuzikAl Viro
authored andcommitted
buffer.c: call thaw_super during emergency thaw
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. Signed-off-by: Mateusz Guzik <mguzik@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent fa7c1d5 commit 08fdc8a

3 files changed

Lines changed: 49 additions & 26 deletions

File tree

‎fs/buffer.c‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -523,35 +523,12 @@ static int osync_buffers_list(spinlock_t *lock, struct list_head *list)
523523
return err;
524524
}
525525

526-
static void do_thaw_one(struct super_block *sb, void *unused)
526+
void emergency_thaw_bdev(struct super_block *sb)
527527
{
528528
while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb))
529529
printk(KERN_WARNING "Emergency Thaw on %pg\n", sb->s_bdev);
530530
}
531531

532-
static void do_thaw_all(struct work_struct *work)
533-
{
534-
iterate_supers(do_thaw_one, NULL);
535-
kfree(work);
536-
printk(KERN_WARNING "Emergency Thaw complete\n");
537-
}
538-
539-
/**
540-
* emergency_thaw_all -- forcibly thaw every frozen filesystem
541-
*
542-
* Used for emergency unfreeze of all filesystems via SysRq
543-
*/
544-
void emergency_thaw_all(void)
545-
{
546-
struct work_struct *work;
547-
548-
work = kmalloc(sizeof(*work), GFP_ATOMIC);
549-
if (work) {
550-
INIT_WORK(work, do_thaw_all);
551-
schedule_work(work);
552-
}
553-
}
554-
555532
/**
556533
* sync_mapping_buffers - write out & wait upon a mapping's "associated" buffers
557534
* @mapping: the mapping which wants those buffers written

‎fs/super.c‎

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/user_namespace.h>
3737
#include "internal.h"
3838

39+
static int thaw_super_locked(struct super_block *sb);
3940

4041
static LIST_HEAD(super_blocks);
4142
static DEFINE_SPINLOCK(sb_lock);
@@ -934,6 +935,40 @@ void emergency_remount(void)
934935
}
935936
}
936937

938+
static void do_thaw_all_callback(struct super_block *sb)
939+
{
940+
down_write(&sb->s_umount);
941+
if (sb->s_root && sb->s_flags & MS_BORN) {
942+
emergency_thaw_bdev(sb);
943+
thaw_super_locked(sb);
944+
} else {
945+
up_write(&sb->s_umount);
946+
}
947+
}
948+
949+
static void do_thaw_all(struct work_struct *work)
950+
{
951+
__iterate_supers(do_thaw_all_callback);
952+
kfree(work);
953+
printk(KERN_WARNING "Emergency Thaw complete\n");
954+
}
955+
956+
/**
957+
* emergency_thaw_all -- forcibly thaw every frozen filesystem
958+
*
959+
* Used for emergency unfreeze of all filesystems via SysRq
960+
*/
961+
void emergency_thaw_all(void)
962+
{
963+
struct work_struct *work;
964+
965+
work = kmalloc(sizeof(*work), GFP_ATOMIC);
966+
if (work) {
967+
INIT_WORK(work, do_thaw_all);
968+
schedule_work(work);
969+
}
970+
}
971+
937972
/*
938973
* Unnamed block devices are dummy devices used by virtual
939974
* filesystems which don't use real block-devices. -- jrs
@@ -1503,11 +1538,10 @@ EXPORT_SYMBOL(freeze_super);
15031538
*
15041539
* Unlocks the filesystem and marks it writeable again after freeze_super().
15051540
*/
1506-
int thaw_super(struct super_block *sb)
1541+
static int thaw_super_locked(struct super_block *sb)
15071542
{
15081543
int error;
15091544

1510-
down_write(&sb->s_umount);
15111545
if (sb->s_writers.frozen != SB_FREEZE_COMPLETE) {
15121546
up_write(&sb->s_umount);
15131547
return -EINVAL;
@@ -1538,4 +1572,10 @@ int thaw_super(struct super_block *sb)
15381572
deactivate_locked_super(sb);
15391573
return 0;
15401574
}
1575+
1576+
int thaw_super(struct super_block *sb)
1577+
{
1578+
down_write(&sb->s_umount);
1579+
return thaw_super_locked(sb);
1580+
}
15411581
EXPORT_SYMBOL(thaw_super);

‎include/linux/fs.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,7 @@ extern int sync_blockdev(struct block_device *bdev);
24282428
extern void kill_bdev(struct block_device *);
24292429
extern struct super_block *freeze_bdev(struct block_device *);
24302430
extern void emergency_thaw_all(void);
2431+
extern void emergency_thaw_bdev(struct super_block *sb);
24312432
extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
24322433
extern int fsync_bdev(struct block_device *);
24332434

@@ -2453,6 +2454,11 @@ static inline int thaw_bdev(struct block_device *bdev, struct super_block *sb)
24532454
return 0;
24542455
}
24552456

2457+
static inline int emergency_thaw_bdev(struct super_block *sb)
2458+
{
2459+
return 0;
2460+
}
2461+
24562462
static inline void iterate_bdevs(void (*f)(struct block_device *, void *), void *arg)
24572463
{
24582464
}

0 commit comments

Comments
 (0)