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>
Subject: [PATCH 31/32] block: Remove blkdev_get_by_*() functions
Date: Tue,  4 Jul 2023 14:21:58 +0200	[thread overview]
Message-ID: <20230704122224.16257-31-jack@suse.cz> (raw)
In-Reply-To: <20230629165206.383-1-jack@suse.cz>

blkdev_get_by_*() and blkdev_put() functions are now unused. Remove
them.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 block/bdev.c           | 89 ++++++++++++++----------------------------
 include/linux/blkdev.h |  5 ---
 2 files changed, 29 insertions(+), 65 deletions(-)

diff --git a/block/bdev.c b/block/bdev.c
index c75de5cac2bc..0423495fe5ac 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -746,7 +746,7 @@ void blkdev_put_no_open(struct block_device *bdev)
 }
 	
 /**
- * blkdev_get_by_dev - open a block device by device number
+ * blkdev_get_handle_by_dev - open a block device by device number
  * @dev: device number of block device to open
  * @mode: open mode (BLK_OPEN_*)
  * @holder: exclusive holder identifier
@@ -758,32 +758,40 @@ void blkdev_put_no_open(struct block_device *bdev)
  *
  * Use this interface ONLY if you really do not have anything better - i.e. when
  * you are behind a truly sucky interface and all you are given is a device
- * number.  Everything else should use blkdev_get_by_path().
+ * number.  Everything else should use blkdev_get_handle_by_path().
  *
  * CONTEXT:
  * Might sleep.
  *
  * RETURNS:
- * Reference to the block_device on success, ERR_PTR(-errno) on failure.
+ * Handle with a reference to the block_device on success, ERR_PTR(-errno) on
+ * failure.
  */
