From patchwork Wed Jan 10 01:49:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10153775 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 4C4B360223 for ; Wed, 10 Jan 2018 01:49:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 415BA204BA for ; Wed, 10 Jan 2018 01:49:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35B2720500; Wed, 10 Jan 2018 01:49:03 +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 C0F65204BA for ; Wed, 10 Jan 2018 01:49:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932858AbeAJBtB (ORCPT ); Tue, 9 Jan 2018 20:49:01 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:58086 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932138AbeAJBs7 (ORCPT ); Tue, 9 Jan 2018 20:48:59 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0A1kvpP077414 for ; Wed, 10 Jan 2018 01:48:59 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=+o7O8Jzw5HVxYpIooogAlrHi4clvHWBgqCC5dBCVdCI=; b=o6yKErmDjO6XXRFk3apk8fMhvqQHfR+rput1XGOqa0EehDiNib2a66AA8ml0djMKXrMx HwXIftOXjj7tkhqVRCCKCE9CEr5Mx5d3i4Ymzp7YgGUosYZALNZKt/BOLJQyJ0mvjD3K oCQQ8ssRyz6oh3ZiK0Fl+z5T4vo4mEy/9DtFqpRumIryx4qGtQQikiVZ2gGaeG89x0AO yVfZOIfZVi4JIGuo7uEI81Q5XdaICpDrHnaI9sCQdsoONqeQ19rl6ha0Cz6EEnGLAp68 gvk8HyQL9kkPZV79AWiuWUghpclqGTSNBGFrlKqgxItMkQ+03srRQ7iYGduTxcDyQuks 9A== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2fd8jn03yb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 10 Jan 2018 01:48:58 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0A1mvTH016313 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 10 Jan 2018 01:48:58 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w0A1mvCo021949 for ; Wed, 10 Jan 2018 01:48:57 GMT Received: from tp.sg.oracle.com (/10.186.49.52) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 09 Jan 2018 17:48:57 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/4] btrfs: get device pointer from device_list_add() Date: Wed, 10 Jan 2018 09:49:49 +0800 Message-Id: <20180110014950.9138-4-anand.jain@oracle.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180110014950.9138-1-anand.jain@oracle.com> References: <20180110014950.9138-1-anand.jain@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8769 signatures=668652 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=995 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801100022 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 Instead of pointer to btrfs_fs_devices as an arg in device_list_add() better to get pointer to btrfs_device as return value, then we have both, pointer to btrfs_device and btrfs_fs_devices. btrfs_device is needed to handle reappearing missing device. Signed-off-by: Anand Jain --- fs/btrfs/volumes.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index f9aaf65e27f5..d74d01971d0c 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -730,9 +730,8 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, * 0 - device already known or newly added * < 0 - error */ -static noinline int device_list_add(const char *path, - struct btrfs_super_block *disk_super, - u64 devid, struct btrfs_fs_devices **fs_devices_ret) +static noinline struct btrfs_device *device_list_add(const char *path, + struct btrfs_super_block *disk_super, u64 devid) { struct btrfs_device *device; struct btrfs_fs_devices *fs_devices; @@ -743,7 +742,7 @@ static noinline int device_list_add(const char *path, if (!fs_devices) { fs_devices = alloc_fs_devices(disk_super->fsid); if (IS_ERR(fs_devices)) - return PTR_ERR(fs_devices); + return ERR_PTR(PTR_ERR(fs_devices)); list_add(&fs_devices->list, &fs_uuids); @@ -755,19 +754,19 @@ static noinline int device_list_add(const char *path, if (!device) { if (fs_devices->opened) - return -EBUSY; + return ERR_PTR(-EBUSY); device = btrfs_alloc_device(NULL, &devid, disk_super->dev_item.uuid); if (IS_ERR(device)) { /* we can safely leave the fs_devices entry around */ - return PTR_ERR(device); + return ERR_PTR(PTR_ERR(device)); } name = rcu_string_strdup(path, GFP_NOFS); if (!name) { free_device(device); - return -ENOMEM; + return ERR_PTR(-ENOMEM); } rcu_assign_pointer(device->name, name); @@ -821,12 +820,12 @@ static noinline int device_list_add(const char *path, * with larger generation number or the last-in if * generation are equal. */ - return -EEXIST; + return ERR_PTR(-EEXIST); } name = rcu_string_strdup(path, GFP_NOFS); if (!name) - return -ENOMEM; + return ERR_PTR(-ENOMEM); rcu_string_free(device->name); rcu_assign_pointer(device->name, name); if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state)) { @@ -846,9 +845,7 @@ static noinline int device_list_add(const char *path, fs_devices->total_devices = btrfs_super_num_devices(disk_super); - *fs_devices_ret = fs_devices; - - return 0; + return device; } static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig) @@ -1183,9 +1180,10 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, struct btrfs_fs_devices **fs_devices_ret) { struct btrfs_super_block *disk_super; + struct btrfs_device *device; struct block_device *bdev; struct page *page; - int ret; + int ret = 0; u64 devid; u64 bytenr; @@ -1210,8 +1208,12 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, devid = btrfs_stack_device_id(&disk_super->dev_item); mutex_lock(&uuid_mutex); - ret = device_list_add(path, disk_super, devid, fs_devices_ret); + device = device_list_add(path, disk_super, devid); mutex_unlock(&uuid_mutex); + if (IS_ERR(device)) + ret = PTR_ERR(device); + + *fs_devices_ret = device->fs_devices; btrfs_release_disk_super(page);