From patchwork Tue Jul 26 03:30:11 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WuBo X-Patchwork-Id: 1007002 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6Q3QB3G025952 for ; Tue, 26 Jul 2011 03:26:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752102Ab1GZD0H (ORCPT ); Mon, 25 Jul 2011 23:26:07 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:61046 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751968Ab1GZD0E (ORCPT ); Mon, 25 Jul 2011 23:26:04 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 4F177170028 for ; Tue, 26 Jul 2011 11:26:02 +0800 (CST) Received: from mailserver.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id p6Q3Q1Jf020496 for ; Tue, 26 Jul 2011 11:26:02 +0800 Received: from localhost.localdomain ([10.167.225.174]) by mailserver.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2011072611250856-13624 ; Tue, 26 Jul 2011 11:25:08 +0800 Message-ID: <4E2E34C3.2040203@cn.fujitsu.com> Date: Tue, 26 Jul 2011 11:30:11 +0800 From: WuBo User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100921 Fedora/3.1.4-1.fc14 Thunderbird/3.1.4 MIME-Version: 1.0 To: Linux Btrfs Subject: [PATCH] Btrfs: Protect the readonly flag of block group X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-07-26 11:25:08, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-07-26 11:25:08, Serialize complete at 2011-07-26 11:25:08 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 26 Jul 2011 03:26:11 +0000 (UTC) The access for ro in btrfs_block_group_cache should be protected because of the racy lock in relocation. Signed-off-by: Wu Bo --- fs/btrfs/extent-tree.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) -- 1.7.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 9ee6bd5..cc9bf80 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -8143,11 +8143,14 @@ static int set_block_group_ro(struct btrfs_block_group_cache *cache) u64 num_bytes; int ret = -ENOSPC; - if (cache->ro) - return 0; - spin_lock(&sinfo->lock); spin_lock(&cache->lock); + + if (cache->ro) { + ret = 0; + goto out; + } + num_bytes = cache->key.offset - cache->reserved - cache->pinned - cache->bytes_super - btrfs_block_group_used(&cache->item); @@ -8160,7 +8163,7 @@ static int set_block_group_ro(struct btrfs_block_group_cache *cache) cache->ro = 1; ret = 0; } - +out: spin_unlock(&cache->lock); spin_unlock(&sinfo->lock); return ret;