linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gioh Kim <gi-oh.kim@ionos.com>
To: linux-rdma@vger.kernel.org
Cc: bvanassche@acm.org, leon@kernel.org, dledford@redhat.com,
	jgg@ziepe.ca, haris.iqbal@ionos.com, jinpu.wang@ionos.com,
	Gioh Kim <gi-oh.kim@cloud.ionos.com>,
	Gioh Kim <gi-oh.kim@ionos.com>,
	Aleksei Marov <aleksei.marov@ionos.com>
Subject: [PATCH for-next 16/20] RDMA/rtrs-srv: Duplicated session name is not allowed
Date: Mon,  3 May 2021 13:48:14 +0200	[thread overview]
Message-ID: <20210503114818.288896-17-gi-oh.kim@ionos.com> (raw)
In-Reply-To: <20210503114818.288896-1-gi-oh.kim@ionos.com>

From: Gioh Kim <gi-oh.kim@cloud.ionos.com>

If two clients try to use the same session name, rtrs-server generates a
kernel error that it failed to create the sysfs because the filename
is duplicated.

This patch adds code to check if there already exists the same session
name with the different UUID. If a client tries to add more session,
it sends the UUID and the session name. Therefore it is ok if there is
already same session name with the same UUID. The rtrs-server must fail
only-if there is the same session name with the different UUID.

Signed-off-by: Gioh Kim <gi-oh.kim@ionos.com>
Signed-off-by: Aleksei Marov <aleksei.marov@ionos.com>
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
Signed-off-by: Md Haris Iqbal <haris.iqbal@ionos.com>
---
 drivers/infiniband/ulp/rtrs/rtrs-srv.c | 42 +++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
index f66f2be9f519..0e1e303dcbee 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
@@ -753,7 +753,40 @@ static void rtrs_srv_sess_down(struct rtrs_srv_sess *sess)
 	mutex_unlock(&srv->paths_ev_mutex);
 }
 
+static bool exist_sessname(struct rtrs_srv_ctx *ctx,
+			   const char *sessname, const uuid_t *path_uuid)
+{
+	struct rtrs_srv *srv;
+	struct rtrs_srv_sess *sess;
+	bool found = false;
+
+	mutex_lock(&ctx->srv_mutex);
+	list_for_each_entry(srv, &ctx->srv_list, ctx_list) {
+		mutex_lock(&srv->paths_mutex);
+
+		/* when a client with same uuid and same sessname tried to add a path */
+		if (uuid_equal(&srv->paths_uuid, path_uuid)) {
+			mutex_unlock(&srv->paths_mutex);
+			continue;
+		}
+
+		list_for_each_entry(sess, &srv->paths_list, s.entry) {
+			if (strlen(sess->s.sessname) == strlen(sessname) &&
+			    !strcmp(sess->s.sessname, sessname)) {
+				found = true;
+				break;
+			}
+		}
+		mutex_unlock(&srv->paths_mutex);
+		if (found)
+			break;
+	}
+	mutex_unlock(&ctx->srv_mutex);
+	return found;
+}
+
 static int post_recv_sess(struct rtrs_srv_sess *sess);
+static int rtrs_rdma_do_reject(struct rdma_cm_id *cm_id, int errno);
 
 static int process_info_req(struct rtrs_srv_con *con,
 			    struct rtrs_msg_info_req *msg)
@@ -772,10 +805,17 @@ static int process_info_req(struct rtrs_srv_con *con,
 		rtrs_err(s, "post_recv_sess(), err: %d\n", err);
 		return err;
 	}
+
+	if (exist_sessname(sess->srv->ctx,
+			   msg->sessname, &sess->srv->paths_uuid)) {
+		rtrs_err(s, "sessname is duplicated: %s\n", msg->sessname);
+		return -EPERM;
+	}
+	strscpy(sess->s.sessname, msg->sessname, sizeof(sess->s.sessname));
+
 	rwr = kcalloc(sess->mrs_num, sizeof(*rwr), GFP_KERNEL);
 	if (unlikely(!rwr))
 		return -ENOMEM;
