From patchwork Thu May 22 00:12:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mason X-Patchwork-Id: 4219251 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2A3FDBEEAB for ; Thu, 22 May 2014 00:09:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3A891202EC for ; Thu, 22 May 2014 00:09:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E087B20166 for ; Thu, 22 May 2014 00:09:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752321AbaEVAJW (ORCPT ); Wed, 21 May 2014 20:09:22 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:13907 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752075AbaEVAJV (ORCPT ); Wed, 21 May 2014 20:09:21 -0400 Received: from pps.filterd (m0004077 [127.0.0.1]) by mx0b-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id s4M086NH006273; Wed, 21 May 2014 17:09:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=message-id : date : from : mime-version : to : subject : content-type : content-transfer-encoding; s=facebook; bh=ixftxL9VAGkegUwJOiFR9zreciaEaVRsG/yJtrY6Jec=; b=hFrsvt/XLyhGcsQ4+OwxSXleDVqHSYwhgiKE7fyNt91nOjr0WygpxaboNdKBuseuHDMm FnPjnU+M1t+nVuM+xgpd1+DSAHwYjy4n9B5aWXrtabrsUAuFZW2JIhcOGdv1eJIx46f+ NiY8iBsM5PjBCxhLtCFNM1zMEhc9XUqqoZg= Received: from mail.thefacebook.com (mailwest.thefacebook.com [173.252.71.148]) by mx0b-00082601.pphosted.com with ESMTP id 1m10esha4y-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK); Wed, 21 May 2014 17:09:14 -0700 Received: from [172.23.2.36] (192.168.16.4) by mail.thefacebook.com (192.168.16.13) with Microsoft SMTP Server (TLS) id 14.3.174.1; Wed, 21 May 2014 17:09:13 -0700 Message-ID: <537D40EB.60906@fb.com> Date: Wed, 21 May 2014 20:12:27 -0400 From: Chris Mason User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: linux-btrfs , David Sterba , Jeff Mahoney Subject: [PATCH] Btrfs: don't remove raid type sysfs entries until unmount X-Enigmail-Version: 1.6 X-Originating-IP: [192.168.16.4] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.11.96, 1.0.14, 0.0.0000 definitions=2014-05-21_08:2014-05-22, 2014-05-21, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 kscore.is_bulkscore=5.55111512312578e-17 kscore.compositescore=0 circleOfTrustscore=0.80783763034781 compositescore=0.999019137448366 urlsuspect_oldscore=0.999019137448366 suspectscore=2 recipient_domain_to_sender_totalscore=0 phishscore=0 bulkscore=0 kscore.is_spamscore=0 recipient_to_sender_totalscore=0 recipient_domain_to_sender_domain_totalscore=64355 rbsscore=0.999019137448366 spamscore=0 recipient_to_sender_domain_totalscore=0 urlsuspectscore=0.9 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1405220000 X-FB-Internal: deliver Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 The Btrfs sysfs code removes entries for raid types that are no longer in use. This means that if you have a raid0 FS and use balance to turn it into a raid1 FS, the raid0 sysfs entries will go away. The rough chain of events is: __link_block_group() -> see we're the first RAIDX, add sysfs entry btrfs_remove_block_group() -> notice we're removing the last RAIDX remove sysfs entry This all makes sense until we try to add RAIDX back into the FS again. The problem is that our RAID kobjects are just in an array that gets freed at unmount time, instead of an array of pointers to kobjects that get freed when the great sysfs in the sky is done with them. When we remove the sysfs entry for a given raid level, the syfs code free's the name. When we use the same kobject to add back the RAIDX entry again, sysfs sees the old name pointer and tries to free it again. All of which is a long way of saying we're using sysfs wrong. For now, just don't remove entries for raid levels that we're no longer using. Signed-off-by: Chris Mason Reported-by: Dave Sterba --- 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 ddf16bf..acdc7ed 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -8535,12 +8535,14 @@ static void __link_block_group(struct btrfs_space_info *space_info, struct kobject *kobj = &space_info->block_group_kobjs[index]; int ret; - kobject_get(&space_info->kobj); /* put in release */ - 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); + if (!kobj->name) { + kobject_get(&space_info->kobj); /* put in release */ + 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); + } } } } @@ -8976,8 +8978,6 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, */ list_del_init(&block_group->list); if (list_empty(&block_group->space_info->block_groups[index])) { - kobject_del(&block_group->space_info->block_group_kobjs[index]); - kobject_put(&block_group->space_info->block_group_kobjs[index]); clear_avail_alloc_bits(root->fs_info, block_group->flags); } up_write(&block_group->space_info->groups_sem);