From patchwork Tue Jul 10 18:22:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10517421 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 D9ECC6020F for ; Tue, 10 Jul 2018 18:19:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C875129282 for ; Tue, 10 Jul 2018 18:19:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD37729283; Tue, 10 Jul 2018 18:19:33 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, 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 6404C29285 for ; Tue, 10 Jul 2018 18:19:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732530AbeGJSTj (ORCPT ); Tue, 10 Jul 2018 14:19:39 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:50802 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732523AbeGJSTi (ORCPT ); Tue, 10 Jul 2018 14:19:38 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6AIJUui062485 for ; Tue, 10 Jul 2018 18:19:30 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-2018-07-02; bh=tcwTlCzaNHpXxRroBZm/74RFcS9Vn9bNQ3PfU8IsOVE=; b=gUDydrzQUOZ6X4GVAmH5qK7qqE+Yo72X2pDSXrLkh0acUhUiB47FxyVGNMKE5C0OKBsR cAf+Swzw++KI4CFD2JkFu9HFbTbGj6WZI56gD7ZBO9oa+5Nl6nwuUsALqhahSHz95g+E sjKjh1jDsYuNFlv3iqsQH5ciR3LSbgqY2XlEAirwZprTrhn/NdQvM8zXMTrOfEfyb1/4 JjiTUy6wnIfl92QYfsqxZed4BLpOgX5faLNkzuWih/CcKgg16qqIrLCLAOG08t4NZFnj 03fA6JgGNd67uL/spb6xovrfv2RW83I5k6k7gc6L86rN6JdEuF31/sWR9veKPj20exAR nQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2k2p7vb3jx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Jul 2018 18:19:30 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w6AIJSmD003625 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Jul 2018 18:19:29 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w6AIJS1p000332 for ; Tue, 10 Jul 2018 18:19:28 GMT Received: from tp.sg.oracle.com (/10.191.38.22) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 10 Jul 2018 11:19:28 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/3] btrfs: add helper function check device delete able Date: Wed, 11 Jul 2018 02:22:41 +0800 Message-Id: <20180710182241.23754-3-anand.jain@oracle.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180710182241.23754-1-anand.jain@oracle.com> References: <20180710182241.23754-1-anand.jain@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8950 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=938 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807100195 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 Move the section of the code which performs the check if the device is indelible, move that into a helper function. Signed-off-by: Anand Jain --- fs/btrfs/volumes.c | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 59a6d8f42c98..feb29c5b44f6 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1945,6 +1945,33 @@ static inline u64 btrfs_num_devices(struct btrfs_fs_info *fs_info) return num_devices; } +static struct btrfs_device *btrfs_device_delete_able( + struct btrfs_fs_info *fs_info, + const char *device_path, u64 devid) +{ + int ret; + struct btrfs_device *device; + + ret = btrfs_check_raid_min_devices(fs_info, + btrfs_num_devices(fs_info) - 1); + if (ret) + return ERR_PTR(ret); + + ret = btrfs_find_device_by_devspec(fs_info, devid, device_path, + &device); + if (ret) + return ERR_PTR(ret); + + if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) + return ERR_PTR(BTRFS_ERROR_DEV_TGT_REPLACE); + + if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) && + fs_info->fs_devices->rw_devices == 1) + return ERR_PTR(BTRFS_ERROR_DEV_ONLY_WRITABLE); + + return device; +} + int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path, u64 devid) { @@ -1958,25 +1985,9 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path, mutex_lock(&uuid_mutex); - num_devices = btrfs_num_devices(fs_info); - - ret = btrfs_check_raid_min_devices(fs_info, num_devices - 1); - if (ret) - goto out; - - ret = btrfs_find_device_by_devspec(fs_info, devid, device_path, - &device); - if (ret) - goto out; - - if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) { - ret = BTRFS_ERROR_DEV_TGT_REPLACE; - goto out; - } - - if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) && - fs_info->fs_devices->rw_devices == 1) { - ret = BTRFS_ERROR_DEV_ONLY_WRITABLE; + device = btrfs_device_delete_able(fs_info, device_path, devid); + if (IS_ERR(device)) { + ret = PTR_ERR(device); goto out; }