-	strscpy(sess->s.sessname, msg->sessname, sizeof(sess->s.sessname));
 
 	tx_sz  = sizeof(*rsp);
 	tx_sz += sizeof(rsp->desc[0]) * sess->mrs_num;
-- 
2.25.1


  parent reply	other threads:[~2021-05-03 11:48 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-03 11:47 [PATCH for-next 00/20] Misc update for rtrs Gioh Kim
2021-05-03 11:47 ` [PATCH for-next 01/20] RDMA/rtrs-srv: Kill reject_w_econnreset label Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 02/20] RDMA/rtrs-clt: Remove MAX_SESS_QUEUE_DEPTH from rtrs_send_sess_info Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 03/20] RDMA/rtrs-clt: No need to check queue_depth when receiving Gioh Kim
2021-05-09 11:24   ` Leon Romanovsky
2021-05-10 11:00     ` Haris Iqbal
2021-05-10 11:53       ` Leon Romanovsky
2021-05-10 12:06         ` Haris Iqbal
2021-05-10 12:17           ` Leon Romanovsky
2021-05-10 12:26             ` Haris Iqbal
2021-05-03 11:48 ` [PATCH for-next 04/20] RDMA/rtrs-srv: Add error messages for cases when failing RDMA connection Gioh Kim
2021-05-09 11:27   ` Leon Romanovsky
2021-05-10 10:55     ` Haris Iqbal
2021-05-10 12:03       ` Leon Romanovsky
2021-05-10 12:16         ` Haris Iqbal
2021-05-10 12:19           ` Leon Romanovsky
2021-05-03 11:48 ` [PATCH for-next 05/20] RDMA/rtrs-srv: Clean up the code in __rtrs_srv_change_state Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 06/20] RDMA/rtrs: Change MAX_SESS_QUEUE_DEPTH Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 07/20] RDMA/rtrs: Define MIN_CHUNK_SIZE Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 08/20] RDMA/rtrs: Use strscpy instead of strlcpy Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 09/20] RDMA/rtrs-clt: Kill rtrs_clt_{start,stop}_hb Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 10/20] RDMA/rtrs-clt: Kill rtrs_clt_disconnect_from_sysfs Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 11/20] RDMA/rtrs-srv: Kill __rtrs_srv_change_state Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 12/20] RDMA/rtrs-clt: Remove redundant 'break' Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 13/20] RDMA/rtrs-clt: Check state of the rtrs_clt_sess before reading its stats Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 14/20] RDMA/rtrs-srv: Replace atomic_t with percpu_ref for ids_inflight Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 15/20] RDMA/rtrs: Do not reset hb_missed_max after re-connection Gioh Kim
2021-05-03 11:48 ` Gioh Kim [this message]
2021-05-03 11:48 ` [PATCH for-next 17/20] RDMA/rtrs-srv: Fix memory leak of unfreed rtrs_srv_stats object Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 18/20] RDMA/rtrs-srv: Fix memory leak when having multiple sessions Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 19/20] RDMA/rtrs-clt: Check if the queue_depth has changed during a reconnection Gioh Kim
2021-05-03 11:48 ` [PATCH for-next 20/20] RDMA/rtrs-clt: Fix memory leak of not-freed sess->stats and stats->pcpu_stats Gioh Kim

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=20210503114818.288896-17-gi-oh.kim@ionos.com \
    --to=gi-oh.kim@ionos.com \
    --cc=aleksei.marov@ionos.com \
    --cc=bvanassche@acm.org \
    --cc=dledford@redhat.com \
    --cc=gi-oh.kim@cloud.ionos.com \
    --cc=haris.iqbal@ionos.com \
    --cc=jgg@ziepe.ca \
    --cc=jinpu.wang@ionos.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).