All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jack Wang <jinpu.wang@cloud.ionos.com>
To: linux-block@vger.kernel.org
Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me,
	bvanassche@acm.org, danil.kipnis@cloud.ionos.com,
	Guoqing Jiang <guoqing.jiang@cloud.ionos.com>,
	Gioh Kim <gi-oh.kim@cloud.ionos.com>,
	Md Haris Iqbal <haris.iqbal@cloud.ionos.com>
Subject: [PATCH for-next 2/8] block/rnbd-clt: support mapping two devices with the same name from different servers
Date: Thu, 26 Nov 2020 11:47:17 +0100	[thread overview]
Message-ID: <20201126104723.150674-3-jinpu.wang@cloud.ionos.com> (raw)
In-Reply-To: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com>

From: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>

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: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
Signed-off-by: Gioh Kim <gi-oh.kim@cloud.ionos.com>
Reviewed-by: Md Haris Iqbal <haris.iqbal@cloud.ionos.com>
Signed-off-by: Jack Wang <jinpu.wang@cloud.ionos.com>
---
 drivers/block/rnbd/rnbd-clt-sysfs.c |  4 ++++
 drivers/block/rnbd/rnbd-clt.c       | 13 ++++++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c
index e7b41ec7cd6a..5d3c3c80dab4 100644
--- a/drivers/block/rnbd/rnbd-clt-sysfs.c
+++ b/drivers/block/rnbd/rnbd-clt-sysfs.c
@@ -480,6 +480,10 @@ static int rnbd_clt_get_path_name(struct rnbd_clt_dev *dev, char *buf,
 	if (ret >= len)
 		return -ENAMETOOLONG;
 
+	ret = snprintf(buf, len, "%s@%s", buf, dev->sess->sessname);
+	if (ret >= len)
+		return -ENAMETOOLONG;
+
 	return 0;
 }
 
diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c
index edefa0761a81..1bb495e50931 100644
--- a/drivers/block/rnbd/rnbd-clt.c
+++ b/drivers/block/rnbd/rnbd-clt.c
@@ -1410,13 +1410,16 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
 	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_dev *dev;
 	bool found = false;
 
 	list_for_each_entry(sess, &sess_list, list) {
+		if (sessname && strncmp(sess->sessname, sessname,
+					sizeof(sess->sessname)))
+			continue;
 		mutex_lock(&sess->lock);
 		list_for_each_entry(dev, &sess->devs_list, list) {
 			if (!strncmp(dev->pathname, pathname,
@@ -1433,12 +1436,12 @@ static bool __exists_dev(const char *pathname)
 	return found;
 }
 
-static bool exists_devpath(const char *pathname)
+static bool exists_devpath(const char *pathname, const char *sessname)
 {
 	bool found;
 
 	mutex_lock(&sess_lock);
-	found = __exists_dev(pathname);
+	found = __exists_dev(pathname, sessname);
 	mutex_unlock(&sess_lock);
 
 	return found;
@@ -1451,7 +1454,7 @@ static bool insert_dev_if_not_exists_devpath(const char *pathname,
 	bool found;
 
 	mutex_lock(&sess_lock);
-	found = __exists_dev(pathname);
+	found = __exists_dev(pathname, sess->sessname);
 	if (!found) {
 		mutex_lock(&sess->lock);
 		list_add_tail(&dev->list, &sess->devs_list);
@@ -1481,7 +1484,7 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname,
 	struct rnbd_clt_dev *dev;
 	int ret;
 
-	if (exists_devpath(pathname))
+	if (unlikely(exists_devpath(pathname, sessname)))
 		return ERR_PTR(-EEXIST);
 
 	sess = find_and_get_or_create_sess(sessname, paths, path_cnt, port_nr);
-- 
2.25.1


  parent reply	other threads:[~2020-11-26 10:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-26 10:47 [PATCH for-next 0/8] update for rnbd Jack Wang
2020-11-26 10:47 ` [PATCH for-next 1/8] block/rnbd-clt: Make path parameter optional for map_device Jack Wang
2020-11-26 10:47 ` Jack Wang [this message]
2020-11-26 10:47 ` [PATCH for-next 3/8] Documentation/ABI/rnbd-clt: fix typo in sysfs-class-rnbd-client Jack Wang
2020-11-26 10:47 ` [PATCH for-next 4/8] Documentation/ABI/rnbd-clt: session name is appended to the device path Jack Wang
2020-11-26 10:47 ` [PATCH for-next 5/8] block/rnbd-srv: close a mapped device from server side Jack Wang
2020-11-26 10:47 ` [PATCH for-next 6/8] Documentation/ABI/rnbd-srv: add document for force_close Jack Wang
2020-11-26 10:47 ` [PATCH for-next 7/8] block/rnbd: call kobject_put in the failure path Jack Wang
2020-11-26 10:47 ` [PATCH for-next 8/8] block/rnbd-clt: Dynamically alloc buffer for pathname & blk_symlink_name Jack Wang
2020-12-04 10:15 ` [PATCH for-next 0/8] update for rnbd Jinpu Wang
2020-12-04 16:41 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201126104723.150674-3-jinpu.wang@cloud.ionos.com \
    --to=jinpu.wang@cloud.ionos.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=danil.kipnis@cloud.ionos.com \
    --cc=gi-oh.kim@cloud.ionos.com \
    --cc=guoqing.jiang@cloud.ionos.com \
    --cc=haris.iqbal@cloud.ionos.com \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.