1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Match Entry management routines
7 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
8 * Copyright (c) 2001-2002 Sandia National Laboratories
10 * This file is part of Lustre, http://www.sf.net/projects/lustre/
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.
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.
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.
29 # define DEBUG_SUBSYSTEM S_PORTALS
30 # include <linux/kp30.h>
33 #include <portals/lib-p30.h>
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)
44 lib_nal_t *nal = apinal->nal_data;
45 lib_ni_t *ni = &nal->libnal_ni;
46 lib_ptl_t *tbl = &ni->ni_portals;
50 if (portal >= tbl->size)
51 return PTL_PT_INDEX_INVALID;
53 /* Should check for valid matchid, but not yet */
55 me = lib_me_alloc (nal);
61 me->match_id = match_id;
62 me->match_bits = match_bits;
63 me->ignore_bits = ignore_bits;
67 lib_initialise_handle (nal, &me->me_lh, PTL_COOKIE_TYPE_ME);
69 if (pos == PTL_INS_AFTER)
70 list_add_tail(&me->me_list, &(tbl->tbl[portal]));
72 list_add(&me->me_list, &(tbl->tbl[portal]));
74 ptl_me2handle(handle, nal, me);
76 LIB_UNLOCK(nal, flags);
82 lib_api_me_insert(nal_t *apinal,
83 ptl_handle_me_t *current_meh,
84 ptl_process_id_t match_id,
85 ptl_match_bits_t match_bits,
86 ptl_match_bits_t ignore_bits,
87 ptl_unlink_t unlink, ptl_ins_pos_t pos,
88 ptl_handle_me_t *handle)
90 lib_nal_t *nal = apinal->nal_data;
95 new_me = lib_me_alloc (nal);
99 /* Should check for valid matchid, but not yet */
101 LIB_LOCK(nal, flags);
103 current_me = ptl_handle2me(current_meh, nal);
104 if (current_me == NULL) {
105 lib_me_free (nal, new_me);
107 LIB_UNLOCK(nal, flags);
108 return PTL_ME_INVALID;
111 new_me->match_id = match_id;
112 new_me->match_bits = match_bits;
113 new_me->ignore_bits = ignore_bits;
114 new_me->unlink = unlink;
117 lib_initialise_handle (nal, &new_me->me_lh, PTL_COOKIE_TYPE_ME);
119 if (pos == PTL_INS_AFTER)
120 list_add_tail(&new_me->me_list, ¤t_me->me_list);
122 list_add(&new_me->me_list, ¤t_me->me_list);
124 ptl_me2handle(handle, nal, new_me);
126 LIB_UNLOCK(nal, flags);
132 lib_api_me_unlink (nal_t *apinal, ptl_handle_me_t *meh)
134 lib_nal_t *nal = apinal->nal_data;
139 LIB_LOCK(nal, flags);
141 me = ptl_handle2me(meh, nal);
145 lib_me_unlink(nal, me);
149 LIB_UNLOCK(nal, flags);
154 /* call with state_lock please */
156 lib_me_unlink(lib_nal_t *nal, lib_me_t *me)
158 list_del (&me->me_list);
162 lib_md_unlink(nal, me->md);
165 lib_invalidate_handle (nal, &me->me_lh);
166 lib_me_free(nal, me);
171 lib_me_dump(lib_nal_t *nal, lib_me_t * me)
173 CWARN("Match Entry %p ("LPX64")\n", me,
174 me->me_lh.lh_cookie);
176 CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
177 me->match_bits, me->ignore_bits);
179 CWARN("\tMD\t= %p\n", me->md);
180 CWARN("\tprev\t= %p\n",
181 list_entry(me->me_list.prev, lib_me_t, me_list));
182 CWARN("\tnext\t= %p\n",
183 list_entry(me->me_list.next, lib_me_t, me_list));