-static int
-lnet_me_match_portal(lnet_portal_t *ptl, lnet_process_id_t id,
- __u64 match_bits, __u64 ignore_bits)
-{
- cfs_list_t *mhash = NULL;
- int unique;
-
- LASSERT (!(lnet_portal_is_unique(ptl) &&
- lnet_portal_is_wildcard(ptl)));
-
- /* prefer to check w/o any lock */
- unique = lnet_match_is_unique(id, match_bits, ignore_bits);
- if (likely(lnet_portal_is_unique(ptl) ||
- lnet_portal_is_wildcard(ptl)))
- goto match;
-
- /* unset, new portal */
- if (unique) {
- mhash = lnet_portal_mhash_alloc();
- if (mhash == NULL)
- return -ENOMEM;
- }
-
- LNET_LOCK();
- if (lnet_portal_is_unique(ptl) ||
- lnet_portal_is_wildcard(ptl)) {
- /* someone set it before me */
- if (mhash != NULL)
- lnet_portal_mhash_free(mhash);
- LNET_UNLOCK();
- goto match;
- }
-
- /* still not set */
- LASSERT (ptl->ptl_mhash == NULL);
- if (unique) {
- ptl->ptl_mhash = mhash;
- lnet_portal_setopt(ptl, LNET_PTL_MATCH_UNIQUE);
- } else {
- lnet_portal_setopt(ptl, LNET_PTL_MATCH_WILDCARD);
- }
- LNET_UNLOCK();
- return 0;
-
- match:
- if (lnet_portal_is_unique(ptl) && !unique)
- return -EPERM;
-
- if (lnet_portal_is_wildcard(ptl) && unique)
- return -EPERM;
-
- return 0;
-}
-