diff mbox series

[rdma-core,v3] srp_daemon: Use maximum initiator to target IU size

Message ID 20191029065240.24963-1-honli@redhat.com (mailing list archive)
State Accepted
Delegated to: Jason Gunthorpe
Headers show
Series [rdma-core,v3] srp_daemon: Use maximum initiator to target IU size | expand

Commit Message

Honggang LI Oct. 29, 2019, 6:52 a.m. UTC
From: Honggang Li <honli@redhat.com>

"ib_srp.ko" module with immediate data support use (8 * 1024)
as default immediate data size. When immediate data support enabled
for "ib_srp.ko" client, the default maximum initiator to target IU
size will greater than (8 * 1024). That means it also greater than
the default maximum initiator to target IU size set by old
"ib_srpt.ko" module, which does not support immediate data.

Pass remote maximum initiator to target IU size as a login parameter,
when immediate data size greater than remote maximum initiator to
target IU size.

This patch fixes backward compatibility for "ib_srp.ko" with [1]
and old srp target does not support immediate data.

[1] 547ed331bbe8 ("RDMA/srp: Add parse function for maximum
initiator to target IU size")

Signed-off-by: Honggang Li <honli@redhat.com>
---
 srp_daemon/srp_daemon.c | 57 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
diff mbox series

Patch

diff --git a/srp_daemon/srp_daemon.c b/srp_daemon/srp_daemon.c
index f0bcf923..b593e245 100644
--- a/srp_daemon/srp_daemon.c
+++ b/srp_daemon/srp_daemon.c
@@ -402,6 +402,50 @@  static int is_enabled_by_rules_file(struct target_details *target)
 }
 
 
+static bool use_imm_data(void)
+{
+	bool ret = false;
+	char flag = 0;
+	int cnt;
+	int fd = open("/sys/module/ib_srp/parameters/use_imm_data", O_RDONLY);
+
+	if (fd < 0)
+		return false;
+	cnt = read(fd, &flag, 1);
+	if (cnt != 1) {
+		close(fd);
+		return false;
+	}
+
+	if (!strncmp(&flag, "Y", 1))
+		ret = true;
+	close(fd);
+	return ret;
+}
+
+static bool imm_data_size_gt_send_size(__be32 send_size)
+{
+	bool ret = false;
+	unsigned int srp_max_imm_data = 0;
+	unsigned int remote_max_it_ui_size = be32toh(send_size);
+	FILE *fp = fopen("/sys/module/ib_srp/parameters/max_imm_data", "r");
+	int cnt;
+
+	if (fp == NULL)
+		return ret;
+
+	cnt = fscanf(fp, "%d", &srp_max_imm_data);
+	if (cnt <= 0) {
+		fclose(fp);
+		return ret;
+	}
+
+	if (srp_max_imm_data > remote_max_it_ui_size)
+		ret = true;
+
+	fclose(fp);
+	return ret;
+}
 
 static int add_non_exist_target(struct target_details *target)
 {
@@ -581,6 +625,19 @@  static int add_non_exist_target(struct target_details *target)
 		}
 	}
 
+	if (use_imm_data() && imm_data_size_gt_send_size(target->ioc_prof.send_size)) {
+		len += snprintf(target_config_str+len,
+			sizeof(target_config_str) - len,
+			",max_it_iu_size=%d",
+			be32toh(target->ioc_prof.send_size));
+
+		if (len >= sizeof(target_config_str)) {
+			pr_err("Target config string is too long, ignoring target\n");
+			closedir(dir);
+			return -1;
+		}
+	}
+
 	target_config_str[len] = '\0';
 
 	pr_cmd(target_config_str, not_connected);