public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: Johannes Thumshirn <jth@kernel.org>, linux-btrfs@vger.kernel.org
Cc: Boris Burkov <boris@bur.io>, Christoph Hellwig <hch@lst.de>,
	David Sterba <dsterba@suse.com>,
	Josef Bacik <josef@toxicpanda.com>,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: Re: [PATCH v2 1/5] btrfs: always open the device read-only in btrfs_scan_one_device
Date: Thu, 12 Jun 2025 06:58:53 +0930	[thread overview]
Message-ID: <e26c5163-e492-4275-bfaa-b36d81e363ea@suse.com> (raw)
In-Reply-To: <20250611100303.110311-2-jth@kernel.org>



在 2025/6/11 19:32, Johannes Thumshirn 写道:
> From: Christoph Hellwig <hch@lst.de>
> 
> 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 <hch@lst.de>
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>   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 2d0d8c6e77b4..b9e08a59da4e 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -364,10 +364,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);
> @@ -1855,7 +1854,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);
> @@ -2233,7 +2232,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;
> @@ -2251,7 +2250,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);
>   			if (IS_ERR(device))
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 1535a425e8f9..1ebfc69012a2 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -1440,7 +1440,7 @@ static bool btrfs_skip_registration(struct btrfs_super_block *disk_super,
>    * 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;
> @@ -1461,7 +1461,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_file = bdev_file_open_by_path(path, flags, NULL, NULL);
> +	bdev_file = bdev_file_open_by_path(path, BLK_OPEN_READ, NULL, NULL);
>   	if (IS_ERR(bdev_file))
>   		return ERR_CAST(bdev_file);
>   
> diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
> index 6d8b1f38e3ee..afa71d315c46 100644
> --- a/fs/btrfs/volumes.h
> +++ b/fs/btrfs/volumes.h
> @@ -719,7 +719,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);


  reply	other threads:[~2025-06-11 21:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-11 10:02 [PATCH v2 0/5] btrfs: use the super_block as bdev holder Johannes Thumshirn
2025-06-11 10:02 ` [PATCH v2 1/5] btrfs: always open the device read-only in btrfs_scan_one_device Johannes Thumshirn
2025-06-11 21:28   ` Qu Wenruo [this message]
2025-06-11 10:03 ` [PATCH v2 2/5] btrfs: call btrfs_close_devices from ->kill_sb Johannes Thumshirn
2025-06-11 21:37   ` Qu Wenruo
2025-06-11 10:03 ` [PATCH v2 3/5] btrfs: split btrfs_fs_devices.opened Johannes Thumshirn
2025-06-11 21:44   ` Qu Wenruo
2025-06-16 10:26   ` Qu Wenruo
2025-06-16 22:37     ` Qu Wenruo
2025-06-11 10:03 ` [PATCH v2 4/5] btrfs: open block devices after superblock creation Johannes Thumshirn
2025-06-11 10:03 ` [PATCH v2 5/5] btrfs: use the super_block as holder when mounting file systems Johannes Thumshirn
2025-06-11 21:49 ` [PATCH v2 0/5] btrfs: use the super_block as bdev holder Qu Wenruo
2025-06-11 22:06   ` Qu Wenruo
2025-06-12 12:15     ` Johannes Thumshirn
2025-06-12 22:21       ` Qu Wenruo
2025-06-13  5:59         ` hch
2025-06-13  8:01           ` Qu Wenruo
2025-06-13  8:14             ` Johannes Thumshirn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e26c5163-e492-4275-bfaa-b36d81e363ea@suse.com \
    --to=wqu@suse.com \
    --cc=boris@bur.io \
    --cc=dsterba@suse.com \
    --cc=hch@lst.de \
    --cc=johannes.thumshirn@wdc.com \
    --cc=josef@toxicpanda.com \
    --cc=jth@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox