From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from userp2130.oracle.com ([156.151.31.86]:46400 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751111AbeAVFzR (ORCPT ); Mon, 22 Jan 2018 00:55:17 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0M5qKSR095679 for ; Mon, 22 Jan 2018 05:55:16 GMT Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2fna5e00ts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 22 Jan 2018 05:55:16 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w0M5oG6m030697 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 22 Jan 2018 05:50:16 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w0M5oF9T013927 for ; Mon, 22 Jan 2018 05:50:15 GMT From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 1/2] btrfs: make code easy to read in btrfs_open_one_device() Date: Mon, 22 Jan 2018 13:51:22 +0800 Message-Id: <20180122055123.10404-1-anand.jain@oracle.com> Sender: linux-btrfs-owner@vger.kernel.org List-ID: From: Anand Jain First set the usual case that is writeable, then check for any special case like a seed device or a rdonly device and set the state appropriately. Signed-off-by: Anand Jain --- v1->v2: Add comment and commit log to explain its safe to set writeable first and then reset to the special case such as seed or readonly device. (no code change). fs/btrfs/volumes.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 5750cd9df417..001894782d84 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -689,14 +689,18 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, device->generation = btrfs_super_generation(disk_super); + /* + * Set the device as writeable and then check if its + * seed or readonly device. Both SUPER_FLAG_SEEDING and + * bdev_read_only(bdev) can be set by the user when device + * is unmounted. And this fn is called at the time of mount. + */ + set_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state); if (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_SEEDING) { clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state); fs_devices->seeding = 1; - } else { - if (bdev_read_only(bdev)) - clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state); - else - set_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state); + } else if (bdev_read_only(bdev)) { + clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state); } q = bdev_get_queue(bdev); -- 2.15.0