All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: <linux-block@vger.kernel.org>
Cc: <linux-fsdevel@vger.kernel.org>, Jens Axboe <axboe@kernel.dk>,
	Christoph Hellwig <hch@infradead.org>, Jan Kara <jack@suse.cz>,
	linux-nfs@vger.kernel.org,
	Trond Myklebust <trond.myklebust@hammerspace.com>,
	Anna Schumaker <anna@kernel.org>
Subject: [PATCH 26/32] nfs/blocklayout: Convert to use blkdev_get_handle_by_dev/path()
Date: Tue,  4 Jul 2023 14:21:53 +0200	[thread overview]
Message-ID: <20230704122224.16257-26-jack@suse.cz> (raw)
In-Reply-To: <20230629165206.383-1-jack@suse.cz>

Convert block device handling to use blkdev_get_handle_by_dev/path() and
pass the handle around.

CC: linux-nfs@vger.kernel.org
CC: Trond Myklebust <trond.myklebust@hammerspace.com>
CC: Anna Schumaker <anna@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/nfs/blocklayout/blocklayout.h |  2 +-
 fs/nfs/blocklayout/dev.c         | 76 ++++++++++++++++----------------
 2 files changed, 38 insertions(+), 40 deletions(-)

diff --git a/fs/nfs/blocklayout/blocklayout.h b/fs/nfs/blocklayout/blocklayout.h
index 716bc75e9ed2..b4294a8aa2d4 100644
--- a/fs/nfs/blocklayout/blocklayout.h
+++ b/fs/nfs/blocklayout/blocklayout.h
@@ -108,7 +108,7 @@ struct pnfs_block_dev {
 	struct pnfs_block_dev		*children;
 	u64				chunk_size;
 
-	struct block_device		*bdev;
+	struct bdev_handle		*bdev_handle;
 	u64				disk_offset;
 
 	u64				pr_key;
diff --git a/fs/nfs/blocklayout/dev.c b/fs/nfs/blocklayout/dev.c
index 70f5563a8e81..549de8600beb 100644
--- a/fs/nfs/blocklayout/dev.c
+++ b/fs/nfs/blocklayout/dev.c
@@ -25,17 +25,17 @@ bl_free_device(struct pnfs_block_dev *dev)
 	} else {
 		if (dev->pr_registered) {
 			const struct pr_ops *ops =
-				dev->bdev->bd_disk->fops->pr_ops;
+				dev->bdev_handle->bdev->bd_disk->fops->pr_ops;
 			int error;
 
-			error = ops->pr_register(dev->bdev, dev->pr_key, 0,
-				false);
+			error = ops->pr_register(dev->bdev_handle->bdev,
+				dev->pr_key, 0, false);
 			if (error)
 				pr_err("failed to unregister PR key.\n");
 		}
 
-		if (dev->bdev)
-			blkdev_put(dev->bdev, NULL);
+		if (dev->bdev_handle)
+			blkdev_handle_put(dev->bdev_handle);
 	}
 }
 
@@ -169,7 +169,7 @@ static bool bl_map_simple(struct pnfs_block_dev *dev, u64 offset,
 	map->start = dev->start;
 	map->len = dev->len;
 	map->disk_offset = dev->disk_offset;
-	map->bdev = dev->bdev;
+	map->bdev = dev->bdev_handle->bdev;
 	return true;
 }
 
@@ -236,28 +236,26 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d,
 		struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
 {
 	struct pnfs_block_volume *v = &volumes[idx];
-	struct block_device *bdev;
+	struct bdev_handle *bdev_handle;
 	dev_t dev;
 
 	dev = bl_resolve_deviceid(server, v, gfp_mask);
 	if (!dev)
 		return -EIO;
 
-	bdev = blkdev_get_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_WRITE, NULL,
-				 NULL);
-	if (IS_ERR(bdev)) {
+	bdev_handle = blkdev_get_handle_by_dev(dev,
+			BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL);
+	if (IS_ERR(bdev_handle)) {
 		printk(KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n",
-			MAJOR(dev), MINOR(dev), PTR_ERR(bdev));
-		return PTR_ERR(bdev);
+			MAJOR(dev), MINOR(dev), PTR_ERR(bdev_handle));
+		return PTR_ERR(bdev_handle);
 	}
