sinclude(build.m4)
sinclude(archdep.m4)
-sinclude<portalsconf.m4)
+sinclude(portalsconf.m4)
if test x$enable_inkernel = xyes ; then
cp Kernelenv.mk Kernelenv.in
}
#endif
-extern lib_handle_t *lib_lookup_cookie (nal_cb_t *nal, __u64 cookie);
-extern void lib_initialise_handle (nal_cb_t *nal, lib_handle_t *lh);
+extern lib_handle_t *lib_lookup_cookie (nal_cb_t *nal, __u64 cookie, int type);
+extern void lib_initialise_handle (nal_cb_t *nal, lib_handle_t *lh, int type);
extern void lib_invalidate_handle (nal_cb_t *nal, lib_handle_t *lh);
static inline void
ptl_handle2eq (ptl_handle_eq_t *handle, nal_cb_t *nal)
{
/* ALWAYS called with statelock held */
- lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie);
-
+ lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie,
+ PTL_COOKIE_TYPE_EQ);
if (lh == NULL)
return (NULL);
ptl_handle2md (ptl_handle_md_t *handle, nal_cb_t *nal)
{
/* ALWAYS called with statelock held */
- lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie);
-
+ lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie,
+ PTL_COOKIE_TYPE_MD);
if (lh == NULL)
return (NULL);
if (wh->wh_interface_cookie != nal->ni.ni_interface_cookie)
return (NULL);
- lh = lib_lookup_cookie (nal, wh->wh_object_cookie);
+ lh = lib_lookup_cookie (nal, wh->wh_object_cookie,
+ PTL_COOKIE_TYPE_MD);
if (lh == NULL)
return (NULL);
ptl_handle2me (ptl_handle_me_t *handle, nal_cb_t *nal)
{
/* ALWAYS called with statelock held */
- lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie);
-
+ lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie,
+ PTL_COOKIE_TYPE_ME);
if (lh == NULL)
return (NULL);
}
#endif
-extern lib_handle_t *lib_lookup_cookie (nal_cb_t *nal, __u64 cookie);
-extern void lib_initialise_handle (nal_cb_t *nal, lib_handle_t *lh);
+extern lib_handle_t *lib_lookup_cookie (nal_cb_t *nal, __u64 cookie, int type);
+extern void lib_initialise_handle (nal_cb_t *nal, lib_handle_t *lh, int type);
extern void lib_invalidate_handle (nal_cb_t *nal, lib_handle_t *lh);
static inline void
ptl_handle2eq (ptl_handle_eq_t *handle, nal_cb_t *nal)
{
/* ALWAYS called with statelock held */
- lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie);
-
+ lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie,
+ PTL_COOKIE_TYPE_EQ);
if (lh == NULL)
return (NULL);
ptl_handle2md (ptl_handle_md_t *handle, nal_cb_t *nal)
{
/* ALWAYS called with statelock held */
- lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie);
-
+ lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie,
+ PTL_COOKIE_TYPE_MD);
if (lh == NULL)
return (NULL);
if (wh->wh_interface_cookie != nal->ni.ni_interface_cookie)
return (NULL);
- lh = lib_lookup_cookie (nal, wh->wh_object_cookie);
+ lh = lib_lookup_cookie (nal, wh->wh_object_cookie,
+ PTL_COOKIE_TYPE_MD);
if (lh == NULL)
return (NULL);
ptl_handle2me (ptl_handle_me_t *handle, nal_cb_t *nal)
{
/* ALWAYS called with statelock held */
- lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie);
-
+ lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie,
+ PTL_COOKIE_TYPE_ME);
if (lh == NULL)
return (NULL);
unsigned int tp_threshold; /* # failures to simulate */
} lib_test_peer_t;
+#define PTL_COOKIE_TYPE_MD 1
+#define PTL_COOKIE_TYPE_ME 2
+#define PTL_COOKIE_TYPE_EQ 3
+#define PTL_COOKIE_TYPES 4
+/* PTL_COOKIE_TYPES must be a power of 2, so the cookie type can be
+ * extracted by masking with (PTL_COOKIE_TYPES - 1) */
+
typedef struct {
int up;
int refcnt;
#CFLAGS:= @KCFLAGS@
#CPPFLAGS:=@KCPPFLAGS@
DEFS =
+CPPFLAGS=@CPPFLAGS@ @with_quadrics@
kqswnal_SOURCES = qswnal.c qswnal_cb.c qswnal.h
#include <portals/api-support.h>
-#define MAX_NIS 8
+/* Put some magic in the NI handle so uninitialised/zeroed handles are easy
+ * to spot */
+#define NI_HANDLE_MAGIC 0xebc0de00
+#define NI_HANDLE_MASK 0x000000ff
+#define MAX_NIS 8
static nal_t *ptl_interfaces[MAX_NIS];
int ptl_num_interfaces = 0;
* setup/teardown. That ensures her NI handle can't get
* invalidated out from under her (or worse, swapped for a
* completely different interface!) */
-
+
+ if (((idx ^ NI_HANDLE_MAGIC) & ~NI_HANDLE_MASK) != 0)
+ return NULL;
+
+ idx &= NI_HANDLE_MASK;
if (idx < MAX_NIS)
return ptl_interfaces[idx];
{
int i;
+ LASSERT (MAX_NIS <= (NI_HANDLE_MASK + 1));
+
for (i = 0; i < MAX_NIS; i++)
ptl_interfaces[i] = NULL;
for (i = 0; i < ptl_num_interfaces; i++) {
if (ptl_interfaces[i] == nal) {
nal->refct++;
- handle->nal_idx = i;
+ handle->nal_idx = (NI_HANDLE_MAGIC & ~NI_HANDLE_MASK) | i;
fprintf(stderr, "Returning existing NAL (%d)\n", i);
ptl_ni_init_mutex_exit ();
return PTL_OK;
}
nal->refct = 1;
- handle->nal_idx = ptl_num_interfaces;
if (ptl_num_interfaces >= MAX_NIS) {
if (nal->shutdown)
nal->shutdown (nal, ptl_num_interfaces);
return PTL_NOSPACE;
}
+ handle->nal_idx = (NI_HANDLE_MAGIC & ~NI_HANDLE_MASK) | ptl_num_interfaces;
ptl_interfaces[ptl_num_interfaces++] = nal;
ptl_eq_ni_init(nal);
int PtlNIFini(ptl_handle_ni_t ni)
{
nal_t *nal;
+ int idx;
int rc;
if (!ptl_init)
return PTL_INV_HANDLE;
}
+ idx = ni.nal_idx & NI_HANDLE_MASK;
+
nal->refct--;
if (nal->refct > 0) {
ptl_ni_init_mutex_exit ();
rc = PTL_OK;
if (nal->shutdown)
- rc = nal->shutdown(nal, ni.nal_idx);
+ rc = nal->shutdown(nal, idx);
- ptl_interfaces[ni.nal_idx] = NULL;
+ ptl_interfaces[idx] = NULL;
ptl_num_interfaces--;
ptl_ni_init_mutex_exit ();
eq->eq_refcount = 0;
eq->event_callback = args->callback_in;
- lib_initialise_handle (nal, &eq->eq_lh);
+ lib_initialise_handle (nal, &eq->eq_lh, PTL_COOKIE_TYPE_EQ);
list_add (&eq->eq_list, &nal->ni.ni_active_eqs);
state_unlock(nal, &flags);
for (i = 0; i < ni->ni_lh_hash_size; i++)
INIT_LIST_HEAD (&ni->ni_lh_hash_table[i]);
- ni->ni_next_object_cookie = 0;
+ ni->ni_next_object_cookie = PTL_COOKIE_TYPES;
return (PTL_OK);
}
}
lib_handle_t *
-lib_lookup_cookie (nal_cb_t *nal, __u64 cookie)
+lib_lookup_cookie (nal_cb_t *nal, __u64 cookie, int type)
{
/* ALWAYS called with statelock held */
lib_ni_t *ni = &nal->ni;
struct list_head *el;
unsigned int hash;
+ if ((cookie & (PTL_COOKIE_TYPES - 1)) != type)
+ return (NULL);
+
hash = ((unsigned int)cookie) % ni->ni_lh_hash_size;
list = &ni->ni_lh_hash_table[hash];
}
void
-lib_initialise_handle (nal_cb_t *nal, lib_handle_t *lh)
+lib_initialise_handle (nal_cb_t *nal, lib_handle_t *lh, int type)
{
/* ALWAYS called with statelock held */
lib_ni_t *ni = &nal->ni;
unsigned int hash;
+
+ LASSERT (type >= 0 && type < PTL_COOKIE_TYPES);
+ lh->lh_cookie = ni->ni_next_object_cookie | type;
+ ni->ni_next_object_cookie += PTL_COOKIE_TYPES;
- lh->lh_cookie = ni->ni_next_object_cookie++;
hash = ((unsigned int)lh->lh_cookie) % ni->ni_lh_hash_size;
list_add (&lh->lh_hash_chain, &ni->ni_lh_hash_table[hash]);
}
eq->eq_refcount++;
/* It's good; let handle2md succeed and add to active mds */
- lib_initialise_handle (nal, &new->md_lh);
+ lib_initialise_handle (nal, &new->md_lh, PTL_COOKIE_TYPE_MD);
list_add (&new->md_list, &nal->ni.ni_active_mds);
return PTL_OK;
me->unlink = args->unlink_in;
me->md = NULL;
- lib_initialise_handle (nal, &me->me_lh);
+ lib_initialise_handle (nal, &me->me_lh, PTL_COOKIE_TYPE_ME);
if (args->position_in == PTL_INS_AFTER)
list_add_tail(&me->me_list, &(tbl->tbl[args->index_in]));
new->unlink = args->unlink_in;
new->md = NULL;
- lib_initialise_handle (nal, &new->me_lh);
+ lib_initialise_handle (nal, &new->me_lh, PTL_COOKIE_TYPE_ME);
if (args->position_in == PTL_INS_AFTER)
list_add_tail(&new->me_list, &me->me_list);
sinclude(build.m4)
sinclude(archdep.m4)
-sinclude<portalsconf.m4)
+sinclude(portalsconf.m4)
if test x$enable_inkernel = xyes ; then
cp Kernelenv.mk Kernelenv.in
}
#endif
-extern lib_handle_t *lib_lookup_cookie (nal_cb_t *nal, __u64 cookie);
-extern void lib_initialise_handle (nal_cb_t *nal, lib_handle_t *lh);
+extern lib_handle_t *lib_lookup_cookie (nal_cb_t *nal, __u64 cookie, int type);
+extern void lib_initialise_handle (nal_cb_t *nal, lib_handle_t *lh, int type);
extern void lib_invalidate_handle (nal_cb_t *nal, lib_handle_t *lh);
static inline void
ptl_handle2eq (ptl_handle_eq_t *handle, nal_cb_t *nal)
{
/* ALWAYS called with statelock held */
- lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie);
-
+ lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie,
+ PTL_COOKIE_TYPE_EQ);
if (lh == NULL)
return (NULL);
ptl_handle2md (ptl_handle_md_t *handle, nal_cb_t *nal)
{
/* ALWAYS called with statelock held */
- lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie);
-
+ lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie,
+ PTL_COOKIE_TYPE_MD);
if (lh == NULL)
return (NULL);
if (wh->wh_interface_cookie != nal->ni.ni_interface_cookie)
return (NULL);
- lh = lib_lookup_cookie (nal, wh->wh_object_cookie);
+ lh = lib_lookup_cookie (nal, wh->wh_object_cookie,
+ PTL_COOKIE_TYPE_MD);
if (lh == NULL)
return (NULL);
ptl_handle2me (ptl_handle_me_t *handle, nal_cb_t *nal)
{
/* ALWAYS called with statelock held */
- lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie);
-
+ lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie,
+ PTL_COOKIE_TYPE_ME);
if (lh == NULL)
return (NULL);
unsigned int tp_threshold; /* # failures to simulate */
} lib_test_peer_t;
+#define PTL_COOKIE_TYPE_MD 1
+#define PTL_COOKIE_TYPE_ME 2
+#define PTL_COOKIE_TYPE_EQ 3
+#define PTL_COOKIE_TYPES 4
+/* PTL_COOKIE_TYPES must be a power of 2, so the cookie type can be
+ * extracted by masking with (PTL_COOKIE_TYPES - 1) */
+
typedef struct {
int up;
int refcnt;
#CFLAGS:= @KCFLAGS@
#CPPFLAGS:=@KCPPFLAGS@
DEFS =
+CPPFLAGS=@CPPFLAGS@ @with_quadrics@
kqswnal_SOURCES = qswnal.c qswnal_cb.c qswnal.h
#include <portals/api-support.h>
-#define MAX_NIS 8
+/* Put some magic in the NI handle so uninitialised/zeroed handles are easy
+ * to spot */
+#define NI_HANDLE_MAGIC 0xebc0de00
+#define NI_HANDLE_MASK 0x000000ff
+#define MAX_NIS 8
static nal_t *ptl_interfaces[MAX_NIS];
int ptl_num_interfaces = 0;
* setup/teardown. That ensures her NI handle can't get
* invalidated out from under her (or worse, swapped for a
* completely different interface!) */
-
+
+ if (((idx ^ NI_HANDLE_MAGIC) & ~NI_HANDLE_MASK) != 0)
+ return NULL;
+
+ idx &= NI_HANDLE_MASK;
if (idx < MAX_NIS)
return ptl_interfaces[idx];
{
int i;
+ LASSERT (MAX_NIS <= (NI_HANDLE_MASK + 1));
+
for (i = 0; i < MAX_NIS; i++)
ptl_interfaces[i] = NULL;
for (i = 0; i < ptl_num_interfaces; i++) {
if (ptl_interfaces[i] == nal) {
nal->refct++;
- handle->nal_idx = i;
+ handle->nal_idx = (NI_HANDLE_MAGIC & ~NI_HANDLE_MASK) | i;
fprintf(stderr, "Returning existing NAL (%d)\n", i);
ptl_ni_init_mutex_exit ();
return PTL_OK;
}
nal->refct = 1;
- handle->nal_idx = ptl_num_interfaces;
if (ptl_num_interfaces >= MAX_NIS) {
if (nal->shutdown)
nal->shutdown (nal, ptl_num_interfaces);
return PTL_NOSPACE;
}
+ handle->nal_idx = (NI_HANDLE_MAGIC & ~NI_HANDLE_MASK) | ptl_num_interfaces;
ptl_interfaces[ptl_num_interfaces++] = nal;
ptl_eq_ni_init(nal);
int PtlNIFini(ptl_handle_ni_t ni)
{
nal_t *nal;
+ int idx;
int rc;
if (!ptl_init)
return PTL_INV_HANDLE;
}
+ idx = ni.nal_idx & NI_HANDLE_MASK;
+
nal->refct--;
if (nal->refct > 0) {
ptl_ni_init_mutex_exit ();
rc = PTL_OK;
if (nal->shutdown)
- rc = nal->shutdown(nal, ni.nal_idx);
+ rc = nal->shutdown(nal, idx);
- ptl_interfaces[ni.nal_idx] = NULL;
+ ptl_interfaces[idx] = NULL;
ptl_num_interfaces--;
ptl_ni_init_mutex_exit ();
eq->eq_refcount = 0;
eq->event_callback = args->callback_in;
- lib_initialise_handle (nal, &eq->eq_lh);
+ lib_initialise_handle (nal, &eq->eq_lh, PTL_COOKIE_TYPE_EQ);
list_add (&eq->eq_list, &nal->ni.ni_active_eqs);
state_unlock(nal, &flags);
for (i = 0; i < ni->ni_lh_hash_size; i++)
INIT_LIST_HEAD (&ni->ni_lh_hash_table[i]);
- ni->ni_next_object_cookie = 0;
+ ni->ni_next_object_cookie = PTL_COOKIE_TYPES;
return (PTL_OK);
}
}
lib_handle_t *
-lib_lookup_cookie (nal_cb_t *nal, __u64 cookie)
+lib_lookup_cookie (nal_cb_t *nal, __u64 cookie, int type)
{
/* ALWAYS called with statelock held */
lib_ni_t *ni = &nal->ni;
struct list_head *el;
unsigned int hash;
+ if ((cookie & (PTL_COOKIE_TYPES - 1)) != type)
+ return (NULL);
+
hash = ((unsigned int)cookie) % ni->ni_lh_hash_size;
list = &ni->ni_lh_hash_table[hash];
}
void
-lib_initialise_handle (nal_cb_t *nal, lib_handle_t *lh)
+lib_initialise_handle (nal_cb_t *nal, lib_handle_t *lh, int type)
{
/* ALWAYS called with statelock held */
lib_ni_t *ni = &nal->ni;
unsigned int hash;
+
+ LASSERT (type >= 0 && type < PTL_COOKIE_TYPES);
+ lh->lh_cookie = ni->ni_next_object_cookie | type;
+ ni->ni_next_object_cookie += PTL_COOKIE_TYPES;
- lh->lh_cookie = ni->ni_next_object_cookie++;
hash = ((unsigned int)lh->lh_cookie) % ni->ni_lh_hash_size;
list_add (&lh->lh_hash_chain, &ni->ni_lh_hash_table[hash]);
}
eq->eq_refcount++;
/* It's good; let handle2md succeed and add to active mds */
- lib_initialise_handle (nal, &new->md_lh);
+ lib_initialise_handle (nal, &new->md_lh, PTL_COOKIE_TYPE_MD);
list_add (&new->md_list, &nal->ni.ni_active_mds);
return PTL_OK;
me->unlink = args->unlink_in;
me->md = NULL;
- lib_initialise_handle (nal, &me->me_lh);
+ lib_initialise_handle (nal, &me->me_lh, PTL_COOKIE_TYPE_ME);
if (args->position_in == PTL_INS_AFTER)
list_add_tail(&me->me_list, &(tbl->tbl[args->index_in]));
new->unlink = args->unlink_in;
new->md = NULL;
- lib_initialise_handle (nal, &new->me_lh);
+ lib_initialise_handle (nal, &new->me_lh, PTL_COOKIE_TYPE_ME);
if (args->position_in == PTL_INS_AFTER)
list_add_tail(&new->me_list, &me->me_list);