Allow the power subsystem to support filesystem freeze for suspend and hibernate. Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx> --- fs/super.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 2 files changed, 36 insertions(+) diff --git a/fs/super.c b/fs/super.c index 58c95210e66c..a2942b21d661 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1197,6 +1197,40 @@ void emergency_thaw_all(void) } } +static void filesystems_freeze_callback(struct super_block *sb, void *flagsp) +{ + if (!sb->s_op->freeze_fs && !sb->s_op->freeze_super) + return; + + if (sb->s_op->freeze_super) + sb->s_op->freeze_super(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_KERNEL); + else + freeze_super(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_KERNEL); +} + +void filesystems_freeze(bool hibernate) +{ + __iterate_supers(filesystems_freeze_callback, NULL, + SUPER_ITER_GRAB | SUPER_ITER_REVERSE); +} + +static void filesystems_thaw_callback(struct super_block *sb, void *flagsp) +{ + if (!sb->s_op->freeze_fs && !sb->s_op->freeze_super) + return; + + if (sb->s_op->thaw_super) + sb->s_op->thaw_super(sb, FREEZE_HOLDER_KERNEL); + else + thaw_super(sb, FREEZE_HOLDER_KERNEL); +} + +void filesystems_thaw(bool hibernate) +{ + __iterate_supers(filesystems_thaw_callback, NULL, + SUPER_ITER_GRAB | SUPER_ITER_REVERSE); +} + static DEFINE_IDA(unnamed_dev_ida); /** diff --git a/include/linux/fs.h b/include/linux/fs.h index c475fa874055..29bd28491eff 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3518,6 +3518,8 @@ extern void drop_super_exclusive(struct super_block *sb); extern void iterate_supers(void (*f)(struct super_block *, void *), void *arg); extern void iterate_supers_type(struct file_system_type *, void (*)(struct super_block *, void *), void *); +void filesystems_freeze(bool hibernate); +void filesystems_thaw(bool hibernate); extern int dcache_dir_open(struct inode *, struct file *); extern int dcache_dir_close(struct inode *, struct file *); -- 2.47.2