Skip to contentSkip to conversation

rsocket: Add support for RDMA_ROUTE option in rgetsockopt

PATCH Superseded Hal Rosenstock 2 participants 3 messages Jun 19, 2014 2 messages not in the archive InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rsocket: Add support for RDMA_ROUTE option in rgetsockopt

Create as many ibv_path_data structs from the RDMA route ibv_sa_path_rec struct for the rsocket based on how many fit into the supplied buffer.

---

src/rsocket.c +48 -0
index 0e5635f..d1d0ebf 100644
@@ -3500,11 +3500,38 @@ int rsetsockopt(int socket, int level, int optname,
 	return ret;
 }
 
+static void rs_convert_sa_path(struct ibv_sa_path_rec *sa_path,
+			       struct ibv_path_data *path_data)
+{
+	uint32_t fl_hop;
+
+	memset(path_data, 0, sizeof(*path_data));
+	path_data->path.dgid = sa_path->dgid;
+	path_data->path.sgid = sa_path->sgid;
+	path_data->path.dlid = sa_path->dlid;
+	path_data->path.slid = sa_path->slid;
+	fl_hop = ntohl(sa_path->flow_label) << 8;
+	path_data->path.flowlabel_hoplimit = htonl(fl_hop) | sa_path->hop_limit;
+	path_data->path.tclass = sa_path->traffic_class;
+	path_data->path.reversible_numpath = sa_path->reversible << 7 | 1;
+	path_data->path.pkey = sa_path->pkey;
+	path_data->path.qosclass_sl = sa_path->sl;
+	path_data->path.mtu = sa_path->mtu | 2 << 6;	/* exactly */
+	path_data->path.rate = sa_path->rate | 2 << 6;
+	path_data->path.packetlifetime = sa_path->packet_life_time | 2 << 6;
+	path_data->flags= sa_path->preference;
+}
+
 int rgetsockopt(int socket, int level, int optname,
 		void *optval, socklen_t *optlen)
 {
 	struct rsocket *rs;
+	void *opt;
+	struct ibv_sa_path_rec *path_rec;
+	struct ibv_path_data path_data;
+	socklen_t len;
 	int ret = 0;
+	int num_paths;
 
 	rs = idm_lookup(&idm, socket);
 	if (!rs)
@@ -3597,6 +3624,27 @@ int rgetsockopt(int socket, int level, int optname,
 			*((int *) optval) = rs->target_iomap_size;
 			*optlen = sizeof(int);
 			break;
+		case RDMA_ROUTE:
+			if (*optlen < sizeof(path_data)) {
+				ret = EINVAL;
+			} else {
+				len = 0;
+				opt = optval;
+				path_rec = rs->cm_id->route.path_rec;
+				num_paths = 0;
+				if (len + sizeof(path_data) <= *optlen &&
+				    num_paths < rs->cm_id->route.num_paths) {
+					rs_convert_sa_path(path_rec, &path_data);
+					memcpy(opt, &path_data, sizeof(path_data));
+					len += sizeof(path_data);
+					opt += sizeof(path_data);
+					path_rec++;
+					num_paths++;
+				}
+				*optlen = len;
+				ret = 0;
+			}
+			break;
 		default:
 			ret = ENOTSUP;
 			break;

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 53A2DC3A.8050204-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org

#2 lore raw

src/rsocket.c int rgetsockopt(int socket, int level, int optname, · line 3635

Quoted 9 lines
src/rsocket.c +9 -0
+		case RDMA_ROUTE:
+			if (*optlen < sizeof(path_data)) {
+				ret = EINVAL;
+			} else {
+				len = 0;
+				opt = optval;
+				path_rec = rs->cm_id->route.path_rec;
+				num_paths = 0;
+				if (len + sizeof(path_data) <= *optlen &&

len is 0 here and we've already checked *optlen

src/rsocket.c int rgetsockopt(int socket, int level, int optname, · line 3636

Quoted 1 line
src/rsocket.c +1 -0
+				    num_paths < rs->cm_id->route.num_paths) {

and num_paths is 0

src/rsocket.c int rgetsockopt(int socket, int level, int optname, · line 3642

Quoted 6 lines
src/rsocket.c +6 -0
+					rs_convert_sa_path(path_rec, &path_data);
+					memcpy(opt, &path_data, sizeof(path_data));
+					len += sizeof(path_data);
+					opt += sizeof(path_data);
+					path_rec++;
+					num_paths++;

were you actually wanting a loop here?

Review

Quoted 1 line
(quoted diff) +1 -0
+				}

This also needs to handle the case where rgetsockopt is called immediately after rsetsockopt. Something like:

if (rs->optval) {
	memcpy(rs->optval, optval, rs->optlen);
	*optlen = rs->optlen;
}

assuming that rs->optlen is verified

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1828884A29C6694DAF28B7E6B8A8237399312AB2-P5GAC/[email protected]

#4 lore raw
Quoted 16 lines · Sean

src/rsocket.c int rgetsockopt(int socket, int level, int optname, · line 3635

Quoted 9 lines
src/rsocket.c +9 -0
+		case RDMA_ROUTE:
+			if (*optlen < sizeof(path_data)) {
+				ret = EINVAL;
+			} else {
+				len = 0;
+				opt = optval;
+				path_rec = rs->cm_id->route.path_rec;
+				num_paths = 0;
+				if (len + sizeof(path_data) <= *optlen &&

len is 0 here and we've already checked *optlen

src/rsocket.c int rgetsockopt(int socket, int level, int optname, · line 3636

Quoted 1 line
src/rsocket.c +1 -0
+				    num_paths < rs->cm_id->route.num_paths) {

and num_paths is 0

Quoted 8 lines

src/rsocket.c int rgetsockopt(int socket, int level, int optname, · line 3642

Quoted 6 lines
src/rsocket.c +6 -0
+					rs_convert_sa_path(path_rec, &path_data);
+					memcpy(opt, &path_data, sizeof(path_data));
+					len += sizeof(path_data);
+					opt += sizeof(path_data);
+					path_rec++;
+					num_paths++;

were you actually wanting a loop here?

Yes; if should have been while

Quoted 11 lines

Review

Quoted 2 lines
(quoted diff) +1 -0
+				}

This also needs to handle the case where rgetsockopt is called immediately after rsetsockopt. Something like:

if (rs->optval) {
	memcpy(rs->optval, optval, rs->optlen);
	*optlen = rs->optlen;
}

assuming that rs->optlen is verified

Sure.

v2 patch shortly...

-- Hal
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html