-	d->bdev = bdev;
-
-
-	d->len = bdev_nr_bytes(d->bdev);
+	d->bdev_handle = bdev_handle;
+	d->len = bdev_nr_bytes(bdev_handle->bdev);
 	d->map = bl_map_simple;
 
 	printk(KERN_INFO "pNFS: using block device %s\n",
-		d->bdev->bd_disk->disk_name);
+		bdev_handle->bdev->bd_disk->disk_name);
 	return 0;
 }
 
@@ -302,10 +300,10 @@ bl_validate_designator(struct pnfs_block_volume *v)
 	}
 }
 
-static struct block_device *
+static struct bdev_handle *
 bl_open_path(struct pnfs_block_volume *v, const char *prefix)
 {
-	struct block_device *bdev;
+	struct bdev_handle *bdev_handle;
 	const char *devname;
 
 	devname = kasprintf(GFP_KERNEL, "/dev/disk/by-id/%s%*phN",
@@ -313,15 +311,15 @@ bl_open_path(struct pnfs_block_volume *v, const char *prefix)
 	if (!devname)
 		return ERR_PTR(-ENOMEM);
 
-	bdev = blkdev_get_by_path(devname, BLK_OPEN_READ | BLK_OPEN_WRITE, NULL,
-				  NULL);
-	if (IS_ERR(bdev)) {
+	bdev_handle = blkdev_get_handle_by_path(devname,
+			BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL);
+	if (IS_ERR(bdev_handle)) {
 		pr_warn("pNFS: failed to open device %s (%ld)\n",
-			devname, PTR_ERR(bdev));
+			devname, PTR_ERR(bdev_handle));
 	}
 
 	kfree(devname);
-	return bdev;
+	return bdev_handle;
 }
 
 static int
@@ -329,7 +327,7 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d,
 		struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
 {
 	struct pnfs_block_volume *v = &volumes[idx];
-	struct block_device *bdev;
+	struct bdev_handle *bdev_handle;
 	const struct pr_ops *ops;
 	int error;
 
@@ -342,32 +340,32 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d,
 	 * On other distributions like Debian, the default SCSI by-id path will
 	 * point to the dm-multipath device if one exists.
 	 */
-	bdev = bl_open_path(v, "dm-uuid-mpath-0x");
-	if (IS_ERR(bdev))
-		bdev = bl_open_path(v, "wwn-0x");
-	if (IS_ERR(bdev))
-		return PTR_ERR(bdev);
-	d->bdev = bdev;
-
-	d->len = bdev_nr_bytes(d->bdev);
+	bdev_handle = bl_open_path(v, "dm-uuid-mpath-0x");
+	if (IS_ERR(bdev_handle))
+		bdev_handle = bl_open_path(v, "wwn-0x");
+	if (IS_ERR(bdev_handle))
+		return PTR_ERR(bdev_handle);
+	d->bdev_handle = bdev_handle;
+
+	d->len = bdev_nr_bytes(d->bdev_handle->bdev);
 	d->map = bl_map_simple;
 	d->pr_key = v->scsi.pr_key;
 
 	pr_info("pNFS: using block device %s (reservation key 0x%llx)\n",
-		d->bdev->bd_disk->disk_name, d->pr_key);
+		d->bdev_handle->bdev->bd_disk->disk_name, d->pr_key);
 
-	ops = d->bdev->bd_disk->fops->pr_ops;
+	ops = d->bdev_handle->bdev->bd_disk->fops->pr_ops;
 	if (!ops) {
 		pr_err("pNFS: block device %s does not support reservations.",
-				d->bdev->bd_disk->disk_name);
+				d->bdev_handle->bdev->bd_disk->disk_name);
 		error = -EINVAL;
 		goto out_blkdev_put;
 	}
 
-	error = ops->pr_register(d->bdev, 0, d->pr_key, true);
+	error = ops->pr_register(d->bdev_handle->bdev, 0, d->pr_key, true);
 	if (error) {
 		pr_err("pNFS: failed to register key for block device %s.",
-				d->bdev->bd_disk->disk_name);
+				d->bdev_handle->bdev->bd_disk->disk_name);
 		goto out_blkdev_put;
 	}
 
@@ -375,7 +373,7 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d,
 	return 0;
 
 out_blkdev_put:
