static int test_hash(void) { Hashtab *h; starttesting("hashtab"); h = hashtabnew(100, hash_cmp, hash_hash); if (!h) return endtesting(1); if (!hashtabadd(h, "one")|| !hashtabadd(h, "two")|| !hashtabadd(h, "three")|| !hashtabadd(h, "four")) return endtesting(1); printf("foreach ----\n"); hashtabforeach(h, hash_print, NULL); printf("search ----\none == %s\ntwo == %s\nthree == %s\nfour == %s\n", (char *)hashtabsearch(h, "one"), (char *)hashtabsearch(h, "two"), (char *)hashtabsearch(h, "three"), (char *)hashtabsearch(h, "four")); hashtabrelease(h); return endtesting(0); }
static void client_init (struct ropa_client *c, uint32_t host, uint16_t port, afsUUID *uuid, interfaceAddr *addr) { c->port = port; if (addr) { client_update_interfaces (c, host, port, addr); } else { int i; for (i = 0; i < c->numberOfInterfaces; i++) { hashtabdel (ht_clients_ip, &c->addr[i]); DIAGNOSTIC_CHECK_ADDR(&c->addr[i]); } c->numberOfInterfaces = 1; DIAGNOSTIC_CHECK_ADDR(&c->addr[0]); c->addr[0].c = c; c->addr[0].addr_in = host; c->addr[0].subnetmask = 0xffffff00; c->addr[0].mtu = ROPA_MTU; hashtabadd (ht_clients_ip, &c->addr[0]); } if (uuid) { c->uuid = *uuid; hashtabadd (ht_clients_uuid, c); } }
int mnode_find (const AFSFid *fid, struct mnode **node) { struct mnode ptr, *res = NULL; ptr.fid = *fid; while (res == NULL) { res = hashtabsearch (mnode_htab, &ptr); if (res) { if (res->flags.removedp == TRUE) return ENOENT; if (res->li) listdel (mnode_lru, res->li); if (res->ref == 0) mnode_numfree--; res->ref++; } else if (mnode_numfree != 0) { res = listdeltail (mnode_lru); assert (res); assert (res->ref == 0); hashtabdel (mnode_htab, res); reset_node (res, fid); hashtabadd (mnode_htab, res); res->ref++; } else { /* XXX */ mlog_log (MDEBWARN, "mnode_find: no free nodes, had to malloc()"); res = malloc(sizeof(struct mnode)); if (res == NULL) { mlog_log (MDEBWARN, "mnode_find: malloc() failed"); LWP_DispatchProcess(); /* Yield */ continue; } reset_node (res, fid); hashtabadd (mnode_htab, res); res->ref++; } } assert(res->flags.removedp == FALSE); *node = res; res->li = listaddhead (mnode_lru, *node); return 0; }
static void client_update_interfaces (struct ropa_client *c, uint32_t host, uint16_t port, interfaceAddr *addr) { int i; int found_addr = 0; if (addr->numberOfInterfaces > AFS_MAX_INTERFACE_ADDR) addr->numberOfInterfaces = AFS_MAX_INTERFACE_ADDR; for (i = 0; i < c->numberOfInterfaces; i++) { hashtabdel (ht_clients_ip, &c->addr[i]); DIAGNOSTIC_CHECK_ADDR(&c->addr[i]); } for (i = 0; i < addr->numberOfInterfaces; i++) { DIAGNOSTIC_CHECK_ADDR(&c->addr[i]); c->addr[i].c = c; c->addr[i].addr_in = addr->addr_in[i]; c->addr[i].subnetmask = addr->subnetmask[i]; c->addr[i].mtu = addr->mtu[i]; hashtabadd (ht_clients_ip, &c->addr[i]); if (host == addr->addr_in[i]) found_addr = 1; } if (!found_addr && i < AFS_MAX_INTERFACE_ADDR) { DIAGNOSTIC_CHECK_ADDR(&c->addr[i]); c->addr[i].c = c; c->addr[i].addr_in = host; c->addr[i].subnetmask = 0xffffff00; c->addr[i].mtu = ROPA_MTU; hashtabadd (ht_clients_ip, &c->addr[i]); i++; } c->numberOfInterfaces = i; for (; i < AFS_MAX_INTERFACE_ADDR; i++) clear_addr (&c->addr[i]); }
static ConnCacheEntry * add_connection(int32_t cell, uint32_t host, uint16_t port, uint16_t service, int (*probe)(struct rx_connection *), CredCacheEntry *ce) { ConnCacheEntry *e; struct rx_securityClass *securityobj; int securityindex; nnpfs_pag_t cred; if (ce) { securityindex = ce->securityindex; cred = ce->cred; switch (ce->type) { #ifdef KERBEROS case CRED_KRB4 : { struct cred_rxkad *cred = (struct cred_rxkad *)ce->cred_data; securityobj = rxkad_NewClientSecurityObject(conn_rxkad_level, cred->ct.HandShakeKey, cred->ct.AuthHandle, cred->ticket_len, cred->ticket); break; } #endif case CRED_NONE : securityobj = rxnull_NewClientSecurityObject (); break; default : errx(1, "Unknown credentials type %d\n", ce->type); } } else { securityobj = rxnull_NewClientSecurityObject (); securityindex = 0; cred = 0; } e = new_connection (cell, host, port, service, cred, securityindex, probe, securityobj); hashtabadd (connhtab, (void *)e); ++nactive_connections; return e; }
static struct ropa_ccpair * add_client (struct ropa_cb *cb, struct ropa_client *c) { struct timeval tv; struct ropa_ccpair cckey, *cc; assert (cb && c); cckey.client = c; cckey.cb = cb; cc = hashtabsearch (ht_ccpairs, &cckey); if (cc) { listdel (lru_ccpair, cc->li); cc->li = listaddhead (lru_ccpair, cc); return cc; } /* The reverse of these are in break_ccpair */ callback_ref (cb); client_ref (c); cc = listdeltail (lru_ccpair); DIAGNOSTIC_CHECK_CCPAIR(cc); cc->li = NULL; if (ccpairs_inuse_p (cc)) break_ccpair (cc, TRUE); /* XXX do it for real */ gettimeofday(&tv, NULL); cc->expire = tv.tv_sec + 3600; heap_insert (heap_ccpairs, cc, &cc->heap); LWP_NoYieldSignal (heap_ccpairs); cc->cb_li = listaddtail (cb->ccpairs, cc); cc->client = c; cc->cb = cb; cc->li = listaddhead (lru_ccpair, cc); hashtabadd (ht_ccpairs, cc); mlog_log (MDEBROPA, "add_client: added %x to callback %x.%x.%x", c->addr[0].addr_in, cb->fid.Volume, cb->fid.Vnode, cb->fid.Unique); return cc; }
Symbol * addsym(char *name) { Symbol key, *s; key.name = name; s = (Symbol *) hashtabsearch(htab, (void *) &key); if (s == NULL) { s = (Symbol *) emalloc(sizeof(*s)); s->name = name; s->gen_name = estrdup(name); output_name(s->gen_name); s->stype = SUndefined; hashtabadd(htab, s); } return s; }
static void register_vols_cb (void *data, int fd) { struct dp_part *dp = (struct dp_part *)data; vstatus vs; int ret; volume_handle *vol; ret = vstatus_read (fd, &vs); if (ret) return; ret = vstatus2volume_handle (&vs, dp, &vol); if (ret) { mlog_log (MDEBERROR, "register_vols_cb: failed to convert vstatus"); return; } ret = VOLOP_OPEN(vol->type, dp, vol->vol, VOLOP_NOFLAGS, &vol->data); if (ret) { mlog_log (MDEBERROR, "register_vols_cb: failed to open volume"); vol->flags.attacherr = TRUE; } else { vol->flags.attacherr = FALSE; } vol->flags.offlinep = TRUE; vol->flags.salvaged = FALSE; vol->li = listaddtail (vol_list, vol); if (vol->li == NULL) errx (1, "register_vols_cb: listaddtail failed"); hashtabadd (volume_htab, vol); return; }
int ropa_getcallback (uint32_t host, uint16_t port, const struct AFSFid *fid, AFSCallBack *callback, int32_t voltype) { struct ropa_client *c; struct ropa_cb cbkey, *cb; struct ropa_ccpair *cc ; struct AFSFid callback_fid; debug_print_callbacks(); c = client_query (host, port); if (c == NULL) { mlog_log (MDEBROPA, "ropa_getcallback: didn't find client %x/%d", host, port); update_callback_time (DEFAULT_TIMEOUT, callback, CBSHARED); return 0; } /* * At this point the client should be firmly set * in the ropa client database. */ #if 0 if (c->have_outstanding_callbacks) break_outstanding_callbacks (c); #endif if (voltype == RWVOL) { callback_fid = *fid; } else { callback_fid.Volume = fid->Volume; callback_fid.Vnode = 0; callback_fid.Unique = 0; } cbkey.fid = callback_fid; cb = hashtabsearch (ht_callbacks, &cbkey); if (cb == NULL) { cb = listdeltail (lru_callback); DIAGNOSTIC_CHECK_CALLBACK(cb); cb->li = NULL; if (callback_inuse_p (cb)) { break_callback (cb, NULL, FALSE); callback_ref(cb); } else { callback_ref(cb); cb->li = listaddhead (lru_callback, cb); } cb->fid = callback_fid; hashtabadd (ht_callbacks, cb); mlog_log (MDEBROPA, "ropa_getcallback: added callback %x.%x.%x:%x", callback_fid.Volume, callback_fid.Vnode, callback_fid.Unique, host); } else { mlog_log (MDEBROPA, "ropa_getcallback: found callback %x.%x.%x:%x", callback_fid.Volume, callback_fid.Vnode, callback_fid.Unique, host); callback_ref(cb); } cc = add_client (cb, c); callback_deref (cb); update_callback (cc, callback, CBSHARED); debug_print_callbacks(); return 0; }