Commit 91f4acb2 authored by Guoqing Jiang's avatar Guoqing Jiang Committed by Jens Axboe

block/rnbd-clt: support mapping two devices with the same name from different servers

Previously, we can't map same device name from different sessions
due to the limitation of sysfs naming mechanism.

root@clt2:~# ls -l /sys/class/rnbd-client/ctl/devices/
total 0
lrwxrwxrwx 1 root 0 Sep  2 16:31 !dev!nullb1 -> ../../../block/rnbd0

We only use the device name in above, which caused device with
the same name can't be mapped from another server. To address
the issue, the sessname is appended to the node to differentiate
where the device comes from.

Also, we need to check if the pathname is existed in a specific
session instead of search it in global sess_list.
Signed-off-by: default avatarGuoqing Jiang <guoqing.jiang@cloud.ionos.com>
Signed-off-by: default avatarGioh Kim <gi-oh.kim@cloud.ionos.com>
Signed-off-by: default avatarJack Wang <jinpu.wang@cloud.ionos.com>
Reviewed-by: default avatarMd Haris Iqbal <haris.iqbal@cloud.ionos.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent ce9fe18a
...@@ -480,6 +480,10 @@ static int rnbd_clt_get_path_name(struct rnbd_clt_dev *dev, char *buf, ...@@ -480,6 +480,10 @@ static int rnbd_clt_get_path_name(struct rnbd_clt_dev *dev, char *buf,
if (ret >= len) if (ret >= len)
return -ENAMETOOLONG; return -ENAMETOOLONG;
ret = snprintf(buf, len, "%s@%s", buf, dev->sess->sessname);
if (ret >= len)
return -ENAMETOOLONG;
return 0; return 0;
} }
......
...@@ -1410,13 +1410,16 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess, ...@@ -1410,13 +1410,16 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
return ERR_PTR(ret); return ERR_PTR(ret);
} }
static bool __exists_dev(const char *pathname) static bool __exists_dev(const char *pathname, const char *sessname)
{ {
struct rnbd_clt_session *sess; struct rnbd_clt_session *sess;
struct rnbd_clt_dev *dev; struct rnbd_clt_dev *dev;
bool found = false; bool found = false;
list_for_each_entry(sess, &sess_list, list) { list_for_each_entry(sess, &sess_list, list) {
if (sessname && strncmp(sess->sessname, sessname,
sizeof(sess->sessname)))
continue;
mutex_lock(&sess->lock); mutex_lock(&sess->lock);
list_for_each_entry(dev, &sess->devs_list, list) { list_for_each_entry(dev, &sess->devs_list, list) {
if (!strncmp(dev->pathname, pathname, if (!strncmp(dev->pathname, pathname,
...@@ -1433,12 +1436,12 @@ static bool __exists_dev(const char *pathname) ...@@ -1433,12 +1436,12 @@ static bool __exists_dev(const char *pathname)
return found; return found;
} }
static bool exists_devpath(const char *pathname) static bool exists_devpath(const char *pathname, const char *sessname)
{ {
bool found; bool found;
mutex_lock(&sess_lock); mutex_lock(&sess_lock);
found = __exists_dev(pathname); found = __exists_dev(pathname, sessname);
mutex_unlock(&sess_lock); mutex_unlock(&sess_lock);
return found; return found;
...@@ -1451,7 +1454,7 @@ static bool insert_dev_if_not_exists_devpath(const char *pathname, ...@@ -1451,7 +1454,7 @@ static bool insert_dev_if_not_exists_devpath(const char *pathname,
bool found; bool found;
mutex_lock(&sess_lock); mutex_lock(&sess_lock);
found = __exists_dev(pathname); found = __exists_dev(pathname, sess->sessname);
if (!found) { if (!found) {
mutex_lock(&sess->lock); mutex_lock(&sess->lock);
list_add_tail(&dev->list, &sess->devs_list); list_add_tail(&dev->list, &sess->devs_list);
...@@ -1481,7 +1484,7 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname, ...@@ -1481,7 +1484,7 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname,
struct rnbd_clt_dev *dev; struct rnbd_clt_dev *dev;
int ret; int ret;
if (exists_devpath(pathname)) if (unlikely(exists_devpath(pathname, sessname)))
return ERR_PTR(-EEXIST); return ERR_PTR(-EEXIST);
sess = find_and_get_or_create_sess(sessname, paths, path_cnt, port_nr); sess = find_and_get_or_create_sess(sessname, paths, path_cnt, port_nr);
......
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