Whamcloud - gitweb
- many gcc4 compilation fixes (warnings)
[fs/lustre-release.git] / lustre / ptlrpc / events.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  *
21  */
22
23 #define DEBUG_SUBSYSTEM S_RPC
24
25 #ifdef __KERNEL__
26 #include <linux/module.h>
27 #else
28 #include <liblustre.h>
29 #endif
30 #include <linux/obd_class.h>
31 #include <linux/lustre_net.h>
32 #include "ptlrpc_internal.h"
33
34 #if !defined(__KERNEL__) && CRAY_PORTALS
35 /* forward ref in events.c */
36 static void cray_portals_callback(ptl_event_t *ev);
37 #endif
38
39
40 struct ptlrpc_ni  ptlrpc_interfaces[8];
41 int               ptlrpc_ninterfaces;
42
43 /*  
44  *  Client's outgoing request callback
45  */
46 void request_out_callback(ptl_event_t *ev)
47 {
48         struct ptlrpc_cb_id   *cbid = ev->md.user_ptr;
49         struct ptlrpc_request *req = cbid->cbid_arg;
50         unsigned long          flags;
51         ENTRY;
52
53         LASSERT (ev->type == PTL_EVENT_SEND_END ||
54                  ev->type == PTL_EVENT_UNLINK);
55         LASSERT (ev->unlinked);
56
57         DEBUG_REQ((ev->ni_fail_type == PTL_NI_OK) ? D_NET : D_ERROR, req,
58                   "type %d, status %d", ev->type, ev->ni_fail_type);
59
60         if (ev->type == PTL_EVENT_UNLINK ||
61             ev->ni_fail_type != PTL_NI_OK) {
62
63                 /* Failed send: make it seem like the reply timed out, just
64                  * like failing sends in client.c does currently...  */
65
66                 spin_lock_irqsave(&req->rq_lock, flags);
67                 req->rq_net_err = 1;
68                 spin_unlock_irqrestore(&req->rq_lock, flags);
69                 
70                 ptlrpc_wake_client_req(req);
71         }
72
73         /* this balances the atomic_inc in ptl_send_rpc() */
74         ptlrpc_req_finished(req);
75         EXIT;
76 }
77
78 /*
79  * Client's incoming reply callback
80  */
81 void reply_in_callback(ptl_event_t *ev)
82 {
83         struct ptlrpc_cb_id   *cbid = ev->md.user_ptr;
84         struct ptlrpc_request *req = cbid->cbid_arg;
85         unsigned long flags;
86         ENTRY;
87
88         LASSERT (ev->type == PTL_EVENT_PUT_END ||
89                  ev->type == PTL_EVENT_UNLINK);
90         LASSERT (ev->unlinked);
91         LASSERT (ev->md.start == req->rq_repbuf);
92         LASSERT (ev->offset == 0);
93         LASSERT (ev->mlength <= req->rq_repbuf_len);
94         
95         DEBUG_REQ((ev->ni_fail_type == PTL_NI_OK) ? D_NET : D_ERROR, req,
96                   "type %d, status %d", ev->type, ev->ni_fail_type);
97
98         spin_lock_irqsave (&req->rq_lock, flags);
99
100         LASSERT (req->rq_receiving_reply);
101         req->rq_receiving_reply = 0;
102
103         if (ev->type == PTL_EVENT_PUT_END &&
104             ev->ni_fail_type == PTL_NI_OK) {
105                 req->rq_replied = 1;
106                 req->rq_nob_received = ev->mlength;
107         }
108
109         /* NB don't unlock till after wakeup; req can disappear under us
110          * since we don't have our own ref */
111         ptlrpc_wake_client_req(req);
112
113         spin_unlock_irqrestore (&req->rq_lock, flags);
114         EXIT;
115 }
116
117 /* 
118  * Client's bulk has been written/read
119  */
120 void client_bulk_callback (ptl_event_t *ev)
121 {
122         struct ptlrpc_cb_id     *cbid = ev->md.user_ptr;
123         struct ptlrpc_bulk_desc *desc = cbid->cbid_arg;
124         unsigned long            flags;
125         ENTRY;
126
127         LASSERT ((desc->bd_type == BULK_PUT_SINK && 
128                   ev->type == PTL_EVENT_PUT_END) ||
129                  (desc->bd_type == BULK_GET_SOURCE &&
130                   ev->type == PTL_EVENT_GET_END) ||
131                  ev->type == PTL_EVENT_UNLINK);
132         LASSERT (ev->unlinked);
133
134         CDEBUG((ev->ni_fail_type == PTL_NI_OK) ? D_NET : D_ERROR,
135                "event type %d, status %d, desc %p\n", 
136                ev->type, ev->ni_fail_type, desc);
137
138         spin_lock_irqsave (&desc->bd_lock, flags);
139
140         LASSERT(desc->bd_network_rw);
141         desc->bd_network_rw = 0;
142
143         if (ev->type != PTL_EVENT_UNLINK &&
144             ev->ni_fail_type == PTL_NI_OK) {
145                 desc->bd_success = 1;
146                 desc->bd_nob_transferred = ev->mlength;
147         }
148
149         /* NB don't unlock till after wakeup; desc can disappear under us
150          * otherwise */
151         ptlrpc_wake_client_req(desc->bd_req);
152
153         spin_unlock_irqrestore (&desc->bd_lock, flags);
154         EXIT;
155 }
156
157 /* 
158  * Server's incoming request callback
159  */
160 void request_in_callback(ptl_event_t *ev)
161 {
162         struct ptlrpc_cb_id               *cbid = ev->md.user_ptr;
163         struct ptlrpc_request_buffer_desc *rqbd = cbid->cbid_arg;
164         struct ptlrpc_srv_ni              *srv_ni = rqbd->rqbd_srv_ni;
165         struct ptlrpc_service             *service = srv_ni->sni_service;
166         struct ptlrpc_request             *req;
167         char                              str[PTL_NALFMT_SIZE];
168         unsigned long                     flags;
169         ENTRY;
170
171         LASSERT (ev->type == PTL_EVENT_PUT_END ||
172                  ev->type == PTL_EVENT_UNLINK);
173         LASSERT ((char *)ev->md.start >= rqbd->rqbd_buffer);
174         LASSERT ((char *)ev->md.start + ev->offset + ev->mlength <=
175                  rqbd->rqbd_buffer + service->srv_buf_size);
176
177         CDEBUG((ev->ni_fail_type == PTL_OK) ? D_NET : D_ERROR,
178                "event type %d, status %d, service %s\n", 
179                ev->type, ev->ni_fail_type, service->srv_name);
180
181         if (ev->unlinked) {
182                 /* If this is the last request message to fit in the
183                  * request buffer we can use the request object embedded in
184                  * rqbd.  Note that if we failed to allocate a request,
185                  * we'd have to re-post the rqbd, which we can't do in this
186                  * context. */
187                 req = &rqbd->rqbd_req;
188                 memset(req, 0, sizeof (*req));
189         } else {
190                 LASSERT (ev->type == PTL_EVENT_PUT_END);
191                 if (ev->ni_fail_type != PTL_NI_OK) {
192                         /* We moaned above already... */
193                         return;
194                 }
195                 OBD_ALLOC_GFP(req, sizeof(*req), GFP_ATOMIC);
196                 if (req == NULL) {
197                         CERROR("Can't allocate incoming request descriptor: "
198                                "Dropping %s RPC from %s\n",
199                                service->srv_name, 
200                                portals_id2str(srv_ni->sni_ni->pni_number,
201                                               ev->initiator, str));
202                         return;
203                 }
204         }
205
206         /* NB we ABSOLUTELY RELY on req being zeroed, so pointers are NULL,
207          * flags are reset and scalars are zero.  We only set the message
208          * size to non-zero if this was a successful receive. */
209         req->rq_xid = ev->match_bits;
210         req->rq_reqbuf = ev->md.start + ev->offset;
211         if (ev->type == PTL_EVENT_PUT_END &&
212             ev->ni_fail_type == PTL_NI_OK)
213                 req->rq_reqbuf_len = ev->mlength;
214         do_gettimeofday(&req->rq_arrival_time);
215         req->rq_peer.peer_id = ev->initiator;
216         req->rq_peer.peer_ni = rqbd->rqbd_srv_ni->sni_ni;
217         ptlrpc_id2str(&req->rq_peer, req->rq_peerstr);
218         req->rq_rqbd = rqbd;
219 #if CRAY_PORTALS
220         req->rq_uid = ev->uid;
221 #endif
222         
223         spin_lock_irqsave (&service->srv_lock, flags);
224
225         if (ev->unlinked) {
226                 srv_ni->sni_nrqbd_receiving--;
227                 if (ev->type != PTL_EVENT_UNLINK &&
228                     srv_ni->sni_nrqbd_receiving == 0) {
229                         /* This service is off-air on this interface because
230                          * all its request buffers are busy.  Portals will
231                          * start dropping incoming requests until more buffers
232                          * get posted.  NB don't moan if it's because we're
233                          * tearing down the service. */
234                         CWARN("All %s %s request buffers busy\n",
235                               service->srv_name, srv_ni->sni_ni->pni_name);
236                 }
237                 /* req takes over the network's ref on rqbd */
238         } else {
239                 /* req takes a ref on rqbd */
240                 rqbd->rqbd_refcount++;
241         }
242
243         list_add_tail(&req->rq_list, &service->srv_request_queue);
244         service->srv_n_queued_reqs++;
245
246         /* NB everything can disappear under us once the request
247          * has been queued and we unlock, so do the wake now... */
248         wake_up(&service->srv_waitq);
249
250         spin_unlock_irqrestore(&service->srv_lock, flags);
251         EXIT;
252 }
253
254 /*  
255  *  Server's outgoing reply callback
256  */
257 void reply_out_callback(ptl_event_t *ev)
258 {
259         struct ptlrpc_cb_id       *cbid = ev->md.user_ptr;
260         struct ptlrpc_reply_state *rs = cbid->cbid_arg;
261         struct ptlrpc_srv_ni      *sni = rs->rs_srv_ni;
262         struct ptlrpc_service     *svc = sni->sni_service;
263         unsigned long              flags;
264         ENTRY;
265
266         LASSERT (ev->type == PTL_EVENT_SEND_END ||
267                  ev->type == PTL_EVENT_ACK ||
268                  ev->type == PTL_EVENT_UNLINK);
269
270         if (!rs->rs_difficult) {
271                 /* I'm totally responsible for freeing "easy" replies */
272                 LASSERT (ev->unlinked);
273                 lustre_free_reply_state (rs);
274                 atomic_dec (&svc->srv_outstanding_replies);
275                 EXIT;
276                 return;
277         }
278
279         LASSERT (rs->rs_on_net);
280
281         if (ev->unlinked) {
282                 /* Last network callback */
283                 spin_lock_irqsave (&svc->srv_lock, flags);
284                 rs->rs_on_net = 0;
285                 ptlrpc_schedule_difficult_reply (rs);
286                 spin_unlock_irqrestore (&svc->srv_lock, flags);
287         }
288
289         EXIT;
290 }
291
292 /*
293  * Server's bulk completion callback
294  */
295 void server_bulk_callback (ptl_event_t *ev)
296 {
297         struct ptlrpc_cb_id     *cbid = ev->md.user_ptr;
298         struct ptlrpc_bulk_desc *desc = cbid->cbid_arg;
299         unsigned long            flags;
300         ENTRY;
301
302         LASSERT (ev->type == PTL_EVENT_SEND_END ||
303                  ev->type == PTL_EVENT_UNLINK ||
304                  (desc->bd_type == BULK_PUT_SOURCE &&
305                   ev->type == PTL_EVENT_ACK) ||
306                  (desc->bd_type == BULK_GET_SINK &&
307                   ev->type == PTL_EVENT_REPLY_END));
308
309         CDEBUG((ev->ni_fail_type == PTL_NI_OK) ? D_NET : D_ERROR,
310                "event type %d, status %d, desc %p\n", 
311                ev->type, ev->ni_fail_type, desc);
312
313         spin_lock_irqsave (&desc->bd_lock, flags);
314         
315         if ((ev->type == PTL_EVENT_ACK ||
316              ev->type == PTL_EVENT_REPLY_END) &&
317             ev->ni_fail_type == PTL_NI_OK) {
318                 /* We heard back from the peer, so even if we get this
319                  * before the SENT event (oh yes we can), we know we
320                  * read/wrote the peer buffer and how much... */
321                 desc->bd_success = 1;
322                 desc->bd_nob_transferred = ev->mlength;
323         }
324
325         if (ev->unlinked) {
326                 /* This is the last callback no matter what... */
327                 desc->bd_network_rw = 0;
328                 wake_up(&desc->bd_waitq);
329         }
330
331         spin_unlock_irqrestore (&desc->bd_lock, flags);
332         EXIT;
333 }
334
335 static void ptlrpc_master_callback(ptl_event_t *ev)
336 {
337         struct ptlrpc_cb_id *cbid = ev->md.user_ptr;
338         void (*callback)(ptl_event_t *ev) = cbid->cbid_fn;
339
340         /* Honestly, it's best to find out early. */
341         LASSERT (cbid->cbid_arg != LP_POISON);
342         LASSERT (callback == request_out_callback ||
343                  callback == reply_in_callback ||
344                  callback == client_bulk_callback ||
345                  callback == request_in_callback ||
346                  callback == reply_out_callback ||
347                  callback == server_bulk_callback);
348         
349         callback (ev);
350 }
351
352 int ptlrpc_uuid_to_peer (struct obd_uuid *uuid, struct ptlrpc_peer *peer)
353 {
354         struct ptlrpc_ni   *pni;
355         __u32               peer_nal;
356         ptl_nid_t           peer_nid;
357         int                 i;
358         char                str[PTL_NALFMT_SIZE];
359         int                 rc = lustre_uuid_to_peer((char *)uuid->uuid, 
360                                                      &peer_nal, &peer_nid);
361         if (rc != 0)
362                 RETURN (rc);
363
364         for (i = 0; i < ptlrpc_ninterfaces; i++) {
365                 pni = &ptlrpc_interfaces[i];
366
367 #ifndef CRAY_PORTALS
368                 if (pni->pni_number == peer_nal) {
369 #else
370                 /* compatible nals but may be from different bridges */
371                 if (NALID_FROM_IFACE(pni->pni_number) == 
372                     NALID_FROM_IFACE(peer_nal)) {
373 #endif
374                         peer->peer_id.nid = peer_nid;
375                         peer->peer_id.pid = LUSTRE_SRV_PTL_PID;
376                         peer->peer_ni = pni;
377                         return (0);
378                 }
379         }
380
381         CERROR("Can't find ptlrpc interface for NAL %x, NID %s\n",
382                peer_nal, portals_nid2str(peer_nal, peer_nid, str));
383         return (-ENOENT);
384 }
385
386 void ptlrpc_ni_fini(struct ptlrpc_ni *pni)
387 {
388         wait_queue_head_t   waitq;
389         struct l_wait_info  lwi;
390         int                 rc;
391         int                 retries;
392         
393         /* Wait for the event queue to become idle since there may still be
394          * messages in flight with pending events (i.e. the fire-and-forget
395          * messages == client requests and "non-difficult" server
396          * replies */
397
398         for (retries = 0;; retries++) {
399                 rc = PtlEQFree(pni->pni_eq_h);
400                 switch (rc) {
401                 default:
402                         LBUG();
403
404                 case PTL_OK:
405                         PtlNIFini(pni->pni_ni_h);
406                         return;
407                         
408                 case PTL_EQ_IN_USE:
409                         if (retries != 0)
410                                 CWARN("Event queue for %s still busy\n",
411                                       pni->pni_name);
412                         
413                         /* Wait for a bit */
414                         init_waitqueue_head(&waitq);
415                         lwi = LWI_TIMEOUT(2*HZ, NULL, NULL);
416                         l_wait_event(waitq, 0, &lwi);
417                         break;
418                 }
419         }
420         /* notreached */
421 }
422
423 ptl_pid_t ptl_get_pid(void)
424 {
425         ptl_pid_t        pid;
426
427 #ifndef  __KERNEL__
428         pid = getpid();
429 #ifdef CRAY_PORTALS
430         /* hack to keep pid in range accepted by ernal */
431         pid &= 0xFF;
432         if (pid == LUSTRE_SRV_PTL_PID)
433                 pid++;
434 #endif
435 #else
436         pid = LUSTRE_SRV_PTL_PID;
437 #endif
438         return pid;
439 }
440         
441 int ptlrpc_ni_init(int number, char *name, struct ptlrpc_ni *pni)
442 {
443         int              rc;
444         char             str[20];
445         ptl_handle_ni_t  nih;
446         ptl_pid_t        pid;
447         
448         pid = ptl_get_pid();
449         
450         /* We're not passing any limits yet... */
451         rc = PtlNIInit(number, pid, NULL, NULL, &nih);
452         if (rc != PTL_OK && rc != PTL_IFACE_DUP) {
453                 CDEBUG (D_NET, "Can't init network interface %s: %d\n", 
454                         name, rc);
455                 return (-ENOENT);
456         }
457
458         CDEBUG(D_NET, "My pid is: %x\n", ptl_get_pid());
459         
460         PtlSnprintHandle(str, sizeof(str), nih);
461         CDEBUG (D_NET, "init %x %s: %s\n", number, name, str);
462
463         pni->pni_name = name;
464         pni->pni_number = number;
465         pni->pni_ni_h = nih;
466
467         pni->pni_eq_h = PTL_INVALID_HANDLE;
468
469         /* CAVEAT EMPTOR: how we process portals events is _radically_
470          * different depending on... */
471 #ifdef __KERNEL__
472         /* kernel portals calls our master callback when events are added to
473          * the event queue.  In fact lustre never pulls events off this queue,
474          * so it's only sized for some debug history. */
475         rc = PtlEQAlloc(pni->pni_ni_h, 1024, ptlrpc_master_callback,
476                         &pni->pni_eq_h);
477 #else
478         /* liblustre calls the master callback when it removes events from the
479          * event queue.  The event queue has to be big enough not to drop
480          * anything */
481 # if CRAY_PORTALS
482         /* cray portals implements a non-standard callback to notify us there
483          * are buffered events even when the app is not doing a filesystem
484          * call. */
485         rc = PtlEQAlloc(pni->pni_ni_h, 10240, cray_portals_callback,
486                         &pni->pni_eq_h);
487 # else
488         rc = PtlEQAlloc(pni->pni_ni_h, 10240, PTL_EQ_HANDLER_NONE,
489                         &pni->pni_eq_h);
490 # endif
491 #endif
492         if (rc != PTL_OK)
493                 GOTO (fail, rc = -ENOMEM);
494
495         return (0);
496  fail:
497         CERROR ("Failed to initialise network interface %s: %d\n",
498                 name, rc);
499
500         /* OK to do complete teardown since we invalidated the handles above */
501         ptlrpc_ni_fini (pni);
502         return (rc);
503 }
504
505 #ifndef __KERNEL__
506 LIST_HEAD(liblustre_wait_callbacks);
507 void *liblustre_services_callback;
508
509 void *
510 liblustre_register_wait_callback (int (*fn)(void *arg), void *arg)
511 {
512         struct liblustre_wait_callback *llwc;
513         
514         OBD_ALLOC(llwc, sizeof(*llwc));
515         LASSERT (llwc != NULL);
516         
517         llwc->llwc_fn = fn;
518         llwc->llwc_arg = arg;
519         list_add_tail(&llwc->llwc_list, &liblustre_wait_callbacks);
520         
521         return (llwc);
522 }
523
524 void
525 liblustre_deregister_wait_callback (void *opaque)
526 {
527         struct liblustre_wait_callback *llwc = opaque;
528         
529         list_del(&llwc->llwc_list);
530         OBD_FREE(llwc, sizeof(*llwc));
531 }
532
533 int
534 liblustre_check_events (int timeout)
535 {
536         ptl_event_t ev;
537         int         rc;
538         int         i;
539         ENTRY;
540
541         rc = PtlEQPoll(&ptlrpc_interfaces[0].pni_eq_h, 1, timeout * 1000,
542                        &ev, &i);
543         if (rc == PTL_EQ_EMPTY)
544                 RETURN(0);
545         
546         LASSERT (rc == PTL_EQ_DROPPED || rc == PTL_OK);
547         
548         /* liblustre: no asynch callback so we can't affort to miss any
549          * events... */
550         if (rc == PTL_EQ_DROPPED) {
551                 CERROR ("Dropped an event!!!\n");
552                 abort();
553         }
554         
555         ptlrpc_master_callback (&ev);
556         RETURN(1);
557 }
558
559 int liblustre_waiting = 0;
560
561 int
562 liblustre_wait_event (int timeout)
563 {
564         struct list_head               *tmp;
565         struct liblustre_wait_callback *llwc;
566         int                             found_something = 0;
567
568         /* single threaded recursion check... */
569         liblustre_waiting = 1;
570
571         for (;;) {
572                 /* Deal with all pending events */
573                 while (liblustre_check_events(0))
574                         found_something = 1;
575
576                 /* Give all registered callbacks a bite at the cherry */
577                 list_for_each(tmp, &liblustre_wait_callbacks) {
578                         llwc = list_entry(tmp, struct liblustre_wait_callback, 
579                                           llwc_list);
580                 
581                         if (llwc->llwc_fn(llwc->llwc_arg))
582                                 found_something = 1;
583                 }
584
585                 if (found_something || timeout == 0)
586                         break;
587
588                 /* Nothing so far, but I'm allowed to block... */
589                 found_something = liblustre_check_events(timeout);
590                 if (!found_something)           /* still nothing */
591                         break;                  /* I timed out */
592         }
593
594         liblustre_waiting = 0;
595
596         return found_something;
597 }
598
599 #if CRAY_PORTALS
600 static void cray_portals_callback(ptl_event_t *ev)
601 {
602         /* We get a callback from the client Cray portals implementation
603          * whenever anyone calls PtlEQPoll(), and an event queue with a
604          * callback handler has outstanding events.
605          *
606          * If it's not liblustre calling PtlEQPoll(), this lets us know we
607          * have outstanding events which we handle with
608          * liblustre_wait_event().
609          *
610          * Otherwise, we're already eagerly consuming events and we'd
611          * handle events out of order if we recursed. */
612         if (!liblustre_waiting)
613                 liblustre_wait_event(0);
614 }
615 #endif
616 #endif /* __KERNEL__ */
617
618 int ptlrpc_default_nal(void)
619 {
620         if (ptlrpc_ninterfaces == 0)
621                 return (-ENOENT);
622
623         return (ptlrpc_interfaces[0].pni_number);
624 }
625
626 int ptlrpc_init_portals(void)
627 {
628         /* Add new portals network interfaces here.
629          * Order is irrelevent! */
630         static struct {
631                 int   number;
632                 char *name;
633         } ptl_nis[] = {
634 #ifndef CRAY_PORTALS
635                 {QSWNAL,    "qswnal"},
636                 {SOCKNAL,   "socknal"},
637                 {GMNAL,     "gmnal"},
638                 {OPENIBNAL, "openibnal"},
639                 {IIBNAL,    "iibnal"},
640                 {VIBNAL,    "vibnal"},
641                 {TCPNAL,    "tcpnal"},
642                 {LONAL,     "lonal"},
643                 {RANAL,     "ranal"},
644 #else
645                 {CRAY_KERN_NAL, "cray_kern_nal"},
646                 {CRAY_QK_NAL, "cray_qk_nal"},
647                 {CRAY_USER_NAL, "cray_user_nal"},
648 #endif
649         };
650         int   rc;
651         int   i;
652
653         LASSERT(ptlrpc_ninterfaces == 0);
654
655         for (i = 0; i < sizeof (ptl_nis) / sizeof (ptl_nis[0]); i++) {
656                 LASSERT(ptlrpc_ninterfaces < (sizeof(ptlrpc_interfaces) /
657                                               sizeof(ptlrpc_interfaces[0])));
658
659                 rc = ptlrpc_ni_init(ptl_nis[i].number, ptl_nis[i].name,
660                                     &ptlrpc_interfaces[ptlrpc_ninterfaces]);
661                 if (rc == 0)
662                         ptlrpc_ninterfaces++;
663         }
664
665         if (ptlrpc_ninterfaces == 0) {
666                 CERROR("network initialisation failed: is a NAL module "
667                        "loaded?\n");
668                 return -EIO;
669         }
670 #ifndef __KERNEL__
671         liblustre_services_callback = 
672                 liblustre_register_wait_callback(&liblustre_check_services, NULL);
673 #endif
674         return 0;
675 }
676
677 void ptlrpc_exit_portals(void)
678 {
679 #ifndef __KERNEL__
680         liblustre_deregister_wait_callback(liblustre_services_callback);
681 #endif
682         while (ptlrpc_ninterfaces > 0)
683                 ptlrpc_ni_fini (&ptlrpc_interfaces[--ptlrpc_ninterfaces]);
684 }