Whamcloud - gitweb
Severity : major
[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_LNET
26
27 #include <lnet/lib-lnet.h>
28
29 int
30 LNetMEAttach(unsigned int portal,
31              lnet_process_id_t match_id, 
32              __u64 match_bits, __u64 ignore_bits,
33              lnet_unlink_t unlink, lnet_ins_pos_t pos, 
34              lnet_handle_me_t *handle)
35 {
36         lnet_me_t     *me;
37
38         LASSERT (the_lnet.ln_init);
39         LASSERT (the_lnet.ln_refcount > 0);
40         
41         if (portal >= the_lnet.ln_nportals)
42                 return -EINVAL;
43
44         me = lnet_me_alloc();
45         if (me == NULL)
46                 return -ENOMEM;
47
48         LNET_LOCK();
49
50         me->me_portal = portal;
51         me->me_match_id = match_id;
52         me->me_match_bits = match_bits;
53         me->me_ignore_bits = ignore_bits;
54         me->me_unlink = unlink;
55         me->me_md = NULL;
56
57         lnet_initialise_handle (&me->me_lh, LNET_COOKIE_TYPE_ME);
58
59         if (pos == LNET_INS_AFTER)
60                 list_add_tail(&me->me_list, &(the_lnet.ln_portals[portal].ptl_ml));
61         else
62                 list_add(&me->me_list, &(the_lnet.ln_portals[portal].ptl_ml));
63
64         lnet_me2handle(handle, me);
65
66         LNET_UNLOCK();
67
68         return 0;
69 }
70
71 int 
72 LNetMEInsert(lnet_handle_me_t current_meh, 
73              lnet_process_id_t match_id, 
74              __u64 match_bits, __u64 ignore_bits,
75              lnet_unlink_t unlink, lnet_ins_pos_t pos,
76              lnet_handle_me_t *handle)
77 {
78         lnet_me_t     *current_me;
79         lnet_me_t     *new_me;
80
81         LASSERT (the_lnet.ln_init);        
82         LASSERT (the_lnet.ln_refcount > 0);
83         
84         new_me = lnet_me_alloc();
85         if (new_me == NULL)
86                 return -ENOMEM;
87
88         LNET_LOCK();
89
90         current_me = lnet_handle2me(&current_meh);
91         if (current_me == NULL) {
92                 lnet_me_free (new_me);
93
94                 LNET_UNLOCK();
95                 return -ENOENT;
96         }
97
98         new_me->me_match_id = match_id;
99         new_me->me_match_bits = match_bits;
100         new_me->me_ignore_bits = ignore_bits;
101         new_me->me_unlink = unlink;
102         new_me->me_md = NULL;
103
104         lnet_initialise_handle (&new_me->me_lh, LNET_COOKIE_TYPE_ME);
105
106         if (pos == LNET_INS_AFTER)
107                 list_add_tail(&new_me->me_list, &current_me->me_list);
108         else
109                 list_add(&new_me->me_list, &current_me->me_list);
110
111         lnet_me2handle(handle, new_me);
112
113         LNET_UNLOCK();
114
115         return 0;
116 }
117
118 int
119 LNetMEUnlink(lnet_handle_me_t meh)
120 {
121         lnet_me_t     *me;
122         int           rc;
123
124         LASSERT (the_lnet.ln_init);        
125         LASSERT (the_lnet.ln_refcount > 0);
126         
127         LNET_LOCK();
128
129         me = lnet_handle2me(&meh);
130         if (me == NULL) {
131                 rc = -ENOENT;
132         } else {
133                 lnet_me_unlink(me);
134                 rc = 0;
135         }
136
137         LNET_UNLOCK();
138
139         return (rc);
140 }
141
142 /* call with LNET_LOCK please */
143 void
144 lnet_me_unlink(lnet_me_t *me)
145 {
146         list_del (&me->me_list);
147
148         if (me->me_md) {
149                 me->me_md->md_me = NULL;
150                 lnet_md_unlink(me->me_md);
151         }
152
153         lnet_invalidate_handle (&me->me_lh);
154         lnet_me_free(me);
155 }
156
157 #if 0
158 static void
159 lib_me_dump(lnet_me_t *me)
160 {
161         CWARN("Match Entry %p ("LPX64")\n", me,
162               me->me_lh.lh_cookie);
163
164         CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
165               me->me_match_bits, me->me_ignore_bits);
166
167         CWARN("\tMD\t= %p\n", me->md);
168         CWARN("\tprev\t= %p\n",
169               list_entry(me->me_list.prev, lnet_me_t, me_list));
170         CWARN("\tnext\t= %p\n",
171               list_entry(me->me_list.next, lnet_me_t, me_list));
172 }
173 #endif