static RbtHandle findrec(char *key) { RbtHandle handle; handle = rbtFind(rbconf, key); if (handle == rbtEnd(rbconf)) { /* Check if there's a clone pointer record */ char *clonekey, *p; clonekey = strdup(key); p = strchr(clonekey, '|'); if (p && *(p+1)) { *p = '='; *(p+1) = '\0'; } handle = rbtFind(rbconf, clonekey); xfree(clonekey); if (handle != rbtEnd(rbconf)) { void *k1, *k2; char *pointsto; char *service; /* Get the origin record for this cloned record, using the same service name */ rbtKeyValue(rbconf, handle, &k1, &k2); pointsto = (char *)k2; service = strchr(key, '|'); if (service) service++; clonekey = (char *)malloc(strlen(pointsto) + strlen(service) + 2); sprintf(clonekey, "%s|%s", pointsto, service); handle = rbtFind(rbconf, clonekey); xfree(clonekey); } } return handle; }
char *knownhost(char *hostname, char *hostip, int ghosthandling) { /* * ghosthandling = 0 : Default BB method (case-sensitive, no logging, keep ghosts) * ghosthandling = 1 : Case-insensitive, no logging, drop ghosts * ghosthandling = 2 : Case-insensitive, log ghosts, drop ghosts */ RbtIterator hosthandle; namelist_t *walk = NULL; static char *result = NULL; void *k1, *k2; time_t now = getcurrenttime(NULL); if (result) xfree(result); result = NULL; /* Find the host in the normal hostname list */ hosthandle = rbtFind(rbhosts, hostname); if (hosthandle != rbtEnd(rbhosts)) { rbtKeyValue(rbhosts, hosthandle, &k1, &k2); walk = (namelist_t *)k2; } else { /* Not found - lookup in the client alias list */ hosthandle = rbtFind(rbclients, hostname); if (hosthandle != rbtEnd(rbclients)) { rbtKeyValue(rbclients, hosthandle, &k1, &k2); walk = (namelist_t *)k2; } } if (walk) { /* * Force our version of the hostname. Done here so CLIENT works always. */ strcpy(hostip, walk->ip); result = strdup(walk->bbhostname); } else { *hostip = '\0'; result = strdup(hostname); } /* If default method, just say yes */ if (ghosthandling == 0) return result; /* Allow all summaries */ if (strcmp(hostname, "summary") == 0) return result; if (walk && ( ((walk->notbefore > now) || (walk->notafter < now)) )) walk = NULL; return (walk ? result : NULL); }
int ofi_mr_insert(struct ofi_mr_map *map, const struct fi_mr_attr *attr, uint64_t *key, void *context) { struct fi_mr_attr *item; item = dup_mr_attr(attr); if (!item) return -FI_ENOMEM; if (!(map->mode & FI_MR_VIRT_ADDR)) item->offset = (uintptr_t) attr->mr_iov[0].iov_base; if (!(map->mode & FI_MR_PROV_KEY)) { if (rbtFind(map->rbtree, &item->requested_key)) { free(item); return -FI_ENOKEY; } } else { item->requested_key = map->key++; } rbtInsert(map->rbtree, &item->requested_key, item); *key = item->requested_key; item->context = context; return 0; }
static void locator_updatecache(enum locator_servicetype_t svc, char *key, char *resp) { RbtIterator handle; cacheitm_t *newitm; if (!havecache[svc]) return; handle = rbtFind(locatorcache[svc], key); if (handle == rbtEnd(locatorcache[svc])) { newitm = (cacheitm_t *)calloc(1, sizeof(cacheitm_t)); newitm->key = strdup(key); newitm->resp = strdup(resp); if (rbtInsert(locatorcache[svc], newitm->key, newitm) != RBT_STATUS_OK) { xfree(newitm->key); xfree(newitm->resp); xfree(newitm); } } else { newitm = (cacheitm_t *)gettreeitem(locatorcache[svc], handle); if (newitm->resp) xfree(newitm->resp); newitm->resp = strdup(resp); newitm->tstamp = getcurrenttime(NULL); } }
int ofi_mr_erase(struct ofi_util_mr * in_mr_h, uint64_t in_key) { void * itr; struct fi_mr_attr * item; if (!in_mr_h) return -FI_EINVAL; itr = rbtFind(in_mr_h->map_handle, &in_key); if (!itr) return -FI_ENOKEY; /*release memory */ rbtKeyValue(in_mr_h->map_handle, itr, (void **)&in_key, (void **) &item); assert(item); free((void *)item->mr_iov); free(item); rbtErase(in_mr_h->map_handle, itr); return 0; }
int ofi_mr_verify(struct ofi_mr_map *map, uintptr_t *io_addr, size_t len, uint64_t key, uint64_t access, void **context) { struct fi_mr_attr *attr; void *itr, *key_ptr, *addr; itr = rbtFind(map->rbtree, &key); if (!itr) return -FI_EINVAL; rbtKeyValue(map->rbtree, itr, &key_ptr, (void **) &attr); assert(attr); if ((access & attr->access) != access) { FI_DBG(map->prov, FI_LOG_MR, "verify_addr: invalid access\n"); return -FI_EACCES; } addr = (void *) (*io_addr + (uintptr_t) attr->offset); if ((addr < attr->mr_iov[0].iov_base) || (((char *) addr + len) > ((char *) attr->mr_iov[0].iov_base + attr->mr_iov[0].iov_len))) { return -FI_EACCES; } if (context) *context = attr->context; *io_addr = (uintptr_t) addr; return 0; }
int ofi_mr_insert(struct ofi_util_mr * in_mr_h, const struct fi_mr_attr *in_attr, uint64_t * out_key, void * in_prov_mr) { struct fi_mr_attr * item; if (!in_attr || in_attr->iov_count <= 0 || !in_prov_mr) { return -FI_EINVAL; } item = create_mr_attr_copy(in_attr, in_prov_mr); if (!item) return -FI_ENOMEM; /* Scalable MR handling: use requested key and offset */ if (in_mr_h->mr_type == FI_MR_SCALABLE) { item->offset = (uintptr_t) in_attr->mr_iov[0].iov_base + in_attr->offset; /* verify key doesn't already exist */ if (rbtFind(in_mr_h->map_handle, &item->requested_key)) { free((void *)item->mr_iov); free(item); return -FI_EINVAL; } } else { item->requested_key = get_mr_key(in_mr_h); item->offset = (uintptr_t) in_attr->mr_iov[0].iov_base; } rbtInsert(in_mr_h->map_handle, &item->requested_key, item); *out_key = item->requested_key; return 0; }
/* io_addr is address of buff (&buf) */ int ofi_mr_retrieve_and_verify(struct ofi_util_mr * in_mr_h, ssize_t in_len, uintptr_t *io_addr, uint64_t in_key, uint64_t in_access, void **out_prov_mr) { int ret = 0; void * itr; struct fi_mr_attr * item; void * key = &in_key; itr = rbtFind(in_mr_h->map_handle, key); if (!itr) return -FI_EINVAL; rbtKeyValue(in_mr_h->map_handle, itr, &key, (void **) &item); /*return providers MR struct */ if (!item || !io_addr) return -FI_EINVAL; if (out_prov_mr) (*out_prov_mr) = item->context; /*offset for scalable */ if (in_mr_h->mr_type == FI_MR_SCALABLE) *io_addr = (*io_addr) + item->offset; ret = verify_addr(in_mr_h, item, in_access, *io_addr, in_len); return ret; }
static int ofi_mr_rbt_storage_erase(struct ofi_mr_storage *storage, struct ofi_mr_entry *entry) { RbtIterator iter = rbtFind(storage->storage, &entry->iov); assert(iter); return (rbtErase((RbtHandle)storage->storage, iter) != RBT_STATUS_OK) ? -FI_EAVAIL : 0; }
static link_t *find_link(char *key) { link_t *l = NULL; RbtIterator handle; handle = rbtFind(linkstree, key); if (handle != rbtEnd(linkstree)) l = (link_t *)gettreeitem(linkstree, handle); return l; }
int delete_nkconfig(char *dropkey, int evenifcloned) { RbtHandle handle; void *k1, *k2; handle = rbtFind(rbconf, dropkey); if (handle == rbtEnd(rbconf)) return 0; if (!evenifcloned) { /* Check if this record has any clones attached to it */ char *hostname, *p; hostname = strdup(dropkey); p = strchr(hostname, '|'); if (p) *p = '\0'; handle = rbtBegin(rbconf); while (handle != rbtEnd(rbconf)) { void *k1, *k2; char *key, *ptr; rbtKeyValue(rbconf, handle, &k1, &k2); key = (char *)k1; ptr = (char *)k2; if ((*(key + strlen(key) - 1) == '=') && (strcmp(hostname, ptr) == 0)) { xfree(hostname); return 1; } handle = rbtNext(rbconf, handle); } xfree(hostname); } handle = rbtFind(rbconf, dropkey); if (handle != rbtEnd(rbconf)) { rbtKeyValue(rbconf, handle, &k1, &k2); rbtErase(rbconf, handle); flushrec(k1, k2); } return 0; }
static inline void psmx_mr_release_key(struct psmx_fid_domain *domain, uint64_t key) { RbtIterator it; fastlock_acquire(&domain->mr_lock); it = rbtFind(domain->mr_map, (void *)key); if (it) rbtErase(domain->mr_map, it); fastlock_release(&domain->mr_lock); }
static struct ofi_mr_entry *ofi_mr_rbt_storage_find(struct ofi_mr_storage *storage, const struct iovec *key) { struct ofi_mr_entry *entry; RbtIterator iter = rbtFind((RbtHandle)storage->storage, (void *)key); if (OFI_UNLIKELY(!iter)) return iter; rbtKeyValue(storage->storage, iter, (void *)&key, (void *)&entry); return entry; }
void addclone_nkconfig(char *origin, char *newclone) { char *newkey; RbtHandle handle; newkey = (char *)malloc(strlen(newclone) + 2); sprintf(newkey, "%s=", newclone); handle = rbtFind(rbconf, newkey); if (handle != rbtEnd(rbconf)) dropclone_nkconfig(newclone); rbtInsert(rbconf, newkey, strdup(origin)); }
void *ofi_mr_get(struct ofi_mr_map *map, uint64_t key) { struct fi_mr_attr *attr; void *itr, *key_ptr; itr = rbtFind(map->rbtree, &key); if (!itr) return NULL; rbtKeyValue(map->rbtree, itr, &key_ptr, (void **) &attr); return attr->context; }
struct psmx_fid_mr *psmx_mr_get(struct psmx_fid_domain *domain, uint64_t key) { RbtIterator it; struct psmx_fid_mr *mr; it = rbtFind(domain->mr_map, (void *)key); if (!it) return NULL; rbtKeyValue(domain->mr_map, it, (void **)&key, (void **)&mr); return mr; }
struct sock_mr *sock_mr_get_entry(struct sock_domain *domain, uint64_t key) { RbtIterator it; void *value; void *mr_key = &key; it = rbtFind(domain->mr_heap, mr_key); if (!it) return NULL; rbtKeyValue(domain->mr_heap, it, &mr_key, &value); return (struct sock_mr *) value; }
static char *locator_querycache(enum locator_servicetype_t svc, char *key) { RbtIterator handle; cacheitm_t *itm; if (!havecache[svc]) return NULL; handle = rbtFind(locatorcache[svc], key); if (handle == rbtEnd(locatorcache[svc])) return NULL; itm = (cacheitm_t *)gettreeitem(locatorcache[svc], handle); return (itm->tstamp + cachetimeout[svc]) > getcurrenttime(NULL) ? itm->resp : NULL; }
int tex_cache_free(int imgid) { KeyType key = imgid; NodeType *p; tex_node_p tex_node; if ((p = rbtFind(rb,key)) != NULL) { tex_node = (tex_node_p)(p->val.node); tex_node->next = free_tex_list; free_tex_list = tex_node; rbtErase(rb,p); return 1; } return 0; }
void * ofi_mr_retrieve(struct ofi_util_mr * in_mr_h, uint64_t in_key) { void * itr; struct fi_mr_attr * item; void * key = &in_key; itr = rbtFind(in_mr_h->map_handle, key); if (!itr) return NULL; rbtKeyValue(in_mr_h->map_handle, itr, (void **)&key, (void **) &item); return item->context; }
static int psmx_ns_map_lookup(int *service, psm_epid_t *name_out) { RbtIterator it; void *key; it = rbtFind(psmx_ns_map, (void *)(uintptr_t)(*service)); if (!it) return -FI_ENOENT; rbtKeyValue(psmx_ns_map, it, &key, (void **)name_out); if (*service == PSMX_ANY_SERVICE) *service = (uintptr_t)key; return 0; }
int ofi_mr_remove(struct ofi_mr_map *map, uint64_t key) { struct fi_mr_attr *attr; void *itr, *key_ptr; itr = rbtFind(map->rbtree, &key); if (!itr) return -FI_ENOKEY; rbtKeyValue(map->rbtree, itr, &key_ptr, (void **) &attr); rbtErase(map->rbtree, itr); free(attr); return 0; }
static int psmx_ns_map_add(int service, psm_epid_t name) { if (rbtFind(psmx_ns_map, (void *)(uintptr_t)service)) { FI_WARN(&psmx_prov, FI_LOG_CORE, "failed to add address: service %u already in use.\n", service); return -FI_EBUSY; } if (rbtInsert(psmx_ns_map, (void *)(uintptr_t)service, (void *)name)) { FI_WARN(&psmx_prov, FI_LOG_CORE, "failed to add address for service %u: out of memory.\n", service); return -FI_ENOMEM; } return 0; }
static int util_ns_map_lookup(struct util_ns *ns, void *service_in, void *name_out) { RbtIterator it; void *key, *name; it = rbtFind(ns->ns_map, service_in); if (!it) return -FI_ENOENT; rbtKeyValue(ns->ns_map, it, &key, (void **)&name); memcpy(name_out, name, ns->name_len); if (ns->is_service_wildcard && ns->is_service_wildcard(service_in)) memcpy(service_in, key, ns->service_len); return FI_SUCCESS; }
void dropclone_nkconfig(char *drop) { RbtHandle handle; char *key; void *k1, *k2; char *dropkey, *dropsrc; key = (char *)malloc(strlen(drop) + 2); sprintf(key, "%s=", drop); handle = rbtFind(rbconf, key); if (handle == rbtEnd(rbconf)) return; rbtKeyValue(rbconf, handle, &k1, &k2); dropkey = k1; dropsrc = k2; rbtErase(rbconf, handle); xfree(dropkey); xfree(dropsrc); xfree(key); }
static void psmx_ns_map_del(int service, psm_epid_t name_in) { RbtIterator it; void *key; psm_epid_t name; it = rbtFind(psmx_ns_map, (void *)(uintptr_t)service); if (it) { rbtKeyValue(psmx_ns_map, it, &key, (void **)&name); if (name != name_in) { FI_WARN(&psmx_prov, FI_LOG_CORE, "failed to delete address for service %u: " "expecting <%lx>, got <%lx>.\n", service, name_in, name); return; } rbtErase(psmx_ns_map, it); } }
void *hostinfo(char *hostname) { RbtIterator hosthandle; namelist_t *result = NULL; time_t now = getcurrenttime(NULL); if (!configloaded) load_hostnames(xgetenv("BBHOSTS"), NULL, get_fqdn()); hosthandle = rbtFind(rbhosts, hostname); if (hosthandle != rbtEnd(rbhosts)) { void *k1, *k2; rbtKeyValue(rbhosts, hosthandle, &k1, &k2); result = (namelist_t *)k2; if ((result->notbefore > now) || (result->notafter < now)) return NULL; } return result; }
void locator_flushcache(enum locator_servicetype_t svc, char *key) { RbtIterator handle; if (!havecache[svc]) return; if (key) { handle = rbtFind(locatorcache[svc], key); if (handle != rbtEnd(locatorcache[svc])) { cacheitm_t *itm = (cacheitm_t *)gettreeitem(locatorcache[svc], handle); itm->tstamp = 0; } } else { for (handle = rbtBegin(locatorcache[svc]); (handle != rbtEnd(locatorcache[svc])); handle = rbtNext(locatorcache[svc], handle)) { cacheitm_t *itm = (cacheitm_t *)gettreeitem(locatorcache[svc], handle); itm->tstamp = 0; } } }
static int util_ns_map_del(struct util_ns *ns, void *service_in, void *name_in) { RbtIterator it; int ret = -FI_ENOENT; void *service, *name; it = rbtFind(ns->ns_map, service_in); if (it) { rbtKeyValue(ns->ns_map, it, &service, &name); if (memcmp(name, name_in, ns->name_len)) return ret; free(service); free(name); rbtErase(ns->ns_map, it); ret = FI_SUCCESS; } return ret; }
static int sock_mr_close(struct fid *fid) { struct sock_domain *dom; struct sock_mr *mr; RbtIterator it; RbtStatus res; uint64_t mr_key; mr = container_of(fid, struct sock_mr, mr_fid.fid); dom = mr->domain; mr_key = mr->key; fastlock_acquire(&dom->lock); it = rbtFind(dom->mr_heap, &mr_key); if (!it || ((res = rbtErase(dom->mr_heap, it)) != RBT_STATUS_OK)) SOCK_LOG_ERROR("Invalid mr\n"); fastlock_release(&dom->lock); atomic_dec(&dom->ref); free(mr); return 0; }