1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
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.
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
29 #define DEBUG_SUBSYSTEM S_RPC
31 #include <linux/obd_support.h>
32 #include <linux/obd_class.h>
33 #include <linux/lustre_net.h>
35 ptl_handle_eq_t sent_pkt_eq, rcvd_rep_eq, bulk_source_eq, bulk_sink_eq;
38 * Free the packet when it has gone out
40 static int sent_packet_callback(ptl_event_t *ev, void *data)
44 if (ev->type == PTL_EVENT_SENT) {
45 OBD_FREE(ev->mem_desc.start, ev->mem_desc.length);
47 // XXX make sure we understand all events, including ACK's
48 CERROR("Unknown event %d\n", ev->type);
57 * Wake up the thread waiting for the reply once it comes in.
59 static int rcvd_reply_callback(ptl_event_t *ev, void *data)
61 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
64 if (ev->type == PTL_EVENT_PUT) {
65 rpc->rq_repbuf = ev->mem_desc.start + ev->offset;
67 wake_up_interruptible(&rpc->rq_wait_for_rep);
69 // XXX make sure we understand all events, including ACK's
70 CERROR("Unknown event %d\n", ev->type);
78 int server_request_callback(ptl_event_t *ev, void *data)
80 struct ptlrpc_service *service = data;
83 if (ev->rlength != ev->mlength)
84 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
85 ev->mlength, ev->rlength);
87 /* The ME is unlinked when there is less than 1024 bytes free
88 * on its MD. This ensures we are always able to handle the rpc,
89 * although the 1024 value is a guess as to the size of a
90 * large rpc (the known safe margin should be determined).
92 * NOTE: The portals API by default unlinks all MD's associated
93 * with an ME when it's unlinked. For now, this behavior
94 * has been commented out of the portals library so the
95 * MD can be unlinked when its ref count drops to zero.
96 * A new MD and ME will then be created that use the same
97 * kmalloc()'ed memory and inserted at the ring tail.
100 service->srv_ref_count[service->srv_md_active]++;
102 if (ev->offset >= (service->srv_buf_size - 1024)) {
103 CDEBUG(D_INODE, "Unlinking ME %d\n", service->srv_me_active);
105 rc = PtlMEUnlink(service->srv_me_h[service->srv_me_active]);
106 service->srv_me_h[service->srv_me_active] = 0;
109 CERROR("PtlMEUnlink failed - DROPPING soon: %d\n", rc);
114 service->srv_me_active = NEXT_INDEX(service->srv_me_active,
115 service->srv_ring_length);
117 if (service->srv_me_h[service->srv_me_active] == 0)
118 CERROR("All %d ring ME's are unlinked!\n",
119 service->srv_ring_length);
122 if (ev->type == PTL_EVENT_PUT) {
123 wake_up(&service->srv_waitq);
125 CERROR("Unexpected event type: %d\n", ev->type);
132 static int bulk_source_callback(ptl_event_t *ev, void *data)
134 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
138 if (ev->type == PTL_EVENT_SENT) {
139 CDEBUG(D_NET, "got SENT event\n");
140 } else if (ev->type == PTL_EVENT_ACK) {
141 CDEBUG(D_NET, "got ACK event\n");
142 wake_up_interruptible(&rpc->rq_wait_for_bulk);
144 CERROR("Unexpected event type!\n");
152 static int bulk_sink_callback(ptl_event_t *ev, void *data)
154 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
158 if (ev->type == PTL_EVENT_PUT) {
159 if (rpc->rq_bulkbuf != ev->mem_desc.start + ev->offset)
160 CERROR("bulkbuf != mem_desc -- why?\n");
161 wake_up_interruptible(&rpc->rq_wait_for_bulk);
163 CERROR("Unexpected event type!\n");
171 int ptlrpc_init_portals(void)
174 const ptl_handle_ni_t *nip;
177 nip = inter_module_get_request(LUSTRE_NAL "_ni", LUSTRE_NAL);
179 CERROR("get_ni failed: is the NAL module loaded?\n");
184 rc = PtlEQAlloc(ni, 128, sent_packet_callback, NULL, &sent_pkt_eq);
186 CERROR("PtlEQAlloc failed: %d\n", rc);
188 rc = PtlEQAlloc(ni, 128, rcvd_reply_callback, NULL, &rcvd_rep_eq);
190 CERROR("PtlEQAlloc failed: %d\n", rc);
192 rc = PtlEQAlloc(ni, 128, bulk_source_callback, NULL, &bulk_source_eq);
194 CERROR("PtlEQAlloc failed: %d\n", rc);
196 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, NULL, &bulk_sink_eq);
198 CERROR("PtlEQAlloc failed: %d\n", rc);
203 void ptlrpc_exit_portals(void)
205 PtlEQFree(sent_pkt_eq);
206 PtlEQFree(rcvd_rep_eq);
207 PtlEQFree(bulk_source_eq);
208 PtlEQFree(bulk_sink_eq);
210 inter_module_put(LUSTRE_NAL "_ni");