From patchwork Wed Jul 16 10:38:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 4566321 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 B055A9F295 for ; Wed, 16 Jul 2014 10:37:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D2D0A2011B for ; Wed, 16 Jul 2014 10:37:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 09A8620117 for ; Wed, 16 Jul 2014 10:37:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756934AbaGPKhB (ORCPT ); Wed, 16 Jul 2014 06:37:01 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:32654 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1755967AbaGPKhA (ORCPT ); Wed, 16 Jul 2014 06:37:00 -0400 X-IronPort-AV: E=Sophos;i="5.00,902,1396972800"; d="scan'208";a="33352023" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 16 Jul 2014 18:34:13 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s6GAavGZ026187 for ; Wed, 16 Jul 2014 18:36:57 +0800 Received: from miao.fnst.cn.fujitsu.com (10.167.226.169) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Wed, 16 Jul 2014 18:37:08 +0800 From: Miao Xie To: Subject: [PATCH 2/2] Btrfs: fix wrong total device counter after removing a seed device Date: Wed, 16 Jul 2014 18:38:37 +0800 Message-ID: <1405507117-8880-1-git-send-email-miaox@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 MIME-Version: 1.0 X-Originating-IP: [10.167.226.169] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 total device counters of all the descendant filesystem account the seed device, so after removing a seed device, we need decrease all those counters. Signed-off-by: Miao Xie --- fs/btrfs/volumes.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 4cfbe76..184e1c4 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1715,12 +1715,16 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) * (super_copy) should hold the device list mutex. */ - cur_devices = device->fs_devices; mutex_lock(&root->fs_info->fs_devices->device_list_mutex); list_del_rcu(&device->dev_list); device->fs_devices->num_devices--; - device->fs_devices->total_devices--; + + cur_devices = root->fs_info->fs_devices; + do { + cur_devices->total_devices--; + cur_devices = cur_devices->seed; + } while (device->fs_devices != cur_devices); if (device->missing) device->fs_devices->missing_devices--; @@ -1738,12 +1742,12 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) /* remove sysfs entry */ btrfs_kobj_rm_device(root->fs_info, device); - call_rcu(&device->rcu, free_device); - num_devices = btrfs_super_num_devices(root->fs_info->super_copy) - 1; btrfs_set_super_num_devices(root->fs_info->super_copy, num_devices); mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); + call_rcu(&device->rcu, free_device); + if (cur_devices->open_devices == 0) { struct btrfs_fs_devices *fs_devices; fs_devices = root->fs_info->fs_devices;