Commit ce11bdf9 authored by Md Haris Iqbal's avatar Md Haris Iqbal Committed by Jens Axboe

block/rnbd-srv: Replace sess_dev_list with index_idr

The structure rnbd_srv_session maintains a list and an xarray of
rnbd_srv_dev. There is no need to keep both as one of them can serve the
purpose.

Since one of the places where the lookup of rnbd_srv_dev using
rnbd_srv_session is IO path, an xarray would serve us better than a list
traversal. Hence remove sess_dev_list from rnbd_srv_session, and replace
its uses from xarray.
Signed-off-by: default avatarMd Haris Iqbal <haris.iqbal@ionos.com>
Reviewed-by: default avatarAleksei Marov <aleksei.marov@ionos.com>
Signed-off-by: default avatarJack Wang <jinpu.wang@ionos.com>
Link: https://lore.kernel.org/r/20220707143122.460362-3-haris.iqbal@ionos.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 4bc14f31
...@@ -224,7 +224,6 @@ void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id) ...@@ -224,7 +224,6 @@ void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id)
wait_for_completion(&dc); /* wait for inflights to drop to zero */ wait_for_completion(&dc); /* wait for inflights to drop to zero */
rnbd_dev_close(sess_dev->rnbd_dev); rnbd_dev_close(sess_dev->rnbd_dev);
list_del(&sess_dev->sess_list);
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)
...@@ -239,14 +238,14 @@ void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id) ...@@ -239,14 +238,14 @@ void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id)
static void destroy_sess(struct rnbd_srv_session *srv_sess) static void destroy_sess(struct rnbd_srv_session *srv_sess)
{ {
struct rnbd_srv_sess_dev *sess_dev, *tmp; struct rnbd_srv_sess_dev *sess_dev;
unsigned long index;
if (list_empty(&srv_sess->sess_dev_list)) if (xa_empty(&srv_sess->index_idr))
goto out; goto out;
mutex_lock(&srv_sess->lock); mutex_lock(&srv_sess->lock);
list_for_each_entry_safe(sess_dev, tmp, &srv_sess->sess_dev_list, xa_for_each(&srv_sess->index_idr, index, sess_dev)
sess_list)
rnbd_srv_destroy_dev_session_sysfs(sess_dev); rnbd_srv_destroy_dev_session_sysfs(sess_dev);
mutex_unlock(&srv_sess->lock); mutex_unlock(&srv_sess->lock);
...@@ -281,7 +280,6 @@ static int create_sess(struct rtrs_srv_sess *rtrs) ...@@ -281,7 +280,6 @@ static int create_sess(struct rtrs_srv_sess *rtrs)
srv_sess->queue_depth = rtrs_srv_get_queue_depth(rtrs); srv_sess->queue_depth = rtrs_srv_get_queue_depth(rtrs);
xa_init_flags(&srv_sess->index_idr, XA_FLAGS_ALLOC); xa_init_flags(&srv_sess->index_idr, XA_FLAGS_ALLOC);
INIT_LIST_HEAD(&srv_sess->sess_dev_list);
mutex_init(&srv_sess->lock); mutex_init(&srv_sess->lock);
mutex_lock(&sess_lock); mutex_lock(&sess_lock);
list_add(&srv_sess->list, &sess_list); list_add(&srv_sess->list, &sess_list);
...@@ -667,11 +665,12 @@ static struct rnbd_srv_sess_dev * ...@@ -667,11 +665,12 @@ static struct rnbd_srv_sess_dev *
find_srv_sess_dev(struct rnbd_srv_session *srv_sess, const char *dev_name) find_srv_sess_dev(struct rnbd_srv_session *srv_sess, const char *dev_name)
{ {
struct rnbd_srv_sess_dev *sess_dev; struct rnbd_srv_sess_dev *sess_dev;
unsigned long index;
if (list_empty(&srv_sess->sess_dev_list)) if (xa_empty(&srv_sess->index_idr))
return NULL; return NULL;
list_for_each_entry(sess_dev, &srv_sess->sess_dev_list, sess_list) xa_for_each(&srv_sess->index_idr, index, sess_dev)
if (!strcmp(sess_dev->pathname, dev_name)) if (!strcmp(sess_dev->pathname, dev_name))
return sess_dev; return sess_dev;
...@@ -781,8 +780,6 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, ...@@ -781,8 +780,6 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
list_add(&srv_sess_dev->dev_list, &srv_dev->sess_dev_list); list_add(&srv_sess_dev->dev_list, &srv_dev->sess_dev_list);
mutex_unlock(&srv_dev->lock); mutex_unlock(&srv_dev->lock);
list_add(&srv_sess_dev->sess_list, &srv_sess->sess_dev_list);
rnbd_srv_info(srv_sess_dev, "Opened device '%s'\n", srv_dev->id); rnbd_srv_info(srv_sess_dev, "Opened device '%s'\n", srv_dev->id);
kfree(full_path); kfree(full_path);
......
...@@ -25,8 +25,6 @@ struct rnbd_srv_session { ...@@ -25,8 +25,6 @@ struct rnbd_srv_session {
int queue_depth; int queue_depth;
struct xarray index_idr; struct xarray index_idr;
/* List of struct rnbd_srv_sess_dev */
struct list_head sess_dev_list;
struct mutex lock; struct mutex lock;
u8 ver; u8 ver;
}; };
...@@ -48,8 +46,6 @@ struct rnbd_srv_dev { ...@@ -48,8 +46,6 @@ 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;
/* Entry inside rnbd_srv_session struct */
struct list_head sess_list;
struct rnbd_dev *rnbd_dev; struct rnbd_dev *rnbd_dev;
struct rnbd_srv_session *sess; struct rnbd_srv_session *sess;
struct rnbd_srv_dev *dev; struct rnbd_srv_dev *dev;
......
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