/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "module-context.h"
#include "eacces-error.h"
#include "mail-index-private.h"
#include "mail-index-alloc-cache.h"
/* How many seconds to keep index opened for reuse after it's been closed */
/* How many closed indexes to keep */
struct mail_index_alloc_cache_list {
char *mailbox_path;
int refcount;
bool referenced;
};
static unsigned int indexes_cache_references_count = 0;
static struct mail_index_alloc_cache_list *
{
return list;
}
static void
{
}
static void
{
if (list->referenced)
}
static struct mail_index_alloc_cache_list *
{
unsigned int destroy_count;
/* already found the index. we're just going through
the rest of them to drop 0 refcounts */
/* index is already closed. don't even try to
reuse it. */
/* make sure the directory still exists.
it might have been renamed and we're trying
to access it via its new path now. */
rec->destroy_time = 0;
else
}
}
destroy_count >= INDEX_CACHE_MAX) {
continue;
} else {
}
}
}
return match;
}
struct mail_index *
{
/* compare index_dir inodes so we don't break even with symlinks.
if index_dir doesn't exist yet or if using in-memory indexes, just
compare mailbox paths */
/* in-memory indexes */
/* it'll be created later */
} else {
}
}
} else {
}
}
{
if (min_destroy_count > 0)
} else {
if (min_destroy_count > 0 &&
rec->referenced) {
/* we're the only one keeping this index open.
we might be here, because the caller is
deleting this mailbox and wants its indexes
to be closed. so close it. */
}
}
}
return destroyed;
}
static void ATTR_NULL(1)
{
destroy_unrefed(0);
}
{
break;
}
}
/* index was already closed. don't even try to cache it. */
}
}
void mail_index_alloc_cache_destroy_unrefed(void)
{
}
{
/* newly created index directory. update its stat. */
}
}
}
{
return;
if (list->referenced) {
/* we're closing our referenced index */
return;
}
while (indexes_cache_references_count > INDEX_CACHE_MAX) {
if (!destroy_unrefed(1)) {
/* our cache is full already, don't keep more */
return;
}
}
/* keep the index referenced for caching */
index->open_count++;
}