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.
25 #define DEBUG_SUBSYSTEM S_PORTALS
30 # include <libcfs/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 me = lib_me_alloc (nal);
59 me->match_id = match_id;
60 me->match_bits = match_bits;
61 me->ignore_bits = ignore_bits;
65 lib_initialise_handle (nal, &me->me_lh, PTL_COOKIE_TYPE_ME);
67 if (pos == PTL_INS_AFTER)
68 list_add_tail(&me->me_list, &(tbl->tbl[portal]));
70 list_add(&me->me_list, &(tbl->tbl[portal]));
72 ptl_me2handle(handle, nal, me);
74 LIB_UNLOCK(nal, flags);
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)
88 lib_nal_t *nal = apinal->nal_data;
93 new_me = lib_me_alloc (nal);
99 current_me = ptl_handle2me(current_meh, nal);
100 if (current_me == NULL) {
101 lib_me_free (nal, new_me);
103 LIB_UNLOCK(nal, flags);
104 return PTL_ME_INVALID;
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;
113 lib_initialise_handle (nal, &new_me->me_lh, PTL_COOKIE_TYPE_ME);
115 if (pos == PTL_INS_AFTER)
116 list_add_tail(&new_me->me_list, ¤t_me->me_list);
118 list_add(&new_me->me_list, ¤t_me->me_list);
120 ptl_me2handle(handle, nal, new_me);
122 LIB_UNLOCK(nal, flags);
128 lib_api_me_unlink (nal_t *apinal, ptl_handle_me_t *meh)
130 lib_nal_t *nal = apinal->nal_data;
135 LIB_LOCK(nal, flags);
137 me = ptl_handle2me(meh, nal);
141 lib_me_unlink(nal, me);
145 LIB_UNLOCK(nal, flags);
150 /* call with state_lock please */
152 lib_me_unlink(lib_nal_t *nal, lib_me_t *me)
154 list_del (&me->me_list);
158 lib_md_unlink(nal, me->md);
161 lib_invalidate_handle (nal, &me->me_lh);
162 lib_me_free(nal, me);
167 lib_me_dump(lib_nal_t *nal, lib_me_t * me)
169 CWARN("Match Entry %p ("LPX64")\n", me,
170 me->me_lh.lh_cookie);
172 CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
173 me->match_bits, me->ignore_bits);
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));