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 >= tbl->size)
48 return ret->rc = PTL_PT_INDEX_INVALID;
50 /* Should check for valid matchid, but not yet */
52 return ret->rc = PTL_PROCESS_INVALID;
54 me = lib_me_alloc (nal);
56 return (ret->rc = PTL_NO_SPACE);
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_NO_SPACE);
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_ME_INVALID);
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_ME_INVALID;
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 list_del (&me->me_list);
153 lib_md_unlink(nal, me->md);
156 lib_invalidate_handle (nal, &me->me_lh);
157 lib_me_free(nal, me);
160 int do_PtlTblDump(nal_cb_t * nal, void *private, void *v_args, void *v_ret)
162 PtlTblDump_in *args = v_args;
163 PtlTblDump_out *ret = v_ret;
164 lib_ptl_t *tbl = &nal->ni.tbl;
165 ptl_handle_any_t handle;
166 struct list_head *tmp;
169 if (args->index_in < 0 || args->index_in >= tbl->size)
170 return ret->rc = PTL_PT_INDEX_INVALID;
172 nal->cb_printf(nal, "Portal table index %d\n", args->index_in);
174 state_lock(nal, &flags);
175 list_for_each(tmp, &(tbl->tbl[args->index_in])) {
176 lib_me_t *me = list_entry(tmp, lib_me_t, me_list);
177 ptl_me2handle(&handle, me);
178 lib_me_dump(nal, me);
180 state_unlock(nal, &flags);
182 return ret->rc = PTL_OK;
185 int do_PtlMEDump(nal_cb_t * nal, void *private, void *v_args, void *v_ret)
187 PtlMEDump_in *args = v_args;
188 PtlMEDump_out *ret = v_ret;
192 state_lock(nal, &flags);
194 me = ptl_handle2me(&args->current_in, nal);
196 ret->rc = PTL_ME_INVALID;
198 lib_me_dump(nal, me);
202 state_unlock(nal, &flags);
207 static void lib_me_dump(nal_cb_t * nal, lib_me_t * me)
209 nal->cb_printf(nal, "Match Entry %p ("LPX64")\n", me,
210 me->me_lh.lh_cookie);
212 nal->cb_printf(nal, "\tMatch/Ignore\t= %016lx / %016lx\n",
213 me->match_bits, me->ignore_bits);
215 nal->cb_printf(nal, "\tMD\t= %p\n", me->md);
216 nal->cb_printf(nal, "\tprev\t= %p\n",
217 list_entry(me->me_list.prev, lib_me_t, me_list));
218 nal->cb_printf(nal, "\tnext\t= %p\n",
219 list_entry(me->me_list.next, lib_me_t, me_list));