Skip to content

Commit bba3141

Browse files
MarkZhang81shefty
authored andcommitted
librdmacm: Provide an interface to write an event into a CM
Support writing an event to a CM channel and add a new user API "rdma_write_cm_event()". Two new events are added and supported to be written: - RDMA_CM_EVENT_USER: User-defined, event details are specified by the user and not interpreted by the librdmacm. This event is useful for a multi-threaded application to signal a thread which may be waiting on the RDMA CM event channel. This is the only event that users can write; - RDMA_CM_EVENT_INTERNAL: Used and consumed internally by the librdmacm. Users should not write this event. A new event parameter "arg" is supported, which will be passed from sender to receiver along with the event. Signed-off-by: Mark Zhang <[email protected]>
1 parent bc5a962 commit bba3141

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

debian/librdmacm1.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ librdmacm.so.1 librdmacm1 #MINVER#
5252
rdma_resolve_route@RDMACM_1.0 1.0.15
5353
rdma_set_local_ece@RDMACM_1.3 31
5454
rdma_set_option@RDMACM_1.0 1.0.15
55+
rdma_write_cm_event@RDMACM_1.4 57
5556
rfcntl@RDMACM_1.0 1.0.16
5657
rgetpeername@RDMACM_1.0 1.0.16
5758
rgetsockname@RDMACM_1.0 1.0.16

librdmacm/cma.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,6 +2752,12 @@ int rdma_get_cm_event(struct rdma_event_channel *channel,
27522752
case RDMA_CM_EVENT_ADDRINFO_ERROR:
27532753
clear_resolving_ai_flag(evt->id_priv);
27542754
break;
2755+
case RDMA_CM_EVENT_USER:
2756+
memcpy(&evt->event.param.arg, resp.param.arg32,
2757+
sizeof(evt->event.param.arg));
2758+
break;
2759+
case RDMA_CM_EVENT_INTERNAL:
2760+
break;
27552761
default:
27562762
evt->id_priv = (void *) (uintptr_t) resp.uid;
27572763
evt->event.id = &evt->id_priv->id;
@@ -3089,6 +3095,36 @@ static void resolve_ai_set_cmd_service(const char *service,
30893095
}
30903096
}
30913097

3098+
static int __rdma_write_cm_event(struct rdma_cm_id *id, enum rdma_cm_event_type event,
3099+
int status, uint64_t arg)
3100+
{
3101+
struct ucma_abi_write_cm_event cmd;
3102+
struct cma_id_private *id_priv;
3103+
int ret;
3104+
3105+
CMA_INIT_CMD(&cmd, sizeof(cmd), WRITE_CM_EVENT);
3106+
3107+
id_priv = container_of(id, struct cma_id_private, id);
3108+
cmd.id = id_priv->handle;
3109+
cmd.event = event;
3110+
cmd.status = status;
3111+
cmd.param.arg = arg;
3112+
ret = write(id->channel->fd, &cmd, sizeof(cmd));
3113+
if (ret != sizeof(cmd))
3114+
return (ret >= 0) ? ERR(ENODATA) : -1;
3115+
3116+
return 0;
3117+
}
3118+
3119+
int rdma_write_cm_event(struct rdma_cm_id *id, enum rdma_cm_event_type event,
3120+
int status, uint64_t arg)
3121+
{
3122+
if (event != RDMA_CM_EVENT_USER)
3123+
return ERR(EINVAL);
3124+
3125+
return __rdma_write_cm_event(id, event, status, arg);
3126+
}
3127+
30923128
static int resolve_ai_sa(struct cma_id_private *id_priv, const char *service)
30933129
{
30943130
struct ucma_abi_resolve_ib_service cmd;

librdmacm/librdmacm.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,5 @@ RDMACM_1.4 {
9292
global:
9393
rdma_query_addrinfo;
9494
rdma_resolve_addrinfo;
95+
rdma_write_cm_event;
9596
} RDMACM_1.3;

librdmacm/rdma_cma.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ enum rdma_cm_event_type {
6666
RDMA_CM_EVENT_TIMEWAIT_EXIT,
6767
RDMA_CM_EVENT_ADDRINFO_RESOLVED,
6868
RDMA_CM_EVENT_ADDRINFO_ERROR,
69+
RDMA_CM_EVENT_USER,
70+
RDMA_CM_EVENT_INTERNAL,
6971
};
7072

7173
enum rdma_port_space {
@@ -173,6 +175,7 @@ struct rdma_cm_event {
173175
union {
174176
struct rdma_conn_param conn;
175177
struct rdma_ud_param ud;
178+
uint64_t arg;
176179
} param;
177180
};
178181

@@ -798,6 +801,12 @@ int rdma_resolve_addrinfo(struct rdma_cm_id *id, const char *node,
798801
*/
799802
int rdma_query_addrinfo(struct rdma_cm_id *id, struct rdma_addrinfo **info);
800803

804+
/**
805+
* rdma_write_cm_event - Write an event into a cm channel.
806+
*/
807+
int rdma_write_cm_event(struct rdma_cm_id *id, enum rdma_cm_event_type event,
808+
int status, uint64_t arg);
809+
801810
#ifdef __cplusplus
802811
}
803812
#endif

librdmacm/rdma_cma_abi.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ enum {
7171
UCMA_CMD_BIND,
7272
UCMA_CMD_RESOLVE_ADDR,
7373
UCMA_CMD_JOIN_MCAST,
74-
UCMA_CMD_RESOLVE_IB_SERVICE
74+
UCMA_CMD_RESOLVE_IB_SERVICE,
75+
UCMA_CMD_WRITE_CM_EVENT,
7576
};
7677

7778
struct ucma_abi_cmd_hdr {
@@ -335,6 +336,7 @@ struct ucma_abi_event_resp {
335336
union {
336337
struct ucma_abi_conn_param conn;
337338
struct ucma_abi_ud_param ud;
339+
__u32 arg32[2];
338340
} param;
339341
struct ucma_abi_ece ece;
340342
};
@@ -403,4 +405,19 @@ struct ucma_abi_query_ib_service_resp {
403405
struct ucma_user_service_rec recs[];
404406
};
405407

408+
struct ucma_abi_write_cm_event {
409+
__u32 cmd;
410+
__u16 in;
411+
__u16 out;
412+
__u32 id;
413+
__u32 reserved;
414+
__u32 event;
415+
__u32 status;
416+
union {
417+
struct ucma_abi_conn_param conn;
418+
struct ucma_abi_ud_param ud;
419+
__u64 arg;
420+
} param;
421+
};
422+
406423
#endif /* RDMA_CMA_ABI_H */

0 commit comments

Comments
 (0)