From patchwork Tue Nov 16 11:00:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Piggin X-Patchwork-Id: 327522 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAGB6F2w017965 for ; Tue, 16 Nov 2010 11:06:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934229Ab0KPLGJ (ORCPT ); Tue, 16 Nov 2010 06:06:09 -0500 Received: from ipmail04.adl6.internode.on.net ([150.101.137.141]:16608 "EHLO ipmail04.adl6.internode.on.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933043Ab0KPLGI (ORCPT ); Tue, 16 Nov 2010 06:06:08 -0500 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 16 Nov 2010 11:06:15 +0000 (UTC) X-Greylist: delayed 303 seconds by postgrey-1.27 at vger.kernel.org; Tue, 16 Nov 2010 06:06:07 EST X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAHXw4Ux5Ldur/2dsb2JhbACiWnK+aIVLBA Received: from ppp121-45-219-171.lns20.cbr1.internode.on.net (HELO laptop.local0.net) ([121.45.219.171]) by ipmail04.adl6.internode.on.net with ESMTP; 16 Nov 2010 21:31:01 +1030 Received: by laptop.local0.net (Postfix, from userid 1000) id 43BD42981A; Tue, 16 Nov 2010 22:00:58 +1100 (EST) Date: Tue, 16 Nov 2010 22:00:58 +1100 From: Nick Piggin To: Andrew Morton , linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [patch] fix up lock order reversal in writeback Message-ID: <20101116110058.GA4298@amd> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Index: linux-2.6/fs/fs-writeback.c =================================================================== --- linux-2.6.orig/fs/fs-writeback.c 2010-11-16 21:44:32.000000000 +1100 +++ linux-2.6/fs/fs-writeback.c 2010-11-16 21:49:37.000000000 +1100 @@ -1125,16 +1125,20 @@ EXPORT_SYMBOL(writeback_inodes_sb); * * Invoke writeback_inodes_sb if no writeback is currently underway. * Returns 1 if writeback was started, 0 if not. + * + * May be called inside i_lock. May not start writeback if locks cannot + * be acquired. */ int writeback_inodes_sb_if_idle(struct super_block *sb) { if (!writeback_in_progress(sb->s_bdi)) { - down_read(&sb->s_umount); - writeback_inodes_sb(sb); - up_read(&sb->s_umount); - return 1; - } else - return 0; + if (down_read_trylock(&sb->s_umount)) { + writeback_inodes_sb(sb); + up_read(&sb->s_umount); + return 1; + } + } + return 0; } EXPORT_SYMBOL(writeback_inodes_sb_if_idle); @@ -1145,17 +1149,21 @@ EXPORT_SYMBOL(writeback_inodes_sb_if_idl * * Invoke writeback_inodes_sb if no writeback is currently underway. * Returns 1 if writeback was started, 0 if not. + * + * May be called inside i_lock. May not start writeback if locks cannot + * be acquired. */ int writeback_inodes_sb_nr_if_idle(struct super_block *sb, unsigned long nr) { if (!writeback_in_progress(sb->s_bdi)) { - down_read(&sb->s_umount); - writeback_inodes_sb_nr(sb, nr); - up_read(&sb->s_umount); - return 1; - } else - return 0; + if (down_read_trylock(&sb->s_umount)) { + writeback_inodes_sb_nr(sb, nr); + up_read(&sb->s_umount); + return 1; + } + } + return 0; } EXPORT_SYMBOL(writeback_inodes_sb_nr_if_idle);