Return-Path: Received: from aserp2130.oracle.com ([141.146.126.79]:59960 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753784AbdLGOgA (ORCPT ); Thu, 7 Dec 2017 09:36:00 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.21/8.16.0.21) with SMTP id vB7EVSjB066300 for ; Thu, 7 Dec 2017 14:36:00 GMT Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2eq4ag8v0j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 07 Dec 2017 14:36:00 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vB7EZxGV010984 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 7 Dec 2017 14:35:59 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id vB7EZxKt008218 for ; Thu, 7 Dec 2017 14:35:59 GMT From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH v5 1/3] btrfs: add function to device list delete Date: Thu, 7 Dec 2017 22:36:21 +0800 Message-Id: <20171207143623.26710-2-anand.jain@oracle.com> In-Reply-To: <20171207143623.26710-1-anand.jain@oracle.com> References: <20171207143623.26710-1-anand.jain@oracle.com> Sender: linux-btrfs-owner@vger.kernel.org List-ID: We need device delete from the dev_list so create a new function. New instead of refactor of btrfs_free_stale_device() because, btrfs_free_stale_device() doesn't hold device_list_mutex which is actually needed here. Signed-off-by: Anand Jain --- v1: title of this patch btrfs: refactor btrfs_free_stale_device() to get device list delete v2: delete_device_from_list() is not pealed from btrfs_free_stale_device() as this needs device_list_mutex. And its static now. v3: Send to correct ML v4: no change v5: use helper free_device() fs/btrfs/volumes.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index d0dd0eb3d2e5..f53d62e92fa9 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -607,6 +607,26 @@ static void pending_bios_fn(struct btrfs_work *work) run_scheduled_bios(device); } +static void delete_device_from_list(struct btrfs_device *device) +{ + struct btrfs_fs_devices *fs_devices; + + fs_devices = device->fs_devices; + + lockdep_assert_held(&uuid_mutex); + + mutex_lock(&fs_devices->device_list_mutex); + fs_devices->num_devices--; + list_del(&device->dev_list); + mutex_unlock(&fs_devices->device_list_mutex); + + free_device(device); + if (fs_devices->num_devices == 0) { + btrfs_sysfs_remove_fsid(fs_devices); + list_del(&fs_devices->list); + free_fs_devices(fs_devices); + } +} static void btrfs_free_stale_device(struct btrfs_device *cur_dev) { -- 2.7.0