Commit f7de4886 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

rnbd-srv: remove struct rnbd_dev

Given that rnbd_srv_sess_dev already has an open_flags member, there
is no need for the rnbd_dev indirection as a simple block_device pointer
works just as well.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
Acked-by: default avatarJack Wang <jinpu.wang@ionos.com>
Link: https://lore.kernel.org/r/20220909131509.3263924-5-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 6856b194
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* RDMA Network Block Driver
*
* Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved.
* Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
* Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved.
*/
#ifndef RNBD_SRV_DEV_H
#define RNBD_SRV_DEV_H
#include <linux/fs.h>
#include "rnbd-proto.h"
struct rnbd_dev {
struct block_device *bdev;
fmode_t blk_open_flags;
};
#endif /* RNBD_SRV_DEV_H */
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include "rnbd-srv.h" #include "rnbd-srv.h"
#include "rnbd-srv-dev.h"
#include "rnbd-srv-trace.h" #include "rnbd-srv-trace.h"
MODULE_DESCRIPTION("RDMA Network Block Device Server"); MODULE_DESCRIPTION("RDMA Network Block Device Server");
...@@ -146,7 +145,7 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, ...@@ -146,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->rnbd_dev->bdev, 1, bio = bio_alloc(sess_dev->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) {
...@@ -220,9 +219,7 @@ void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id) ...@@ -220,9 +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->rnbd_dev->bdev, blkdev_put(sess_dev->bdev, sess_dev->open_flags);
sess_dev->rnbd_dev->blk_open_flags);
kfree(sess_dev->rnbd_dev);
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->open_flags & FMODE_WRITE) if (sess_dev->open_flags & FMODE_WRITE)
...@@ -513,14 +510,14 @@ static int rnbd_srv_check_update_open_perm(struct rnbd_srv_dev *srv_dev, ...@@ -513,14 +510,14 @@ static int rnbd_srv_check_update_open_perm(struct rnbd_srv_dev *srv_dev,
} }
static struct rnbd_srv_dev * static struct rnbd_srv_dev *
rnbd_srv_get_or_create_srv_dev(struct rnbd_dev *rnbd_dev, rnbd_srv_get_or_create_srv_dev(struct block_device *bdev,
struct rnbd_srv_session *srv_sess, struct rnbd_srv_session *srv_sess,
enum rnbd_access_mode access_mode) enum rnbd_access_mode access_mode)
{ {
int ret; int ret;
struct rnbd_srv_dev *new_dev, *dev; struct rnbd_srv_dev *new_dev, *dev;
new_dev = rnbd_srv_init_srv_dev(rnbd_dev->bdev); new_dev = rnbd_srv_init_srv_dev(bdev);
if (IS_ERR(new_dev)) if (IS_ERR(new_dev))
return new_dev; return new_dev;
...@@ -540,7 +537,7 @@ rnbd_srv_get_or_create_srv_dev(struct rnbd_dev *rnbd_dev, ...@@ -540,7 +537,7 @@ rnbd_srv_get_or_create_srv_dev(struct rnbd_dev *rnbd_dev,
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->rnbd_dev->bdev; struct block_device *bdev = sess_dev->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);
...@@ -565,7 +562,7 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp, ...@@ -565,7 +562,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 rnbd_dev *rnbd_dev, fmode_t open_flags, struct block_device *bdev, fmode_t open_flags,
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);
...@@ -577,7 +574,7 @@ rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess, ...@@ -577,7 +574,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->rnbd_dev = rnbd_dev; sdev->bdev = bdev;
sdev->sess = srv_sess; sdev->sess = srv_sess;
sdev->dev = srv_dev; sdev->dev = srv_dev;
sdev->open_flags = open_flags; sdev->open_flags = open_flags;
...@@ -684,9 +681,9 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, ...@@ -684,9 +681,9 @@ 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;
fmode_t open_flags; fmode_t open_flags;
char *full_path; char *full_path;
struct rnbd_dev *rnbd_dev;
struct rnbd_msg_open_rsp *rsp = data; struct rnbd_msg_open_rsp *rsp = data;
trace_process_msg_open(srv_sess, open_msg); trace_process_msg_open(srv_sess, open_msg);
...@@ -723,33 +720,25 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, ...@@ -723,33 +720,25 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
goto reject; goto reject;
} }
rnbd_dev = kzalloc(sizeof(*rnbd_dev), GFP_KERNEL); bdev = blkdev_get_by_path(full_path, open_flags, THIS_MODULE);
if (!rnbd_dev) { if (IS_ERR(bdev)) {
ret = -ENOMEM; ret = PTR_ERR(bdev);
goto free_path;
}
rnbd_dev->blk_open_flags = open_flags;
rnbd_dev->bdev = blkdev_get_by_path(full_path, open_flags, THIS_MODULE);
if (IS_ERR(rnbd_dev->bdev)) {
ret = PTR_ERR(rnbd_dev->bdev);
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);
kfree(rnbd_dev);
goto free_path; goto free_path;
} }
srv_dev = rnbd_srv_get_or_create_srv_dev(rnbd_dev, srv_sess, srv_dev = rnbd_srv_get_or_create_srv_dev(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",
full_path, srv_sess->sessname, PTR_ERR(srv_dev)); full_path, srv_sess->sessname, PTR_ERR(srv_dev));
ret = PTR_ERR(srv_dev); ret = PTR_ERR(srv_dev);
goto rnbd_dev_close; goto blkdev_put;
} }
srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg, srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg,
rnbd_dev, open_flags, bdev, open_flags,
srv_dev); srv_dev);
if (IS_ERR(srv_sess_dev)) { if (IS_ERR(srv_sess_dev)) {
pr_err("Opening device '%s' on session %s failed, creating sess_dev failed, err: %ld\n", pr_err("Opening device '%s' on session %s failed, creating sess_dev failed, err: %ld\n",
...@@ -764,7 +753,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, ...@@ -764,7 +753,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, rnbd_dev->bdev); ret = rnbd_srv_create_dev_sysfs(srv_dev, 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,
...@@ -806,9 +795,8 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, ...@@ -806,9 +795,8 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
mutex_unlock(&srv_dev->lock); mutex_unlock(&srv_dev->lock);
} }
rnbd_put_srv_dev(srv_dev); rnbd_put_srv_dev(srv_dev);
rnbd_dev_close: blkdev_put:
blkdev_put(rnbd_dev->bdev, rnbd_dev->blk_open_flags); blkdev_put(bdev, open_flags);
kfree(rnbd_dev);
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 rnbd_dev *rnbd_dev; struct block_device *bdev;
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