Lines Matching refs:nscdb
429 hash_find(nsc_db_t *nscdb, nsc_entry_t *entry, uint_t *hash,
434 if (nscdb->gethash)
435 *hash = nscdb->gethash(&entry->key, nscdb->htsize);
439 hashentry = nscdb->htable[*hash];
442 if (nscdb->compar) {
443 if (nscdb->compar(entry, hashentry) == 0)
450 #define HASH_REMOVE(nscdb, entry, hash, cmp) \
451 if (nscdb->htable) { \
452 if (entry == hash_find(nscdb, entry, &hash, cmp)) \
453 nscdb->htable[hash] = NULL; \
457 #define HASH_INSERT(nscdb, entry, hash, cmp) \
458 if (nscdb->htable) { \
459 (void) hash_find(nscdb, entry, &hash, cmp); \
460 nscdb->htable[hash] = entry; \
466 print_entry(nsc_db_t *nscdb, time_t now, nsc_entry_t *entry) {
496 (void) nscdb->getlogstr(nscdb->name, whoami, sizeof (whoami), &args);
557 hash_dump(nsc_db_t *nscdb, time_t now) {
562 for (i = 0; i < nscdb->htsize; i++) {
563 if ((entry = nscdb->htable[i]) != NULL) {
565 print_entry(nscdb, now, entry);
574 avl_dump(nsc_db_t *nscdb, time_t now) {
579 for (entry = avl_first(&nscdb->tree), i = 0; entry != NULL;
580 entry = avl_walk(&nscdb->tree, entry, AVL_AFTER)) {
582 print_entry(nscdb, now, entry);
590 queue_dump(nsc_db_t *nscdb, time_t now) {
596 nscdb->name, avl_numnodes(&nscdb->tree));
601 for (entry = nscdb->qtail, i = 0; entry; entry = entry->qnext) {
603 print_entry(nscdb, now, entry);
609 queue_remove(nsc_db_t *nscdb, nsc_entry_t *entry) {
611 if (nscdb->qtail == entry)
612 nscdb->qtail = entry->qnext;
616 if (nscdb->qhead == entry)
617 nscdb->qhead = entry->qprev;
621 if (nscdb->reap_node == entry)
622 nscdb->reap_node = entry->qnext;
628 queue_adjust(nsc_db_t *nscdb, nsc_entry_t *entry) {
631 assert(nscdb->qtail || entry->qnext == NULL &&
634 assert(nscdb->qtail && nscdb->qhead ||
635 nscdb->qtail == NULL && nscdb->qhead == NULL);
638 nscdb->qtail == entry);
642 if (nscdb->qtail == entry)
646 if (nscdb->qtail == NULL) {
647 nscdb->qhead = nscdb->qtail = entry;
653 nscdb->qtail->qprev = entry;
654 entry->qnext = nscdb->qtail;
655 nscdb->qtail = entry;
660 if (nscdb->reap_node == entry)
661 nscdb->reap_node = entry->qnext;
662 if (nscdb->qhead == entry)
663 nscdb->qhead = entry->qprev;
668 entry->qnext = nscdb->qtail;
669 nscdb->qtail->qprev = entry;
670 nscdb->qtail = entry;
701 nsc_db_t *nscdb;
704 nscdb = (nsc_db_t *)malloc(sizeof (*nscdb));
705 if (nscdb == NULL) {
710 (void) memset(nscdb, 0, sizeof (*nscdb));
712 nscdb->dbop = dbop;
713 nscdb->name = name;
714 nscdb->db_type = dbtype;
718 if (_NSC_DB_CES_KEY(nscdb))
719 nscdb->compar = nsc_db_ces_key_compar;
720 else if (_NSC_DB_CIS_KEY(nscdb))
721 nscdb->compar = nsc_db_cis_key_compar;
722 else if (_NSC_DB_INT_KEY(nscdb))
723 nscdb->compar = nsc_db_int_key_compar;
727 nscdb->compar = compar;
731 avl_create(&nscdb->tree, nscdb->compar, sizeof (nsc_entry_t),
736 if (_NSC_DB_STR_KEY(nscdb))
737 nscdb->getlogstr = nsc_db_str_key_getlogstr;
738 else if (_NSC_DB_INT_KEY(nscdb))
739 nscdb->getlogstr = nsc_db_int_key_getlogstr;
741 nscdb->getlogstr = nsc_db_any_key_getlogstr;
743 nscdb->getlogstr = getlogstr;
749 nscdb->hash_type = httype;
761 nscdb->htsize = htsize;
764 nscdb->htable = calloc(htsize, sizeof (*(nscdb->htable)));
765 if (nscdb->htable == NULL) {
773 if (_NSC_DB_CES_KEY(nscdb))
774 nscdb->gethash = nsc_db_ces_key_gethash;
775 else if (_NSC_DB_CIS_KEY(nscdb))
776 nscdb->gethash = nsc_db_cis_key_gethash;
777 else if (_NSC_DB_INT_KEY(nscdb))
778 nscdb->gethash = nsc_db_int_key_gethash;
782 nscdb->gethash = gethash;
786 (void) mutex_init(&nscdb->db_mutex, USYNC_THREAD, NULL);
787 return (nscdb);
790 if (nscdb->htable)
791 free(nscdb->htable);
792 if (nscdb)
793 free(nscdb);
1047 nsc_db_t *nscdb;
1077 nscdb = nsc_get_db(ctx, dbop);
1078 if (nscdb == NULL) {
1084 (void) mutex_lock(&nscdb->db_mutex);
1085 (void) queue_dump(nscdb, now);
1086 (void) hash_dump(nscdb, now);
1087 (void) avl_dump(nscdb, now);
1088 (void) mutex_unlock(&nscdb->db_mutex);
1249 nsc_db_t *nscdb;
1254 nscdb = largs->nscdb;
1257 if (nscdb->cfg_mtime != ctx->cfg_mtime) {
1259 nscdb->cfg = ctx->cfg;
1260 nscdb->cfg_mtime = ctx->cfg_mtime;
1264 ctx->dbname, nscdb->name);
1266 *cfgp = nscdb->cfg;
1351 nsc_db_t *nscdb;
1390 if (largs->nscdb == NULL) {
1391 if ((largs->nscdb = nsc_get_db(ctx, dbop)) == NULL) {
1403 nscdb = largs->nscdb;
1406 (void) nscdb->getlogstr(nscdb->name, whoami,
1428 (void) mutex_lock(&nscdb->db_mutex);
1435 (void) mutex_unlock(&nscdb->db_mutex);
1459 (void) mutex_unlock(&nscdb->db_mutex);
1468 (void) mutex_unlock(&nscdb->db_mutex);
1475 (void) mutex_unlock(&nscdb->db_mutex);
1509 (void) mutex_unlock(&nscdb->db_mutex);
1515 (void) nscd_wait(ctx, nscdb, this_entry);
1534 delete_entry(nscdb, ctx, this_entry);
1540 (void) mutex_unlock(&nscdb->db_mutex);
1551 (void) mutex_unlock(&nscdb->db_mutex);
1554 (void) mutex_lock(&nscdb->db_mutex);
1559 (void) nscd_signal(ctx, nscdb, this_entry);
1574 delete_entry(nscdb, ctx, this_entry);
1575 (void) mutex_unlock(&nscdb->db_mutex);
1588 delete_entry(nscdb, ctx, this_entry);
1589 (void) mutex_unlock(&nscdb->db_mutex);
1616 (void) mutex_unlock(&nscdb->db_mutex);
1629 delete_entry(nscdb, ctx, this_entry);
1630 (void) mutex_unlock(&nscdb->db_mutex);
1639 delete_entry(nscdb, ctx, this_entry);
1640 (void) mutex_unlock(&nscdb->db_mutex);
1651 delete_entry(nscdb, ctx, this_entry);
1652 (void) mutex_unlock(&nscdb->db_mutex);
1675 (void) mutex_unlock(&nscdb->db_mutex);
1688 delete_entry(nscdb, ctx, this_entry);
1692 (void) mutex_unlock(&nscdb->db_mutex);
1705 (void) mutex_unlock(&nscdb->db_mutex);
1720 (void) mutex_unlock(&nscdb->db_mutex);
1726 (void) mutex_unlock(&nscdb->db_mutex);
1742 (void) mutex_unlock(&nscdb->db_mutex);
1749 (void) mutex_unlock(&nscdb->db_mutex);
1846 getxy_keepalive(nsc_ctx_t *ctx, nsc_db_t *nscdb, int keep, int interval)
1859 (me, "%s: keep alive\n", nscdb->name);
1867 (void) mutex_lock(&nscdb->db_mutex);
1868 entry = nscdb->qtail;
1901 (void) mutex_unlock(&nscdb->db_mutex);
1910 (void) mutex_unlock(&nscdb->db_mutex);
1917 (me, "%s: launching update\n", nscdb->name);
1927 largs->nscdb = nscdb;
1952 in->nscdb->name, errnum);
2050 * nscdb->db_mutex lock must be held before calling this function
2053 delete_entry(nsc_db_t *nscdb, nsc_ctx_t *ctx, nsc_entry_t *entry) {
2056 avl_remove(&nscdb->tree, entry);
2057 HASH_REMOVE(nscdb, entry, hash, nscd_false);
2058 queue_remove(nscdb, entry);
2074 nsc_db_t *nscdb;
2083 nscdb = largs->nscdb;
2089 if (nscdb->htable) {
2090 *entry = hash_find(nscdb, &find_entry, &hash, nscd_true);
2092 (void) queue_adjust(nscdb, *entry);
2098 *entry = (nsc_entry_t *)avl_find(&nscdb->tree, &find_entry, &pos);
2100 (void) queue_adjust(nscdb, *entry);
2102 if (nscdb->htable) {
2103 if (nscdb->htable[hash] == NULL ||
2105 nscdb->htable[hash]->stats.hits) {
2106 nscdb->htable[hash] = *entry;
2147 avl_insert(&nscdb->tree, *entry, pos); /* O(log n) */
2148 (void) queue_adjust(nscdb, *entry); /* constant */
2149 if (nscdb->htable) /* constant */
2150 nscdb->htable[hash] = *entry;
2164 node = nscdb->qhead;
2168 delete_entry(nscdb, ctx, node);
2257 nsc_db_t *nscdb;
2269 nscdb = ctx->nsc_db[i];
2270 (void) mutex_lock(&nscdb->db_mutex);
2271 nscdb->reap_node = nscdb->qtail;
2272 while (nscdb->reap_node != NULL) {
2274 (void) mutex_unlock(&nscdb->db_mutex);
2279 (void) mutex_lock(&nscdb->db_mutex);
2282 if ((node = nscdb->reap_node) == NULL)
2292 * nscdb->reap_node will be adjusted
2295 delete_entry(nscdb, ctx, node);
2298 nscdb->reap_node = node->qnext;
2303 if (nscdb->htsize == 0) {
2304 (void) mutex_unlock(&nscdb->db_mutex);
2316 nentries = avl_numnodes(&nscdb->tree);
2321 if (nscdb->hash_type == nsc_ht_power2)
2327 if (nscdb->htsize == newhtsize) {
2328 (void) mutex_unlock(&nscdb->db_mutex);
2334 nscdb->name, nscdb->htsize, newhtsize);
2340 (void) free(nscdb->htable);
2341 nscdb->htable = calloc(newhtsize, sizeof (*(nscdb->htable)));
2342 if (nscdb->htable == NULL) {
2345 nscdb->name);
2347 nscdb->htsize = -1;
2349 nscdb->htsize = newhtsize;
2351 (void) mutex_unlock(&nscdb->db_mutex);
2387 nscdb = ctx->nsc_db[i];
2388 (void) mutex_lock(&nscdb->db_mutex);
2389 nodes_togo = (value * avl_numnodes(&nscdb->tree)) / 100;
2392 next_node = nscdb->qhead;
2399 delete_entry(nscdb, ctx, node);
2404 (void) mutex_unlock(&nscdb->db_mutex);