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>
34 #include <portals/arg-blocks.h>
36 static void lib_me_dump(nal_cb_t * nal, lib_me_t * me);
38 int do_PtlMEAttach(nal_cb_t * nal, void *private, void *v_args, void *v_ret)
40 PtlMEAttach_in *args = v_args;
41 PtlMEAttach_out *ret = v_ret;
42 lib_ni_t *ni = &nal->ni;
43 lib_ptl_t *tbl = &ni->tbl;
47 if (args->index_in < 0 || args->index_in >= tbl->size)
48 return ret->rc = PTL_INV_PTINDEX;
50 /* Should check for valid matchid, but not yet */
52 return ret->rc = PTL_INV_PROC;
54 me = lib_me_alloc (nal);
56 return (ret->rc = PTL_NOSPACE);
58 state_lock(nal, &flags);
60 me->match_id = args->match_id_in;
61 me->match_bits = args->match_bits_in;
62 me->ignore_bits = args->ignore_bits_in;
63 me->unlink = args->unlink_in;
66 lib_initialise_handle (nal, &me->me_lh, PTL_COOKIE_TYPE_ME);
68 if (args->position_in == PTL_INS_AFTER)
69 list_add_tail(&me->me_list, &(tbl->tbl[args->index_in]));
71 list_add(&me->me_list, &(tbl->tbl[args->index_in]));
73 ptl_me2handle(&ret->handle_out, me);
75 state_unlock(nal, &flags);
77 return ret->rc = PTL_OK;
80 int do_PtlMEInsert(nal_cb_t * nal, void *private, void *v_args, void *v_ret)
82 PtlMEInsert_in *args = v_args;
83 PtlMEInsert_out *ret = v_ret;
88 new = lib_me_alloc (nal);
90 return (ret->rc = PTL_NOSPACE);
92 /* Should check for valid matchid, but not yet */
94 state_lock(nal, &flags);
96 me = ptl_handle2me(&args->current_in, nal);
98 lib_me_free (nal, new);
100 state_unlock (nal, &flags);
101 return (ret->rc = PTL_INV_ME);
104 new->match_id = args->match_id_in;
105 new->match_bits = args->match_bits_in;
106 new->ignore_bits = args->ignore_bits_in;
107 new->unlink = args->unlink_in;
110 lib_initialise_handle (nal, &new->me_lh, PTL_COOKIE_TYPE_ME);
112 if (args->position_in == PTL_INS_AFTER)
113 list_add_tail(&new->me_list, &me->me_list);
115 list_add(&new->me_list, &me->me_list);
117 ptl_me2handle(&ret->handle_out, new);
119 state_unlock(nal, &flags);
121 return ret->rc = PTL_OK;
124 int do_PtlMEUnlink(nal_cb_t * nal, void *private, void *v_args, void *v_ret)
126 PtlMEUnlink_in *args = v_args;
127 PtlMEUnlink_out *ret = v_ret;
131 state_lock(nal, &flags);
133 me = ptl_handle2me(&args->current_in, nal);
135 ret->rc = PTL_INV_ME;
137 lib_me_unlink(nal, me);
141 state_unlock(nal, &flags);
146 /* call with state_lock please */
147 void lib_me_unlink(nal_cb_t *nal, lib_me_t *me)
149 lib_ni_t *ni = &nal->ni;
151 if (ni->debug & PTL_DEBUG_UNLINK) {
152 ptl_handle_any_t handle;
153 ptl_me2handle(&handle, me);
156 list_del (&me->me_list);
160 lib_md_unlink(nal, me->md);
163 lib_invalidate_handle (nal, &me->me_lh);
164 lib_me_free(nal, me);
167 int do_PtlTblDump(nal_cb_t * nal, void *private, void *v_args, void *v_ret)
169 PtlTblDump_in *args = v_args;
170 PtlTblDump_out *ret = v_ret;
171 lib_ptl_t *tbl = &nal->ni.tbl;
172 ptl_handle_any_t handle;
173 struct list_head *tmp;
176 if (args->index_in < 0 || args->index_in >= tbl->size)
177 return ret->rc = PTL_INV_PTINDEX;
179 nal->cb_printf(nal, "Portal table index %d\n", args->index_in);
181 state_lock(nal, &flags);
182 list_for_each(tmp, &(tbl->tbl[args->index_in])) {
183 lib_me_t *me = list_entry(tmp, lib_me_t, me_list);
184 ptl_me2handle(&handle, me);
185 lib_me_dump(nal, me);
187 state_unlock(nal, &flags);
189 return ret->rc = PTL_OK;
192 int do_PtlMEDump(nal_cb_t * nal, void *private, void *v_args, void *v_ret)
194 PtlMEDump_in *args = v_args;
195 PtlMEDump_out *ret = v_ret;
199 state_lock(nal, &flags);
201 me = ptl_handle2me(&args->current_in, nal);
203 ret->rc = PTL_INV_ME;
205 lib_me_dump(nal, me);
209 state_unlock(nal, &flags);
214 static void lib_me_dump(nal_cb_t * nal, lib_me_t * me)
216 nal->cb_printf(nal, "Match Entry %p ("LPX64")\n", me,
217 me->me_lh.lh_cookie);
219 nal->cb_printf(nal, "\tMatch/Ignore\t= %016lx / %016lx\n",
220 me->match_bits, me->ignore_bits);
222 nal->cb_printf(nal, "\tMD\t= %p\n", me->md);
223 nal->cb_printf(nal, "\tprev\t= %p\n",
224 list_entry(me->me_list.prev, lib_me_t, me_list));
225 nal->cb_printf(nal, "\tnext\t= %p\n",
226 list_entry(me->me_list.next, lib_me_t, me_list));