All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Christian Brauner <brauner@kernel.org>,
	Christoph Hellwig <hch@lst.de>,
	linux-block@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
	linux-btrfs@vger.kernel.org,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 6/7] btrfs_get_dev_args_from_path(): don't call set_blocksize()
Date: Mon, 29 Apr 2024 17:11:25 +0200	[thread overview]
Message-ID: <20240429151124.GC2585@twin.jikos.cz> (raw)
In-Reply-To: <20240427211230.GF1495312@ZenIV>

On Sat, Apr 27, 2024 at 10:12:30PM +0100, Al Viro wrote:
> We don't have bdev opened exclusive there.  And I'm rather dubious
> about the need to do set_blocksize() anywhere in btrfs, to be
> honest - there's some access to page cache of underlying block
> devices in there, but it's nowhere near the hot paths, AFAICT.

Long time ago we fixed a bug that involved set_blocksize(), 6f60cbd3ae44
("btrfs: access superblock via pagecache in scan_one_device").
Concurrent access from scan, mount and mkfs could interact and some
writes would be dropped, but the argument was rather not to use
set_blocksize.

I do not recall all the details but I think that the problem was when it
was called in the middle of the other operation in progress. The only
reason it's ever called is for the super block read and to call it
explicitly from our code rather than rely on some eventual call from
block layer.  But it's more than 10 years ago and things have changed,
we don't use buffer_head for superblock anymore.

> In any case, btrfs_get_dev_args_from_path() only needs to read
> the on-disk superblock and copy several fields out of it; all
> callers are only interested in devices that are already opened
> and brought into per-filesystem set, so setting the block size
> is redundant for those and actively harmful if we are given
> a pathname of unrelated device.

Calling set_blocksize on already opened devices will avoid the
scan/mount/mkfs interactions so this seems safe.

> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
>  fs/btrfs/volumes.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index f15591f3e54f..43af5a9fb547 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -482,10 +482,12 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,
>  
>  	if (flush)
>  		sync_blockdev(bdev);
> -	ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE);
> -	if (ret) {
> -		fput(*bdev_file);
> -		goto error;
> +	if (holder) {
> +		ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE);

The subject mentions a different function, you're removing it from
btrfs_get_bdev_and_sb() not btrfs_get_dev_args_from_path().

> +		if (ret) {
> +			fput(*bdev_file);
> +			goto error;
> +		}
>  	}
>  	invalidate_bdev(bdev);
>  	*disk_super = btrfs_read_dev_super(bdev);
> @@ -498,6 +500,7 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,
>  	return 0;
>  
>  error:
> +	*disk_super = NULL;
>  	*bdev_file = NULL;
>  	return ret;
>  }
> -- 
> 2.39.2
> 

  parent reply	other threads:[~2024-04-29 15:18 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-27 21:09 [PATCHES][RFC] set_blocksize() rework Al Viro
2024-04-27 21:10 ` [PATCH 1/7] bcache_register(): don't bother with set_blocksize() Al Viro
2024-04-29  5:06   ` Christoph Hellwig
2024-04-29  8:37   ` Christian Brauner
2024-04-27 21:10 ` [PATCH 2/7] pktcdvd: sort set_blocksize() calls out Al Viro
2024-04-29  5:07   ` Christoph Hellwig
2024-04-29  8:38   ` Christian Brauner
2024-04-27 21:10 ` [PATCH 3/7] swapon(2)/swapoff(2): don't bother with block size Al Viro
2024-04-29  5:08   ` Christoph Hellwig
2024-04-29  8:38   ` Christian Brauner
2024-04-27 21:11 ` [PATCH 4/7] swapon(2): open swap with O_EXCL Al Viro
2024-04-27 21:40   ` Linus Torvalds
2024-04-27 23:46     ` Al Viro
2024-04-28  1:25       ` Al Viro
2024-04-28 18:19       ` Al Viro
2024-04-28 18:46         ` Linus Torvalds
2024-04-28 19:07           ` Al Viro
2024-04-29  5:10             ` Christoph Hellwig
2024-04-29  5:09   ` Christoph Hellwig
2024-04-29  8:39   ` Christian Brauner
2024-04-27 21:11 ` [PATCH 5/7] swsusp: don't bother with setting block size Al Viro
2024-04-29  5:10   ` Christoph Hellwig
2024-04-29  8:40   ` Christian Brauner
2024-04-27 21:12 ` [PATCH 6/7] btrfs_get_dev_args_from_path(): don't call set_blocksize() Al Viro
2024-04-29  5:11   ` Christoph Hellwig
2024-04-29  8:40   ` Christian Brauner
2024-04-29 15:11   ` David Sterba [this message]
2024-04-30  2:05     ` Al Viro
2024-04-27 21:13 ` [PATCH 7/7] set_blocksize(): switch to passing struct file *, fail if it's not opened exclusive Al Viro
2024-04-29  5:12   ` Christoph Hellwig
2024-04-29  8:42   ` Christian Brauner
2024-05-03  3:18 ` [PATCHES v2][RFC] set_blocksize() rework Al Viro
2024-05-03  3:23   ` [PATCH v2 1/9] bcache_register(): don't bother with set_blocksize() Al Viro
2024-05-03  3:23     ` [PATCH v2 2/9] pktcdvd: sort set_blocksize() calls out Al Viro
2024-05-03  3:23     ` [PATCH v2 3/9] swapon(2)/swapoff(2): don't bother with block size Al Viro
2024-05-03  3:23     ` [PATCH v2 4/9] swapon(2): open swap with O_EXCL Al Viro
2024-05-03  3:23     ` [PATCH v2 5/9] zram: don't bother with reopening - just use O_EXCL for open Al Viro
2024-05-03  3:23     ` [PATCH v2 6/9] swsusp: don't bother with setting block size Al Viro
2024-05-03  3:23     ` [PATCH v2 7/9] btrfs_get_bdev_and_sb(): call set_blocksize() only for exclusive opens Al Viro
2024-05-10 13:41       ` David Sterba
2024-05-03  3:23     ` [PATCH v2 8/9] set_blocksize(): switch to passing struct file * Al Viro
2024-05-03  3:23     ` [PATCH v2 9/9] make set_blocksize() fail unless block device is opened exclusive Al Viro
2024-05-03  4:17   ` [PATCH v2 1/9] bcache_register(): don't bother with set_blocksize() Al Viro
2024-05-03  4:17     ` [PATCH v2 2/9] pktcdvd: sort set_blocksize() calls out Al Viro
2024-05-03  4:17     ` [PATCH v2 3/9] swapon(2)/swapoff(2): don't bother with block size Al Viro
2024-05-03  4:17     ` [PATCH v2 4/9] swapon(2): open swap with O_EXCL Al Viro
2024-05-03  4:17     ` [PATCH v2 5/9] zram: don't bother with reopening - just use O_EXCL for open Al Viro
2024-05-03  4:17     ` [PATCH v2 6/9] swsusp: don't bother with setting block size Al Viro
2024-05-03  4:17     ` [PATCH v2 7/9] btrfs_get_bdev_and_sb(): call set_blocksize() only for exclusive opens Al Viro
2024-05-03  4:17     ` [PATCH v2 8/9] set_blocksize(): switch to passing struct file * Al Viro
2024-05-03  4:17     ` [PATCH v2 9/9] make set_blocksize() fail unless block device is opened exclusive Al Viro

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=20240429151124.GC2585@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.