static void break_ccpairs (struct ropa_client *c, Bool notify_clientp) { AFSCBFids fids; AFSCBs cbs; struct ropa_ccpair *cc; AFSCallBack callback; DIAGNOSTIC_CHECK_CLIENT(c); fids.val = NULL; fids.len = 0; cbs.val = NULL; cbs.len = 0; while ((cc = listdeltail (c->callbacks)) != NULL) { DIAGNOSTIC_CHECK_CCPAIR(cc); update_callback (cc, &callback, CBDROPPED); add_to_cb (&cc->cb->fid, &callback, &fids, &cbs); break_ccpair (cc, FALSE); } if (notify_clientp) notify_client (c, &fids, &cbs); }
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 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; }
static struct ropa_client * obtain_client (void) { struct ropa_client *c; c = listdeltail (lru_clients); DIAGNOSTIC_CHECK_CLIENT(c); c->li = NULL; if (client_inuse_p (c)) break_client (c, TRUE); if (c->li) { listdel(lru_clients, c->li); c->li = NULL; } return c; }
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; }