From patchwork Wed Feb 14 16:42:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13556778 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 518AF60860; Wed, 14 Feb 2024 16:42:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928941; cv=none; b=SbQQ1KwLgD2QYohU8C6joPKRm+yfAxCHMK1jgdBFq9kxDEJL0NcyZYKRdp3h61ojWK6bavbT91uhp4YYKNR44Yw3Ny33NqNZffW4RBTCp2+KpfdKth/NAYwz4SXuEQyaVTOORL19t2a+JaUd/1RSeurOa5IvNpBQWiY+pYYASuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928941; c=relaxed/simple; bh=1xeJ1LAvHPKE2uqjKayiHpy8JrwfEHaEiYJ0ln71pjA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZKfIl9GqHNKCJEWHe3wvtQsyVMmfMdK40jUL/cP/XDk9m2lG87FhlMoGosxIX7uEt6T3SKQ7pSjenZM6dT5PaD0hF94LzvCdbm/bKbfADuAFylPre/wgLn5IUnQ5jrOTI1q7fyjMBJnY+niuSCwNr176uO4PLjGmEZtNTc4/Z1c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=gWyeO5M2; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="gWyeO5M2" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1707928938; x=1739464938; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=1xeJ1LAvHPKE2uqjKayiHpy8JrwfEHaEiYJ0ln71pjA=; b=gWyeO5M2DW33/34phvrG7H17PTtXUMtYAvTUzhfHyxGicWhM2W9SE1fM U57l+Na17W6/vVcEGTl+WkGWG7XW9U2rNubCSpDhD3RpT6iWW7olbrZXF kMoWao3TzdSrlTnr/2YD2ir49FcGxCNiFGXaU1szEaNS3YFva7EZo4UeV ns3JlruveX9B+JK15hJ42M+kwEmNCZjhhYMxaoJE9KaT0tUw/rJsgAQV+ cd4ks9phyaOG6Tp4+DdX9VYELIEo/VBa4XR76METyZokfC55qS80FmqWR 9fjIbTyBx8zhMVYsc8s7MESJYSt3Jp3hvBq6/fJNbvKlplNDNu5/u5/VU A==; X-CSE-ConnectionGUID: BSdo3bonT1awm+9IyK8hhQ== X-CSE-MsgGUID: kessTWlvSrKc7mwPYVF/cA== X-IronPort-AV: E=Sophos;i="6.06,159,1705334400"; d="scan'208";a="9294734" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2024 00:42:17 +0800 IronPort-SDR: FBPImsUYqgy2slPze6245I3L7boT3T5vL9pTLSjYHJC/yqxdRAi6sbXdfa4F5lg1rUfRB8wicI FJ2KfAeXBD0Q== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2024 07:51:52 -0800 IronPort-SDR: Tq7El7VtOBEASrvLRsJaPhJ3TJtkXIAzXvaipqaQxReCEvamLj5riI1VV30aXXcK62y96V957B wdBi8O8E63XQ== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 14 Feb 2024 08:42:15 -0800 From: Johannes Thumshirn Date: Wed, 14 Feb 2024 08:42:12 -0800 Subject: [PATCH 1/5] btrfs: always open the device read-only in btrfs_scan_one_device Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-hch-device-open-v1-1-b153428b4f72@wdc.com> References: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> In-Reply-To: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> To: Chris Mason , Josef Bacik , David Sterba , Christoph Hellwig Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707928933; l=3992; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=I14e53DoeQrG1yDNK+J7DI2KG2AGVZJx0PKdwyMYBvM=; b=Hc3gvACCQXK46UZERZp3NW3WwFKPPZM0OXn0ZdSDS1ytfZw068ymxH7eAvEAqSp7XR+nuiaIQ CNt/P+GtokWDaknu/D346I71mNYhm/cHImof6ZfmrmOCmx4eOK0LzMl X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= From: Christoph Hellwig btrfs_scan_one_device opens the block device only to read the super block. Instead of passing a blk_mode_t argument to sometimes open it for writing, just hard code BLK_OPEN_READ as it will never write to the device or hand the block_device out to someone else. Signed-off-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/super.c | 9 ++++----- fs/btrfs/volumes.c | 4 ++-- fs/btrfs/volumes.h | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 40ae264fd3ed..b6cadf4f21b8 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -299,10 +299,9 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param) break; case Opt_device: { struct btrfs_device *device; - blk_mode_t mode = btrfs_open_mode(fc); mutex_lock(&uuid_mutex); - device = btrfs_scan_one_device(param->string, mode, false); + device = btrfs_scan_one_device(param->string, false); mutex_unlock(&uuid_mutex); if (IS_ERR(device)) return PTR_ERR(device); @@ -1808,7 +1807,7 @@ static int btrfs_get_tree_super(struct fs_context *fc) * With 'true' passed to btrfs_scan_one_device() (mount time) we expect * either a valid device or an error. */ - device = btrfs_scan_one_device(fc->source, mode, true); + device = btrfs_scan_one_device(fc->source, true); ASSERT(device != NULL); if (IS_ERR(device)) { mutex_unlock(&uuid_mutex); @@ -2210,7 +2209,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, * Scanning outside of mount can return NULL which would turn * into 0 error code. */ - device = btrfs_scan_one_device(vol->name, BLK_OPEN_READ, false); + device = btrfs_scan_one_device(vol->name, false); ret = PTR_ERR_OR_ZERO(device); mutex_unlock(&uuid_mutex); break; @@ -2228,7 +2227,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, * Scanning outside of mount can return NULL which would turn * into 0 error code. */ - device = btrfs_scan_one_device(vol->name, BLK_OPEN_READ, false); + device = btrfs_scan_one_device(vol->name, false); if (IS_ERR_OR_NULL(device)) { mutex_unlock(&uuid_mutex); ret = PTR_ERR(device); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 4ad9eca9b46c..44caf1a48d33 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1308,7 +1308,7 @@ int btrfs_forget_devices(dev_t devt) * the device or return an error. Multi-device and seeding devices are registered * in both cases. */ -struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, +struct btrfs_device *btrfs_scan_one_device(const char *path, bool mount_arg_dev) { struct btrfs_super_block *disk_super; @@ -1337,7 +1337,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, * values temporarily, as the device paths of the fsid are the only * required information for assembling the volume. */ - bdev_handle = bdev_open_by_path(path, flags, NULL, NULL); + bdev_handle = bdev_open_by_path(path, BLK_OPEN_READ, NULL, NULL); if (IS_ERR(bdev_handle)) return ERR_CAST(bdev_handle); diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 21d4de0e3f1f..97c7284e7565 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -655,7 +655,7 @@ struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans, void btrfs_mapping_tree_free(struct btrfs_fs_info *fs_info); int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, blk_mode_t flags, void *holder); -struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, +struct btrfs_device *btrfs_scan_one_device(const char *path, bool mount_arg_dev); int btrfs_forget_devices(dev_t devt); void btrfs_close_devices(struct btrfs_fs_devices *fs_devices); From patchwork Wed Feb 14 16:42:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13556779 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BB426088E; Wed, 14 Feb 2024 16:42:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928941; cv=none; b=B/cLux9nKy6JndNdhRlrB3SRb4CeO2l5+3OswYN2oASX1Kaw3buPOSx4wRjrH/RPoy1qjWXO+PqzlhkHpeSaP21VMK2ApxJQXbl38sDuaG3ITsdFIs3LISHAcs/1+izDya/wiOA1H3gBl8BuBINxA5Rqw3EAwme887U/6kzRpR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928941; c=relaxed/simple; bh=SA54NmB9VaxafMJvx4jeBf6OXC9qGXNN/wzW6KwJc0I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mNXoH6iR5Uvr0urGtsryURAl0EK0ac22a/2RjHL5sELZwlzWdmIpuWRRWXNYXCFNWfEZ8g0uSxBlVHgQAUeL8vWS7rxStwqxPDhZeYyFj6H8rhNpDSDWohUMXVAP9l09D0bO6/Gpy6eY3XmKVQli5aSj2kwLJ6xrwxMYUU0+dW4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=OTXlyxz/; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="OTXlyxz/" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1707928939; x=1739464939; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=SA54NmB9VaxafMJvx4jeBf6OXC9qGXNN/wzW6KwJc0I=; b=OTXlyxz/jrALoPlvgPJzl2l3j6Ad2++yq69zKJX2aTzWfccC7e3VhP3w xzDD4VsDppbE2IU9VFQirwqm92ebYBdMDO2DTf4cO7IYxPxWOmf/cQ2Hu dHEAZTJVfo9vQA1GfuCmK2lx/4zemARnrb2O+k5XJufUYW4uFpMgYLfZa ytaRQs80t8cEbvpBjeQph44kkPQh2n9cwAT6RXkGbJc7Ip/utogFzpXYH EFIVEVmu1dZLBBfOCtCfTR6qmzM9pAeSpULfyp9kJokGsLCroC7VMI3yd LTlAZXMhxABCVeXsQyw2VvS04HZd7ONCAYXEMXnf4ImLep3kya/YrN/BP w==; X-CSE-ConnectionGUID: 7QyyfYlsS8mTXGUHHx2Y4w== X-CSE-MsgGUID: m0Inx8HrSS6WwaLWObvFWg== X-IronPort-AV: E=Sophos;i="6.06,159,1705334400"; d="scan'208";a="9294737" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2024 00:42:18 +0800 IronPort-SDR: SSrVPLBH4vuMc4cfZHfQ/b+pDujGtMWHIns6NHaF9lyahd7FbJ8+K0Ph82pk76CGBQ3dPPJcyE LD/icZemTUzQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2024 07:51:54 -0800 IronPort-SDR: 8lGAdnDhx9j3WWMhmeE/nADvuABDMthU2whT2b4eR+cuepsze0JD82+A9/n3GNyZi4iPcg+MnS eZJ0R8+KqUwA== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 14 Feb 2024 08:42:16 -0800 From: Johannes Thumshirn Date: Wed, 14 Feb 2024 08:42:13 -0800 Subject: [PATCH 2/5] btrfs: call btrfs_close_devices from ->kill_sb Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-hch-device-open-v1-2-b153428b4f72@wdc.com> References: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> In-Reply-To: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> To: Chris Mason , Josef Bacik , David Sterba , Christoph Hellwig Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707928933; l=3686; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=RnNhAJkrtFJkaTBsB+8lN1Jcoq+lAOAadAngBZomtdQ=; b=fdg6RARFVrH5MCrjpINABNkYuCuzvEPtTY7ekxao+ARnqHZcN8sMsTmI86xex910XbA9fCcTd wrZYN8wJ1xrAZ+y0BCAWlDIvZLKuRm+kYV5Qmk6G3YUPq7BAjec6DTh X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= From: Christoph Hellwig blkdev_put must not be called under sb->s_umount to avoid a lock order reversal with disk->open_mutex once call backs from block devices to the file system using the holder ops are supported. Move the call to btrfs_close_devices into btrfs_free_fs_info so that it is closed from ->kill_sb (which is also called from the mount failure handling path unlike ->put_super) as well as when an fs_info is freed because an existing superblock already exists. Signed-off-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/super.c | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8ab185182c30..4aa67e2a48f6 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1266,6 +1266,8 @@ static void free_global_roots(struct btrfs_fs_info *fs_info) void btrfs_free_fs_info(struct btrfs_fs_info *fs_info) { + if (fs_info->fs_devices) + btrfs_close_devices(fs_info->fs_devices); percpu_counter_destroy(&fs_info->dirty_metadata_bytes); percpu_counter_destroy(&fs_info->delalloc_bytes); percpu_counter_destroy(&fs_info->ordered_bytes); @@ -3609,7 +3611,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device iput(fs_info->btree_inode); fail: - btrfs_close_devices(fs_info->fs_devices); ASSERT(ret < 0); return ret; } @@ -4389,7 +4390,6 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info) iput(fs_info->btree_inode); btrfs_mapping_tree_free(fs_info); - btrfs_close_devices(fs_info->fs_devices); } void btrfs_mark_buffer_dirty(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index b6cadf4f21b8..51b8fd272b15 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1822,10 +1822,8 @@ static int btrfs_get_tree_super(struct fs_context *fc) if (ret) return ret; - if (!(fc->sb_flags & SB_RDONLY) && fs_devices->rw_devices == 0) { - ret = -EACCES; - goto error; - } + if (!(fc->sb_flags & SB_RDONLY) && fs_devices->rw_devices == 0) + return -EACCES; bdev = fs_devices->latest_dev->bdev; @@ -1839,15 +1837,12 @@ static int btrfs_get_tree_super(struct fs_context *fc) * otherwise it's tied to the lifetime of the super_block. */ sb = sget_fc(fc, btrfs_fc_test_super, set_anon_super_fc); - if (IS_ERR(sb)) { - ret = PTR_ERR(sb); - goto error; - } + if (IS_ERR(sb)) + return PTR_ERR(sb); set_device_specific_options(fs_info); if (sb->s_root) { - btrfs_close_devices(fs_devices); if ((fc->sb_flags ^ sb->s_flags) & SB_RDONLY) ret = -EBUSY; } else { @@ -1866,10 +1861,6 @@ static int btrfs_get_tree_super(struct fs_context *fc) fc->root = dget(sb->s_root); return 0; - -error: - btrfs_close_devices(fs_devices); - return ret; } /* @@ -1962,10 +1953,20 @@ static int btrfs_get_tree_super(struct fs_context *fc) */ static struct vfsmount *btrfs_reconfigure_for_mount(struct fs_context *fc) { + struct btrfs_fs_info *fs_info = fc->s_fs_info; struct vfsmount *mnt; int ret; const bool ro2rw = !(fc->sb_flags & SB_RDONLY); + /* + * We got a reference to our fs_devices, so we need to close it here to + * make sure we don't leak our reference on the fs_devices. + */ + if (fs_info->fs_devices) { + btrfs_close_devices(fs_info->fs_devices); + fs_info->fs_devices = NULL; + } + /* * We got an EBUSY because our SB_RDONLY flag didn't match the existing * super block, so invert our setting here and retry the mount so we From patchwork Wed Feb 14 16:42:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13556780 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B1BF60DC4; Wed, 14 Feb 2024 16:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928943; cv=none; b=J7rETqQN4RVmIdQn6JYycW/CisxrQTu7upZsgSIRUu8MPXakz1Ww4U6W498kUPFvy1TWWdjEKOCAN17MPXwuWv19nviHHTBStFNwWVTxDwXN6Xky1KoVG8Xg5LpO6j7VsjVrS8TVjZPOfbF+ry1kwpwPgta9bVyfspzDHrc04eQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928943; c=relaxed/simple; bh=x+9XsgsJofMkp/phXpfhTtoOFnnITRJ8Y+D2z+U3vrI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ha9GObcN3dZkAMqmhqKUUz366vrGoxBM40aoY9FrwK4DWySzSf5fYcAET+tUnteqwPY8lYwpwbHMtU2PinDWEMXAIOTYAs8Iz6ZcVWDuLcJiRXUoptMWCctyzw9BlR7UXpP0cbkL1ngL8ne5+ajQ2dGHpiIfpKR9he9iK6A9H5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=e8giFPlK; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="e8giFPlK" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1707928941; x=1739464941; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=x+9XsgsJofMkp/phXpfhTtoOFnnITRJ8Y+D2z+U3vrI=; b=e8giFPlKAyYFeuj9BXHpasdhA6aTK9PVDhueudCFBc9C8pyykB5ejcwa LL5JpzG3ouBhFdlunhQcMR0OrRdIt7Tzn9sgRSX3J55nT0h9Hj0/5SKqa JMdkKTewDVCTIL/hdb1LXTgG+EG5tj3TGlz9KkMe38I9LPvxO/HX5BGAS ElUrSaVxsJx8iF0BCjzt4TePyFoR1WNZT+/CSs5zsifdtqTWGZrgmxqdD HGLp+9u10xU6fsWrVrsd5a3kc6glvgymtViv2LNcY30OBUGy0lbp9MQaU AEkSRChUeLY+XKmM3MZBgaB/T+1VKIQ0w+XcCJfo0v9w35R7DNDRUO7Iy A==; X-CSE-ConnectionGUID: 6xxSmU/ORtSOGRLm4HW5nw== X-CSE-MsgGUID: w0+miKYWQCuvoZ7o/OvvBg== X-IronPort-AV: E=Sophos;i="6.06,159,1705334400"; d="scan'208";a="9294741" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2024 00:42:20 +0800 IronPort-SDR: 8TCrt7yX0Q48V8HjcqzQEwKMlalzZRSlOa3kRgFQBfGmlg1Im2R1bmF7wNuHCcXlRGPOCP61+a RdtngOX2GeBQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2024 07:51:55 -0800 IronPort-SDR: iuSycV2C7J0cH1F3CsA6m8xOWSjY3EWg//M6hxtOqxSaWP2SjXECa+d46LefzsFRyg0ezdBZCN BD6Qy+KqWBqg== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 14 Feb 2024 08:42:18 -0800 From: Johannes Thumshirn Date: Wed, 14 Feb 2024 08:42:14 -0800 Subject: [PATCH 3/5] btrfs: split btrfs_fs_devices.opened Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-hch-device-open-v1-3-b153428b4f72@wdc.com> References: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> In-Reply-To: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> To: Chris Mason , Josef Bacik , David Sterba , Christoph Hellwig Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707928933; l=7104; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=7OH2aIo02sm6W0LG0E/ZUUuGzuFnEGpt1qc6hy3w+JE=; b=FkYNdzB4EGUPbJR4wd55k6sFzciP0YyBfUAzNUq1ey9V5wEM/iIDoRfoMUh/Vw8IxzfKp+2VQ t40Z+ink6bQCOPfiFPCC+9oIcuwtwtNXlxrWawYpnyLqFQKjxkLU/EV X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= From: Christoph Hellwig The btrfs_fs_devices.opened member mixes an in use counter for the fs_devices structure that prevents it from being garbage collected with a flag if the underlying devices were actually opened. This not only makes the code hard to follow, but also prevents btrfs from switching to opening the block device only after super block creation. Split it into an in_use counter and an is_open boolean flag instead. Signed-off-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 51 +++++++++++++++++++++++++++++---------------------- fs/btrfs/volumes.h | 6 ++++-- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 44caf1a48d33..f27af155abf0 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -412,7 +412,8 @@ static void free_fs_devices(struct btrfs_fs_devices *fs_devices) { struct btrfs_device *device; - WARN_ON(fs_devices->opened); + WARN_ON_ONCE(fs_devices->in_use); + WARN_ON_ONCE(fs_devices->is_open); while (!list_empty(&fs_devices->devices)) { device = list_entry(fs_devices->devices.next, struct btrfs_device, dev_list); @@ -535,7 +536,7 @@ static int btrfs_free_stale_devices(dev_t devt, struct btrfs_device *skip_device continue; if (devt && devt != device->devt) continue; - if (fs_devices->opened) { + if (fs_devices->in_use) { if (devt) ret = -EBUSY; break; @@ -607,7 +608,7 @@ static struct btrfs_fs_devices *find_fsid_by_device( if (found_by_devt) { /* Existing device. */ if (fsid_fs_devices == NULL) { - if (devt_fs_devices->opened == 0) { + if (devt_fs_devices->in_use == 0) { /* Stale device. */ return NULL; } else { @@ -795,7 +796,7 @@ static noinline struct btrfs_device *device_list_add(const char *path, if (!device) { unsigned int nofs_flag; - if (fs_devices->opened) { + if (fs_devices->in_use) { btrfs_err(NULL, "device %s belongs to fsid %pU, and the fs is already mounted, scanned by %s (%d)", path, fs_devices->fsid, current->comm, @@ -860,7 +861,7 @@ static noinline struct btrfs_device *device_list_add(const char *path, * tracking a problem where systems fail mount by subvolume id * when we reject replacement on a mounted FS. */ - if (!fs_devices->opened && found_transid < device->generation) { + if (!fs_devices->in_use && found_transid < device->generation) { /* * That is if the FS is _not_ mounted and if you * are here, that means there is more than one @@ -921,7 +922,7 @@ static noinline struct btrfs_device *device_list_add(const char *path, * it back. We need it to pick the disk with largest generation * (as above). */ - if (!fs_devices->opened) { + if (!fs_devices->in_use) { device->generation = found_transid; fs_devices->latest_generation = max_t(u64, found_transid, fs_devices->latest_generation); @@ -1120,15 +1121,19 @@ static void close_fs_devices(struct btrfs_fs_devices *fs_devices) lockdep_assert_held(&uuid_mutex); - if (--fs_devices->opened > 0) + if (--fs_devices->in_use > 0) return; + if (!fs_devices->is_open) + goto done; + list_for_each_entry_safe(device, tmp, &fs_devices->devices, dev_list) btrfs_close_one_device(device); WARN_ON(fs_devices->open_devices); WARN_ON(fs_devices->rw_devices); - fs_devices->opened = 0; + fs_devices->is_open = false; +done: fs_devices->seeding = false; fs_devices->fs_info = NULL; } @@ -1140,7 +1145,7 @@ void btrfs_close_devices(struct btrfs_fs_devices *fs_devices) mutex_lock(&uuid_mutex); close_fs_devices(fs_devices); - if (!fs_devices->opened) { + if (!fs_devices->in_use) { list_splice_init(&fs_devices->seed_list, &list); /* @@ -1188,7 +1193,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices, if (fs_devices->open_devices == 0) return -EINVAL; - fs_devices->opened = 1; + fs_devices->is_open = true; fs_devices->latest_dev = latest_dev; fs_devices->total_rw_bytes = 0; fs_devices->chunk_alloc_policy = BTRFS_CHUNK_ALLOC_REGULAR; @@ -1225,16 +1230,14 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, * We also don't need the lock here as this is called during mount and * exclusion is provided by uuid_mutex */ - - if (fs_devices->opened) { - fs_devices->opened++; - ret = 0; - } else { + if (!fs_devices->is_open) { list_sort(NULL, &fs_devices->devices, devid_cmp); ret = open_fs_devices(fs_devices, flags, holder); + if (ret) + return ret; } - - return ret; + fs_devices->in_use++; + return 0; } void btrfs_release_disk_super(struct btrfs_super_block *super) @@ -2201,13 +2204,14 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, * This can happen if cur_devices is the private seed devices list. We * cannot call close_fs_devices() here because it expects the uuid_mutex * to be held, but in fact we don't need that for the private - * seed_devices, we can simply decrement cur_devices->opened and then + * seed_devices, we can simply decrement cur_devices->in_use and then * remove it from our list and free the fs_devices. */ if (cur_devices->num_devices == 0) { list_del_init(&cur_devices->seed_list); - ASSERT(cur_devices->opened == 1); - cur_devices->opened--; + ASSERT(cur_devices->in_use == 1); + cur_devices->in_use--; + cur_devices->is_open = false; free_fs_devices(cur_devices); } @@ -2437,7 +2441,8 @@ static struct btrfs_fs_devices *btrfs_init_sprout(struct btrfs_fs_info *fs_info) list_add(&old_devices->fs_list, &fs_uuids); memcpy(seed_devices, fs_devices, sizeof(*seed_devices)); - seed_devices->opened = 1; + seed_devices->in_use = 1; + seed_devices->is_open = true; INIT_LIST_HEAD(&seed_devices->devices); INIT_LIST_HEAD(&seed_devices->alloc_list); mutex_init(&seed_devices->device_list_mutex); @@ -7115,7 +7120,8 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info, return fs_devices; fs_devices->seeding = true; - fs_devices->opened = 1; + fs_devices->in_use = 1; + fs_devices->is_open = true; return fs_devices; } @@ -7132,6 +7138,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info, free_fs_devices(fs_devices); return ERR_PTR(ret); } + fs_devices->in_use = 1; if (!fs_devices->seeding) { close_fs_devices(fs_devices); diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 97c7284e7565..d6dc41c62998 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -372,8 +372,10 @@ struct btrfs_fs_devices { struct list_head seed_list; - /* Count fs-devices opened. */ - int opened; + /* Count if fs_device is in used. */ + unsigned int in_use; + /* True if the devices were opened. */ + bool is_open; /* Set when we find or add a device that doesn't have the nonrot flag set. */ bool rotating; From patchwork Wed Feb 14 16:42:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13556781 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A36C61690; Wed, 14 Feb 2024 16:42:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928946; cv=none; b=WhOXRdtTcRfQAQFP8xUFZKnABSCbhbxLRgB45UcsAQkmy3M2Zx2u1eHzpUOGTIMoILz0I7r/C/SFJDJT/2GiVFmTC47VECrwfZSiNdMTydTrMSA3IHmwxtxO/LpYn63Kgiik9inIy1973YFNYRm18URHY9lL9VV0fljiS/MjBeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928946; c=relaxed/simple; bh=bH6vWRw60xnuXV0jlirxZDKuiOZGmQa5D7tTxE57gpM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EFVsLQOekGiNBqQwrjFcDvv2hc/7Pz2EiD7F02stiqIKuAbazCdhFDTbU/3ZAGG2rr8uThjXwPIJbO0u56xICu2Lysc262i7z+LwlsMksEjHQf3eH8UcK/GU3j0oPWpICPLm5rV82cXXVlBJP24kVpezKcQN4mrVybJwIUCG/tY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=d/BdmOG0; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="d/BdmOG0" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1707928945; x=1739464945; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=bH6vWRw60xnuXV0jlirxZDKuiOZGmQa5D7tTxE57gpM=; b=d/BdmOG0rUTis69cavNFSxT/qUmh+8lAB4x2Rw/OlCqlLqkAP2E2JVUf 9HhskvMWb1tr+/NfNjZ26vo2InuOFhCZJT1KJ0FJ6hWohJzkZ98YA8F5Y A+ETILS0xBMaCLpFAuAD7khkrnLpq3AnRyPhXN0A2tYP3YDAB8QIkg+Lw Is8PwkOEXvjgLDKNy3yQ/dCpy6OfTxe8zlNufEo1Tkewj8MJKQM2xJGTV 3O5lnggEF8NKfNvZt+6dY5rZZpRlKzFGty1izQsINT5Kskerkubq1q333 1Gi1g3+vnOtvb29v7EK78e/9dXjbQdKEmVtc5GzI9tdeuAWlSUzuga9fV g==; X-CSE-ConnectionGUID: 9drc1YFoQvaidyriv7WFXA== X-CSE-MsgGUID: 1iiedHrNQFeM2XliwCveJw== X-IronPort-AV: E=Sophos;i="6.06,159,1705334400"; d="scan'208";a="9294745" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2024 00:42:23 +0800 IronPort-SDR: HDZ2Vp1/6Jl6rHnVkIgbbev376ZIPH6QAGHVdQ4BFcUDRhNY7aAjSM2HQQNk+XuE6RhaTJrLSc 2a80kDhOYg9A== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2024 07:51:58 -0800 IronPort-SDR: sQgZ3eP1XpqDvjkE+iOQ0S3gHN20lFei3m2a7KcuC3C15nUIrDy/vEBRQRaz8S+T2zm0rZY0YB iia0adWGSQxQ== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 14 Feb 2024 08:42:20 -0800 From: Johannes Thumshirn Date: Wed, 14 Feb 2024 08:42:15 -0800 Subject: [PATCH 4/5] btrfs: open block devices after superblock creation Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-hch-device-open-v1-4-b153428b4f72@wdc.com> References: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> In-Reply-To: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> To: Chris Mason , Josef Bacik , David Sterba , Christoph Hellwig Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707928933; l=4352; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=BhQPNDpB6/btBxArh/7gqFHYFe5pci1QG9ex6aK98P8=; b=v3u1ICI2D2ErbuWaEOekpBh2t3TtBEN3cbKtZ8iM6jF6pkBBUMzIEybn0Do9bfzM/wXANeICX QTKnpY1mqK3B6BtWioo70IqPyFlv4LU2/jLdo32dTbJ408sqVww6yC+ X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= From: Christoph Hellwig Currently btrfs_mount_root opens the block devices before committing to allocating a super block. That creates problems for restricting the number of writers to a device, and also leads to a unusual and not very helpful holder (the fs_type). Reorganize the code to first check whether the superblock for a particular fsid does already exist and open the block devices only if it doesn't, mirroring the recent changes to the VFS mount helpers. To do this the increment of the in_use counter moves out of btrfs_open_devices and into the only caller in btrfs_mount_root so that it happens before dropping uuid_mutex around the call to sget. Signed-off-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/super.c | 41 +++++++++++++++++++++++++---------------- fs/btrfs/volumes.c | 15 +++++---------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 51b8fd272b15..1fa7d83d02c1 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1794,7 +1794,6 @@ static int btrfs_get_tree_super(struct fs_context *fc) struct btrfs_fs_info *fs_info = fc->s_fs_info; struct btrfs_fs_context *ctx = fc->fs_private; struct btrfs_fs_devices *fs_devices = NULL; - struct block_device *bdev; struct btrfs_device *device; struct super_block *sb; blk_mode_t mode = btrfs_open_mode(fc); @@ -1817,15 +1816,8 @@ static int btrfs_get_tree_super(struct fs_context *fc) fs_devices = device->fs_devices; fs_info->fs_devices = fs_devices; - ret = btrfs_open_devices(fs_devices, mode, &btrfs_fs_type); + fs_devices->in_use++; mutex_unlock(&uuid_mutex); - if (ret) - return ret; - - if (!(fc->sb_flags & SB_RDONLY) && fs_devices->rw_devices == 0) - return -EACCES; - - bdev = fs_devices->latest_dev->bdev; /* * From now on the error handling is not straightforward. @@ -1843,24 +1835,41 @@ static int btrfs_get_tree_super(struct fs_context *fc) set_device_specific_options(fs_info); if (sb->s_root) { - if ((fc->sb_flags ^ sb->s_flags) & SB_RDONLY) + if ((fc->sb_flags ^ sb->s_flags) & SB_RDONLY) { ret = -EBUSY; + goto error_deactivate; + } } else { - snprintf(sb->s_id, sizeof(sb->s_id), "%pg", bdev); + struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; + + mutex_lock(&uuid_mutex); + ret = btrfs_open_devices(fs_devices, mode, &btrfs_fs_type); + mutex_unlock(&uuid_mutex); + if (ret) + goto error_deactivate; + + if (!(fc->sb_flags & SB_RDONLY) && !fs_devices->rw_devices) { + ret = -EACCES; + goto error_deactivate; + } + + snprintf(sb->s_id, sizeof(sb->s_id), "%pg", + fs_devices->latest_dev->bdev); shrinker_debugfs_rename(sb->s_shrink, "sb-btrfs:%s", sb->s_id); btrfs_sb(sb)->bdev_holder = &btrfs_fs_type; ret = btrfs_fill_super(sb, fs_devices, NULL); - } - - if (ret) { - deactivate_locked_super(sb); - return ret; + if (ret) + goto error_deactivate; } btrfs_clear_oneshot_options(fs_info); fc->root = dget(sb->s_root); return 0; + +error_deactivate: + deactivate_locked_super(sb); + return ret; } /* diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index f27af155abf0..6e82bd7ce501 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1220,8 +1220,6 @@ static int devid_cmp(void *priv, const struct list_head *a, int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, blk_mode_t flags, void *holder) { - int ret; - lockdep_assert_held(&uuid_mutex); /* * The device_list_mutex cannot be taken here in case opening the @@ -1230,14 +1228,11 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, * We also don't need the lock here as this is called during mount and * exclusion is provided by uuid_mutex */ - if (!fs_devices->is_open) { - list_sort(NULL, &fs_devices->devices, devid_cmp); - ret = open_fs_devices(fs_devices, flags, holder); - if (ret) - return ret; - } - fs_devices->in_use++; - return 0; + ASSERT(fs_devices->in_use); + if (fs_devices->is_open) + return 0; + list_sort(NULL, &fs_devices->devices, devid_cmp); + return open_fs_devices(fs_devices, flags, holder); } void btrfs_release_disk_super(struct btrfs_super_block *super) From patchwork Wed Feb 14 16:42:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13556782 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 401A761695; Wed, 14 Feb 2024 16:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928947; cv=none; b=uZl5QRCvb852R/GPCacDcDhwHFPXlthGbVcfH0iLcR3bONJU/2+f5QFYp5N6bbrXf7V8VIcEhBPFgLLST9/yRBiWKfPIiYoMyO75kNf7k85YA5TNviD9oWambqPd/2LCIMvJzqSeBTXKVThigOvbT+c9jT2WEg0a7hw2d7Isddo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928947; c=relaxed/simple; bh=n/Ct+FOCPnbG6TCxKfw5AO3FWijGxGRtmVbb789OJTM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ILtSj1VWUASBZGvy/KXiwnqdu7GORtmE1twnAR5NFSErthNGku1yPjdEtI1w1FdgkbLo0nmvuVYmUOOxtXcJDNwLCo4QgtxrYKx/lHxA9b9+GqvHeeRxxNauNtiCUIqabA3k9K3Z+DJv+YtWkSmDGdVEACXXYo5Y8+HXUdzxyk8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=BqTZuWEZ; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="BqTZuWEZ" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1707928945; x=1739464945; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=n/Ct+FOCPnbG6TCxKfw5AO3FWijGxGRtmVbb789OJTM=; b=BqTZuWEZE8YUEPxhjGR4fbzg1nQbl4ttkg14Bs3PCw5WOX0bh+X1UHZy kX216bsZwX6lcZwjhu68P/HtyH8DYx0OcJbojGT+XiKhiAvaRbZYG/kdE iRgvLvRLA3fHCxggF+kM2SfxGBnd0Sy/FNOAjLT7VG9G/zyD0uh9jbxnl /XM7weEPIy5g0DS771TjTq9tBavolPHGu6b0hVvmclv2hyxfw+OVlws6A 72nWsI5FK00mLti2H7/xD7lxYYHqN+eA+Q+o5mPQg4p1NPb/E+TK7sC5a SBmV1Uz4v7GHPbjN2UHZ3khkOCnQmG3FhssqauFoCiepqRrCjyVgMO4Yq A==; X-CSE-ConnectionGUID: 3PqAXj1mRHCgh1akvRC+cw== X-CSE-MsgGUID: qvE74kfMRh+XStqcluh2OA== X-IronPort-AV: E=Sophos;i="6.06,159,1705334400"; d="scan'208";a="9294747" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2024 00:42:24 +0800 IronPort-SDR: F6k1MLOE5/8J8qKOpxUSURReH5Yusmwr/nIa58Ltsl2GXDjoysUKZnXpdmsY27sfc0rQGqJpsI Da6NvglNaSQg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2024 07:51:59 -0800 IronPort-SDR: gqvyFZhGSaw04+Ud78YXDxHFnxQddOfK8ygif5khsnA6k0J5jME4Cy2ASv3MXe0GseQVdGmh5s aDi1iUDBXXGg== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 14 Feb 2024 08:42:22 -0800 From: Johannes Thumshirn Date: Wed, 14 Feb 2024 08:42:16 -0800 Subject: [PATCH 5/5] btrfs: use the super_block as holder when mounting file systems Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-hch-device-open-v1-5-b153428b4f72@wdc.com> References: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> In-Reply-To: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> To: Chris Mason , Josef Bacik , David Sterba , Christoph Hellwig Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707928933; l=1407; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=5rfa6IXupj7Jvp1HyDQOjFATBDPTi0LqbzcMFjmSCro=; b=YI3WD5e/SUmGdIE0DfNpjyBwSXRjmr39hdskYzorTvIHh9L6oUFmy4XE+lzd7sgCkziaYG8x2 iNlLie//3u3DKi7tZZpXW/p1nuhTq0YEolIZFV0utmEplJ4NRDB7IDR X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= From: Christoph Hellwig The file system type is not a very useful holder as it doesn't allow us to go back to the actual file system instance. Pass the super_block instead which is useful when passed back to the file system driver. This matches what is done for all other block device based file systems. Signed-off-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 1fa7d83d02c1..0c7956e8f21e 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1843,7 +1843,7 @@ static int btrfs_get_tree_super(struct fs_context *fc) struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; mutex_lock(&uuid_mutex); - ret = btrfs_open_devices(fs_devices, mode, &btrfs_fs_type); + ret = btrfs_open_devices(fs_devices, mode, sb); mutex_unlock(&uuid_mutex); if (ret) goto error_deactivate; @@ -1856,7 +1856,7 @@ static int btrfs_get_tree_super(struct fs_context *fc) snprintf(sb->s_id, sizeof(sb->s_id), "%pg", fs_devices->latest_dev->bdev); shrinker_debugfs_rename(sb->s_shrink, "sb-btrfs:%s", sb->s_id); - btrfs_sb(sb)->bdev_holder = &btrfs_fs_type; + btrfs_sb(sb)->bdev_holder = sb; ret = btrfs_fill_super(sb, fs_devices, NULL); if (ret) goto error_deactivate;