/* no more packets queued */
conn->ksnc_tx_carrier = NULL;
} else {
- conn->ksnc_tx_carrier = list_entry(tx->tx_list.next,
- struct ksock_tx, tx_list);
+ conn->ksnc_tx_carrier = list_next_entry(tx, tx_list);
LASSERT(conn->ksnc_tx_carrier->tx_msg.ksm_type ==
tx->tx_msg.ksm_type);
}
return 1;
}
- if (cookie == tx->tx_msg.ksm_zc_cookies[0] ||
- cookie == tx->tx_msg.ksm_zc_cookies[1]) {
+ if (cookie == tx->tx_msg.ksm_zc_cookies[0] ||
+ cookie == tx->tx_msg.ksm_zc_cookies[1]) {
CWARN("%s: duplicated ZC cookie: %llu\n",
- libcfs_id2str(conn->ksnc_peer->ksnp_id), cookie);
- return 1; /* XXX return error in the future */
- }
+ libcfs_idstr(&conn->ksnc_peer->ksnp_id), cookie);
+ return 1; /* XXX return error in the future */
+ }
if (tx->tx_msg.ksm_zc_cookies[0] == 0) {
/* NOOP tx has only one ZC-ACK cookie, can carry at least one more */
}
} else {
- /* ksm_zc_cookies[0] < ksm_zc_cookies[1], it is range of cookies */
- if (cookie >= tx->tx_msg.ksm_zc_cookies[0] &&
- cookie <= tx->tx_msg.ksm_zc_cookies[1]) {
+ /* ksm_zc_cookies[0] < ksm_zc_cookies[1], it is a range
+ * of cookies
+ */
+ if (cookie >= tx->tx_msg.ksm_zc_cookies[0] &&
+ cookie <= tx->tx_msg.ksm_zc_cookies[1]) {
CWARN("%s: duplicated ZC cookie: %llu\n",
- libcfs_id2str(conn->ksnc_peer->ksnp_id), cookie);
- return 1; /* XXX: return error in the future */
- }
+ libcfs_idstr(&conn->ksnc_peer->ksnp_id),
+ cookie);
+ return 1; /* XXX: return error in the future */
+ }
if (cookie == tx->tx_msg.ksm_zc_cookies[1] + 1) {
tx->tx_msg.ksm_zc_cookies[1] = cookie;
return SOCKNAL_MATCH_YES;
#endif
- if (tx == NULL || tx->tx_lnetmsg == NULL) {
- /* noop packet */
- nob = offsetof(struct ksock_msg, ksm_u);
- } else {
- nob = tx->tx_lnetmsg->msg_len +
- ((conn->ksnc_proto == &ksocknal_protocol_v1x) ?
- sizeof(struct lnet_hdr) : sizeof(struct ksock_msg));
- }
+ if (tx == NULL || tx->tx_lnetmsg == NULL) {
+ /* noop packet */
+ nob = sizeof(struct ksock_msg_hdr);
+ } else {
+ nob = tx->tx_lnetmsg->msg_len +
+ ((conn->ksnc_proto == &ksocknal_protocol_v1x) ?
+ 0 : sizeof(struct ksock_msg_hdr)) +
+ sizeof(struct lnet_hdr_nid4);
+ }
/* default checking for typed connection */
switch (conn->ksnc_type) {
{
int nob;
- if (tx == NULL || tx->tx_lnetmsg == NULL)
- nob = offsetof(struct ksock_msg, ksm_u);
- else
- nob = tx->tx_lnetmsg->msg_len + sizeof(struct ksock_msg);
+ if (tx == NULL || tx->tx_lnetmsg == NULL)
+ nob = sizeof(struct ksock_msg_hdr);
+ else
+ nob = sizeof(struct ksock_msg_hdr) +
+ sizeof(struct lnet_hdr_nid4) +
+ tx->tx_lnetmsg->msg_len;
switch (conn->ksnc_type) {
default:
}
}
+static int
+ksocknal_match_tx_v4(struct ksock_conn *conn, struct ksock_tx *tx, int nonblk)
+{
+ int nob;
+
+ if (!tx || !tx->tx_lnetmsg)
+ nob = sizeof(struct ksock_msg_hdr);
+ else
+ nob = sizeof(struct ksock_msg_hdr) +
+ sizeof(struct lnet_hdr_nid16) +
+ tx->tx_lnetmsg->msg_len;
+
+ switch (conn->ksnc_type) {
+ default:
+ CERROR("ksnc_type bad: %u\n", conn->ksnc_type);
+ LBUG();
+ case SOCKLND_CONN_ANY:
+ return SOCKNAL_MATCH_NO;
+
+ case SOCKLND_CONN_ACK:
+ if (nonblk)
+ return SOCKNAL_MATCH_YES;
+ else if (tx == NULL || tx->tx_lnetmsg == NULL)
+ return SOCKNAL_MATCH_MAY;
+ else
+ return SOCKNAL_MATCH_NO;
+
+ case SOCKLND_CONN_BULK_OUT:
+ if (nonblk)
+ return SOCKNAL_MATCH_NO;
+ else if (nob < *ksocknal_tunables.ksnd_min_bulk)
+ return SOCKNAL_MATCH_MAY;
+ else
+ return SOCKNAL_MATCH_YES;
+
+ case SOCKLND_CONN_CONTROL:
+ if (nonblk)
+ return SOCKNAL_MATCH_NO;
+ else if (nob >= *ksocknal_tunables.ksnd_min_bulk)
+ return SOCKNAL_MATCH_MAY;
+ else
+ return SOCKNAL_MATCH_YES;
+ }
+}
+
/* (Sink) handle incoming ZC request from sender */
static int
ksocknal_handle_zcreq(struct ksock_conn *c, __u64 cookie, int remote)
if (tx == NULL)
return -ENOMEM;
- if ((rc = ksocknal_launch_packet(peer_ni->ksnp_ni, tx, peer_ni->ksnp_id)) == 0)
- return 0;
+ rc = ksocknal_launch_packet(peer_ni->ksnp_ni, tx, &peer_ni->ksnp_id);
+ if (rc == 0)
+ return 0;
- ksocknal_free_tx(tx);
- return rc;
+ ksocknal_free_tx(tx);
+ return rc;
}
/* (Sender) handle ZC_ACK from sink */
count = (cookie1 > cookie2) ? 2 : (cookie2 - cookie1 + 1);
- if (cookie2 == SOCKNAL_KEEPALIVE_PING &&
- conn->ksnc_proto == &ksocknal_protocol_v3x) {
- /* keepalive PING for V3.x, just ignore it */
- return count == 1 ? 0 : -EPROTO;
- }
+ if (cookie2 == SOCKNAL_KEEPALIVE_PING &&
+ (conn->ksnc_proto == &ksocknal_protocol_v3x ||
+ conn->ksnc_proto == &ksocknal_protocol_v4x)) {
+ /* keepalive PING for V3.x, just ignore it */
+ return count == 1 ? 0 : -EPROTO;
+ }
spin_lock(&peer_ni->ksnp_lock);
- list_for_each_entry_safe(tx, tmp,
- &peer_ni->ksnp_zc_req_list, tx_zc_list) {
+ list_for_each_entry_safe(tx, tmp, &peer_ni->ksnp_zc_req_list,
+ tx_zc_list) {
__u64 c = tx->tx_msg.ksm_zc_cookies[0];
if (c == cookie1 || c == cookie2 || (cookie1 < c && c < cookie2)) {
ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello)
{
struct socket *sock = conn->ksnc_sock;
- struct lnet_hdr *hdr;
+ struct _lnet_hdr_nid4 *hdr;
struct lnet_magicversion *hmv;
int rc;
int i;
BUILD_BUG_ON(sizeof(struct lnet_magicversion) !=
- offsetof(struct lnet_hdr, src_nid));
+ offsetof(struct _lnet_hdr_nid4, src_nid));
LIBCFS_ALLOC(hdr, sizeof(*hdr));
if (hdr == NULL) {
- CERROR("Can't allocate struct lnet_hdr\n");
+ CERROR("Can't allocate struct lnet_hdr_nid4\n");
return -ENOMEM;
}
hmv = (struct lnet_magicversion *)&hdr->dest_nid;
- /* Re-organize V2.x message header to V1.x (struct lnet_hdr)
- * header and send out */
- hmv->magic = cpu_to_le32 (LNET_PROTO_TCP_MAGIC);
- hmv->version_major = cpu_to_le16 (KSOCK_PROTO_V1_MAJOR);
- hmv->version_minor = cpu_to_le16 (KSOCK_PROTO_V1_MINOR);
+ /* Re-organize V2.x message header to V1.x (struct lnet_hdr_nid4)
+ * header and send out
+ */
+ hmv->magic = cpu_to_le32 (LNET_PROTO_TCP_MAGIC);
+ hmv->version_major = cpu_to_le16 (KSOCK_PROTO_V1_MAJOR);
+ hmv->version_minor = cpu_to_le16 (KSOCK_PROTO_V1_MINOR);
if (the_lnet.ln_testprotocompat) {
/* single-shot proto check */
hmv->magic = LNET_PROTO_MAGIC;
}
- hdr->src_nid = cpu_to_le64 (hello->kshm_src_nid);
- hdr->src_pid = cpu_to_le32 (hello->kshm_src_pid);
- hdr->type = cpu_to_le32 (LNET_MSG_HELLO);
- hdr->payload_length = cpu_to_le32 (hello->kshm_nips * sizeof(__u32));
- hdr->msg.hello.type = cpu_to_le32 (hello->kshm_ctype);
- hdr->msg.hello.incarnation = cpu_to_le64 (hello->kshm_src_incarnation);
+ hdr->src_nid = cpu_to_le64(lnet_nid_to_nid4(&hello->kshm_src_nid));
+ hdr->src_pid = cpu_to_le32 (hello->kshm_src_pid);
+ hdr->type = cpu_to_le32 (LNET_MSG_HELLO);
+ hdr->payload_length = cpu_to_le32 (hello->kshm_nips * sizeof(__u32));
+ hdr->msg.hello.type = cpu_to_le32 (hello->kshm_ctype);
+ hdr->msg.hello.incarnation = cpu_to_le64 (hello->kshm_src_incarnation);
rc = lnet_sock_write(sock, hdr, sizeof(*hdr), lnet_acceptor_timeout());
if (rc != 0) {
- CNETERR("Error %d sending HELLO hdr to %pISp\n",
+ CNETERR("Error %d sending HELLO hdr to %pIScp\n",
rc, &conn->ksnc_peeraddr);
goto out;
}
- if (hello->kshm_nips == 0)
- goto out;
+ if (hello->kshm_nips == 0)
+ goto out;
- for (i = 0; i < (int) hello->kshm_nips; i++) {
- hello->kshm_ips[i] = __cpu_to_le32 (hello->kshm_ips[i]);
- }
+ for (i = 0; i < (int) hello->kshm_nips; i++)
+ hello->kshm_ips[i] = __cpu_to_le32 (hello->kshm_ips[i]);
rc = lnet_sock_write(sock, hello->kshm_ips,
hello->kshm_nips * sizeof(__u32),
lnet_acceptor_timeout());
if (rc != 0) {
- CNETERR("Error %d sending HELLO payload (%d) to %pISp\n",
+ CNETERR("Error %d sending HELLO payload (%d) to %pIScp\n",
rc, hello->kshm_nips,
&conn->ksnc_peeraddr);
- }
+ }
out:
- LIBCFS_FREE(hdr, sizeof(*hdr));
+ LIBCFS_FREE(hdr, sizeof(*hdr));
- return rc;
+ return rc;
}
static int
{
struct socket *sock = conn->ksnc_sock;
int rc;
+ struct ksock_hello_msg_nid4 *hello4;
+
+ CFS_ALLOC_PTR(hello4);
+ if (!hello4) {
+ CERROR("Can't allocate struct ksock_hello_msg_nid4\n");
+ return -ENOMEM;
+ }
+
+ hello->kshm_magic = LNET_PROTO_MAGIC;
+ hello->kshm_version = conn->ksnc_proto->pro_version;
- hello->kshm_magic = LNET_PROTO_MAGIC;
- hello->kshm_version = conn->ksnc_proto->pro_version;
+ hello4->kshm_magic = LNET_PROTO_MAGIC;
+ hello4->kshm_version = conn->ksnc_proto->pro_version;
+ hello4->kshm_src_nid = lnet_nid_to_nid4(&hello->kshm_src_nid);
+ hello4->kshm_dst_nid = lnet_nid_to_nid4(&hello->kshm_dst_nid);
+ hello4->kshm_src_pid = hello->kshm_src_pid;
+ hello4->kshm_dst_pid = hello->kshm_dst_pid;
+ hello4->kshm_src_incarnation = hello->kshm_src_incarnation;
+ hello4->kshm_dst_incarnation = hello->kshm_dst_incarnation;
+ hello4->kshm_ctype = hello->kshm_ctype;
+ hello4->kshm_nips = hello->kshm_nips;
if (the_lnet.ln_testprotocompat) {
/* single-shot proto check */
if (test_and_clear_bit(0, &the_lnet.ln_testprotocompat))
hello->kshm_version++; /* just different! */
}
-
- rc = lnet_sock_write(sock, hello, offsetof(struct ksock_hello_msg, kshm_ips),
- lnet_acceptor_timeout());
-
- if (rc != 0) {
- CNETERR("Error %d sending HELLO hdr to %pISp\n",
+ hello4->kshm_magic = LNET_PROTO_MAGIC;
+ hello4->kshm_version = hello->kshm_version;
+ hello4->kshm_src_nid = lnet_nid_to_nid4(&hello->kshm_src_nid);
+ hello4->kshm_dst_nid = lnet_nid_to_nid4(&hello->kshm_dst_nid);
+ hello4->kshm_src_pid = hello->kshm_src_pid;
+ hello4->kshm_dst_pid = hello->kshm_dst_pid;
+ hello4->kshm_src_incarnation = hello->kshm_src_incarnation;
+ hello4->kshm_dst_incarnation = hello->kshm_dst_incarnation;
+ hello4->kshm_ctype = hello->kshm_ctype;
+ hello4->kshm_nips = hello->kshm_nips;
+
+ rc = lnet_sock_write(sock, hello4, sizeof(*hello4),
+ lnet_acceptor_timeout());
+ CFS_FREE_PTR(hello4);
+ if (rc) {
+ CNETERR("Error %d sending HELLO hdr to %pIScp\n",
rc, &conn->ksnc_peeraddr);
return rc;
}
- if (hello->kshm_nips == 0)
- return 0;
+ if (hello->kshm_nips == 0)
+ return 0;
rc = lnet_sock_write(sock, hello->kshm_ips,
hello->kshm_nips * sizeof(__u32),
lnet_acceptor_timeout());
if (rc != 0) {
- CNETERR("Error %d sending HELLO payload (%d) to %pISp\n", rc,
+ CNETERR("Error %d sending HELLO payload (%d) to %pIScp\n", rc,
hello->kshm_nips,
&conn->ksnc_peeraddr);
}
}
static int
+ksocknal_send_hello_v4(struct ksock_conn *conn, struct ksock_hello_msg *hello)
+{
+ struct socket *sock = conn->ksnc_sock;
+ int rc;
+
+ hello->kshm_magic = LNET_PROTO_MAGIC;
+ hello->kshm_version = conn->ksnc_proto->pro_version;
+
+ rc = lnet_sock_write(sock, hello, sizeof(*hello),
+ lnet_acceptor_timeout());
+
+ if (rc != 0)
+ CNETERR("Error %d sending HELLO hdr to %pIScp\n",
+ rc, &conn->ksnc_peeraddr);
+ return rc;
+}
+
+static int
ksocknal_recv_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello,
int timeout)
{
struct socket *sock = conn->ksnc_sock;
- struct lnet_hdr *hdr;
+ struct _lnet_hdr_nid4 *hdr;
int rc;
int i;
- LIBCFS_ALLOC(hdr, sizeof(*hdr));
- if (hdr == NULL) {
- CERROR("Can't allocate struct lnet_hdr\n");
+ CFS_ALLOC_PTR(hdr);
+ if (!hdr) {
+ CERROR("Can't allocate struct lnet_hdr_nid4\n");
return -ENOMEM;
}
rc = lnet_sock_read(sock, &hdr->src_nid,
- sizeof(*hdr) - offsetof(struct lnet_hdr, src_nid),
- timeout);
+ sizeof(*hdr) - offsetof(struct _lnet_hdr_nid4,
+ src_nid),
+ timeout);
if (rc != 0) {
- CERROR("Error %d reading rest of HELLO hdr from %pIS\n",
+ CERROR("Error %d reading rest of HELLO hdr from %pISc\n",
rc, &conn->ksnc_peeraddr);
LASSERT(rc < 0 && rc != -EALREADY);
goto out;
/* ...and check we got what we expected */
if (hdr->type != cpu_to_le32 (LNET_MSG_HELLO)) {
- CERROR("Expecting a HELLO hdr, but got type %d from %pIS\n",
+ CERROR("Expecting a HELLO hdr, but got type %d from %pISc\n",
le32_to_cpu(hdr->type),
&conn->ksnc_peeraddr);
rc = -EPROTO;
goto out;
}
- hello->kshm_src_nid = le64_to_cpu (hdr->src_nid);
- hello->kshm_src_pid = le32_to_cpu (hdr->src_pid);
- hello->kshm_src_incarnation = le64_to_cpu (hdr->msg.hello.incarnation);
- hello->kshm_ctype = le32_to_cpu (hdr->msg.hello.type);
- hello->kshm_nips = le32_to_cpu (hdr->payload_length) /
- sizeof (__u32);
+ lnet_nid4_to_nid(le64_to_cpu(hdr->src_nid), &hello->kshm_src_nid);
+ hello->kshm_src_pid = le32_to_cpu(hdr->src_pid);
+ hello->kshm_src_incarnation = le64_to_cpu(hdr->msg.hello.incarnation);
+ hello->kshm_ctype = le32_to_cpu(hdr->msg.hello.type);
+ hello->kshm_nips = le32_to_cpu(hdr->payload_length) / sizeof(__u32);
if (hello->kshm_nips > LNET_INTERFACES_NUM) {
- CERROR("Bad nips %d from ip %pIS\n",
+ CERROR("Bad nips %d from ip %pISc\n",
hello->kshm_nips, &conn->ksnc_peeraddr);
rc = -EPROTO;
goto out;
}
- if (hello->kshm_nips == 0)
- goto out;
+ if (hello->kshm_nips == 0)
+ goto out;
rc = lnet_sock_read(sock, hello->kshm_ips,
- hello->kshm_nips * sizeof(__u32), timeout);
- if (rc != 0) {
- CERROR("Error %d reading IPs from ip %pIS\n",
+ hello->kshm_nips * sizeof(__u32), timeout);
+ if (rc != 0) {
+ CERROR("Error %d reading IPs from ip %pISc\n",
rc, &conn->ksnc_peeraddr);
LASSERT(rc < 0 && rc != -EALREADY);
- goto out;
- }
+ goto out;
+ }
- for (i = 0; i < (int) hello->kshm_nips; i++) {
- hello->kshm_ips[i] = __le32_to_cpu(hello->kshm_ips[i]);
+ for (i = 0; i < (int) hello->kshm_nips; i++) {
+ hello->kshm_ips[i] = __le32_to_cpu(hello->kshm_ips[i]);
- if (hello->kshm_ips[i] == 0) {
- CERROR("Zero IP[%d] from ip %pIS\n",
+ if (hello->kshm_ips[i] == 0) {
+ CERROR("Zero IP[%d] from ip %pISc\n",
i, &conn->ksnc_peeraddr);
- rc = -EPROTO;
- break;
- }
- }
+ rc = -EPROTO;
+ break;
+ }
+ }
out:
- LIBCFS_FREE(hdr, sizeof(*hdr));
+ CFS_FREE_PTR(hdr);
- return rc;
+ return rc;
}
static int
ksocknal_recv_hello_v2(struct ksock_conn *conn, struct ksock_hello_msg *hello,
int timeout)
{
- struct socket *sock = conn->ksnc_sock;
- int rc;
- int i;
+ struct socket *sock = conn->ksnc_sock;
+ struct ksock_hello_msg_nid4 *hello4 = (void *)hello;
+ int rc;
+ int i;
- if (hello->kshm_magic == LNET_PROTO_MAGIC)
- conn->ksnc_flip = 0;
- else
- conn->ksnc_flip = 1;
+ if (hello->kshm_magic == LNET_PROTO_MAGIC)
+ conn->ksnc_flip = 0;
+ else
+ conn->ksnc_flip = 1;
- rc = lnet_sock_read(sock, &hello->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 %pIS\n",
+ rc = lnet_sock_read(sock, &hello4->kshm_src_nid,
+ offsetof(struct ksock_hello_msg_nid4, kshm_ips) -
+ offsetof(struct ksock_hello_msg_nid4, kshm_src_nid),
+ timeout);
+ if (rc != 0) {
+ CERROR("Error %d reading HELLO from %pISc\n",
rc, &conn->ksnc_peeraddr);
LASSERT(rc < 0 && rc != -EALREADY);
- return rc;
- }
+ return rc;
+ }
- if (conn->ksnc_flip) {
- __swab32s(&hello->kshm_src_pid);
- __swab64s(&hello->kshm_src_nid);
- __swab32s(&hello->kshm_dst_pid);
- __swab64s(&hello->kshm_dst_nid);
- __swab64s(&hello->kshm_src_incarnation);
- __swab64s(&hello->kshm_dst_incarnation);
- __swab32s(&hello->kshm_ctype);
- __swab32s(&hello->kshm_nips);
- }
+ if (conn->ksnc_flip) {
+ /* These must be copied in reverse order to avoid corruption. */
+ hello->kshm_nips = __swab32(hello4->kshm_nips);
+ hello->kshm_ctype = __swab32(hello4->kshm_ctype);
+ hello->kshm_dst_incarnation = __swab64(hello4->kshm_dst_incarnation);
+ hello->kshm_src_incarnation = __swab64(hello4->kshm_src_incarnation);
+ hello->kshm_dst_pid = __swab32(hello4->kshm_dst_pid);
+ hello->kshm_src_pid = __swab32(hello4->kshm_src_pid);
+ lnet_nid4_to_nid(hello4->kshm_dst_nid, &hello->kshm_dst_nid);
+ lnet_nid4_to_nid(hello4->kshm_src_nid, &hello->kshm_src_nid);
+ } else {
+ /* These must be copied in reverse order to avoid corruption. */
+ hello->kshm_nips = hello4->kshm_nips;
+ hello->kshm_ctype = hello4->kshm_ctype;
+ hello->kshm_dst_incarnation = hello4->kshm_dst_incarnation;
+ hello->kshm_src_incarnation = hello4->kshm_src_incarnation;
+ hello->kshm_dst_pid = hello4->kshm_dst_pid;
+ hello->kshm_src_pid = hello4->kshm_src_pid;
+ lnet_nid4_to_nid(hello4->kshm_dst_nid, &hello->kshm_dst_nid);
+ lnet_nid4_to_nid(hello4->kshm_src_nid, &hello->kshm_src_nid);
+ }
if (hello->kshm_nips > LNET_INTERFACES_NUM) {
- CERROR("Bad nips %d from ip %pIS\n",
+ CERROR("Bad nips %d from ip %pISc\n",
hello->kshm_nips, &conn->ksnc_peeraddr);
return -EPROTO;
}
- if (hello->kshm_nips == 0)
- return 0;
+ if (hello->kshm_nips == 0)
+ return 0;
rc = lnet_sock_read(sock, hello->kshm_ips,
hello->kshm_nips * sizeof(__u32), timeout);
if (rc != 0) {
- CERROR("Error %d reading IPs from ip %pIS\n",
+ CERROR("Error %d reading IPs from ip %pISc\n",
rc, &conn->ksnc_peeraddr);
LASSERT(rc < 0 && rc != -EALREADY);
return rc;
}
- for (i = 0; i < (int) hello->kshm_nips; i++) {
- if (conn->ksnc_flip)
- __swab32s(&hello->kshm_ips[i]);
+ for (i = 0; i < (int) hello->kshm_nips; i++) {
+ if (conn->ksnc_flip)
+ __swab32s(&hello->kshm_ips[i]);
if (hello->kshm_ips[i] == 0) {
- CERROR("Zero IP[%d] from ip %pIS\n",
+ CERROR("Zero IP[%d] from ip %pISc\n",
i, &conn->ksnc_peeraddr);
return -EPROTO;
}
- }
+ }
- return 0;
+ return 0;
+}
+
+static int
+ksocknal_recv_hello_v4(struct ksock_conn *conn, struct ksock_hello_msg *hello,
+ int timeout)
+{
+ struct socket *sock = conn->ksnc_sock;
+ int rc;
+
+ if (hello->kshm_magic == LNET_PROTO_MAGIC)
+ conn->ksnc_flip = 0;
+ else
+ conn->ksnc_flip = 1;
+
+ rc = lnet_sock_read(sock, &hello->kshm_src_nid,
+ sizeof(*hello) -
+ offsetof(struct ksock_hello_msg, kshm_src_nid),
+ timeout);
+ if (rc) {
+ CERROR("Error %d reading HELLO from %pISc\n",
+ rc, &conn->ksnc_peeraddr);
+ LASSERT(rc < 0 && rc != -EALREADY);
+ return rc;
+ }
+
+ if (conn->ksnc_flip) {
+ __swab32s(&hello->kshm_src_pid);
+ __swab32s(&hello->kshm_dst_pid);
+ __swab64s(&hello->kshm_src_incarnation);
+ __swab64s(&hello->kshm_dst_incarnation);
+ __swab32s(&hello->kshm_ctype);
+ }
+
+ return 0;
}
static void
LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
LASSERT(tx->tx_lnetmsg != NULL);
- tx->tx_hdr.iov_base = (void *)&tx->tx_lnetmsg->msg_hdr;
- tx->tx_hdr.iov_len = sizeof(struct lnet_hdr);
+ lnet_hdr_to_nid4(&tx->tx_lnetmsg->msg_hdr,
+ &tx->tx_msg.ksm_u.lnetmsg_nid4);
+ tx->tx_hdr.iov_base = (void *)&tx->tx_msg.ksm_u.lnetmsg_nid4;
+ tx->tx_hdr.iov_len = sizeof(struct lnet_hdr_nid4);
- tx->tx_nob = tx->tx_lnetmsg->msg_len + sizeof(struct lnet_hdr);
+ tx->tx_nob = tx->tx_lnetmsg->msg_len + sizeof(struct lnet_hdr_nid4);
tx->tx_resid = tx->tx_nob;
}
static void
ksocknal_pack_msg_v2(struct ksock_tx *tx)
{
+ int hdr_size;
+
tx->tx_hdr.iov_base = (void *)&tx->tx_msg;
- if (tx->tx_lnetmsg != NULL) {
- LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
+ switch (tx->tx_msg.ksm_type) {
+ case KSOCK_MSG_LNET:
+ LASSERT(tx->tx_lnetmsg != NULL);
+ hdr_size = (sizeof(struct ksock_msg_hdr) +
+ sizeof(struct lnet_hdr_nid4));
+
+ lnet_hdr_to_nid4(&tx->tx_lnetmsg->msg_hdr,
+ &tx->tx_msg.ksm_u.lnetmsg_nid4);
+ tx->tx_hdr.iov_len = hdr_size;
+ tx->tx_resid = tx->tx_nob = hdr_size + tx->tx_lnetmsg->msg_len;
+ break;
+ case KSOCK_MSG_NOOP:
+ LASSERT(tx->tx_lnetmsg == NULL);
+ hdr_size = sizeof(struct ksock_msg_hdr);
+
+ tx->tx_hdr.iov_len = hdr_size;
+ tx->tx_resid = tx->tx_nob = hdr_size;
+ break;
+ default:
+ LASSERT(0);
+ }
+ /* Don't checksum before start sending, because packet can be
+ * piggybacked with ACK
+ */
+}
- tx->tx_msg.ksm_u.lnetmsg.ksnm_hdr = tx->tx_lnetmsg->msg_hdr;
- tx->tx_hdr.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);
+static void
+ksocknal_pack_msg_v4(struct ksock_tx *tx)
+{
+ int hdr_size;
- tx->tx_hdr.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 */
+ tx->tx_hdr.iov_base = (void *)&tx->tx_msg;
+
+ switch (tx->tx_msg.ksm_type) {
+ case KSOCK_MSG_LNET:
+ LASSERT(tx->tx_lnetmsg != NULL);
+ hdr_size = (sizeof(struct ksock_msg_hdr) +
+ sizeof(struct lnet_hdr_nid16));
+
+ lnet_hdr_to_nid16(&tx->tx_lnetmsg->msg_hdr,
+ &tx->tx_msg.ksm_u.lnetmsg_nid16);
+ tx->tx_hdr.iov_len = hdr_size;
+ tx->tx_resid = tx->tx_nob = hdr_size + tx->tx_lnetmsg->msg_len;
+ break;
+ case KSOCK_MSG_NOOP:
+ LASSERT(tx->tx_lnetmsg == NULL);
+ hdr_size = sizeof(struct ksock_msg_hdr);
+
+ tx->tx_hdr.iov_len = hdr_size;
+ tx->tx_resid = tx->tx_nob = hdr_size;
+ break;
+ default:
+ LASSERT(0);
+ }
+ /* Don't checksum before start sending, because packet can be
+ * piggybacked with ACK
+ */
+}
+
+static void
+ksocknal_unpack_msg_v1(struct ksock_msg *msg, struct lnet_hdr *hdr)
+{
+ msg->ksm_csum = 0;
+ msg->ksm_type = KSOCK_MSG_LNET;
+ msg->ksm_zc_cookies[0] = msg->ksm_zc_cookies[1] = 0;
+ lnet_hdr_from_nid4(hdr, &msg->ksm_u.lnetmsg_nid4);
}
static void
-ksocknal_unpack_msg_v1(struct ksock_msg *msg)
+ksocknal_unpack_msg_v2(struct ksock_msg *msg, struct lnet_hdr *hdr)
{
- msg->ksm_csum = 0;
- msg->ksm_type = KSOCK_MSG_LNET;
- msg->ksm_zc_cookies[0] = msg->ksm_zc_cookies[1] = 0;
+ lnet_hdr_from_nid4(hdr, &msg->ksm_u.lnetmsg_nid4);
}
static void
-ksocknal_unpack_msg_v2(struct ksock_msg *msg)
+ksocknal_unpack_msg_v4(struct ksock_msg *msg, struct lnet_hdr *hdr)
{
- return; /* Do nothing */
+ lnet_hdr_from_nid16(hdr, &msg->ksm_u.lnetmsg_nid16);
}
const struct ksock_proto ksocknal_protocol_v1x =
.pro_match_tx = ksocknal_match_tx_v3
};
+const struct ksock_proto ksocknal_protocol_v4x = {
+ .pro_version = KSOCK_PROTO_V4,
+ .pro_send_hello = ksocknal_send_hello_v4,
+ .pro_recv_hello = ksocknal_recv_hello_v4,
+ .pro_pack = ksocknal_pack_msg_v4,
+ .pro_unpack = ksocknal_unpack_msg_v4,
+ .pro_queue_tx_msg = ksocknal_queue_tx_msg_v2,
+ .pro_queue_tx_zcack = ksocknal_queue_tx_zcack_v3,
+ .pro_handle_zcreq = ksocknal_handle_zcreq,
+ .pro_handle_zcack = ksocknal_handle_zcack,
+ .pro_match_tx = ksocknal_match_tx_v4,
+};