From: Fernando Luis =?ISO-8859-1?Q?V=E1zquez?= Cao Subject: [PATCH 2/17] fsfreeze: add unlocked version of thaw_super Date: Mon, 07 Jan 2013 20:22:15 +0900 Message-ID: <1357557735.8183.4.camel@nexus.lab.ntt.co.jp> References: <1357557492.8183.1.camel@nexus.lab.ntt.co.jp> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: Josef Bacik , Eric Sandeen , Dave Chinner , Christoph Hellwig , Jan Kara , Luiz Capitulino , linux-fsdevel@vger.kernel.org To: Al Viro Return-path: Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]:54378 "EHLO tama500.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751626Ab3AGLXM (ORCPT ); Mon, 7 Jan 2013 06:23:12 -0500 In-Reply-To: <1357557492.8183.1.camel@nexus.lab.ntt.co.jp> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: thaw_super may be called with superblock lock already taken (fsfreeze's emergency thaw being one example), so we need an unlocked version to avoid lockups. Cc: linux-fsdevel@vger.kernel.org Cc: Josef Bacik Cc: Christoph Hellwig Cc: Dave Chinner Cc: Luiz Capitulino Reviewed-by: Eric Sandeen Reviewed-by: Jan Kara Signed-off-by: Fernando Luis Vazquez Cao --- diff -urNp linux-3.8-rc1-orig/fs/super.c linux-3.8-rc1/fs/super.c --- linux-3.8-rc1-orig/fs/super.c 2012-12-25 11:30:38.208018000 +0900 +++ linux-3.8-rc1/fs/super.c 2012-12-25 11:33:32.796018000 +0900 @@ -1399,40 +1399,59 @@ int freeze_super(struct super_block *sb) EXPORT_SYMBOL(freeze_super); /** - * thaw_super -- unlock filesystem + * __thaw_super -- unlock filesystem * @sb: the super to thaw * - * Unlocks the filesystem and marks it writeable again after freeze_super(). + * Unlocks the filesystem and marks it writeable again. + * + * This is the unlocked version of thaw_super, so it is the caller's job to + * to protect the superblock by grabbing the s_umount semaphore in write mode + * and release it again on return. See thaw_super() for an example. */ -int thaw_super(struct super_block *sb) +int __thaw_super(struct super_block *sb) { - int error; + int error = 0; - down_write(&sb->s_umount); if (sb->s_writers.frozen == SB_UNFROZEN) { - up_write(&sb->s_umount); - return -EINVAL; + error = -EINVAL; + goto out; } if (sb->s_flags & MS_RDONLY) - goto out; + goto out_thaw; if (sb->s_op->unfreeze_fs) { error = sb->s_op->unfreeze_fs(sb); if (error) { printk(KERN_ERR "VFS:Filesystem thaw failed\n"); - up_write(&sb->s_umount); - return error; + goto out; } } -out: +out_thaw: sb->s_writers.frozen = SB_UNFROZEN; smp_wmb(); wake_up(&sb->s_writers.wait_unfrozen); - deactivate_locked_super(sb); +out: + return error; +} - return 0; +/** + * thaw_super -- unlock filesystem + * @sb: the super to thaw + * + * Unlocks the filesystem and marks it writeable again after freeze_super(). + */ +int thaw_super(struct super_block *sb) +{ + int res; + down_write(&sb->s_umount); + res = __thaw_super(sb); + if (!res) + deactivate_locked_super(sb); + else + up_write(&sb->s_umount); + return res; } EXPORT_SYMBOL(thaw_super); diff -urNp linux-3.8-rc1-orig/include/linux/fs.h linux-3.8-rc1/include/linux/fs.h --- linux-3.8-rc1-orig/include/linux/fs.h 2012-12-25 11:30:38.212018000 +0900 +++ linux-3.8-rc1/include/linux/fs.h 2012-12-25 11:33:32.796018000 +0900 @@ -1879,6 +1879,7 @@ extern int user_statfs(const char __user extern int fd_statfs(int, struct kstatfs *); extern int vfs_ustat(dev_t, struct kstatfs *); extern int freeze_super(struct super_block *super); +extern int __thaw_super(struct super_block *super); extern int thaw_super(struct super_block *super); extern bool our_mnt(struct vfsmount *mnt);