[openib-general] [RFC] [PATCH 2/3] RDMA CM: expose rdma_get/set_option calls to userspace

Sean Hefty sean.hefty at intel.com
Tue Apr 25 16:45:56 PDT 2006


Resending with correct subject.

Expose rdma_get_option / rdma_set_option routines to userspace.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
Index: include/rdma/rdma_user_cm.h
===================================================================
--- include/rdma/rdma_user_cm.h	(revision 6418)
+++ include/rdma/rdma_user_cm.h	(working copy)
@@ -55,7 +55,9 @@ enum {
 	RDMA_USER_CM_CMD_REJECT,
 	RDMA_USER_CM_CMD_DISCONNECT,
 	RDMA_USER_CM_CMD_INIT_QP_ATTR,
-	RDMA_USER_CM_CMD_GET_EVENT
+	RDMA_USER_CM_CMD_GET_EVENT,
+	RDMA_USER_CM_CMD_GET_OPTION,
+	RDMA_USER_CM_CMD_SET_OPTION,
 };
 
 /*
@@ -183,4 +185,25 @@ struct rdma_ucm_event_resp {
 	__u8  private_data[RDMA_MAX_PRIVATE_DATA];
 };
 
+struct rdma_ucm_get_option {
+	__u64 response;
+	__u64 optval;
+	__u32 id;
+	__u32 level;
+	__u32 optname;
+	__u32 optlen;
+};
+
+struct rdma_ucm_get_option_resp {
+	__u32 optlen;
+};
+
+struct rdma_ucm_set_option {
+	__u64 optval;
+	__u32 id;
+	__u32 level;
+	__u32 optname;
+	__u32 optlen;
+};
+
 #endif /* RDMA_USER_CM_H */
Index: core/ucma.c
===================================================================
--- core/ucma.c	(revision 6418)
+++ core/ucma.c	(working copy)
@@ -656,6 +656,61 @@ out:
 	return ret;
 }
 
+static ssize_t ucma_get_option(struct ucma_file *file, const char __user *inbuf,
+			       int in_len, int out_len)
+{
+	struct rdma_ucm_get_option cmd;
+	struct rdma_ucm_get_option_resp resp;
+	struct ucma_context *ctx;
+	int ret;
+
+	if (out_len < sizeof(resp))
+		return -ENOSPC;
+
+	if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
+		return -EFAULT;
+
+	ctx = ucma_get_ctx(file, cmd.id);
+	if (IS_ERR(ctx))
+		return PTR_ERR(ctx);
+
+	resp.optlen = cmd.optlen;
+	ret = rdma_get_option(ctx->cm_id, cmd.level, cmd.optname,
+			      (void *) (unsigned long) cmd.optval,
+			      &resp.optlen);
+	if (ret)
+		goto out;
+
+	if (copy_to_user((void __user *)(unsigned long)cmd.response,
+			 &resp, sizeof(resp)))
+		ret = -EFAULT;
+out:
+	ucma_put_ctx(ctx);
+	return ret;
+}
+
+static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf,
+			       int in_len, int out_len)
+{
+	struct rdma_ucm_set_option cmd;
+	struct ucma_context *ctx;
+	int ret;
+
+	if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
+		return -EFAULT;
+
+	ctx = ucma_get_ctx(file, cmd.id);
+	if (IS_ERR(ctx))
+		return PTR_ERR(ctx);
+
+	ret = rdma_set_option(ctx->cm_id, cmd.level, cmd.optname,
+			      (void *) (unsigned long) cmd.optval,
+			      cmd.optlen);
+
+	ucma_put_ctx(ctx);
+	return ret;
+}
+
 static ssize_t (*ucma_cmd_table[])(struct ucma_file *file,
 				   const char __user *inbuf,
 				   int in_len, int out_len) = {
@@ -671,7 +726,9 @@ static ssize_t (*ucma_cmd_table[])(struc
 	[RDMA_USER_CM_CMD_REJECT]	= ucma_reject,
 	[RDMA_USER_CM_CMD_DISCONNECT]	= ucma_disconnect,
 	[RDMA_USER_CM_CMD_INIT_QP_ATTR]	= ucma_init_qp_attr,
-	[RDMA_USER_CM_CMD_GET_EVENT]	= ucma_get_event
+	[RDMA_USER_CM_CMD_GET_EVENT]	= ucma_get_event,
+	[RDMA_USER_CM_CMD_GET_OPTION]	= ucma_get_option,
+	[RDMA_USER_CM_CMD_SET_OPTION]	= ucma_set_option
 };
 
 static ssize_t ucma_write(struct file *filp, const char __user *buf,




More information about the general mailing list