Whamcloud - gitweb
file jbd-stats-2.6.9.patch was initially added on branch b1_4.
[fs/lustre-release.git] / lnet / lnet / lib-me.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * lib/lib-me.c
5  * Match Entry management routines
6  *
7  *  Copyright (c) 2001-2003 Cluster File Systems, Inc.
8  *
9  *   This file is part of Lustre, http://www.lustre.org
10  *
11  *   Lustre is free software; you can redistribute it and/or
12  *   modify it under the terms of version 2 of the GNU General Public
13  *   License as published by the Free Software Foundation.
14  *
15  *   Lustre is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with Lustre; if not, write to the Free Software
22  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25 #define DEBUG_SUBSYSTEM S_PORTALS
26
27 #ifndef __KERNEL__
28 # include <stdio.h>
29 #else
30 # include <libcfs/kp30.h>
31 #endif
32
33 #include <portals/lib-p30.h>
34
35 int
36 lib_api_me_attach(nal_t *apinal,
37                   ptl_pt_index_t portal,
38                   ptl_process_id_t match_id,
39                   ptl_match_bits_t match_bits,
40                   ptl_match_bits_t ignore_bits,
41                   ptl_unlink_t unlink, ptl_ins_pos_t pos,
42                   ptl_handle_me_t *handle)
43 {
44         lib_nal_t    *nal = apinal->nal_data;
45         lib_ni_t     *ni = &nal->libnal_ni;
46         lib_ptl_t    *tbl = &ni->ni_portals;
47         lib_me_t     *me;
48         unsigned long flags;
49
50         if (portal >= tbl->size)
51                 return PTL_PT_INDEX_INVALID;
52
53         me = lib_me_alloc (nal);
54         if (me == NULL)
55                 return PTL_NO_SPACE;
56
57         LIB_LOCK(nal, flags);
58
59         me->match_id = match_id;
60         me->match_bits = match_bits;
61         me->ignore_bits = ignore_bits;
62         me->unlink = unlink;
63         me->md = NULL;
64
65         lib_initialise_handle (nal, &me->me_lh, PTL_COOKIE_TYPE_ME);
66
67         if (pos == PTL_INS_AFTER)
68                 list_add_tail(&me->me_list, &(tbl->tbl[portal]));
69         else
70                 list_add(&me->me_list, &(tbl->tbl[portal]));
71
72         ptl_me2handle(handle, nal, me);
73
74         LIB_UNLOCK(nal, flags);
75
76         return PTL_OK;
77 }
78
79 int
80 lib_api_me_insert(nal_t *apinal,
81                   ptl_handle_me_t *current_meh,
82                   ptl_process_id_t match_id,
83                   ptl_match_bits_t match_bits,
84                   ptl_match_bits_t ignore_bits,
85                   ptl_unlink_t unlink, ptl_ins_pos_t pos,
86                   ptl_handle_me_t *handle)
87 {
88         lib_nal_t    *nal = apinal->nal_data;
89         lib_me_t     *current_me;
90         lib_me_t     *new_me;
91         unsigned long flags;
92
93         new_me = lib_me_alloc (nal);
94         if (new_me == NULL)
95                 return PTL_NO_SPACE;
96
97         LIB_LOCK(nal, flags);
98
99         current_me = ptl_handle2me(current_meh, nal);
100         if (current_me == NULL) {
101                 lib_me_free (nal, new_me);
102
103                 LIB_UNLOCK(nal, flags);
104                 return PTL_ME_INVALID;
105         }
106
107         new_me->match_id = match_id;
108         new_me->match_bits = match_bits;
109         new_me->ignore_bits = ignore_bits;
110         new_me->unlink = unlink;
111         new_me->md = NULL;
112
113         lib_initialise_handle (nal, &new_me->me_lh, PTL_COOKIE_TYPE_ME);
114
115         if (pos == PTL_INS_AFTER)
116                 list_add_tail(&new_me->me_list, &current_me->me_list);
117         else
118                 list_add(&new_me->me_list, &current_me->me_list);
119
120         ptl_me2handle(handle, nal, new_me);
121
122         LIB_UNLOCK(nal, flags);
123
124         return PTL_OK;
125 }
126
127 int
128 lib_api_me_unlink (nal_t *apinal, ptl_handle_me_t *meh)
129 {
130         lib_nal_t    *nal = apinal->nal_data;
131         unsigned long flags;
132         lib_me_t     *me;
133         int           rc;
134
135         LIB_LOCK(nal, flags);
136
137         me = ptl_handle2me(meh, nal);
138         if (me == NULL) {
139                 rc = PTL_ME_INVALID;
140         } else {
141                 lib_me_unlink(nal, me);
142                 rc = PTL_OK;
143         }
144
145         LIB_UNLOCK(nal, flags);
146
147         return (rc);
148 }
149
150 /* call with state_lock please */
151 void
152 lib_me_unlink(lib_nal_t *nal, lib_me_t *me)
153 {
154         list_del (&me->me_list);
155
156         if (me->md) {
157                 me->md->me = NULL;
158                 lib_md_unlink(nal, me->md);
159         }
160
161         lib_invalidate_handle (nal, &me->me_lh);
162         lib_me_free(nal, me);
163 }
164
165 #if 0
166 static void
167 lib_me_dump(lib_nal_t *nal, lib_me_t * me)
168 {
169         CWARN("Match Entry %p ("LPX64")\n", me,
170               me->me_lh.lh_cookie);
171
172         CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
173               me->match_bits, me->ignore_bits);
174
175         CWARN("\tMD\t= %p\n", me->md);
176         CWARN("\tprev\t= %p\n",
177               list_entry(me->me_list.prev, lib_me_t, me_list));
178         CWARN("\tnext\t= %p\n",
179               list_entry(me->me_list.next, lib_me_t, me_list));
180 }
181 #endif