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.
9 * This file is part of Lustre, http://www.lustre.org
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.
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.
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.
28 # define DEBUG_SUBSYSTEM S_PORTALS
29 # include <linux/kp30.h>
32 #include <portals/lib-p30.h>
35 lib_api_me_attach(nal_t *apinal,
36 ptl_pt_index_t portal,
37 ptl_process_id_t match_id,
38 ptl_match_bits_t match_bits,
39 ptl_match_bits_t ignore_bits,
40 ptl_unlink_t unlink, ptl_ins_pos_t pos,
41 ptl_handle_me_t *handle)
43 lib_nal_t *nal = apinal->nal_data;
44 lib_ni_t *ni = &nal->libnal_ni;
45 lib_ptl_t *tbl = &ni->ni_portals;
49 if (portal >= tbl->size)
50 return PTL_PT_INDEX_INVALID;
52 me = lib_me_alloc (nal);
58 me->match_id = match_id;
59 me->match_bits = match_bits;
60 me->ignore_bits = ignore_bits;
64 lib_initialise_handle (nal, &me->me_lh, PTL_COOKIE_TYPE_ME);
66 if (pos == PTL_INS_AFTER)
67 list_add_tail(&me->me_list, &(tbl->tbl[portal]));
69 list_add(&me->me_list, &(tbl->tbl[portal]));
71 ptl_me2handle(handle, nal, me);
73 LIB_UNLOCK(nal, flags);
79 lib_api_me_insert(nal_t *apinal,
80 ptl_handle_me_t *current_meh,
81 ptl_process_id_t match_id,
82 ptl_match_bits_t match_bits,
83 ptl_match_bits_t ignore_bits,
84 ptl_unlink_t unlink, ptl_ins_pos_t pos,
85 ptl_handle_me_t *handle)
87 lib_nal_t *nal = apinal->nal_data;
92 new_me = lib_me_alloc (nal);
98 current_me = ptl_handle2me(current_meh, nal);
99 if (current_me == NULL) {
100 lib_me_free (nal, new_me);
102 LIB_UNLOCK(nal, flags);
103 return PTL_ME_INVALID;
106 new_me->match_id = match_id;
107 new_me->match_bits = match_bits;
108 new_me->ignore_bits = ignore_bits;
109 new_me->unlink = unlink;
112 lib_initialise_handle (nal, &new_me->me_lh, PTL_COOKIE_TYPE_ME);
114 if (pos == PTL_INS_AFTER)
115 list_add_tail(&new_me->me_list, ¤t_me->me_list);
117 list_add(&new_me->me_list, ¤t_me->me_list);
119 ptl_me2handle(handle, nal, new_me);
121 LIB_UNLOCK(nal, flags);
127 lib_api_me_unlink (nal_t *apinal, ptl_handle_me_t *meh)
129 lib_nal_t *nal = apinal->nal_data;
134 LIB_LOCK(nal, flags);
136 me = ptl_handle2me(meh, nal);
140 lib_me_unlink(nal, me);
144 LIB_UNLOCK(nal, flags);
149 /* call with state_lock please */
151 lib_me_unlink(lib_nal_t *nal, lib_me_t *me)
153 list_del (&me->me_list);
157 lib_md_unlink(nal, me->md);
160 lib_invalidate_handle (nal, &me->me_lh);
161 lib_me_free(nal, me);
166 lib_me_dump(lib_nal_t *nal, lib_me_t * me)
168 CWARN("Match Entry %p ("LPX64")\n", me,
169 me->me_lh.lh_cookie);
171 CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
172 me->match_bits, me->ignore_bits);
174 CWARN("\tMD\t= %p\n", me->md);
175 CWARN("\tprev\t= %p\n",
176 list_entry(me->me_list.prev, lib_me_t, me_list));
177 CWARN("\tnext\t= %p\n",
178 list_entry(me->me_list.next, lib_me_t, me_list));