4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lnet/ulnds/socklnd/usocklnd_cb.c
36 * Author: Maxim Patlasov <maxim@clusterfs.com>
42 usocklnd_send_tx_immediately(usock_conn_t *conn, usock_tx_t *tx)
47 usock_peer_t *peer = conn->uc_peer;
49 LASSERT (peer != NULL);
51 /* usocklnd_enqueue_tx() turned it on for us */
52 LASSERT(conn->uc_sending);
54 //counter_imm_start++;
55 rc = usocklnd_send_tx(conn, tx);
56 if (rc == 0) { /* partial send or connection closed */
57 pthread_mutex_lock(&conn->uc_lock);
58 cfs_list_add(&tx->tx_list, &conn->uc_tx_list);
60 pthread_mutex_unlock(&conn->uc_lock);
63 usocklnd_destroy_tx(peer->up_ni, tx);
64 /* NB: lnetmsg was finalized, so we *must* return 0 */
66 if (rc < 0) { /* real error */
67 usocklnd_conn_kill(conn);
71 /* rc == 1: tx was sent completely */
72 rc = 0; /* let's say to caller 'Ok' */
73 //counter_imm_complete++;
76 pthread_mutex_lock(&conn->uc_lock);
79 /* schedule write handler */
81 (conn->uc_state == UC_READY &&
82 (!cfs_list_empty(&conn->uc_tx_list) ||
83 !cfs_list_empty(&conn->uc_zcack_list)))) {
84 conn->uc_tx_deadline =
85 cfs_time_shift(usock_tuns.ut_timeout);
87 rc2 = usocklnd_add_pollrequest(conn, POLL_TX_SET_REQUEST, POLLOUT);
89 usocklnd_conn_kill_locked(conn);
91 usocklnd_wakeup_pollthread(conn->uc_pt_idx);
94 pthread_mutex_unlock(&conn->uc_lock);
100 usocklnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
103 lnet_process_id_t target = lntmsg->msg_target;
108 int send_immediately;
110 tx = usocklnd_create_tx(lntmsg);
114 rc = usocklnd_find_or_create_peer(ni, target, &peer);
116 LIBCFS_FREE (tx, tx->tx_size);
119 /* peer cannot disappear now because its refcount was incremented */
121 type = usocklnd_get_conn_type(lntmsg);
122 rc = usocklnd_find_or_create_conn(peer, type, &conn, tx, NULL,
125 usocklnd_peer_decref(peer);
126 usocklnd_check_peer_stale(ni, target);
127 LIBCFS_FREE (tx, tx->tx_size);
130 /* conn cannot disappear now because its refcount was incremented */
132 if (send_immediately)
133 rc = usocklnd_send_tx_immediately(conn, tx);
135 usocklnd_conn_decref(conn);
136 usocklnd_peer_decref(peer);
141 usocklnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
142 unsigned int niov, struct iovec *iov, lnet_kiov_t *kiov,
143 unsigned int offset, unsigned int mlen, unsigned int rlen)
146 usock_conn_t *conn = (usock_conn_t *)private;
148 /* I don't think that we'll win much concurrency moving lock()
149 * call below lnet_extract_iov() */
150 pthread_mutex_lock(&conn->uc_lock);
152 conn->uc_rx_lnetmsg = msg;
153 conn->uc_rx_nob_wanted = mlen;
154 conn->uc_rx_nob_left = rlen;
155 conn->uc_rx_iov = conn->uc_rx_iova;
157 lnet_extract_iov(LNET_MAX_IOV, conn->uc_rx_iov,
158 niov, iov, offset, mlen);
160 /* the gap between lnet_parse() and usocklnd_recv() happened? */
161 if (conn->uc_rx_state == UC_RX_PARSE_WAIT) {
162 conn->uc_rx_flag = 1; /* waiting for incoming lnet payload */
163 conn->uc_rx_deadline =
164 cfs_time_shift(usock_tuns.ut_timeout);
165 rc = usocklnd_add_pollrequest(conn, POLL_RX_SET_REQUEST, POLLIN);
167 usocklnd_conn_kill_locked(conn);
170 usocklnd_wakeup_pollthread(conn->uc_pt_idx);
173 conn->uc_rx_state = UC_RX_LNET_PAYLOAD;
175 pthread_mutex_unlock(&conn->uc_lock);
176 usocklnd_conn_decref(conn);
181 usocklnd_accept(lnet_ni_t *ni, cfs_socket_t *sock)
186 rc = usocklnd_create_passive_conn(ni, sock, &conn);
189 LASSERT(conn != NULL);
191 /* disable shutdown event temporarily */
194 rc = usocklnd_add_pollrequest(conn, POLL_ADD_REQUEST, POLLIN);
196 usocklnd_wakeup_pollthread(conn->uc_pt_idx);
198 /* NB: conn reference counter was incremented while adding
199 * poll request if rc == 0 */
201 usocklnd_conn_decref(conn); /* should destroy conn if rc != 0 */