Skip to content

Commit

Permalink
nvmet: Convert to bdev_open_by_path()
Browse files Browse the repository at this point in the history
Convert nvmet to use bdev_open_by_path() and pass the handle around.

CC: linux-nvme@lists.infradead.org
Acked-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian Brauner <brauner@kernel.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230927093442.25915-13-jack@suse.cz
Signed-off-by: Christian Brauner <brauner@kernel.org>
  • Loading branch information
Jan Kara authored and Christian Brauner committed Oct 28, 2023
1 parent 3817d4b commit 2a4936e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
20 changes: 11 additions & 9 deletions drivers/nvme/target/io-cmd-bdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
if (ns->bdev) {
blkdev_put(ns->bdev, NULL);
if (ns->bdev_handle) {
bdev_release(ns->bdev_handle);
ns->bdev = NULL;
ns->bdev_handle = NULL;
}
}

Expand Down Expand Up @@ -84,17 +85,18 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
if (ns->buffered_io)
return -ENOTBLK;

ns->bdev = blkdev_get_by_path(ns->device_path,
BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL);
if (IS_ERR(ns->bdev)) {
ret = PTR_ERR(ns->bdev);
ns->bdev_handle = bdev_open_by_path(ns->device_path,
BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL);
if (IS_ERR(ns->bdev_handle)) {
ret = PTR_ERR(ns->bdev_handle);
if (ret != -ENOTBLK) {
pr_err("failed to open block device %s: (%ld)\n",
ns->device_path, PTR_ERR(ns->bdev));
pr_err("failed to open block device %s: (%d)\n",
ns->device_path, ret);
}
ns->bdev = NULL;
ns->bdev_handle = NULL;
return ret;
}
ns->bdev = ns->bdev_handle->bdev;
ns->size = bdev_nr_bytes(ns->bdev);
ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));

Expand Down
1 change: 1 addition & 0 deletions drivers/nvme/target/nvmet.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

struct nvmet_ns {
struct percpu_ref ref;
struct bdev_handle *bdev_handle;
struct block_device *bdev;
struct file *file;
bool readonly;
Expand Down

0 comments on commit 2a4936e

Please sign in to comment.