/** * __eblob_l2hash_lookup() - internal function that walks @l2h->root * tree using eblob_l2hash_key(@key) as key. * * Returns pointer to tree entry on success or NULL if node with matching @key * was not found. */ static struct eblob_l2hash_entry * __eblob_l2hash_lookup(struct eblob_l2hash *l2h, struct eblob_key *key) { struct rb_node *n; assert(l2h != NULL); assert(key != NULL); assert(pthread_mutex_trylock(&l2h->root_lock) == EBUSY); if ((n = __eblob_l2hash_noncollision_walk(&l2h->root, key, NULL, NULL)) == NULL) return NULL; return rb_entry(n, struct eblob_l2hash_entry, node); }
/** * __eblob_l2hash_lookup() - internal function that walks @l2h->root * tree using eblob_l2hash_key(@key) as key. * * Returns pointer to tree entry on success or NULL if node with matching @key * was not found. */ static struct eblob_l2hash_entry * __eblob_l2hash_lookup(struct eblob_l2hash *l2h, const struct eblob_key *key) { struct rb_node *n; assert(l2h != NULL); assert(key != NULL); if ((n = __eblob_l2hash_noncollision_walk(&l2h->root, key, NULL, NULL)) == NULL) return NULL; return rb_entry(n, struct eblob_l2hash_entry, node); }
/** * __eblob_l2hash_noncollision_insert() - inserts entry in l2hash tree */ static int __eblob_l2hash_noncollision_insert(struct rb_root *root, struct eblob_key *key, struct eblob_ram_control *rctl) { struct eblob_l2hash_entry *e; struct rb_node *n, *parent, **node; n = __eblob_l2hash_noncollision_walk(root, key, &parent, &node); if (n != NULL) return -EEXIST; e = calloc(1, sizeof(struct eblob_l2hash_entry)); if (e == NULL) return -ENOMEM; e->l2key = eblob_l2hash_key(key); e->rctl = *rctl; rb_link_node(&e->node, parent, node); rb_insert_color(&e->node, root); return 0; }