Commit 43783460 authored by Stratos Psomadakis's avatar Stratos Psomadakis

Merge branch 'hotfix-0.4.1'

parents 6261b41d c389ef80
......@@ -64,10 +64,8 @@ EXPORT_SYMBOL(xseg_bind_dynport);
EXPORT_SYMBOL(xseg_leave_dynport);
EXPORT_SYMBOL(xseg_portno_nonstatic);
EXPORT_SYMBOL(xseg_snprintf);
EXPORT_SYMBOL(__xseg_errbuf);
EXPORT_SYMBOL(__xseg_log);
EXPORT_SYMBOL(init_logctx);
EXPORT_SYMBOL(renew_logctx);
EXPORT_SYMBOL(init_logctx);
EXPORT_SYMBOL(__xseg_log2);
EXPORT_SYMBOL(xseg_printtrace);
/*
Copyright (C) 2010-2014 GRNET S.A.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _SYSUTIL_H
#define _SYSUTIL_H
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/time.h>
#include <sys/domain.h>
#define REOPEN_FILE (1 << 1)
#define REDIRECT_STDOUT (1 << 1)
#define REDIRECT_STDERR (1 << 2)
struct log_ctx {
// int stdout_orig;
// int stderr_orig;
char filename[MAX_LOGFILE_LEN];
volatile int logfile;
char peer_name[MAX_PEER_NAME];
unsigned int log_level;
uint32_t flags;
};
#endif
......@@ -34,16 +34,12 @@ uint64_t __get_id(void);
void __get_current_time(struct timeval *tv);
extern char __xseg_errbuf[4096];
void __xseg_log(const char *msg);
extern int (*xseg_snprintf)(char *str, size_t size, const char *format, ...);
struct log_ctx;
enum log_level { E = 0, W = 1, I = 2, D = 3};
extern int (*init_logctx)(struct log_ctx *lc, char *peer_name,
enum log_level log_level, char *logfile, uint32_t flags);
extern int (*renew_logctx)(struct log_ctx *lc, char *peer_name,
enum log_level log_level, char *logfile, uint32_t flags);
void __xseg_log2(struct log_ctx *lc, enum log_level level, char *fmt, ...);
extern void (*renew_logctx)(enum log_level level);
extern void (*init_logctx)(char *peer_name, enum log_level level);
void __xseg_log2(enum log_level level, char *fmt, ...);
void xseg_printtrace(void);
#endif
......@@ -41,14 +41,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define FMTARG(fmt, arg, format, ...) fmt format "%s", arg, ## __VA_ARGS__
#define XSEGLOG(...) (xseg_snprintf(__xseg_errbuf, 4096, FMTARG("%s: ", __func__, ## __VA_ARGS__, "")), \
__xseg_errbuf[4095] = 0, __xseg_log(__xseg_errbuf))
#define XSEGLOG2(__ctx, __level, ...) \
#define XSEGLOG2(__level, ...) \
do { \
if (__level <= ((__ctx)->log_level)) { \
__xseg_log2(__ctx, __level, FMTARG("%s: ", __func__, ## __VA_ARGS__ ,"")); \
} \
__xseg_log2(__level, FMTARG("%s: ", __func__, ## __VA_ARGS__ ,"")); \
} while(0)
/*
......@@ -121,19 +117,4 @@ typedef uint64_t xptr;
#define XPTR_TAKE(xptrval, base) \
( (void *) ( (unsigned long) base + (unsigned long) xptrval))
#define REOPEN_FILE (1 << 1)
#define REDIRECT_STDOUT (1 << 1)
#define REDIRECT_STDERR (1 << 2)
struct log_ctx {
// int stdout_orig;
// int stderr_orig;
char filename[MAX_LOGFILE_LEN];
volatile int logfile;
char peer_name[MAX_PEER_NAME];
unsigned int log_level;
uint32_t flags;
};
#endif
......@@ -162,7 +162,7 @@ __attribute__((always_inline)) static inline unsigned long xlock_acquire(struct
#ifdef XLOCK_CONGESTION_NOTIFY
if (!(times & ((1<<shift) -1))) {
xlock_unpack_owner(owner, &opid, &otid, &opc);
XSEGLOG("xlock %p spinned for %llu times"
XSEGLOG2(I, "xlock %p spinned for %llu times"
"\n\t who: (%d, %d, %p), "
"owner: (%d, %d, %p) (full pc: %p)",
(unsigned long) lock, times,
......
This diff is collapsed.
......@@ -43,7 +43,7 @@ static long posix_allocate(const char *name, uint64_t size)
fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0770);
if (fd < 0) {
err_no = errno;
XSEGLOG("Cannot create shared segment: %s\n",
XSEGLOG2(W, "Cannot create shared segment: %s\n",
strerror_r(errno, errbuf, ERRSIZE));
ret = fd;
goto exit;
......@@ -53,7 +53,7 @@ static long posix_allocate(const char *name, uint64_t size)
if (lr == (off_t)-1) {
err_no = errno;
close(fd);
XSEGLOG("Cannot seek into segment file: %s\n",
XSEGLOG2(W, "Cannot seek into segment file: %s\n",
strerror_r(errno, errbuf, ERRSIZE));
ret = lr;
goto exit;
......@@ -64,7 +64,7 @@ static long posix_allocate(const char *name, uint64_t size)
if (r != 1) {
err_no = errno;
close(fd);
XSEGLOG("Failed to set segment size: %s\n",
XSEGLOG2(W, "Failed to set segment size: %s\n",
strerror_r(errno, errbuf, ERRSIZE));
ret = r;
goto exit;
......@@ -90,7 +90,7 @@ static void *posix_map(const char *name, uint64_t size, struct xseg *seg)
fd = shm_open(name, O_RDWR, 0000);
if (fd < 0) {
err_no = errno;
XSEGLOG("Failed to open '%s' for mapping: %s\n",
XSEGLOG2(W, "Failed to open '%s' for mapping: %s\n",
name, strerror_r(errno, errbuf, ERRSIZE));
errno = err_no;
return NULL;
......@@ -104,7 +104,7 @@ static void *posix_map(const char *name, uint64_t size, struct xseg *seg)
if (xseg == MAP_FAILED) {
err_no = errno;
XSEGLOG("Could not map segment: %s\n",
XSEGLOG2(W, "Could not map segment: %s\n",
strerror_r(errno, errbuf, ERRSIZE));
errno = err_no;
return NULL;
......@@ -126,7 +126,8 @@ static void posix_unmap(void *ptr, uint64_t size)
static void handler(int signum)
{
static unsigned long counter;
printf("%lu: signal %d: this shouldn't have happened.\n", counter, signum);
XSEGLOG2(E, "%lu: signal %d: this shouldn't have happened.\n", counter,
signum);
counter ++;
}
......
......@@ -219,7 +219,7 @@ static int posixfd_wait_signal(struct xseg *xseg, void *sd, uint32_t usec_timeou
FD_SET(psd->fd, &fds);
r = select(psd->fd + 1, &fds, NULL, NULL, &tv);
//XSEGLOG("Tv sec: %ld, tv_usec: %ld", tv.tv_sec, tv.tv_usec);
//XSEGLOG2(I, "Tv sec: %ld, tv_usec: %ld", tv.tv_sec, tv.tv_usec);
if (r < 0) {
if (errno != EINTR) {
......
......@@ -43,7 +43,7 @@ static long pthread_allocate(const char *name, uint64_t size)
off_t lr;
fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0770);
if (fd < 0) {
XSEGLOG("Cannot create shared segment: %s\n",
XSEGLOG2(W, "Cannot create shared segment: %s\n",
strerror_r(errno, errbuf, ERRSIZE));
return fd;
}
......@@ -51,7 +51,7 @@ static long pthread_allocate(const char *name, uint64_t size)
lr = lseek(fd, size -1, SEEK_SET);
if (lr == (off_t)-1) {
close(fd);
XSEGLOG("Cannot seek into segment file: %s\n",
XSEGLOG2(W, "Cannot seek into segment file: %s\n",
strerror_r(errno, errbuf, ERRSIZE));
return lr;
}
......@@ -60,7 +60,7 @@ static long pthread_allocate(const char *name, uint64_t size)
r = write(fd, errbuf, 1);
if (r != 1) {
close(fd);
XSEGLOG("Failed to set segment size: %s\n",
XSEGLOG2(W, "Failed to set segment size: %s\n",
strerror_r(errno, errbuf, ERRSIZE));
return r;
}
......@@ -80,11 +80,11 @@ static void *pthread_map(const char *name, uint64_t size, struct xseg *seg)
int fd;
// if (seg)
// XSEGLOG("struct xseg * is not NULL. Ignoring...\n");
// XSEGLOG2(I, "struct xseg * is not NULL. Ignoring...\n");
fd = shm_open(name, O_RDWR, 0000);
if (fd < 0) {
XSEGLOG("Failed to open '%s' for mapping: %s\n",
XSEGLOG2(W, "Failed to open '%s' for mapping: %s\n",
name, strerror_r(errno, errbuf, ERRSIZE));
return NULL;
}
......@@ -96,7 +96,7 @@ static void *pthread_map(const char *name, uint64_t size, struct xseg *seg)
fd, 0 );
if (xseg == MAP_FAILED) {
XSEGLOG("Could not map segment: %s\n",
XSEGLOG2(W, "Could not map segment: %s\n",
strerror_r(errno, errbuf, ERRSIZE));
return NULL;
}
......@@ -115,7 +115,8 @@ static void pthread_unmap(void *ptr, uint64_t size)
static void handler(int signum)
{
static unsigned long counter;
printf("%lu: signal %d: this shouldn't have happened.\n", counter, signum);
XSEGLOG2(E, "%lu: signal %d: this shouldn't have happened.\n", counter,
signum);
counter ++;
}
......
......@@ -31,14 +31,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <fcntl.h>
#include <sys/time.h>
#include <execinfo.h>
#include <syslog.h>
#include <xseg/util.h>
#include <xseg/xtypes.h>
#include <xseg/domain.h>
#include <xseg/xlock.h>
int (*xseg_snprintf)(char *str, size_t size, const char *format, ...) = snprintf;
char __xseg_errbuf[4096];
static struct xlock __lock = { .owner = XLOCK_NOONE};
......@@ -66,7 +65,7 @@ void __load_plugin(const char *name)
_name[5 + namelen + 3 ] = 0;
dl = dlopen(_name, RTLD_NOW);
if (!dl) {
XSEGLOG("Cannot load plugin '%s': %s\n", _name, dlerror());
XSEGLOG2(W, "Cannot load plugin '%s': %s\n", _name, dlerror());
return;
}
......@@ -74,12 +73,12 @@ void __load_plugin(const char *name)
_name[127] = 0;
init = (void (*)(void))(long)dlsym(dl, _name);
if (!init) {
XSEGLOG("Init function '%s' not found!\n", _name);
XSEGLOG2(W, "Init function '%s' not found!\n", _name);
return;
}
init();
//XSEGLOG("Plugin '%s' loaded.\n", name);
//XSEGLOG2(I, "Plugin '%s' loaded.\n", name);
}
uint64_t __get_id(void)
......@@ -87,12 +86,6 @@ uint64_t __get_id(void)
return (uint64_t)syscall(SYS_gettid);
}
void __xseg_log(const char *msg)
{
fprintf(stderr, "%s", msg);
fflush(stderr);
}
void *xtypes_malloc(unsigned long size)
{
return malloc(size);
......@@ -107,170 +100,48 @@ void __get_current_time(struct timeval *tv) {
gettimeofday(tv, NULL);
}
int __renew_logctx(struct log_ctx *lc, char *peer_name,
enum log_level log_level, char *logfile, uint32_t flags)
{
int fd, tmp_fd;
mode_t old_mode;
if (peer_name){
strncpy(lc->peer_name, peer_name, MAX_PEER_NAME);
lc->peer_name[MAX_PEER_NAME -1] = 0;
}
lc->log_level = log_level;
if (logfile && logfile[0]) {
strncpy(lc->filename, logfile, MAX_LOGFILE_LEN);
lc->filename[MAX_LOGFILE_LEN - 1] = 0;
}
else if (!(flags & REOPEN_FILE) || lc->logfile == STDERR_FILENO)
return 0;
fd = open(lc->filename, O_WRONLY|O_CREAT|O_APPEND,
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (fd < 0){
return -1;
}
static inline int get_syslog_level(enum log_level level) {
int syslog_level;
tmp_fd = lc->logfile;
lc->logfile = fd;
close(tmp_fd);
flags &= ~REOPEN_FILE;
if ((flags|lc->flags) & REDIRECT_STDOUT){
fd = dup2(lc->logfile, STDOUT_FILENO);
if (fd < 0)
return -1;
}
if ((flags|lc->flags) & REDIRECT_STDERR){
fd = dup2(lc->logfile, STDERR_FILENO);
if (fd < 0)
return -1;
}
lc->flags |= flags;
switch (level) {
case E: syslog_level = LOG_ERR; break;
case W: syslog_level = LOG_WARNING; break;
case I: syslog_level = LOG_INFO; break;
case D: syslog_level = LOG_DEBUG; break;
default: syslog_level = LOG_DEBUG; break;
}
return 0;
return syslog_level;
}
int (*renew_logctx)(struct log_ctx *lc, char *peer_name,
enum log_level log_level, char *logfile, uint32_t flags) = __renew_logctx;
int __init_logctx(struct log_ctx *lc, char *peer_name,
enum log_level log_level, char *logfile, uint32_t flags)
static void __renew_logctx(enum log_level level)
{
int fd;
/* FIXME: LOG_UPTO portability */
setlogmask(LOG_UPTO(get_syslog_level(level)));
if (peer_name){
strncpy(lc->peer_name, peer_name, MAX_PEER_NAME);
lc->peer_name[MAX_PEER_NAME -1] = 0;
}
else {
return -1;
}
/* set logfile to stderr by default */
lc->logfile = STDERR_FILENO;
#if 0
/* duplicate stdout, stderr */
fd = dup(STDOUT_FILENO);
if (fd < 0){
return -1;
}
lc->stdout_orig = fd;
return;
}
fd = dup(STDERR_FILENO);
if (fd < 0){
return -1;
}
lc->stderr_orig = fd;
#endif
lc->log_level = log_level;
if (!logfile || !logfile[0]) {
// lc->logfile = lc->stderr_orig;
return 0;
}
void (*renew_logctx)(enum log_level level) = __renew_logctx;
strncpy(lc->filename, logfile, MAX_LOGFILE_LEN);
lc->filename[MAX_LOGFILE_LEN - 1] = 0;
fd = open(lc->filename, O_WRONLY|O_CREAT|O_APPEND,
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (fd < 1){
// lc->logfile = lc->stderr_orig;
return -1;
}
lc->logfile = fd;
static void __init_logctx(char *peer_name, enum log_level level)
{
openlog(peer_name, LOG_PID | LOG_CONS, LOG_LOCAL0);
if (flags & REDIRECT_STDOUT){
fd = dup2(lc->logfile, STDOUT_FILENO);
if (fd < 0)
return -1;
}
if (flags & REDIRECT_STDERR){
fd = dup2(lc->logfile, STDERR_FILENO);
if (fd < 0)
return -1;
}
lc->flags = flags;
/* FIXME: LOG_UPTO portability */
setlogmask(LOG_UPTO(get_syslog_level(level)));
return 0;
return;
}
int (*init_logctx)(struct log_ctx *lc, char *peer_name,
enum log_level log_level, char *logfile, uint32_t flags) = __init_logctx;
void __xseg_log2(struct log_ctx *lc, enum log_level level, char *fmt, ...)
void (*init_logctx)(char *peer_name, enum log_level level) = __init_logctx;
void __xseg_log2(enum log_level level, char *fmt, ...)
{
va_list ap;
time_t timeval;
char timebuf[1024], buffer[4096];
char *buf = buffer;
char *t = NULL, *pn = NULL;
ssize_t r, sum;
size_t count;
int fd;
va_start(ap, fmt);
switch (level) {
case E: t = "XSEG[EE]"; break;
case W: t = "XSEG[WW]"; break;
case I: t = "XSEG[II]"; break;
case D: t = "XSEG[DD]"; break;
default: t = "XSEG[UNKNONW]"; break;
}
pn = lc->peer_name;
if (!pn)
pn = "Invalid peer name";
time(&timeval);
ctime_r(&timeval, timebuf);
*strchr(timebuf, '\n') = '\0';
buf += sprintf(buf, "%s: ", t);
buf += snprintf(buf, MAX_PEER_NAME + 2, "%s: ", lc->peer_name);
buf += sprintf(buf, "%s (%ld):\n\t", timebuf, timeval);
unsigned long rem = sizeof(buffer) - (buf - buffer);
buf += vsnprintf(buf, rem, fmt, ap);
if (buf >= buffer + sizeof(buffer))
buf = buffer + sizeof(buffer) - 2;/* enough to hold \n and \0 */
buf += sprintf(buf, "\n");
count = buf-buffer;
sum = 0;
r = 0;
fd = *(volatile int *)&lc->logfile;
do {
r = write(fd, buffer + sum, count - sum);
if (r < 0){
if (errno == EBADF)
fd = *(volatile int *)&lc->logfile;
else {
//XSEGLOG("Error while writing log");
break;
}
} else {
sum += r;
}
} while (sum < count);
/* No need to check for error */
//fsync(fd);
vsyslog(get_syslog_level(level), fmt, ap);
va_end(ap);
return;
......@@ -291,9 +162,9 @@ void xseg_printtrace(void)
return;
}
XSEGLOG("Backtrace of tid %d:", tid);
XSEGLOG2(I, "Backtrace of tid %d:", tid);
for (i = 0; i < size; ++i)
{
XSEGLOG("\t%s", bt[i]);
XSEGLOG2(I, "\t%s", bt[i]);
}
}
......@@ -34,12 +34,12 @@ static inline void swap_nodes(struct xbinheap *h, xbinheapidx a, xbinheapidx b)
xbinheapidx h1, h2;
h1 = h->nodes[a].h;
h2 = h->nodes[b].h;
//XSEGLOG("Swaping %llu, %llu", a, b);
//XSEGLOG2(I, "Swaping %llu, %llu", a, b);
SWAP(h->nodes[a].key, h->nodes[b].key);
SWAP(h->nodes[a].value, h->nodes[b].value);
SWAP(h->nodes[a].h, h->nodes[b].h);
SWAP(h->indexes[h1], h->indexes[h2]);
//XSEGLOG("Index[%llu]: %llu, Index[%llu]: %lli", a, h->indexes[a], b, h->indexes[b]);
//XSEGLOG2(I, "Index[%llu]: %llu, Index[%llu]: %lli", a, h->indexes[a], b, h->indexes[b]);
}
static inline int isMaxHeap(struct xbinheap *h)
......@@ -57,7 +57,7 @@ static int heapify_up(struct xbinheap *h, xbinheapidx i)
parent = (i-1)/2;
n = &h->nodes[i];
pn = &h->nodes[parent];
//XSEGLOG("i: %llu, p: %llu, count: %lu", n->key, pn->key, h->count);
//XSEGLOG2(I, "i: %llu, p: %llu, count: %lu", n->key, pn->key, h->count);
if (isMaxHeap(h)){
cmp = pn->key < n->key;
} else {
......@@ -83,7 +83,7 @@ static int heapify_down(struct xbinheap *h, xbinheapidx i)
rn = &h->nodes[right];
largest_n = &h->nodes[largest];
if (isMaxHeap(h)){
// XSEGLOG("l: %llu, r: %llu, p: %llu, count: %lu", ln->key, rn->key, largest_n->key, h->count);
// XSEGLOG2(I, "l: %llu, r: %llu, p: %llu, count: %lu", ln->key, rn->key, largest_n->key, h->count);
if (left < h->count && (ln->key > largest_n->key)){
largest = left;
largest_n = &h->nodes[largest];
......@@ -159,7 +159,7 @@ int xbinheap_increasekey(struct xbinheap *h, xbinheap_handler idx,
int r;
xbinheapidx i = h->indexes[idx];
struct xbinheap_node *hn = &h->nodes[i];
//XSEGLOG("h: %llu, index: %llu, key: %llu, newkey:%llu",
//XSEGLOG2(I, "h: %llu, index: %llu, key: %llu, newkey:%llu",
// idx, i, hn->key, newkey);
//assert newkey > hn->key
hn->key = newkey;
......@@ -217,7 +217,7 @@ int xbinheap_decreasekey(struct xbinheap *h, xbinheap_handler idx,
int r;
xbinheapidx i = h->indexes[idx];
struct xbinheap_node *hn = &h->nodes[i];
//XSEGLOG("h: %llu, index: %llu, key: %llu, newkey:%llu",
//XSEGLOG2(I, "h: %llu, index: %llu, key: %llu, newkey:%llu",
// idx, i, hn->key, newkey);
//assert newkey > hn->key
hn->key = newkey;
......
......@@ -39,7 +39,7 @@ static xqindex __alloc_cache_entry(struct xcache *cache)
static void __free_cache_entry(struct xcache *cache, xqindex idx)
{
if (__xq_append_head(&cache->free_nodes, idx) == Noneidx)
XSEGLOG("BUG: Could not free cache entry node. Queue is full");
XSEGLOG2(W, "BUG: Could not free cache entry node. Queue is full");
}
#endif
......@@ -61,10 +61,10 @@ static int __table_insert(xhash_t **table, struct xcache * cache, xcache_handler
r = xhash_insert(*table, (xhashidx)ce->name, idx);
if (r == -XHASH_ERESIZE){
XSEGLOG("Rebuilding internal hash table");
XSEGLOG2(I, "Rebuilding internal hash table");
new = xhash_resize(*table, (*table)->size_shift, (*table)->limit, NULL);
if (!new) {
XSEGLOG("Error resizing hash table");
XSEGLOG2(W, "Error resizing hash table");
return -1;
}
*table = new;
......@@ -72,7 +72,7 @@ static int __table_insert(xhash_t **table, struct xcache * cache, xcache_handler
/* We give insertion a second shot */
r = xhash_insert(*table, (xhashidx)ce->name, idx);
if (r == -XHASH_ERESIZE) {
XSEGLOG("BUG: failed to insert entry after resize");
XSEGLOG2(W, "BUG: failed to insert entry after resize");
return -1;
}
}
......@@ -87,9 +87,9 @@ static int __table_remove(xhash_t *table, char *name)
r = xhash_delete(table, (xhashidx)name);
if (UNLIKELY(r<0)){
if (r == -XHASH_ERESIZE)
XSEGLOG("BUG: hash table must be resized");
XSEGLOG2(W, "BUG: hash table must be resized");
else if (r == -XHASH_EEXIST)
XSEGLOG("BUG: Entry %s not found in hash table", name);
XSEGLOG2(W, "BUG: Entry %s not found in hash table", name);
}
return r;
}
......@@ -102,7 +102,7 @@ static xqindex alloc_cache_entry(struct xcache *cache)
static void __free_cache_entry(struct xcache *cache, xqindex idx)
{
if (UNLIKELY(xq_append_head(&cache->free_nodes, idx) == Noneidx))
XSEGLOG("BUG: Could not free cache entry node. Queue is full");
XSEGLOG2(W, "BUG: Could not free cache entry node. Queue is full");
}
static void free_cache_entry(struct xcache *cache, xqindex idx)
......@@ -110,7 +110,7 @@ static void free_cache_entry(struct xcache *cache, xqindex idx)
struct xcache_entry *ce = &cache->nodes[idx];
if (ce->ref != 0)
XSEGLOG("BUG: Free entry has ref %lu (priv: %p, h: %p)", ce->priv, idx);
XSEGLOG2(W, "BUG: Free entry has ref %lu (priv: %p, h: %p)", ce->priv, idx);
__free_cache_entry(cache, idx);
if (cache->ops.on_free)
......@@ -175,7 +175,7 @@ static void __update_access_time(struct xcache *cache, xqindex idx)
} else {
ce->h = xbinheap_insert(&cache->binheap, cache->time, idx);
if (ce->h == NoNode){
XSEGLOG("BUG: Cannot insert to lru binary heap");
XSEGLOG2(W, "BUG: Cannot insert to lru binary heap");
}
}
}
......@@ -207,7 +207,7 @@ static int __xcache_remove_entries(struct xcache *cache, xcache_handler h)
r = __table_remove(cache->entries, ce->name);
if (UNLIKELY(r < 0)){
XSEGLOG("Couldn't delete cache entry from hash table:\n"
XSEGLOG2(W, "Couldn't delete cache entry from hash table:\n"
"h: %llu, name: %s, cache->nodes[h].priv: %p, ref: %llu",
h, ce->name, cache->nodes[idx].priv, cache->nodes[idx].ref);
return r;
......@@ -218,15 +218,15 @@ static int __xcache_remove_entries(struct xcache *cache, xcache_handler h)
else if (cache->flags & XCACHE_LRU_HEAP) {
if (ce->h != NoNode) {
if (xbinheap_increasekey(&cache->binheap, ce->h, XCACHE_LRU_MAX) < 0){
XSEGLOG("BUG: cannot increase key to XCACHE_LRU_MAX");
XSEGLOG2(W, "BUG: cannot increase key to XCACHE_LRU_MAX");
}
if (xbinheap_extract(&cache->binheap) == NoNode){
XSEGLOG("BUG: cannot remove cache entry from lru");
XSEGLOG2(W, "BUG: cannot remove cache entry from lru");
}
ce->h = NoNode;
}
}
//XSEGLOG("cache->times[%llu] = %llu", idx, cache->times[idx]);
//XSEGLOG2(I, "cache->times[%llu] = %llu", idx, cache->times[idx]);
return 0;
}
......@@ -242,7 +242,7 @@ static int __xcache_remove_rm(struct xcache *cache, xcache_handler h)
r = __table_remove(cache->rm_entries, ce->name);
if (UNLIKELY(r < 0)) {
XSEGLOG("Couldn't delete cache entry from hash table:\n"
XSEGLOG2(W, "Couldn't delete cache entry from hash table:\n"
"h: %llu, name: %s, cache->nodes[h].priv: %p, ref: %llu",
h, ce->name, cache->nodes[idx].priv, cache->nodes[idx].ref);
}
......@@ -364,7 +364,7 @@ static int xcache_entry_init(struct xcache *cache, xqindex idx, char *name)
xlock_release(&ce->lock);
if (UNLIKELY(ce->ref != 0))
XSEGLOG("BUG: New entry has ref != 0 (h: %lu, ref: %lu, priv: %p)",
XSEGLOG2(W, "BUG: New entry has ref != 0 (h: %lu, ref: %lu, priv: %p)",
idx, ce->ref, ce->priv);
ce->ref = 1;
strncpy(ce->name, name, XSEG_MAX_TARGETLEN);
......@@ -387,7 +387,7 @@ static xqindex __xcache_lru(struct xcache *cache)
if (cache->flags & XCACHE_LRU_ARRAY){
for (i = 0; i < cache->nr_nodes; i++) {
//XSEGLOG("cache->times[%llu] = %llu", i, cache->times[i]);
//XSEGLOG2(I, "cache->times[%llu] = %llu", i, cache->times[i]);
if (min > cache->times[i]){
min = cache->times[i];
lru = i;
......@@ -395,7 +395,7 @@ static xqindex __xcache_lru(struct xcache *cache)
}
//FIXME if cache->times[lru] == XCACHE_LRU_MAX
// lru = NoEntry;
//XSEGLOG("Found lru cache->times[%llu] = %llu", lru, cache->times[lru]);
//XSEGLOG2(I, "Found lru cache->times[%llu] = %llu", lru, cache->times[lru]);
} else if (cache->flags & XCACHE_LRU_HEAP) {
lru = xbinheap_extract(&cache->binheap);
if (lru == NoNode)
......@@ -418,7 +418,7 @@ static int __xcache_evict(struct xcache *cache, xcache_handler h)
r = __xcache_remove_entries(cache, h);
if (r < 0) {
XSEGLOG("Failed to evict %llu from entries", h);
XSEGLOG2(W, "Failed to evict %llu from entries", h);
return -1;
}
......@@ -429,7 +429,7 @@ static int __xcache_evict(struct xcache *cache, xcache_handler h)
ce = &cache->nodes[h];
if (UNLIKELY(ce->state == NODE_EVICTED))
XSEGLOG("BUG: Evicting an already evicted entry (h: %lu, priv: %p)",
XSEGLOG2(W, "BUG: Evicting an already evicted entry (h: %lu, priv: %p)",
h, ce->priv);
if (!(cache->flags & XCACHE_USE_RMTABLE))
......@@ -442,7 +442,7 @@ static int __xcache_evict(struct xcache *cache, xcache_handler h)
if (r < 0) {
ce->state = NODE_ACTIVE;
XSEGLOG("BUG: Failed insert %llu to rm_entries", h);
XSEGLOG2(W, "BUG: Failed insert %llu to rm_entries", h);
return -1;
}
......@@ -456,7 +456,7 @@ static xcache_handler __xcache_evict_lru(struct xcache *cache)
lru = __xcache_lru(cache);
if (lru == NoEntry){
XSEGLOG("BUG: No lru found");
XSEGLOG2(W, "BUG: No lru found");
return NoEntry;
}
......@@ -519,7 +519,7 @@ static xcache_handler __xcache_insert(struct xcache *cache, xcache_handler h,
/* if so then remove it from rm table */
r = __xcache_remove_rm(cache, tmp_h);
if (UNLIKELY(r < 0)) {
XSEGLOG("Could not remove found entry (%llu) for %s"
XSEGLOG2(W, "Could not remove found entry (%llu) for %s"
"from rm_entries", tmp_h, ce->name);
xlock_release(&cache->rm_lock);
return NoEntry;
......@@ -528,7 +528,7 @@ static xcache_handler __xcache_insert(struct xcache *cache, xcache_handler h,
/* and prepare it for reinsertion */
ce = &cache->nodes[tmp_h];
if (UNLIKELY(ce->state != NODE_EVICTED))
XSEGLOG("BUG: Entry (%llu) in rm table not in evicted state", tmp_h);
XSEGLOG2(W, "BUG: Entry (%llu) in rm table not in evicted state", tmp_h);
ce->state = NODE_ACTIVE;
__xcache_entry_get(cache, tmp_h);
......@@ -543,7 +543,7 @@ insert:
if (r == -XHASH_ENOSPC){
lru = __xcache_evict_lru(cache);
if (UNLIKELY(lru == NoEntry)) {
XSEGLOG("BUG: Failed to evict lru entry");