-	blkdev_put(d->bdev, NULL);
+	blkdev_handle_put(d->bdev_handle);
 	return error;
 }
 
-- 
2.35.3


  parent reply	other threads:[~2023-07-04 12:24 UTC|newest]

Thread overview: 168+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-04 12:21 [PATCH RFC 0/32] block: Make blkdev_get_by_*() return handle Jan Kara
2023-07-04 12:21 ` Jan Kara
2023-07-04 12:21 ` [dm-devel] " Jan Kara
2023-07-04 12:21 ` [f2fs-dev] " Jan Kara
2023-07-04 12:21 ` Jan Kara
2023-07-04 12:21 ` Jan Kara
2023-07-04 12:21 ` [PATCH 01/32] block: Provide blkdev_get_handle_* functions Jan Kara
2023-07-04 12:21   ` Jan Kara
2023-07-04 12:21   ` [dm-devel] " Jan Kara
2023-07-04 12:21   ` [f2fs-dev] " Jan Kara
2023-07-04 12:21   ` Jan Kara
2023-07-04 12:21   ` Jan Kara
2023-07-04 12:43   ` Matthew Wilcox
2023-07-04 12:43     ` Matthew Wilcox
2023-07-04 12:43     ` Matthew Wilcox
2023-07-04 12:43     ` [dm-devel] " Matthew Wilcox
2023-07-04 12:43     ` Matthew Wilcox
2023-07-04 12:43     ` [f2fs-dev] " Matthew Wilcox
2023-07-04 13:03     ` Jan Kara
2023-07-04 13:03       ` Jan Kara
2023-07-04 13:03       ` [dm-devel] " Jan Kara
2023-07-04 13:03       ` Jan Kara
2023-07-04 13:03       ` [f2fs-dev] " Jan Kara
2023-07-04 13:03       ` Jan Kara
2023-07-04 14:06   ` Bart Van Assche
2023-07-04 14:06     ` Bart Van Assche
2023-07-04 14:06     ` Bart Van Assche
2023-07-04 14:06     ` [dm-devel] " Bart Van Assche
2023-07-04 14:06     ` Bart Van Assche
2023-07-04 14:06     ` [f2fs-dev] " Bart Van Assche
2023-07-04 16:14     ` Matthew Wilcox
2023-07-04 16:14       ` Matthew Wilcox
2023-07-04 16:14       ` [dm-devel] " Matthew Wilcox
2023-07-04 16:14       ` Matthew Wilcox
2023-07-04 16:14       ` Matthew Wilcox
2023-07-04 16:14       ` [f2fs-dev] " Matthew Wilcox
2023-07-05 15:19       ` Bart Van Assche
2023-07-05 15:19         ` Bart Van Assche
2023-07-05 15:19         ` [dm-devel] " Bart Van Assche
2023-07-05 15:19         ` Bart Van Assche
2023-07-05 15:19         ` Bart Van Assche
2023-07-05 15:19         ` [f2fs-dev] " Bart Van Assche
2023-07-05 16:12     ` Jan Kara
2023-07-05 16:12       ` Jan Kara
2023-07-05 16:12       ` [dm-devel] " Jan Kara
2023-07-05 16:12       ` Jan Kara
2023-07-05 16:12       ` Jan Kara
2023-07-05 16:12       ` [f2fs-dev] " Jan Kara
2023-07-04 16:28   ` Keith Busch
2023-07-04 16:28     ` Keith Busch
2023-07-04 16:28     ` Keith Busch
2023-07-04 16:28     ` [dm-devel] " Keith Busch
2023-07-04 16:28     ` Keith Busch
2023-07-04 16:28     ` [f2fs-dev] " Keith Busch
2023-07-05 10:21     ` Jan Kara
2023-07-05 10:21       ` Jan Kara
2023-07-05 10:21       ` [dm-devel] " Jan Kara
2023-07-05 10:21       ` Jan Kara
2023-07-05 10:21       ` Jan Kara
2023-07-05 10:21       ` [f2fs-dev] " Jan Kara
2023-07-06 15:38   ` Christoph Hellwig
2023-07-06 15:38     ` Christoph Hellwig
2023-07-06 15:38     ` Christoph Hellwig
2023-07-06 15:38     ` [dm-devel] " Christoph Hellwig
2023-07-06 15:38     ` Christoph Hellwig
2023-07-06 15:38     ` [f2fs-dev] " Christoph Hellwig
2023-07-06 16:14     ` Jan Kara
2023-07-06 16:14       ` Jan Kara
2023-07-06 16:14       ` [dm-devel] " Jan Kara
2023-07-06 16:14       ` Jan Kara
2023-07-06 16:14       ` Jan Kara
2023-07-06 16:14       ` [f2fs-dev] " Jan Kara
2023-07-07 11:28       ` Christoph Hellwig
2023-07-07 11:28         ` Christoph Hellwig
2023-07-07 11:28         ` Christoph Hellwig
2023-07-07 11:28         ` [dm-devel] " Christoph Hellwig
2023-07-07 11:28         ` Christoph Hellwig
2023-07-07 11:28         ` [f2fs-dev] " Christoph Hellwig
2023-07-07 12:24         ` Jan Kara
2023-07-07 12:24           ` Jan Kara
2023-07-07 12:24           ` [dm-devel] " Jan Kara
2023-07-07 12:24           ` Jan Kara
2023-07-07 12:24           ` Jan Kara
2023-07-07 12:24           ` [f2fs-dev] " Jan Kara
2023-07-12 13:39     ` Haris Iqbal
2023-07-12 13:39       ` Haris Iqbal
2023-07-12 13:39       ` [dm-devel] " Haris Iqbal
2023-07-12 13:39       ` Haris Iqbal via Linux-erofs
2023-07-12 16:06     ` Haris Iqbal
2023-07-12 16:06       ` Haris Iqbal
2023-07-12 16:06       ` [dm-devel] " Haris Iqbal
2023-07-12 16:06       ` Haris Iqbal via Linux-erofs
2023-07-12 16:06       ` Haris Iqbal
2023-07-12 16:06       ` [f2fs-dev] " Haris Iqbal via Linux-f2fs-devel
2023-07-31 10:50       ` Jan Kara
2023-07-31 10:50         ` Jan Kara
2023-07-31 10:50         ` [dm-devel] " Jan Kara
2023-07-31 10:50         ` Jan Kara
2023-07-31 10:50         ` Jan Kara
2023-07-31 10:50         ` [f2fs-dev] " Jan Kara
2023-07-31 11:13         ` Christoph Hellwig
2023-07-31 11:13           ` Christoph Hellwig
2023-07-31 11:13           ` Christoph Hellwig
2023-07-31 11:13           ` [dm-devel] " Christoph Hellwig
2023-07-31 11:13           ` [f2fs-dev] " Christoph Hellwig
2023-07-31 11:13           ` Christoph Hellwig
2023-07-04 12:21 ` [PATCH 02/32] block: Use file->f_flags for determining exclusive opens in file_to_blk_mode() Jan Kara
2023-07-06 15:35   ` Christoph Hellwig
2023-07-06 16:35     ` Jan Kara
2023-07-07 11:29       ` Christoph Hellwig
2023-07-04 12:21 ` [PATCH 03/32] block: Use blkdev_get_handle_by_dev() in blkdev_open() Jan Kara
2023-07-05  5:05   ` Kanchan Joshi
2023-07-05 10:17     ` Jan Kara
2023-07-04 12:21 ` [PATCH 04/32] block: Use blkdev_get_handle_by_dev() in disk_scan_partitions() and blkdev_bszset() Jan Kara
2023-07-04 12:21 ` [PATCH 05/32] drdb: Convert to use blkdev_get_handle_by_path() Jan Kara
2023-07-04 12:21 ` [PATCH 06/32] pktcdvd: Convert to blkdev_get_handle_by_dev() Jan Kara
2023-07-04 12:21 ` [PATCH 07/32] rnbd-srv: Convert to use blkdev_get_handle_by_path() Jan Kara
2023-07-12 15:54   ` Haris Iqbal
2023-07-04 12:21 ` [PATCH 08/32] xen/blkback: Convert to blkdev_get_handle_by_dev() Jan Kara
2023-07-04 12:21 ` [PATCH 09/32] zram: Convert to use blkdev_get_handle_by_dev() Jan Kara
2023-07-05  0:52   ` Sergey Senozhatsky
2023-07-04 12:21 ` [PATCH 10/32] bcache: Convert to blkdev_get_handle_by_path() Jan Kara
2023-07-04 13:06   ` Coly Li
2023-07-04 12:21 ` [PATCH 11/32] dm: Convert to blkdev_get_handle_by_dev() Jan Kara
2023-07-04 12:21   ` [dm-devel] " Jan Kara
2023-07-04 12:21 ` [PATCH 12/32] md: " Jan Kara
2023-07-04 12:21 ` [PATCH 13/32] mtd: block2mtd: Convert to blkdev_get_handle_by_dev/path() Jan Kara
2023-07-04 12:21   ` Jan Kara
2023-07-04 12:21 ` [PATCH 14/32] nvmet: Convert to blkdev_get_handle_by_path() Jan Kara
2023-07-04 12:21 ` [PATCH 15/32] s390/dasd: " Jan Kara
2023-07-04 12:21 ` [PATCH 16/32] scsi: target: " Jan Kara
2023-07-04 12:21 ` [PATCH 17/32] PM: hibernate: Convert to blkdev_get_handle_by_dev() Jan Kara
2023-07-04 12:21 ` [PATCH 18/32] PM: hibernate: Drop unused snapshot_test argument Jan Kara
2023-07-04 12:21 ` [PATCH 19/32] mm/swap: Convert to use blkdev_get_handle_by_dev() Jan Kara
2023-07-04 12:21 ` [PATCH 20/32] fs: Convert to blkdev_get_handle_by_path() Jan Kara
2023-07-04 12:21 ` [PATCH 21/32] btrfs: " Jan Kara
2023-07-04 12:21 ` [PATCH 22/32] erofs: Convert to use blkdev_get_handle_by_path() Jan Kara
2023-07-04 12:21   ` Jan Kara
2023-07-06 15:16   ` Gao Xiang
2023-07-06 15:16     ` Gao Xiang
2023-07-04 12:21 ` [PATCH 23/32] ext4: Convert to blkdev_get_handle_by_dev() Jan Kara
2023-07-04 12:21 ` [PATCH 24/32] f2fs: Convert to blkdev_get_handle_by_dev/path() Jan Kara
2023-07-04 12:21   ` [f2fs-dev] " Jan Kara
2023-07-04 12:21 ` [PATCH 25/32] jfs: Convert to blkdev_get_handle_by_dev() Jan Kara
2023-07-05 15:16   ` Dave Kleikamp
2023-07-04 12:21 ` Jan Kara [this message]
2023-07-04 12:21 ` [PATCH 27/32] nilfs2: Convert to use blkdev_get_handle_by_path() Jan Kara
2023-07-04 12:21   ` Jan Kara
2023-07-21  5:22   ` Ryusuke Konishi
2023-07-21  5:22     ` Ryusuke Konishi
2023-07-04 12:21 ` [PATCH 28/32] ocfs2: Convert to use blkdev_get_handle_by_dev() Jan Kara
2023-07-05 10:55   ` Joseph Qi
2023-07-04 12:21 ` [PATCH 29/32] reiserfs: Convert to blkdev_get_handle_by_dev/path() Jan Kara
2023-07-04 12:21   ` Jan Kara
2023-07-04 12:21 ` [PATCH 30/32] xfs: Convert to blkdev_get_handle_by_path() Jan Kara
2023-07-04 12:21 ` [PATCH 31/32] block: Remove blkdev_get_by_*() functions Jan Kara
2023-07-04 12:21 ` [PATCH 32/32] block: Rename blkdev_get_handle_by_*() and blkdev_handle_put() Jan Kara
2023-07-04 12:21   ` Jan Kara
2023-07-04 12:21   ` [dm-devel] " Jan Kara
2023-07-04 12:21   ` [f2fs-dev] " Jan Kara
2023-07-04 12:21   ` Jan Kara
2023-07-04 12:21   ` Jan Kara
2023-07-06 14:54 ` [PATCH RFC 0/32] block: Make blkdev_get_by_*() return handle Christoph Hellwig
2023-07-06 14:54   ` Christoph Hellwig
2023-07-06 14:54   ` Christoph Hellwig
2023-07-06 14:54   ` [dm-devel] " Christoph Hellwig
2023-07-06 14:54   ` [f2fs-dev] " Christoph Hellwig
2023-07-06 14:54   ` Christoph Hellwig

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=20230704122224.16257-26-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=anna@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@hammerspace.com \
    /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.