Commit c2114f11 authored by Jan Kara's avatar Jan Kara Committed by Christian Brauner

rnbd-srv: Convert to use bdev_open_by_path()

Convert rnbd-srv to use bdev_open_by_path() and pass the handle
around.

CC: Jack Wang <jinpu.wang@ionos.com>
CC: "Md. Haris Iqbal" <haris.iqbal@ionos.com>
Acked-by: default avatar"Md. Haris Iqbal" <haris.iqbal@ionos.com>
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230927093442.25915-6-jack@suse.czSigned-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 7ac86df8
...@@ -145,7 +145,7 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, ...@@ -145,7 +145,7 @@ static int process_rdma(struct rnbd_srv_session *srv_sess,
priv->sess_dev = sess_dev; priv->sess_dev = sess_dev;
priv->id = id; priv->id = id;
bio = bio_alloc(sess_dev->bdev, 1, bio = bio_alloc(sess_dev->bdev_handle->bdev, 1,
rnbd_to_bio_flags(le32_to_cpu(msg->rw)), GFP_KERNEL); rnbd_to_bio_flags(le32_to_cpu(msg->rw)), GFP_KERNEL);
if (bio_add_page(bio, virt_to_page(data), datalen, if (bio_add_page(bio, virt_to_page(data), datalen,
offset_in_page(data)) != datalen) { offset_in_page(data)) != datalen) {
...@@ -219,7 +219,7 @@ void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id) ...@@ -219,7 +219,7 @@ void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id)
rnbd_put_sess_dev(sess_dev); rnbd_put_sess_dev(sess_dev);
wait_for_completion(&dc); /* wait for inflights to drop to zero */ wait_for_completion(&dc); /* wait for inflights to drop to zero */
blkdev_put(sess_dev->bdev, NULL); bdev_release(sess_dev->bdev_handle);
mutex_lock(&sess_dev->dev->lock); mutex_lock(&sess_dev->dev->lock);
list_del(&sess_dev->dev_list); list_del(&sess_dev->dev_list);
if (!sess_dev->readonly) if (!sess_dev->readonly)
...@@ -534,7 +534,7 @@ rnbd_srv_get_or_create_srv_dev(struct block_device *bdev, ...@@ -534,7 +534,7 @@ rnbd_srv_get_or_create_srv_dev(struct block_device *bdev,
static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp, static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp,
struct rnbd_srv_sess_dev *sess_dev) struct rnbd_srv_sess_dev *sess_dev)
{ {
struct block_device *bdev = sess_dev->bdev; struct block_device *bdev = sess_dev->bdev_handle->bdev;
rsp->hdr.type = cpu_to_le16(RNBD_MSG_OPEN_RSP); rsp->hdr.type = cpu_to_le16(RNBD_MSG_OPEN_RSP);
rsp->device_id = cpu_to_le32(sess_dev->device_id); rsp->device_id = cpu_to_le32(sess_dev->device_id);
...@@ -559,7 +559,7 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp, ...@@ -559,7 +559,7 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp,
static struct rnbd_srv_sess_dev * static struct rnbd_srv_sess_dev *
rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess, rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess,
const struct rnbd_msg_open *open_msg, const struct rnbd_msg_open *open_msg,
struct block_device *bdev, bool readonly, struct bdev_handle *handle, bool readonly,
struct rnbd_srv_dev *srv_dev) struct rnbd_srv_dev *srv_dev)
{ {
struct rnbd_srv_sess_dev *sdev = rnbd_sess_dev_alloc(srv_sess); struct rnbd_srv_sess_dev *sdev = rnbd_sess_dev_alloc(srv_sess);
...@@ -571,7 +571,7 @@ rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess, ...@@ -571,7 +571,7 @@ rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess,
strscpy(sdev->pathname, open_msg->dev_name, sizeof(sdev->pathname)); strscpy(sdev->pathname, open_msg->dev_name, sizeof(sdev->pathname));
sdev->bdev = bdev; sdev->bdev_handle = handle;
sdev->sess = srv_sess; sdev->sess = srv_sess;
sdev->dev = srv_dev; sdev->dev = srv_dev;
sdev->readonly = readonly; sdev->readonly = readonly;
...@@ -676,7 +676,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, ...@@ -676,7 +676,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
struct rnbd_srv_dev *srv_dev; struct rnbd_srv_dev *srv_dev;
struct rnbd_srv_sess_dev *srv_sess_dev; struct rnbd_srv_sess_dev *srv_sess_dev;
const struct rnbd_msg_open *open_msg = msg; const struct rnbd_msg_open *open_msg = msg;
struct block_device *bdev; struct bdev_handle *bdev_handle;
blk_mode_t open_flags = BLK_OPEN_READ; blk_mode_t open_flags = BLK_OPEN_READ;
char *full_path; char *full_path;
struct rnbd_msg_open_rsp *rsp = data; struct rnbd_msg_open_rsp *rsp = data;
...@@ -714,15 +714,15 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, ...@@ -714,15 +714,15 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
goto reject; goto reject;
} }
bdev = blkdev_get_by_path(full_path, open_flags, NULL, NULL); bdev_handle = bdev_open_by_path(full_path, open_flags, NULL, NULL);
if (IS_ERR(bdev)) { if (IS_ERR(bdev_handle)) {
ret = PTR_ERR(bdev); ret = PTR_ERR(bdev_handle);
pr_err("Opening device '%s' on session %s failed, failed to open the block device, err: %d\n", pr_err("Opening device '%s' on session %s failed, failed to open the block device, err: %d\n",
full_path, srv_sess->sessname, ret); full_path, srv_sess->sessname, ret);
goto free_path; goto free_path;
} }
srv_dev = rnbd_srv_get_or_create_srv_dev(bdev, srv_sess, srv_dev = rnbd_srv_get_or_create_srv_dev(bdev_handle->bdev, srv_sess,
open_msg->access_mode); open_msg->access_mode);
if (IS_ERR(srv_dev)) { if (IS_ERR(srv_dev)) {
pr_err("Opening device '%s' on session %s failed, creating srv_dev failed, err: %ld\n", pr_err("Opening device '%s' on session %s failed, creating srv_dev failed, err: %ld\n",
...@@ -731,7 +731,8 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, ...@@ -731,7 +731,8 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
goto blkdev_put; goto blkdev_put;
} }
srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg, bdev, srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg,
bdev_handle,
open_msg->access_mode == RNBD_ACCESS_RO, open_msg->access_mode == RNBD_ACCESS_RO,
srv_dev); srv_dev);
if (IS_ERR(srv_sess_dev)) { if (IS_ERR(srv_sess_dev)) {
...@@ -747,7 +748,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, ...@@ -747,7 +748,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
*/ */
mutex_lock(&srv_dev->lock); mutex_lock(&srv_dev->lock);
if (!srv_dev->dev_kobj.state_in_sysfs) { if (!srv_dev->dev_kobj.state_in_sysfs) {
ret = rnbd_srv_create_dev_sysfs(srv_dev, bdev); ret = rnbd_srv_create_dev_sysfs(srv_dev, bdev_handle->bdev);
if (ret) { if (ret) {
mutex_unlock(&srv_dev->lock); mutex_unlock(&srv_dev->lock);
rnbd_srv_err(srv_sess_dev, rnbd_srv_err(srv_sess_dev,
...@@ -790,7 +791,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, ...@@ -790,7 +791,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
} }
rnbd_put_srv_dev(srv_dev); rnbd_put_srv_dev(srv_dev);
blkdev_put: blkdev_put:
blkdev_put(bdev, NULL); bdev_release(bdev_handle);
free_path: free_path:
kfree(full_path); kfree(full_path);
reject: reject:
......
...@@ -46,7 +46,7 @@ struct rnbd_srv_dev { ...@@ -46,7 +46,7 @@ struct rnbd_srv_dev {
struct rnbd_srv_sess_dev { struct rnbd_srv_sess_dev {
/* Entry inside rnbd_srv_dev struct */ /* Entry inside rnbd_srv_dev struct */
struct list_head dev_list; struct list_head dev_list;
struct block_device *bdev; struct bdev_handle *bdev_handle;
struct rnbd_srv_session *sess; struct rnbd_srv_session *sess;
struct rnbd_srv_dev *dev; struct rnbd_srv_dev *dev;
struct kobject kobj; struct kobject kobj;
......
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