From: Fernando Luis =?ISO-8859-1?Q?V=E1zquez?= Cao Subject: [PATCH 4/9] fsfreeze: emergency thaw will deadlock on s_umount Date: Fri, 14 Sep 2012 15:48:56 +0900 Message-ID: <1347605336.6868.6.camel@nexus.lab.ntt.co.jp> References: <1347605006.6868.2.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 , linux-fsdevel@vger.kernel.org, fernando@intellilink.co.jp To: Al Viro Return-path: Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]:34481 "EHLO tama50.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751034Ab2INGtI (ORCPT ); Fri, 14 Sep 2012 02:49:08 -0400 In-Reply-To: <1347605006.6868.2.camel@nexus.lab.ntt.co.jp> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: The emergency thaw process uses iterate_super() which holds the sb->s_umount lock in read mode. The current thaw_super() code takes the sb->s_umount lock in write mode, hence leading to an instant deadlock. Use the unlocked version of thaw_super() to do the thawing and replace iterate_supers() with __iterate_supers() so that the unfreeze operation can be performed with s_umount held as the locking rules for fsfreeze indicate. As a bonus, by using thaw_super(), which does not nest, instead of thaw_bdev() when can get rid of the ugly while loop. Cc: Josef Bacik Cc: Eric Sandeen Cc: Christoph Hellwig Cc: Jan Kara Cc: Dave Chinner Signed-off-by: Fernando Luis Vazquez Cao --- diff -urNp linux-3.6-rc5-orig/fs/buffer.c linux-3.6-rc5/fs/buffer.c --- linux-3.6-rc5-orig/fs/buffer.c 2012-09-14 12:46:22.988871880 +0900 +++ linux-3.6-rc5/fs/buffer.c 2012-09-14 13:05:47.812919103 +0900 @@ -513,15 +513,27 @@ repeat: static void do_thaw_one(struct super_block *sb, void *unused) { - char b[BDEVNAME_SIZE]; - while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb)) - printk(KERN_WARNING "Emergency Thaw on %s\n", + int res; + + if (sb->s_bdev) { + char b[BDEVNAME_SIZE]; + printk(KERN_WARNING "Emergency Thaw on %s.\n", bdevname(sb->s_bdev, b)); + } + + /* We were called from __iterate_supers with superblock lock taken + * so we do not need to do it here. */ + res = __thaw_super(sb); + if (!res) + deactivate_locked_super(sb); + else + up_write(&sb->s_umount); + return res; } static void do_thaw_all(struct work_struct *work) { - iterate_supers_read(do_thaw_one, NULL); + iterate_supers_write(do_thaw_one, NULL); kfree(work); printk(KERN_WARNING "Emergency Thaw complete\n"); }