version 1.1.1.1, 2013/10/14 10:32:48
|
version 1.1.1.2, 2014/06/15 20:20:06
|
Line 69
|
Line 69
|
#ifdef HAVE_FAM_H |
#ifdef HAVE_FAM_H |
typedef struct { |
typedef struct { |
FAMRequest *req; |
FAMRequest *req; |
FAMConnection *fc; |
|
|
|
buffer *name; |
buffer *name; |
|
|
Line 102 static fake_keys ctrl;
|
Line 101 static fake_keys ctrl;
|
#endif |
#endif |
|
|
stat_cache *stat_cache_init(void) { |
stat_cache *stat_cache_init(void) { |
stat_cache *fc = NULL; | stat_cache *sc = NULL; |
|
|
fc = calloc(1, sizeof(*fc)); | sc = calloc(1, sizeof(*sc)); |
|
|
fc->dir_name = buffer_init(); | sc->dir_name = buffer_init(); |
fc->hash_key = buffer_init(); | sc->hash_key = buffer_init(); |
| |
#ifdef HAVE_FAM_H |
#ifdef HAVE_FAM_H |
fc->fam = calloc(1, sizeof(*fc->fam)); | sc->fam_fcce_ndx = -1; |
#endif |
#endif |
|
|
#ifdef DEBUG_STAT_CACHE |
#ifdef DEBUG_STAT_CACHE |
ctrl.size = 0; |
ctrl.size = 0; |
#endif |
#endif |
|
|
return fc; | return sc; |
} |
} |
|
|
static stat_cache_entry * stat_cache_entry_init(void) { |
static stat_cache_entry * stat_cache_entry_init(void) { |
Line 153 static fam_dir_entry * fam_dir_entry_init(void) {
|
Line 153 static fam_dir_entry * fam_dir_entry_init(void) {
|
return fam_dir; |
return fam_dir; |
} |
} |
|
|
static void fam_dir_entry_free(void *data) { | static void fam_dir_entry_free(FAMConnection *fc, void *data) { |
fam_dir_entry *fam_dir = data; |
fam_dir_entry *fam_dir = data; |
|
|
if (!fam_dir) return; |
if (!fam_dir) return; |
|
|
FAMCancelMonitor(fam_dir->fc, fam_dir->req); | FAMCancelMonitor(fc, fam_dir->req); |
|
|
buffer_free(fam_dir->name); |
buffer_free(fam_dir->name); |
free(fam_dir->req); |
free(fam_dir->req); |
Line 177 void stat_cache_free(stat_cache *sc) {
|
Line 177 void stat_cache_free(stat_cache *sc) {
|
stat_cache_entry_free(node->data); |
stat_cache_entry_free(node->data); |
sc->files = splaytree_delete(sc->files, node->key); |
sc->files = splaytree_delete(sc->files, node->key); |
|
|
assert(osize - 1 == splaytree_size(sc->files)); | force_assert(osize - 1 == splaytree_size(sc->files)); |
} |
} |
|
|
buffer_free(sc->dir_name); |
buffer_free(sc->dir_name); |
Line 190 void stat_cache_free(stat_cache *sc) {
|
Line 190 void stat_cache_free(stat_cache *sc) {
|
|
|
osize = sc->dirs->size; |
osize = sc->dirs->size; |
|
|
fam_dir_entry_free(node->data); | fam_dir_entry_free(&sc->fam, node->data); |
sc->dirs = splaytree_delete(sc->dirs, node->key); |
sc->dirs = splaytree_delete(sc->dirs, node->key); |
|
|
if (osize == 1) { |
if (osize == 1) { |
assert(NULL == sc->dirs); | force_assert(NULL == sc->dirs); |
} else { |
} else { |
assert(osize == (sc->dirs->size + 1)); | force_assert(osize == (sc->dirs->size + 1)); |
} |
} |
} |
} |
|
|
if (sc->fam) { | if (-1 != sc->fam_fcce_ndx) { |
FAMClose(sc->fam); | /* fd events already gone */ |
free(sc->fam); | sc->fam_fcce_ndx = -1; |
| |
| FAMClose(&sc->fam); |
} |
} |
#endif |
#endif |
free(sc); |
free(sc); |
Line 246 handler_t stat_cache_handle_fdevent(server *srv, void
|
Line 248 handler_t stat_cache_handle_fdevent(server *srv, void
|
UNUSED(_fce); |
UNUSED(_fce); |
/* */ |
/* */ |
|
|
if ((revent & FDEVENT_IN) && | if (revent & FDEVENT_IN) { |
sc->fam) { | events = FAMPending(&sc->fam); |
|
|
events = FAMPending(sc->fam); |
|
|
|
for (i = 0; i < events; i++) { |
for (i = 0; i < events; i++) { |
FAMEvent fe; |
FAMEvent fe; |
fam_dir_entry *fam_dir; |
fam_dir_entry *fam_dir; |
splay_tree *node; |
splay_tree *node; |
int ndx, j; |
int ndx, j; |
|
|
FAMNextEvent(sc->fam, &fe); | FAMNextEvent(&sc->fam, &fe); |
|
|
/* handle event */ |
/* handle event */ |
|
|
Line 287 handler_t stat_cache_handle_fdevent(server *srv, void
|
Line 287 handler_t stat_cache_handle_fdevent(server *srv, void
|
if (node && (node->key == ndx)) { |
if (node && (node->key == ndx)) { |
int osize = splaytree_size(sc->dirs); |
int osize = splaytree_size(sc->dirs); |
|
|
fam_dir_entry_free(node->data); | fam_dir_entry_free(&sc->fam, node->data); |
sc->dirs = splaytree_delete(sc->dirs, ndx); |
sc->dirs = splaytree_delete(sc->dirs, ndx); |
|
|
assert(osize - 1 == splaytree_size(sc->dirs)); | force_assert(osize - 1 == splaytree_size(sc->dirs)); |
} |
} |
} |
} |
break; |
break; |
Line 302 handler_t stat_cache_handle_fdevent(server *srv, void
|
Line 302 handler_t stat_cache_handle_fdevent(server *srv, void
|
|
|
if (revent & FDEVENT_HUP) { |
if (revent & FDEVENT_HUP) { |
/* fam closed the connection */ |
/* fam closed the connection */ |
srv->stat_cache->fam_fcce_ndx = -1; | fdevent_event_del(srv->ev, &(sc->fam_fcce_ndx), FAMCONNECTION_GETFD(&sc->fam)); |
| fdevent_unregister(srv->ev, FAMCONNECTION_GETFD(&sc->fam)); |
|
|
fdevent_event_del(srv->ev, &(sc->fam_fcce_ndx), FAMCONNECTION_GETFD(sc->fam)); | FAMClose(&sc->fam); |
fdevent_unregister(srv->ev, FAMCONNECTION_GETFD(sc->fam)); | |
| |
FAMClose(sc->fam); | |
free(sc->fam); | |
| |
sc->fam = NULL; | |
} |
} |
|
|
return HANDLER_GO_ON; |
return HANDLER_GO_ON; |
Line 397 handler_t stat_cache_get_entry(server *srv, connection
|
Line 392 handler_t stat_cache_get_entry(server *srv, connection
|
if (sc->files && (sc->files->key == file_ndx)) { |
if (sc->files && (sc->files->key == file_ndx)) { |
#ifdef DEBUG_STAT_CACHE |
#ifdef DEBUG_STAT_CACHE |
/* it was in the cache */ |
/* it was in the cache */ |
assert(i < ctrl.used); | force_assert(i < ctrl.used); |
#endif |
#endif |
|
|
/* we have seen this file already and |
/* we have seen this file already and |
Line 435 handler_t stat_cache_get_entry(server *srv, connection
|
Line 430 handler_t stat_cache_get_entry(server *srv, connection
|
log_error_write(srv, __FILE__, __LINE__, "xSB", |
log_error_write(srv, __FILE__, __LINE__, "xSB", |
file_ndx, "was already inserted but not found in cache, ", name); |
file_ndx, "was already inserted but not found in cache, ", name); |
} |
} |
assert(i == ctrl.used); | force_assert(i == ctrl.used); |
#endif |
#endif |
} |
} |
|
|
Line 521 handler_t stat_cache_get_entry(server *srv, connection
|
Line 516 handler_t stat_cache_get_entry(server *srv, connection
|
|
|
ctrl.ptr[ctrl.used++] = file_ndx; |
ctrl.ptr[ctrl.used++] = file_ndx; |
|
|
assert(sc->files); | force_assert(sc->files); |
assert(sc->files->data == sce); | force_assert(sc->files->data == sce); |
assert(osize + 1 == splaytree_size(sc->files)); | force_assert(osize + 1 == splaytree_size(sc->files)); |
#endif |
#endif |
} |
} |
|
|
Line 625 handler_t stat_cache_get_entry(server *srv, connection
|
Line 620 handler_t stat_cache_get_entry(server *srv, connection
|
} |
} |
|
|
#ifdef HAVE_FAM_H |
#ifdef HAVE_FAM_H |
if (sc->fam && | if (srv->srvconf.stat_cache_engine == STAT_CACHE_ENGINE_FAM) { |
(srv->srvconf.stat_cache_engine == STAT_CACHE_ENGINE_FAM)) { | |
/* is this directory already registered ? */ |
/* is this directory already registered ? */ |
if (!dir_node) { |
if (!dir_node) { |
fam_dir = fam_dir_entry_init(); |
fam_dir = fam_dir_entry_init(); |
fam_dir->fc = sc->fam; |
|
|
|
buffer_copy_string_buffer(fam_dir->name, sc->dir_name); |
buffer_copy_string_buffer(fam_dir->name, sc->dir_name); |
|
|
Line 638 handler_t stat_cache_get_entry(server *srv, connection
|
Line 631 handler_t stat_cache_get_entry(server *srv, connection
|
|
|
fam_dir->req = calloc(1, sizeof(FAMRequest)); |
fam_dir->req = calloc(1, sizeof(FAMRequest)); |
|
|
if (0 != FAMMonitorDirectory(sc->fam, fam_dir->name->ptr, | if (0 != FAMMonitorDirectory(&sc->fam, fam_dir->name->ptr, |
fam_dir->req, fam_dir)) { |
fam_dir->req, fam_dir)) { |
|
|
log_error_write(srv, __FILE__, __LINE__, "sbsbs", |
log_error_write(srv, __FILE__, __LINE__, "sbsbs", |
Line 647 handler_t stat_cache_get_entry(server *srv, connection
|
Line 640 handler_t stat_cache_get_entry(server *srv, connection
|
"file:", name, |
"file:", name, |
FamErrlist[FAMErrno]); |
FamErrlist[FAMErrno]); |
|
|
fam_dir_entry_free(fam_dir); | fam_dir_entry_free(&sc->fam, fam_dir); |
| fam_dir = NULL; |
} else { |
} else { |
int osize = 0; |
int osize = 0; |
|
|
if (sc->dirs) { | if (sc->dirs) { |
osize = sc->dirs->size; |
osize = sc->dirs->size; |
} |
} |
|
|
sc->dirs = splaytree_insert(sc->dirs, dir_ndx, fam_dir); |
sc->dirs = splaytree_insert(sc->dirs, dir_ndx, fam_dir); |
assert(sc->dirs); | force_assert(sc->dirs); |
assert(sc->dirs->data == fam_dir); | force_assert(sc->dirs->data == fam_dir); |
assert(osize == (sc->dirs->size - 1)); | force_assert(osize == (sc->dirs->size - 1)); |
} |
} |
} else { |
} else { |
fam_dir = dir_node->data; |
fam_dir = dir_node->data; |
Line 668 handler_t stat_cache_get_entry(server *srv, connection
|
Line 662 handler_t stat_cache_get_entry(server *srv, connection
|
|
|
if (fam_dir) { |
if (fam_dir) { |
sce->dir_version = fam_dir->version; |
sce->dir_version = fam_dir->version; |
sce->dir_ndx = dir_ndx; |
|
} |
} |
} |
} |
#endif |
#endif |
Line 713 int stat_cache_trigger_cleanup(server *srv) {
|
Line 706 int stat_cache_trigger_cleanup(server *srv) {
|
|
|
if (!sc->files) return 0; |
if (!sc->files) return 0; |
|
|
keys = calloc(1, sizeof(size_t) * sc->files->size); | keys = calloc(1, sizeof(int) * sc->files->size); |
|
|
stat_cache_tag_old_entries(srv, sc->files, keys, &max_ndx); |
stat_cache_tag_old_entries(srv, sc->files, keys, &max_ndx); |
|
|
Line 742 int stat_cache_trigger_cleanup(server *srv) {
|
Line 735 int stat_cache_trigger_cleanup(server *srv) {
|
} |
} |
} |
} |
|
|
assert(osize - 1 == splaytree_size(sc->files)); | force_assert(osize - 1 == splaytree_size(sc->files)); |
#endif |
#endif |
} |
} |
} |
} |