From patchwork Tue Dec 5 08:52:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10092513 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8774C6035E for ; Tue, 5 Dec 2017 08:53:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78A7129553 for ; Tue, 5 Dec 2017 08:53:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C5312955C; Tue, 5 Dec 2017 08:53:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F033229553 for ; Tue, 5 Dec 2017 08:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753001AbdLEIx0 (ORCPT ); Tue, 5 Dec 2017 03:53:26 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:42778 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752857AbdLEIwf (ORCPT ); Tue, 5 Dec 2017 03:52:35 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.21/8.16.0.21) with SMTP id vB58plwl008851 for ; Tue, 5 Dec 2017 08:52:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=H4ln+NsVg+rQTLfqgHcnXgswL8GW7cnriVFB7CsEzDU=; b=OlKndMid5fa1Qv1C+VFGItY14JG9QzmwmIZrsPghgkmthZdOL4nQaDK1Rc/r6pP1l/sP EpjgGfhugfrBMD+4pokuTX9MeAelcno24j5vMJYe5bgsxl7qgsee7Jw9AbHfmMiQImWJ hDnZbqd7vkIezzWWwG20vLGZuJ4bZuV0dsx5K1W8w96h6ldlwasjdwwkk00fRc7y9cf0 qiTSwxQU8TDB/iaDHwGr2n9BoNdW+qFcRuex317Y3lD1CU3dUSV7e7rDTusugktWEEvR Rq5bMVQJdRcnzVeTKoM2ea6yO8PXkLLM+CCU/dvPz0CHNuUDI4EnKcc0JX5Ah9bQPV2O BA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2enc2g1mum-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 05 Dec 2017 08:52:34 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id vB58qXU5031151 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 5 Dec 2017 08:52:33 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id vB58qXwe020802 for ; Tue, 5 Dec 2017 08:52:33 GMT Received: from tp.sg.oracle.com (/10.186.50.132) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 05 Dec 2017 00:52:32 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH v4 1/2] btrfs: add function to device list delete Date: Tue, 5 Dec 2017 16:52:56 +0800 Message-Id: <20171205085258.4038-2-anand.jain@oracle.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171205085258.4038-1-anand.jain@oracle.com> References: <20171205085258.4038-1-anand.jain@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8735 signatures=668637 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712050132 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 fs/btrfs/volumes.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 04164337ac69..5deda80316f0 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -531,6 +531,28 @@ 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); + + rcu_string_free(device->name); + kfree(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) {