5 #define __STDC_FORMAT_MACROS
7 #include "cvmfs_config.h"
52 for (
unsigned i = 0; i < map_.capacity(); ++i) {
53 if (map_.keys()[i] != empty_path) {
54 (map_.values() + i)->name =
55 string_heap_->AddString(map_.values()[i].name.length(),
56 map_.values()[i].name.data());
65 void InodeTracker::InitLock() {
67 reinterpret_cast<pthread_mutex_t *
>(smalloc(
sizeof(pthread_mutex_t)));
68 int retval = pthread_mutex_init(lock_, NULL);
83 InodeTracker::InodeTracker() {
104 InodeTracker::~InodeTracker() {
105 pthread_mutex_destroy(lock_);
112 DentryTracker::DentryTracker() : version_(
kVersion), is_active_(true) {
126 pthread_mutex_destroy(
lock_);
184 struct pollfd watch_term;
186 watch_term.events = POLLIN | POLLPRI;
190 watch_term.revents = 0;
191 int retval = poll(&watch_term, 1, timeout_ms);
193 if (errno == EINTR) {
194 if (timeout_ms >= 0) {
196 timeout_ms = (now > deadline) ? 0 : (deadline - now) * 1000;
211 assert(watch_term.revents != 0);
225 reinterpret_cast<pthread_mutex_t *
>(smalloc(
sizeof(pthread_mutex_t)));
226 int retval = pthread_mutex_init(
lock_, NULL);
249 if (cursor->
head == NULL)
276 pthread_mutex_destroy(
lock_);
312 reinterpret_cast<pthread_mutex_t *
>(smalloc(
sizeof(pthread_mutex_t)));
313 int retval = pthread_mutex_init(
lock_, NULL);
318 uint64_t inode,
const shash::Any &hash,
const struct stat &info)
320 assert(inode == info.st_ino);
325 return open_directives;
327 if (inode != info.st_ino) {
329 "invalid entry on open: %" PRIu64
" with st_ino=%" PRIu64,
330 " hash=%s size=%" PRIu64,
331 inode, info.st_ino, hash.
ToString().c_str(), info.st_size);
337 bool retval =
map_.Lookup(inode, &entry);
347 map_.Insert(inode, entry);
348 return open_directives;
351 if (entry.
hash == hash) {
353 if (entry.
nopen < 0) {
359 map_.Insert(inode, entry);
360 return open_directives;
364 if (entry.
nopen++ == 0)
366 map_.Insert(inode, entry);
367 return open_directives;
374 if (entry.
nopen != 0) {
378 return open_directives;
391 map_.Insert(inode, entry);
392 return open_directives;
399 return open_directives;
403 return open_directives;
412 bool retval =
map_.Lookup(inode, &entry);
415 "PageCacheTracker::Close Race condition? "
416 "Did not find inode %lu",
419 "PageCacheTracker::Close Race condition? "
420 "Inode %lu has no open entries",
425 const int32_t old_open = entry.
nopen;
426 if (entry.
nopen < 0) {
433 if (entry.
nopen == 0) {
437 "page cache tracker: missing stat entry! Entry info: inode %" PRIu64
438 " - open counter %d - hash %s",
443 retval =
map_.Lookup(inode_update, &entry_update);
446 "invalid inode in page cache tracker: inode %" PRIu64
447 ", replacing %" PRIu64, inode_update, inode);
451 map_.Insert(inode_update, entry_update);
454 map_.Insert(inode, entry);
465 int retval = pthread_mutex_unlock(tracker_->lock_);
470 if (!tracker_->is_active_)
473 bool contained_inode = tracker_->map_.Erase(inode);
475 tracker_->statistics_.n_remove++;
InodeReferences inode_references_
void DoPrune(uint64_t now)
PageCacheTracker & operator=(const PageCacheTracker &other)
std::string ToString(const bool with_suffix=false) const
void CopyFrom(const DentryTracker &other)
perf::Statistics * statistics_
pthread_t thread_cleaner_
assert((mem||(size==0))&&"Out Of Memory")
bool NextEntry(Cursor *cursor, uint64_t *inode_parent, NameString *name)
StringHeap * string_heap_
void MakePipe(int pipe_fd[2])
static uint32_t hasher_inode(const uint64_t &inode)
void EndEnumerate(Cursor *cursor)
void SpawnCleaner(unsigned interval_s)
static bool AssertOrLog(int t, const LogSource, const int, const char *,...)
int32_t Add(const struct stat &info)
static const unsigned kVersion
SmallHashDynamic< shash::Md5, PathInfo > map_
OpenDirectives Open(uint64_t inode, const shash::Any &hash, const struct stat &info)
void Evict(uint64_t inode)
void Close(uint64_t inode)
OpenDirectives OpenDirect()
EvictRaii(PageCacheTracker *t)
PageCacheTracker * tracker_
uint64_t Erase(int32_t index)
DentryTracker & operator=(const DentryTracker &other)
void CopyFrom(const PageCacheTracker &other)
BigQueue< Entry > entries_
static void * MainCleaner(void *data)
static const unsigned kVersion
int cleaning_interval_ms_
void WritePipe(int fd, const void *buf, size_t nbyte)
void ReadPipe(int fd, void *buf, size_t nbyte)
void ClosePipe(int pipe_fd[2])
SmallHashDynamic< uint64_t, Entry > map_
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)