1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2003 Los Alamos National Laboratory (LANL)
6 * This file is part of Lustre, http://www.lustre.org/
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * This file implements the nal cb functions
31 gmnal_cb_recv(lib_nal_t *libnal, void *private,
33 unsigned int niov, struct iovec *iov,
34 size_t offset, size_t mlen, size_t rlen)
36 gmnal_rx_t *rx = (gmnal_rx_t*)private;
37 gmnal_msg_t *msg = rx->rx_msg;
38 size_t nobleft = mlen;
43 CDEBUG(D_TRACE, "gmnal_cb_recv libnal [%p], private[%p], libmsg[%p], "
44 "niov[%d], iov [%p], offset["LPSZ"], mlen["LPSZ"], rlen["LPSZ"]\n",
45 libnal, private, libmsg, niov, iov, offset, mlen, rlen);
47 LASSERT (msg->gmm_type == GMNAL_MSG_IMMEDIATE);
49 buffer = &msg->gmm_u.immediate.gmim_payload[0];
50 rxnob = offsetof(gmnal_msg_t, gmm_u.immediate.gmim_payload[nobleft]);
52 if (rx->rx_recv_nob < rxnob) {
53 CERROR("Short message from nid "LPD64": got %d, need %d\n",
54 msg->gmm_srcnid, rx->rx_recv_nob, rxnob);
61 if (offset >= iov->iov_len) {
62 offset -= iov->iov_len;
64 nob = MIN (iov->iov_len - offset, nobleft);
66 gm_bcopy(buffer, iov->iov_base + offset, nob);
76 lib_finalize(libnal, private, libmsg, PTL_OK);
81 gmnal_cb_recv_pages(lib_nal_t *libnal, void *private,
83 unsigned int nkiov, ptl_kiov_t *kiov,
84 size_t offset, size_t mlen, size_t rlen)
86 gmnal_rx_t *rx = (gmnal_rx_t*)private;
87 gmnal_msg_t *msg = rx->rx_msg;
88 size_t nobleft = mlen;
94 CDEBUG(D_TRACE, "gmnal_cb_recv_pages libnal [%p],private[%p], "
95 "libmsg[%p], kniov[%d], kiov [%p], "
96 "offset["LPSZ"], mlen["LPSZ"], rlen["LPSZ"]\n",
97 libnal, private, libmsg, nkiov, kiov, offset, mlen, rlen);
99 LASSERT (msg->gmm_type == GMNAL_MSG_IMMEDIATE);
101 buffer = &msg->gmm_u.immediate.gmim_payload[0];
102 rxnob = offsetof(gmnal_msg_t, gmm_u.immediate.gmim_payload[nobleft]);
104 if (rx->rx_recv_nob < rxnob) {
105 CERROR("Short message from nid "LPD64": got %d, need %d\n",
106 msg->gmm_srcnid, rx->rx_recv_nob, rxnob);
110 while (nobleft > 0) {
113 if (offset >= kiov->kiov_len) {
114 offset -= kiov->kiov_len;
116 nob = MIN (kiov->kiov_len - offset, nobleft);
118 ptr = ((char *)kmap(kiov->kiov_page)) +
121 gm_bcopy(buffer, ptr + offset, nob);
123 kunmap(kiov->kiov_page);
133 lib_finalize(libnal, private, libmsg, PTL_OK);
138 gmnal_cb_send(lib_nal_t *libnal, void *private,
139 lib_msg_t *libmsg, ptl_hdr_t *hdr, int type,
140 ptl_nid_t nid, ptl_pid_t pid,
141 unsigned int niov, struct iovec *iov,
142 size_t offset, size_t len)
145 gmnal_ni_t *gmnalni = libnal->libnal_data;
146 size_t nobleft = len;
151 CDEBUG(D_TRACE, "gmnal_cb_send niov[%d] offset["LPSZ"] "
152 "len["LPSZ"] nid["LPU64"]\n", niov, offset, len, nid);
154 if ((nid >> 32) != 0) {
155 CERROR("Illegal nid: "LPU64"\n", nid);
159 tx = gmnal_get_tx(gmnalni, 1);
161 gmnal_pack_msg(gmnalni, tx, nid, GMNAL_MSG_IMMEDIATE);
162 gm_bcopy(hdr, &tx->tx_msg->gmm_u.immediate.gmim_hdr, sizeof(*hdr));
164 buffer = &tx->tx_msg->gmm_u.immediate.gmim_payload[0];
165 while (nobleft > 0) {
168 if (offset >= iov->iov_len) {
169 offset -= iov->iov_len;
171 nob = MIN (iov->iov_len - offset, nobleft);
173 gm_bcopy(iov->iov_base + offset, buffer, nob);
183 nob = offsetof(gmnal_msg_t, gmm_u.immediate.gmim_payload[len]);
184 return gmnal_post_tx(gmnalni, tx, libmsg, nid, nob);
188 gmnal_cb_send_pages(lib_nal_t *libnal, void *private,
189 lib_msg_t *libmsg, ptl_hdr_t *hdr, int type,
190 ptl_nid_t nid, ptl_pid_t pid,
191 unsigned int nkiov, ptl_kiov_t *kiov,
192 size_t offset, size_t len)
195 gmnal_ni_t *gmnalni = libnal->libnal_data;
196 size_t nobleft = len;
202 CDEBUG(D_TRACE, "gmnal_cb_send_pages nid ["LPU64"] niov[%d] offset["
203 LPSZ"] len["LPSZ"]\n", nid, nkiov, offset, len);
205 if ((nid >> 32) != 0) {
206 CERROR("Illegal nid: "LPU64"\n", nid);
210 tx = gmnal_get_tx(gmnalni, 1);
212 gmnal_pack_msg(gmnalni, tx, nid, GMNAL_MSG_IMMEDIATE);
213 gm_bcopy(hdr, &tx->tx_msg->gmm_u.immediate.gmim_hdr, sizeof(*hdr));
215 buffer = &tx->tx_msg->gmm_u.immediate.gmim_payload[0];
216 while (nobleft > 0) {
219 if (offset >= kiov->kiov_len) {
220 offset -= kiov->kiov_len;
222 nob = MIN (kiov->kiov_len - offset, nobleft);
224 ptr = ((char *)kmap(kiov->kiov_page)) +
227 gm_bcopy(ptr + offset, buffer, nob);
229 kunmap(kiov->kiov_page);
239 nob = offsetof(gmnal_msg_t, gmm_u.immediate.gmim_payload[len]);
240 return gmnal_post_tx(gmnalni, tx, libmsg, nid, nob);
244 gmnal_cb_dist(lib_nal_t *libnal, ptl_nid_t nid, unsigned long *dist)
246 CDEBUG(D_TRACE, "gmnal_cb_dist\n");