Commit 2a4936e9 authored by Jan Kara's avatar Jan Kara Committed by Christian Brauner

nvmet: Convert to bdev_open_by_path()

Convert nvmet to use bdev_open_by_path() and pass the handle around.

CC: linux-nvme@lists.infradead.org
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarChristian Brauner <brauner@kernel.org>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230927093442.25915-13-jack@suse.czSigned-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 3817d4b1
...@@ -50,9 +50,10 @@ void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id) ...@@ -50,9 +50,10 @@ void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id)
void nvmet_bdev_ns_disable(struct nvmet_ns *ns) void nvmet_bdev_ns_disable(struct nvmet_ns *ns)
{ {
if (ns->bdev) { if (ns->bdev_handle) {
blkdev_put(ns->bdev, NULL); bdev_release(ns->bdev_handle);
ns->bdev = NULL; ns->bdev = NULL;
ns->bdev_handle = NULL;
} }
} }
...@@ -84,17 +85,18 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns) ...@@ -84,17 +85,18 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
if (ns->buffered_io) if (ns->buffered_io)
return -ENOTBLK; return -ENOTBLK;
ns->bdev = blkdev_get_by_path(ns->device_path, ns->bdev_handle = bdev_open_by_path(ns->device_path,
BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL); BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL);
if (IS_ERR(ns->bdev)) { if (IS_ERR(ns->bdev_handle)) {
ret = PTR_ERR(ns->bdev); ret = PTR_ERR(ns->bdev_handle);
if (ret != -ENOTBLK) { if (ret != -ENOTBLK) {
pr_err("failed to open block device %s: (%ld)\n", pr_err("failed to open block device %s: (%d)\n",
ns->device_path, PTR_ERR(ns->bdev)); ns->device_path, ret);
} }
ns->bdev = NULL; ns->bdev_handle = NULL;
return ret; return ret;
} }
ns->bdev = ns->bdev_handle->bdev;
ns->size = bdev_nr_bytes(ns->bdev); ns->size = bdev_nr_bytes(ns->bdev);
ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev)); ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
struct nvmet_ns { struct nvmet_ns {
struct percpu_ref ref; struct percpu_ref ref;
struct bdev_handle *bdev_handle;
struct block_device *bdev; struct block_device *bdev;
struct file *file; struct file *file;
bool readonly; bool readonly;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment