From 3e753d381565875c685342e28e76476bee75a4ca Mon Sep 17 00:00:00 2001 From: James Simmons Date: Mon, 12 Dec 2016 13:15:48 -0500 Subject: [PATCH 1/1] LU-6142 socklnd: change UAPI typedefs to proper structure The upstream kernel requires proper structures so convert all the UAPI typedefs in socklnd.h. Remove the inline function socklnd_init_msg. Its only used by the kernel code and functions are not allowed in UAPI headers. Change-Id: I4120c5abc4dda456289146452ed61e0162062cea Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/18506 Reviewed-by: Dmitry Eremin Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Doug Oucharek Reviewed-by: John L. Hammond Reviewed-by: Oleg Drokin --- lnet/include/lnet/socklnd.h | 24 ++++++++---------------- lnet/klnds/socklnd/socklnd.c | 14 +++++++------- lnet/klnds/socklnd/socklnd.h | 20 ++++++++++---------- lnet/klnds/socklnd/socklnd_cb.c | 35 ++++++++++++++++++++--------------- lnet/klnds/socklnd/socklnd_proto.c | 34 +++++++++++++++++----------------- 5 files changed, 62 insertions(+), 65 deletions(-) diff --git a/lnet/include/lnet/socklnd.h b/lnet/include/lnet/socklnd.h index f876bf6..45d8320 100644 --- a/lnet/include/lnet/socklnd.h +++ b/lnet/include/lnet/socklnd.h @@ -45,7 +45,7 @@ #define SOCKLND_CONN_ACK SOCKLND_CONN_BULK_IN -typedef struct { +struct ksock_hello_msg { __u32 kshm_magic; /* magic number of socklnd message */ __u32 kshm_version; /* version of socklnd message */ lnet_nid_t kshm_src_nid; /* sender's nid */ @@ -57,35 +57,27 @@ typedef struct { __u32 kshm_ctype; /* connection type */ __u32 kshm_nips; /* # IP addrs */ __u32 kshm_ips[0]; /* IP addrs */ -} WIRE_ATTR ksock_hello_msg_t; +} WIRE_ATTR; -typedef struct { +struct ksock_lnet_msg { lnet_hdr_t ksnm_hdr; /* lnet hdr */ /* * ksnm_payload is removed because of winnt compiler's limitation: * zero-sized array can only be placed at the tail of [nested] * structure definitions. lnet payload will be stored just after - * the body of structure ksock_lnet_msg_t + * the body of structure struct ksock_lnet_msg */ -} WIRE_ATTR ksock_lnet_msg_t; +} WIRE_ATTR; -typedef struct { +struct ksock_msg { __u32 ksm_type; /* type of socklnd message */ __u32 ksm_csum; /* checksum if != 0 */ __u64 ksm_zc_cookies[2]; /* Zero-Copy request/ACK cookie */ union { - ksock_lnet_msg_t lnetmsg; /* lnet message, it's empty if it's NOOP */ + struct ksock_lnet_msg lnetmsg; /* lnet message, it's empty if it's NOOP */ } WIRE_ATTR ksm_u; -} WIRE_ATTR ksock_msg_t; - -static inline void -socklnd_init_msg(ksock_msg_t *msg, int type) -{ - msg->ksm_csum = 0; - msg->ksm_type = type; - msg->ksm_zc_cookies[0] = msg->ksm_zc_cookies[1] = 0; -} +} WIRE_ATTR; #define KSOCK_MSG_NOOP 0xc0 /* ksm_u empty */ #define KSOCK_MSG_LNET 0xc1 /* lnet msg */ diff --git a/lnet/klnds/socklnd/socklnd.c b/lnet/klnds/socklnd/socklnd.c index d1dd16b..f3a5dfd 100644 --- a/lnet/klnds/socklnd/socklnd.c +++ b/lnet/klnds/socklnd/socklnd.c @@ -1022,7 +1022,7 @@ ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route, ksock_peer_t *peer = NULL; ksock_peer_t *peer2; ksock_sched_t *sched; - ksock_hello_msg_t *hello; + struct ksock_hello_msg *hello; int cpt; ksock_tx_t *tx; ksock_tx_t *txtmp; @@ -1059,7 +1059,7 @@ ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route, conn->ksnc_tx_carrier = NULL; atomic_set (&conn->ksnc_tx_nob, 0); - LIBCFS_ALLOC(hello, offsetof(ksock_hello_msg_t, + LIBCFS_ALLOC(hello, offsetof(struct ksock_hello_msg, kshm_ips[LNET_MAX_INTERFACES])); if (hello == NULL) { rc = -ENOMEM; @@ -1308,7 +1308,7 @@ ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route, rc = ksocknal_send_hello(ni, conn, peerid.nid, hello); } - LIBCFS_FREE(hello, offsetof(ksock_hello_msg_t, + LIBCFS_FREE(hello, offsetof(struct ksock_hello_msg, kshm_ips[LNET_MAX_INTERFACES])); /* setup the socket AFTER I've received hello (it disables @@ -1384,10 +1384,10 @@ failed_2: ksocknal_txlist_done(ni, &zombies, 1); ksocknal_peer_decref(peer); - failed_1: - if (hello != NULL) - LIBCFS_FREE(hello, offsetof(ksock_hello_msg_t, - kshm_ips[LNET_MAX_INTERFACES])); +failed_1: + if (hello != NULL) + LIBCFS_FREE(hello, offsetof(struct ksock_hello_msg, + kshm_ips[LNET_MAX_INTERFACES])); LIBCFS_FREE(conn, sizeof(*conn)); diff --git a/lnet/klnds/socklnd/socklnd.h b/lnet/klnds/socklnd/socklnd.h index 805fa15..4e89053 100644 --- a/lnet/klnds/socklnd/socklnd.h +++ b/lnet/klnds/socklnd/socklnd.h @@ -288,7 +288,7 @@ typedef struct /* transmit packet */ struct ksock_conn *tx_conn; /* owning conn */ lnet_msg_t *tx_lnetmsg; /* lnet message for lnet_finalize() */ cfs_time_t tx_deadline; /* when (in jiffies) tx times out */ - ksock_msg_t tx_msg; /* socklnd message buffer */ + struct ksock_msg tx_msg; /* socklnd message buffer */ int tx_desc_size; /* size of this descriptor */ union { struct { @@ -358,7 +358,7 @@ typedef struct ksock_conn ksock_rxiovspace_t ksnc_rx_iov_space;/* space for frag descriptors */ __u32 ksnc_rx_csum; /* partial checksum for incoming data */ void *ksnc_cookie; /* rx lnet_finalize passthru arg */ - ksock_msg_t ksnc_msg; /* incoming message buffer: + struct ksock_msg ksnc_msg; /* incoming message buffer: * V2.x message takes the * whole struct * V1.x message is a bare @@ -452,10 +452,10 @@ extern ksock_tunables_t ksocknal_tunables; typedef struct ksock_proto { int pro_version; /* version number of protocol */ - int (*pro_send_hello)(ksock_conn_t *, ksock_hello_msg_t *); /* handshake function */ - int (*pro_recv_hello)(ksock_conn_t *, ksock_hello_msg_t *, int);/* handshake function */ + int (*pro_send_hello)(ksock_conn_t *, struct ksock_hello_msg *); /* handshake function */ + int (*pro_recv_hello)(ksock_conn_t *, struct ksock_hello_msg *, int);/* handshake function */ void (*pro_pack)(ksock_tx_t *); /* message pack */ - void (*pro_unpack)(ksock_msg_t *); /* message unpack */ + void (*pro_unpack)(struct ksock_msg *); /* message unpack */ ksock_tx_t *(*pro_queue_tx_msg)(ksock_conn_t *, ksock_tx_t *); /* queue tx on the connection */ int (*pro_queue_tx_zcack)(ksock_conn_t *, ksock_tx_t *, __u64); /* queue ZC ack on the connection */ int (*pro_handle_zcreq)(ksock_conn_t *, __u64, int); /* handle ZC request */ @@ -654,11 +654,11 @@ extern int ksocknal_new_packet (ksock_conn_t *conn, int skip); extern int ksocknal_scheduler (void *arg); extern int ksocknal_connd (void *arg); extern int ksocknal_reaper (void *arg); -extern int ksocknal_send_hello (lnet_ni_t *ni, ksock_conn_t *conn, - lnet_nid_t peer_nid, ksock_hello_msg_t *hello); -extern int ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn, - ksock_hello_msg_t *hello, lnet_process_id_t *id, - __u64 *incarnation); +extern int ksocknal_send_hello(lnet_ni_t *ni, ksock_conn_t *conn, + lnet_nid_t peer_nid, struct ksock_hello_msg *hello); +extern int ksocknal_recv_hello(lnet_ni_t *ni, ksock_conn_t *conn, + struct ksock_hello_msg *hello, lnet_process_id_t *id, + __u64 *incarnation); extern void ksocknal_read_callback(ksock_conn_t *conn); extern void ksocknal_write_callback(ksock_conn_t *conn); diff --git a/lnet/klnds/socklnd/socklnd_cb.c b/lnet/klnds/socklnd/socklnd_cb.c index 3b8fa74..c2f7c57 100644 --- a/lnet/klnds/socklnd/socklnd_cb.c +++ b/lnet/klnds/socklnd/socklnd_cb.c @@ -83,7 +83,9 @@ ksocknal_alloc_tx_noop(__u64 cookie, int nonblk) tx->tx_niov = 1; tx->tx_nonblk = nonblk; - socklnd_init_msg(&tx->tx_msg, KSOCK_MSG_NOOP); + tx->tx_msg.ksm_csum = 0; + tx->tx_msg.ksm_type = KSOCK_MSG_NOOP; + tx->tx_msg.ksm_zc_cookies[0] = 0; tx->tx_msg.ksm_zc_cookies[1] = cookie; return tx; @@ -690,7 +692,7 @@ void ksocknal_queue_tx_locked (ksock_tx_t *tx, ksock_conn_t *conn) { ksock_sched_t *sched = conn->ksnc_scheduler; - ksock_msg_t *msg = &tx->tx_msg; + struct ksock_msg *msg = &tx->tx_msg; ksock_tx_t *ztx = NULL; int bufnob = 0; @@ -988,7 +990,10 @@ ksocknal_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg) tx->tx_zc_capable = 1; } - socklnd_init_msg(&tx->tx_msg, KSOCK_MSG_LNET); + tx->tx_msg.ksm_csum = 0; + tx->tx_msg.ksm_type = KSOCK_MSG_LNET; + tx->tx_msg.ksm_zc_cookies[0] = 0; + tx->tx_msg.ksm_zc_cookies[1] = 0; /* The first fragment will be set later in pro_pack */ rc = ksocknal_launch_packet(ni, tx, target); @@ -1051,9 +1056,9 @@ ksocknal_new_packet (ksock_conn_t *conn, int nob_to_skip) conn->ksnc_rx_iov = (struct kvec *)&conn->ksnc_rx_iov_space; conn->ksnc_rx_iov[0].iov_base = (char *)&conn->ksnc_msg; - conn->ksnc_rx_nob_wanted = offsetof(ksock_msg_t, ksm_u); - conn->ksnc_rx_nob_left = offsetof(ksock_msg_t, ksm_u); - conn->ksnc_rx_iov[0].iov_len = offsetof(ksock_msg_t, ksm_u); + conn->ksnc_rx_nob_wanted = offsetof(struct ksock_msg, ksm_u); + conn->ksnc_rx_nob_left = offsetof(struct ksock_msg, ksm_u); + conn->ksnc_rx_iov[0].iov_len = offsetof(struct ksock_msg, ksm_u); break; case KSOCK_PROTO_V1: @@ -1212,12 +1217,12 @@ ksocknal_process_receive (ksock_conn_t *conn) } conn->ksnc_rx_state = SOCKNAL_RX_LNET_HEADER; - conn->ksnc_rx_nob_wanted = sizeof(ksock_lnet_msg_t); - conn->ksnc_rx_nob_left = sizeof(ksock_lnet_msg_t); + conn->ksnc_rx_nob_wanted = sizeof(struct ksock_lnet_msg); + conn->ksnc_rx_nob_left = sizeof(struct ksock_lnet_msg); conn->ksnc_rx_iov = (struct kvec *)&conn->ksnc_rx_iov_space; conn->ksnc_rx_iov[0].iov_base = (char *)&conn->ksnc_msg.ksm_u.lnetmsg; - conn->ksnc_rx_iov[0].iov_len = sizeof(ksock_lnet_msg_t); + conn->ksnc_rx_iov[0].iov_len = sizeof(struct ksock_lnet_msg); conn->ksnc_rx_niov = 1; conn->ksnc_rx_kiov = NULL; @@ -1612,7 +1617,7 @@ void ksocknal_write_callback(ksock_conn_t *conn) } static ksock_proto_t * -ksocknal_parse_proto_version (ksock_hello_msg_t *hello) +ksocknal_parse_proto_version (struct ksock_hello_msg *hello) { __u32 version = 0; @@ -1643,7 +1648,7 @@ ksocknal_parse_proto_version (ksock_hello_msg_t *hello) lnet_magicversion_t *hmv = (lnet_magicversion_t *)hello; CLASSERT (sizeof (lnet_magicversion_t) == - offsetof (ksock_hello_msg_t, kshm_src_nid)); + offsetof (struct ksock_hello_msg, kshm_src_nid)); if (hmv->version_major == cpu_to_le16 (KSOCK_PROTO_V1_MAJOR) && hmv->version_minor == cpu_to_le16 (KSOCK_PROTO_V1_MINOR)) @@ -1655,7 +1660,7 @@ ksocknal_parse_proto_version (ksock_hello_msg_t *hello) int ksocknal_send_hello (lnet_ni_t *ni, ksock_conn_t *conn, - lnet_nid_t peer_nid, ksock_hello_msg_t *hello) + lnet_nid_t peer_nid, struct ksock_hello_msg *hello) { /* CAVEAT EMPTOR: this byte flips 'ipaddrs' */ ksock_net_t *net = (ksock_net_t *)ni->ni_data; @@ -1693,9 +1698,9 @@ ksocknal_invert_type(int type) } int -ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn, - ksock_hello_msg_t *hello, lnet_process_id_t *peerid, - __u64 *incarnation) +ksocknal_recv_hello(lnet_ni_t *ni, ksock_conn_t *conn, + struct ksock_hello_msg *hello, lnet_process_id_t *peerid, + __u64 *incarnation) { /* Return < 0 fatal error * 0 success diff --git a/lnet/klnds/socklnd/socklnd_proto.c b/lnet/klnds/socklnd/socklnd_proto.c index 6ea8494..12165a3 100644 --- a/lnet/klnds/socklnd/socklnd_proto.c +++ b/lnet/klnds/socklnd/socklnd_proto.c @@ -282,11 +282,11 @@ ksocknal_match_tx(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk) if (tx == NULL || tx->tx_lnetmsg == NULL) { /* noop packet */ - nob = offsetof(ksock_msg_t, ksm_u); + nob = offsetof(struct ksock_msg, ksm_u); } else { nob = tx->tx_lnetmsg->msg_len + ((conn->ksnc_proto == &ksocknal_protocol_v1x) ? - sizeof(lnet_hdr_t) : sizeof(ksock_msg_t)); + sizeof(lnet_hdr_t) : sizeof(struct ksock_msg)); } /* default checking for typed connection */ @@ -320,9 +320,9 @@ ksocknal_match_tx_v3(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk) int nob; if (tx == NULL || tx->tx_lnetmsg == NULL) - nob = offsetof(ksock_msg_t, ksm_u); + nob = offsetof(struct ksock_msg, ksm_u); else - nob = tx->tx_lnetmsg->msg_len + sizeof(ksock_msg_t); + nob = tx->tx_lnetmsg->msg_len + sizeof(struct ksock_msg); switch (conn->ksnc_type) { default: @@ -449,7 +449,7 @@ ksocknal_handle_zcack(ksock_conn_t *conn, __u64 cookie1, __u64 cookie2) } static int -ksocknal_send_hello_v1 (ksock_conn_t *conn, ksock_hello_msg_t *hello) +ksocknal_send_hello_v1 (ksock_conn_t *conn, struct ksock_hello_msg *hello) { struct socket *sock = conn->ksnc_sock; lnet_hdr_t *hdr; @@ -523,7 +523,7 @@ out: } static int -ksocknal_send_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello) +ksocknal_send_hello_v2 (ksock_conn_t *conn, struct ksock_hello_msg *hello) { struct socket *sock = conn->ksnc_sock; int rc; @@ -541,7 +541,7 @@ ksocknal_send_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello) LNET_UNLOCK(); } - rc = lnet_sock_write(sock, hello, offsetof(ksock_hello_msg_t, kshm_ips), + rc = lnet_sock_write(sock, hello, offsetof(struct ksock_hello_msg, kshm_ips), lnet_acceptor_timeout()); if (rc != 0) { @@ -566,7 +566,7 @@ ksocknal_send_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello) } static int -ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,int timeout) +ksocknal_recv_hello_v1(ksock_conn_t *conn, struct ksock_hello_msg *hello,int timeout) { struct socket *sock = conn->ksnc_sock; lnet_hdr_t *hdr; @@ -642,7 +642,7 @@ out: } static int -ksocknal_recv_hello_v2(ksock_conn_t *conn, ksock_hello_msg_t *hello, +ksocknal_recv_hello_v2(ksock_conn_t *conn, struct ksock_hello_msg *hello, int timeout) { struct socket *sock = conn->ksnc_sock; @@ -655,8 +655,8 @@ ksocknal_recv_hello_v2(ksock_conn_t *conn, ksock_hello_msg_t *hello, conn->ksnc_flip = 1; rc = lnet_sock_read(sock, &hello->kshm_src_nid, - offsetof(ksock_hello_msg_t, kshm_ips) - - offsetof(ksock_hello_msg_t, kshm_src_nid), + offsetof(struct ksock_hello_msg, kshm_ips) - + offsetof(struct ksock_hello_msg, kshm_src_nid), timeout); if (rc != 0) { CERROR("Error %d reading HELLO from %pI4h\n", @@ -730,19 +730,19 @@ ksocknal_pack_msg_v2(ksock_tx_t *tx) LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP); tx->tx_msg.ksm_u.lnetmsg.ksnm_hdr = tx->tx_lnetmsg->msg_hdr; - tx->tx_iov[0].iov_len = sizeof(ksock_msg_t); - tx->tx_resid = tx->tx_nob = sizeof(ksock_msg_t) + tx->tx_lnetmsg->msg_len; + tx->tx_iov[0].iov_len = sizeof(struct ksock_msg); + tx->tx_resid = tx->tx_nob = sizeof(struct ksock_msg) + tx->tx_lnetmsg->msg_len; } else { LASSERT(tx->tx_msg.ksm_type == KSOCK_MSG_NOOP); - tx->tx_iov[0].iov_len = offsetof(ksock_msg_t, ksm_u.lnetmsg.ksnm_hdr); - tx->tx_resid = tx->tx_nob = offsetof(ksock_msg_t, ksm_u.lnetmsg.ksnm_hdr); + tx->tx_iov[0].iov_len = offsetof(struct ksock_msg, ksm_u.lnetmsg.ksnm_hdr); + tx->tx_resid = tx->tx_nob = offsetof(struct ksock_msg, ksm_u.lnetmsg.ksnm_hdr); } /* Don't checksum before start sending, because packet can be piggybacked with ACK */ } static void -ksocknal_unpack_msg_v1(ksock_msg_t *msg) +ksocknal_unpack_msg_v1(struct ksock_msg *msg) { msg->ksm_csum = 0; msg->ksm_type = KSOCK_MSG_LNET; @@ -750,7 +750,7 @@ ksocknal_unpack_msg_v1(ksock_msg_t *msg) } static void -ksocknal_unpack_msg_v2(ksock_msg_t *msg) +ksocknal_unpack_msg_v2(struct ksock_msg *msg) { return; /* Do nothing */ } -- 1.8.3.1