-struct block_device *blkdev_get_by_dev(dev_t dev, blk_mode_t mode, void *holder,
-		const struct blk_holder_ops *hops)
+struct bdev_handle *blkdev_get_handle_by_dev(dev_t dev, blk_mode_t mode,
+		void *holder, const struct blk_holder_ops *hops)
 {
-	bool unblock_events = true;
+	struct bdev_handle *handle = kmalloc(sizeof(struct bdev_handle),
+					     GFP_KERNEL);
 	struct block_device *bdev;
+	bool unblock_events = true;
 	struct gendisk *disk;
 	int ret;
 
+	if (!handle)
+		return ERR_PTR(-ENOMEM);
+
 	ret = devcgroup_check_permission(DEVCG_DEV_BLOCK,
 			MAJOR(dev), MINOR(dev),
 			((mode & BLK_OPEN_READ) ? DEVCG_ACC_READ : 0) |
 			((mode & BLK_OPEN_WRITE) ? DEVCG_ACC_WRITE : 0));
 	if (ret)
-		return ERR_PTR(ret);
+		goto free_handle;
 
 	bdev = blkdev_get_no_open(dev);
-	if (!bdev)
-		return ERR_PTR(-ENXIO);
+	if (!bdev) {
+		ret = -ENXIO;
+		goto free_handle;
+	}
 	disk = bdev->bd_disk;
 
 	if (holder) {
@@ -832,7 +840,9 @@ struct block_device *blkdev_get_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 
 	if (unblock_events)
 		disk_unblock_events(disk);
-	return bdev;
+	handle->bdev = bdev;
+	handle->holder = holder;
+	return handle;
 put_module:
 	module_put(disk->fops->owner);
 abort_claiming:
@@ -842,30 +852,14 @@ struct block_device *blkdev_get_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 	disk_unblock_events(disk);
 put_blkdev:
 	blkdev_put_no_open(bdev);
+free_handle:
+	kfree(handle);
 	return ERR_PTR(ret);
 }
-EXPORT_SYMBOL(blkdev_get_by_dev);
-
-struct bdev_handle *blkdev_get_handle_by_dev(dev_t dev, blk_mode_t mode,
-		void *holder, const struct blk_holder_ops *hops)
-{
-	struct bdev_handle *handle = kmalloc(sizeof(struct bdev_handle),
-					     GFP_KERNEL);
-	struct block_device *bdev;
-
-	if (!handle)
-		return ERR_PTR(-ENOMEM);
-	bdev = blkdev_get_by_dev(dev, mode, holder, hops);
-	if (IS_ERR(bdev))
-		return ERR_CAST(bdev);
-	handle->bdev = bdev;
-	handle->holder = holder;
-	return handle;
-}
 EXPORT_SYMBOL(blkdev_get_handle_by_dev);
 
 /**
- * blkdev_get_by_path - open a block device by name
+ * blkdev_get_handle_by_path - open a block device by name
  * @path: path to the block device to open
  * @mode: open mode (BLK_OPEN_*)
  * @holder: exclusive holder identifier
@@ -879,29 +873,9 @@ EXPORT_SYMBOL(blkdev_get_handle_by_dev);
  * Might sleep.
  *
  * RETURNS:
- * Reference to the block_device on success, ERR_PTR(-errno) on failure.
+ * Handle with a reference to the block_device on success, ERR_PTR(-errno) on
+ * failure.
  */
-struct block_device *blkdev_get_by_path(const char *path, blk_mode_t mode,
-		void *holder, const struct blk_holder_ops *hops)
-{
-	struct block_device *bdev;
-	dev_t dev;
-	int error;
-
-	error = lookup_bdev(path, &dev);
-	if (error)
-		return ERR_PTR(error);
-
-	bdev = blkdev_get_by_dev(dev, mode, holder, hops);
-	if (!IS_ERR(bdev) && (mode & BLK_OPEN_WRITE) && bdev_read_only(bdev)) {
-		blkdev_put(bdev, holder);
-		return ERR_PTR(-EACCES);
-	}
-
-	return bdev;
-}
-EXPORT_SYMBOL(blkdev_get_by_path);
-
 struct bdev_handle *blkdev_get_handle_by_path(const char *path, blk_mode_t mode,
 		void *holder, const struct blk_holder_ops *hops)
 {
@@ -924,8 +898,9 @@ struct bdev_handle *blkdev_get_handle_by_path(const char *path, blk_mode_t mode,
 }
 EXPORT_SYMBOL(blkdev_get_handle_by_path);
 
-void blkdev_put(struct block_device *bdev, void *holder)
+void blkdev_handle_put(struct bdev_handle *handle)
 {
+	struct block_device *bdev = handle->bdev;
 	struct gendisk *disk = bdev->bd_disk;
 
 	/*
@@ -939,8 +914,8 @@ void blkdev_put(struct block_device *bdev, void *holder)
 		sync_blockdev(bdev);
 
 	mutex_lock(&disk->open_mutex);
-	if (holder)
-		bd_end_claim(bdev, holder);
+	if (handle->holder)
+		bd_end_claim(bdev, handle->holder);
 
 	/*
 	 * Trigger event checking and tell drivers to flush MEDIA_CHANGE
@@ -957,12 +932,6 @@ void blkdev_put(struct block_device *bdev, void *holder)
 
 	module_put(disk->fops->owner);
 	blkdev_put_no_open(bdev);
-}
-EXPORT_SYMBOL(blkdev_put);
-
-void blkdev_handle_put(struct bdev_handle *handle)
-{
-	blkdev_put(handle->bdev, handle->holder);
 	kfree(handle);
 }
 EXPORT_SYMBOL(blkdev_handle_put);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index a910e9997ddd..134dfd1162e2 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1476,10 +1476,6 @@ struct bdev_handle {
 	void *holder;
 };
 
-struct block_device *blkdev_get_by_dev(dev_t dev, blk_mode_t mode, void *holder,
-		const struct blk_holder_ops *hops);
-struct block_device *blkdev_get_by_path(const char *path, blk_mode_t mode,
-		void *holder, const struct blk_holder_ops *hops);
 struct bdev_handle *blkdev_get_handle_by_dev(dev_t dev, blk_mode_t mode,
 		void *holder, const struct blk_holder_ops *hops);
 struct bdev_handle *blkdev_get_handle_by_path(const char *path, blk_mode_t mode,
@@ -1487,7 +1483,6 @@ struct bdev_handle *blkdev_get_handle_by_path(const char *path, blk_mode_t mode,
 int bd_prepare_to_claim(struct block_device *bdev, void *holder,
 		const struct blk_holder_ops *hops);
 void bd_abort_claiming(struct block_device *bdev, void *holder);
-void blkdev_put(struct block_device *bdev, void *holder);
 void blkdev_handle_put(struct bdev_handle *handle);
 
 /* just for blk-cgroup, don't use elsewhere */
-- 
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 ` [PATCH 26/32] nfs/blocklayout: Convert to use blkdev_get_handle_by_dev/path() Jan Kara
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 ` Jan Kara [this message]
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-31-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@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 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.