Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[fs/lustre-release.git] / lnet / lnet / lib-eq.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * lib/lib-eq.c
5  * Library level Event queue management routines
6  *
7  *  Copyright (c) 2001-2003 Cluster File Systems, Inc.
8  *  Copyright (c) 2001-2002 Sandia National Laboratories
9  *
10  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
11  *
12  *   Lustre is free software; you can redistribute it and/or
13  *   modify it under the terms of version 2 of the GNU General Public
14  *   License as published by the Free Software Foundation.
15  *
16  *   Lustre is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Lustre; if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #define DEBUG_SUBSYSTEM S_PORTALS
27 #include <portals/lib-p30.h>
28 #include <portals/arg-blocks.h>
29
30 int do_PtlEQAlloc_internal(nal_cb_t * nal, void *private, void *v_args,
31                            void *v_ret)
32 {
33         /*
34          * Incoming:
35          *      ptl_handle_ni_t ni_in
36          *      ptl_size_t count_in
37          *      void                    * base_in
38          *
39          * Outgoing:
40          *      ptl_handle_eq_t         * handle_out
41          */
42
43         PtlEQAlloc_in *args = v_args;
44         PtlEQAlloc_out *ret = v_ret;
45
46         lib_eq_t *eq;
47         unsigned long flags;
48
49         /* api should have rounded up */
50         if (args->count_in != LOWEST_BIT_SET (args->count_in))
51                 return ret->rc = PTL_VAL_FAILED;
52
53         eq = lib_eq_alloc (nal);
54         if (eq == NULL)
55                 return (ret->rc = PTL_NOSPACE);
56
57         state_lock(nal, &flags);
58
59         if (nal->cb_map != NULL) {
60                 struct iovec iov = {
61                         .iov_base = args->base_in,
62                         .iov_len = args->count_in * sizeof (ptl_event_t) };
63
64                 ret->rc = nal->cb_map (nal, 1, &iov, &eq->eq_addrkey);
65                 if (ret->rc != PTL_OK) {
66                         lib_eq_free (nal, eq);
67                         
68                         state_unlock (nal, &flags);
69                         return (ret->rc);
70                 }
71         }
72
73         eq->sequence = 1;
74         eq->base = args->base_in;
75         eq->size = args->count_in;
76         eq->eq_refcount = 0;
77         eq->event_callback = args->callback_in;
78
79         lib_initialise_handle (nal, &eq->eq_lh, PTL_COOKIE_TYPE_EQ);
80         list_add (&eq->eq_list, &nal->ni.ni_active_eqs);
81
82         state_unlock(nal, &flags);
83
84         ptl_eq2handle(&ret->handle_out, eq);
85         return (ret->rc = PTL_OK);
86 }
87
88 int do_PtlEQFree_internal(nal_cb_t * nal, void *private, void *v_args,
89                           void *v_ret)
90 {
91         /*
92          * Incoming:
93          *      ptl_handle_eq_t eventq_in
94          *
95          * Outgoing:
96          */
97
98         PtlEQFree_in *args = v_args;
99         PtlEQFree_out *ret = v_ret;
100         lib_eq_t *eq;
101         long flags;
102
103         state_lock (nal, &flags);
104
105         eq = ptl_handle2eq(&args->eventq_in, nal);
106         if (eq == NULL) {
107                 ret->rc = PTL_INV_EQ;
108         } else if (eq->eq_refcount != 0) {
109                 ret->rc = PTL_EQ_INUSE;
110         } else {
111                 if (nal->cb_unmap != NULL) {
112                         struct iovec iov = {
113                                 .iov_base = eq->base,
114                                 .iov_len = eq->size * sizeof (ptl_event_t) };
115                         
116                         nal->cb_unmap(nal, 1, &iov, &eq->eq_addrkey);
117                 }
118
119                 lib_invalidate_handle (nal, &eq->eq_lh);
120                 list_del (&eq->eq_list);
121                 lib_eq_free (nal, eq);
122                 ret->rc = PTL_OK;
123         }
124
125         state_unlock (nal, &flags);
126
127         return (ret->rc);
128 }