void stat_cache_free(stat_cache *sc) { while (sc->files) { int osize; splay_tree *node = sc->files; osize = sc->files->size; stat_cache_entry_free(node->data); sc->files = splaytree_delete(sc->files, node->key); force_assert(osize - 1 == splaytree_size(sc->files)); } buffer_free(sc->dir_name); buffer_free(sc->hash_key); #ifdef HAVE_FAM_H while (sc->dirs) { int osize; splay_tree *node = sc->dirs; osize = sc->dirs->size; fam_dir_entry_free(&sc->fam, node->data); sc->dirs = splaytree_delete(sc->dirs, node->key); if (osize == 1) { force_assert(NULL == sc->dirs); } else { force_assert(osize == (sc->dirs->size + 1)); } } if (-1 != sc->fam_fcce_ndx) { /* fd events already gone */ sc->fam_fcce_ndx = -1; FAMClose(&sc->fam); } #endif free(sc); }
void stat_cache_free(stat_cache *sc) { while (sc->files) { int osize; splay_tree *node = sc->files; osize = sc->files->size; stat_cache_entry_free(node->data); sc->files = splaytree_delete(sc->files, node->key); assert(osize - 1 == splaytree_size(sc->files)); } buffer_free(sc->dir_name); buffer_free(sc->hash_key); #ifdef HAVE_FAM_H while (sc->dirs) { int osize; splay_tree *node = sc->dirs; osize = sc->dirs->size; fam_dir_entry_free(node->data); sc->dirs = splaytree_delete(sc->dirs, node->key); if (osize == 1) { assert(NULL == sc->dirs); } else { assert(osize == (sc->dirs->size + 1)); } } if (sc->fam) { FAMClose(sc->fam); free(sc->fam); } #endif free(sc); }
int stat_cache_trigger_cleanup(server *srv) { stat_cache *sc; size_t max_ndx = 0, i; int *keys; sc = srv->stat_cache; if (!sc->files) return 0; keys = calloc(1, sizeof(int) * sc->files->size); stat_cache_tag_old_entries(srv, sc->files, keys, &max_ndx); for (i = 0; i < max_ndx; i++) { int ndx = keys[i]; splay_tree *node; sc->files = splaytree_splay(sc->files, ndx); node = sc->files; if (node && (node->key == ndx)) { #ifdef DEBUG_STAT_CACHE size_t j; int osize = splaytree_size(sc->files); stat_cache_entry *sce = node->data; #endif stat_cache_entry_free(node->data); sc->files = splaytree_delete(sc->files, ndx); #ifdef DEBUG_STAT_CACHE for (j = 0; j < ctrl.used; j++) { if (ctrl.ptr[j] == ndx) { ctrl.ptr[j] = ctrl.ptr[--ctrl.used]; break; } } force_assert(osize - 1 == splaytree_size(sc->files)); #endif } } free(keys); return 0; }
handler_t stat_cache_handle_fdevent(server *srv, void *_fce, int revent) { size_t i; stat_cache *sc = srv->stat_cache; size_t events; UNUSED(_fce); /* */ if (revent & FDEVENT_IN) { events = FAMPending(&sc->fam); for (i = 0; i < events; i++) { FAMEvent fe; fam_dir_entry *fam_dir; splay_tree *node; int ndx, j; FAMNextEvent(&sc->fam, &fe); /* handle event */ switch(fe.code) { case FAMChanged: case FAMDeleted: case FAMMoved: /* if the filename is a directory remove the entry */ fam_dir = fe.userdata; fam_dir->version++; /* file/dir is still here */ if (fe.code == FAMChanged) break; /* we have 2 versions, follow and no-follow-symlink */ for (j = 0; j < 2; j++) { buffer_copy_string(sc->hash_key, fe.filename); buffer_append_int(sc->hash_key, j); ndx = hashme(sc->hash_key); sc->dirs = splaytree_splay(sc->dirs, ndx); node = sc->dirs; if (node && (node->key == ndx)) { int osize = splaytree_size(sc->dirs); fam_dir_entry_free(&sc->fam, node->data); sc->dirs = splaytree_delete(sc->dirs, ndx); force_assert(osize - 1 == splaytree_size(sc->dirs)); } } break; default: break; } } } if (revent & FDEVENT_HUP) { /* fam closed the connection */ fdevent_event_del(srv->ev, &(sc->fam_fcce_ndx), FAMCONNECTION_GETFD(&sc->fam)); fdevent_unregister(srv->ev, FAMCONNECTION_GETFD(&sc->fam)); FAMClose(&sc->fam); } return HANDLER_GO_ON; }