From patchwork Tue Dec 17 04:01:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 3358651 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AC2B09F314 for ; Tue, 17 Dec 2013 04:01:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A0C0B20211 for ; Tue, 17 Dec 2013 04:01:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8FA6E2020A for ; Tue, 17 Dec 2013 04:01:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752044Ab3LQEBA (ORCPT ); Mon, 16 Dec 2013 23:01:00 -0500 Received: from [222.73.24.84] ([222.73.24.84]:4493 "EHLO song.cn.fujitsu.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751169Ab3LQEA7 (ORCPT ); Mon, 16 Dec 2013 23:00:59 -0500 X-IronPort-AV: E=Sophos;i="4.95,498,1384272000"; d="scan'208";a="9273369" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 17 Dec 2013 11:56:31 +0800 Received: from fnstmail02.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 rBH402sw004408; Tue, 17 Dec 2013 12:00:02 +0800 Received: from miao.fnst.cn.fujitsu.com ([10.167.226.106]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013121711593524-491433 ; Tue, 17 Dec 2013 11:59:35 +0800 From: Miao Xie To: linux-btrfs@vger.kernel.org Cc: jeffm@suse.com Subject: [PATCH] Btrfs: fix double initialization of the raid kobject Date: Tue, 17 Dec 2013 12:01:12 +0800 Message-Id: <1387252872-20521-1-git-send-email-miaox@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/12/17 11:59:35, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/12/17 11:59:35, Serialize complete at 2013/12/17 11:59:35 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY, URIBL_RHS_DOB autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We met the following oops when doing space balance: kobject (ffff88081b590278): tried to init an initialized object, something is seriously wrong. ... Call Trace: [] dump_stack+0x49/0x5f [] kobject_init+0x89/0xa0 [] kobject_init_and_add+0x2a/0x70 [] ? clear_extent_bit+0x199/0x470 [btrfs] [] __link_block_group+0xfc/0x120 [btrfs] [] btrfs_make_block_group+0x24b/0x370 [btrfs] [] __btrfs_alloc_chunk+0x54b/0x7e0 [btrfs] [] btrfs_alloc_chunk+0x3f/0x50 [btrfs] [] do_chunk_alloc+0x363/0x440 [btrfs] [] btrfs_check_data_free_space+0x104/0x310 [btrfs] [] btrfs_write_dirty_block_groups+0x48d/0x600 [btrfs] [] commit_cowonly_roots+0x184/0x250 [btrfs] ... Steps to reproduce: # mkfs.btrfs -f # mount -o nospace_cache # btrfs balance start # dd if=/dev/zero of=/tmpfile bs=1M count=1 The reason of this problem is that we initialized the raid kobject when we added a block group into a empty raid list. As we know, when we mounted a btrfs filesystem, the raid list was empty, we would initialize the raid kobject when we added the first block group. But if there was not data stored in the block group, the block group would be freed when doing balance, and the raid list would be empty. And then if we allocated a new block group and added it into the raid list, we would initialize the raid kobject again, the oops happened. Fix this problem by initializing the raid kobject just when mounting the fs. Signed-off-by: Miao Xie Reported-by: Wang Shilong --- fs/btrfs/extent-tree.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index cd4d9ca..d667aad 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3464,8 +3464,10 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags, return ret; } - for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) + for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) { INIT_LIST_HEAD(&found->block_groups[i]); + kobject_init(&found->block_group_kobjs[i], &btrfs_raid_ktype); + } init_rwsem(&found->groups_sem); spin_lock_init(&found->lock); found->flags = flags & BTRFS_BLOCK_GROUP_TYPE_MASK; @@ -8423,9 +8425,8 @@ static void __link_block_group(struct btrfs_space_info *space_info, int ret; kobject_get(&space_info->kobj); /* put in release */ - ret = kobject_init_and_add(kobj, &btrfs_raid_ktype, - &space_info->kobj, "%s", - get_raid_name(index)); + ret = kobject_add(kobj, &space_info->kobj, "%s", + get_raid_name(index)); if (ret) { pr_warn("btrfs: failed to add kobject for block cache. ignoring.\n"); kobject_put(&space_info->kobj);