Skip to content

Commit 7214dd4

Browse files
committed
Merge branch 'work.thaw' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs thaw updates from Al Viro: "An ancient series that has fallen through the cracks in the previous cycle" * 'work.thaw' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: buffer.c: call thaw_super during emergency thaw vfs: factor sb iteration out of do_emergency_remount
2 parents 19e8a2f + 08fdc8a commit 7214dd4

3 files changed

Lines changed: 85 additions & 51 deletions

File tree

‎fs/buffer.c‎

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

497-
static void do_thaw_one(struct super_block *sb, void *unused)
497+
void emergency_thaw_bdev(struct super_block *sb)
498498
{
499499
while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb))
500500
printk(KERN_WARNING "Emergency Thaw on %pg\n", sb->s_bdev);
501501
}
502502

503-
static void do_thaw_all(struct work_struct *work)
504-
{
505-
iterate_supers(do_thaw_one, NULL);
506-
kfree(work);
507-
printk(KERN_WARNING "Emergency Thaw complete\n");
508-
}
509-
510-
/**
511-
* emergency_thaw_all -- forcibly thaw every frozen filesystem
512-
*
513-
* Used for emergency unfreeze of all filesystems via SysRq
514-
*/
515-
void emergency_thaw_all(void)
516-
{
517-
struct work_struct *work;
518-
519-
work = kmalloc(sizeof(*work), GFP_ATOMIC);
520-
if (work) {
521-
INIT_WORK(work, do_thaw_all);
522-
schedule_work(work);
523-
}
524-
}
525-
526503
/**
527504
* sync_mapping_buffers - write out & wait upon a mapping's "associated" buffers
528505
* @mapping: the mapping which wants those buffers written

‎fs/super.c‎

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/user_namespace.h>
3838
#include "internal.h"
3939

40+
static int thaw_super_locked(struct super_block *sb);
4041

4142
static LIST_HEAD(super_blocks);
4243
static DEFINE_SPINLOCK(sb_lock);
@@ -574,6 +575,28 @@ void drop_super_exclusive(struct super_block *sb)
574575
}
575576
EXPORT_SYMBOL(drop_super_exclusive);
576577

578+
static void __iterate_supers(void (*f)(struct super_block *))
579+
{
580+
struct super_block *sb, *p = NULL;
581+
582+
spin_lock(&sb_lock);
583+
list_for_each_entry(sb, &super_blocks, s_list) {
584+
if (hlist_unhashed(&sb->s_instances))
585+
continue;
586+
sb->s_count++;
587+
spin_unlock(&sb_lock);
588+
589+
f(sb);
590+
591+
spin_lock(&sb_lock);
592+
if (p)
593+
__put_super(p);
594+
p = sb;
595+
}
596+
if (p)
597+
__put_super(p);
598+
spin_unlock(&sb_lock);
599+
}
577600
/**
578601
* iterate_supers - call function for all active superblocks
579602
* @f: function to call
@@ -881,33 +904,22 @@ int do_remount_sb(struct super_block *sb, int sb_flags, void *data, int force)
881904
return retval;
882905
}
883906

884-
static void do_emergency_remount(struct work_struct *work)
907+
static void do_emergency_remount_callback(struct super_block *sb)
885908
{
886-
struct super_block *sb, *p = NULL;
887-
888-
spin_lock(&sb_lock);
889-
list_for_each_entry(sb, &super_blocks, s_list) {
890-
if (hlist_unhashed(&sb->s_instances))
891-
continue;
892-
sb->s_count++;
893-
spin_unlock(&sb_lock);
894-
down_write(&sb->s_umount);
895-
if (sb->s_root && sb->s_bdev && (sb->s_flags & SB_BORN) &&
896-
!sb_rdonly(sb)) {
897-
/*
898-
* What lock protects sb->s_flags??
899-
*/
900-
do_remount_sb(sb, SB_RDONLY, NULL, 1);
901-
}
902-
up_write(&sb->s_umount);
903-
spin_lock(&sb_lock);
904-
if (p)
905-
__put_super(p);
906-
p = sb;
909+
down_write(&sb->s_umount);
910+
if (sb->s_root && sb->s_bdev && (sb->s_flags & SB_BORN) &&
911+
!sb_rdonly(sb)) {
912+
/*
913+
* What lock protects sb->s_flags??
914+
*/
915+
do_remount_sb(sb, SB_RDONLY, NULL, 1);
907916
}
908-
if (p)
909-
__put_super(p);
910-
spin_unlock(&sb_lock);
917+
up_write(&sb->s_umount);
918+
}
919+
920+
static void do_emergency_remount(struct work_struct *work)
921+
{
922+
__iterate_supers(do_emergency_remount_callback);
911923
kfree(work);
912924
printk("Emergency Remount complete\n");
913925
}
@@ -923,6 +935,40 @@ void emergency_remount(void)
923935
}
924936
}
925937

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+
926972
/*
927973
* Unnamed block devices are dummy devices used by virtual
928974
* filesystems which don't use real block-devices. -- jrs
@@ -1492,11 +1538,10 @@ EXPORT_SYMBOL(freeze_super);
14921538
*
14931539
* Unlocks the filesystem and marks it writeable again after freeze_super().
14941540
*/
1495-
int thaw_super(struct super_block *sb)
1541+
static int thaw_super_locked(struct super_block *sb)
14961542
{
14971543
int error;
14981544

1499-
down_write(&sb->s_umount);
15001545
if (sb->s_writers.frozen != SB_FREEZE_COMPLETE) {
15011546
up_write(&sb->s_umount);
15021547
return -EINVAL;
@@ -1527,4 +1572,10 @@ int thaw_super(struct super_block *sb)
15271572
deactivate_locked_super(sb);
15281573
return 0;
15291574
}
1575+
1576+
int thaw_super(struct super_block *sb)
1577+
{
1578+
down_write(&sb->s_umount);
1579+
return thaw_super_locked(sb);
1580+
}
15301581
EXPORT_SYMBOL(thaw_super);

‎include/linux/fs.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,6 +2445,7 @@ extern int sync_blockdev(struct block_device *bdev);
24452445
extern void kill_bdev(struct block_device *);
24462446
extern struct super_block *freeze_bdev(struct block_device *);
24472447
extern void emergency_thaw_all(void);
2448+
extern void emergency_thaw_bdev(struct super_block *sb);
24482449
extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
24492450
extern int fsync_bdev(struct block_device *);
24502451

@@ -2470,6 +2471,11 @@ static inline int thaw_bdev(struct block_device *bdev, struct super_block *sb)
24702471
return 0;
24712472
}
24722473

2474+
static inline int emergency_thaw_bdev(struct super_block *sb)
2475+
{
2476+
return 0;
2477+
}
2478+
24732479
static inline void iterate_bdevs(void (*f)(struct block_device *, void *), void *arg)
24742480
{
24752481
}

0 commit comments

Comments
 (0)