/*
- Copyright (C) 2010 Proxmox Server Solutions GmbH
+ Copyright (C) 2010 - 2020 Proxmox Server Solutions GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
#include <unistd.h>
#include <stdio.h>
+#include <inttypes.h>
#include <stdint.h>
#include <glib.h>
#include <string.h>
char tbuf[256];
strftime(tbuf, sizeof(tbuf), "%F %T", localtime(<));
printf("cpos %05d %08x %s", cpos, cur->uid, tbuf);
- printf(" %s{%016zX} %s[%s{%016zX}]: %s\n", node, cur->node_digest, tag, ident, cur->ident_digest, msg);
+ printf(" %s{%016" PRIX64 "} %s[%s{%016" PRIX64 "}]: %s\n", node, cur->node_digest, tag, ident, cur->ident_digest, msg);
}
while (cpos && (cpos <= clog->cpos || cpos > (clog->cpos + CLOG_MAX_ENTRY_SIZE))) {
clog_entry_t *cur = (clog_entry_t *)((char *)clog + cpos);
clog_dump_entry(cur, cpos);
+
+ // wrap-around has to land after initial position
+ if (cpos < cur->prev && cur->prev <= clog->cpos) {
+ break;
+ }
cpos = cur->prev;
}
}
guint count = 0;
while (cpos && (cpos <= clog->cpos || cpos > (clog->cpos + CLOG_MAX_ENTRY_SIZE))) {
clog_entry_t *cur = (clog_entry_t *)((char *)clog + cpos);
+
+ // wrap-around has to land after initial position
+ if (cpos < cur->prev && cur->prev <= clog->cpos) {
+ break;
+ }
cpos = cur->prev;
if (count >= max_entries)
clog_entry_t *new;
if ((new = clog_alloc_entry(clog, size)))
memcpy((char *)new + 8, (char *)entry + 8, size - 8);
-};
+}
uint32_t
clog_pack(
g_tree_insert(tree, cur, cur);
+ // wrap-around has to land after initial position
+ if (cpos < cur->prev && cur->prev <= clog->cpos) {
+ break;
+ }
+
cpos = cur->prev;
}
struct clusterlog {
GHashTable *dedup;
- GMutex *mutex;
+ GMutex mutex;
clog_base_t *base;
};
g_return_if_fail(cl != NULL);
g_return_if_fail(str != NULL);
- g_mutex_lock(cl->mutex);
+ g_mutex_lock(&cl->mutex);
clog_dump_json(cl->base, str, user, max_entries);
- g_mutex_unlock(cl->mutex);
+ g_mutex_unlock(&cl->mutex);
}
clog_base_t *
return NULL;
}
- g_mutex_lock(cl->mutex);
+ g_mutex_lock(&cl->mutex);
for (int i = 0; i < count; i++) {
if (i == local_index)
break;
}
- if (!cur->prev) {
+ // no previous entry or wrap-around into already overwritten entry
+ if (!cur->prev || (cpos[found] < cur->prev && cur->prev <= clog[found]->cpos)) {
cpos[found] = 0;
} else {
cpos[found] = cur->prev;
+ // wrap-around into current entry
if (!(cpos[found] <= clog[found]->cpos ||
cpos[found] > (clog[found]->cpos + CLOG_MAX_ENTRY_SIZE))) {
cpos[found] = 0;
g_free(cl->base);
cl->base = res;
- g_mutex_unlock(cl->mutex);
+ g_mutex_unlock(&cl->mutex);
return res;
}
{
g_return_if_fail(cl != NULL);
- if (cl->mutex)
- g_mutex_free(cl->mutex);
+ g_mutex_clear(&cl->mutex);
if (cl->base)
g_free(cl->base);
if (!cl)
return NULL;
- if (!(cl->mutex = g_mutex_new()))
- goto fail;
+ g_mutex_init(&cl->mutex);
if (!(cl->base = clog_new(0)))
goto fail;
g_return_val_if_fail(cl != NULL, NULL);
g_return_val_if_fail(res_len != NULL, NULL);
- g_mutex_lock(cl->mutex);
+ g_mutex_lock(&cl->mutex);
clog_base_t *new;
if ((new = clog_sort(cl->base))) {
}
*res_len = clog_size(cl->base);
- gpointer msg = g_memdup(cl->base, *res_len);
+ gpointer msg = g_memdup2(cl->base, *res_len);
- g_mutex_unlock(cl->mutex);
+ g_mutex_unlock(&cl->mutex);
return msg;
}
g_return_if_fail(cl != NULL);
g_return_if_fail(entry != NULL);
- g_mutex_lock(cl->mutex);
+ g_mutex_lock(&cl->mutex);
if (dedup_lookup(cl->dedup, entry)) {
clog_copy(cl->base, entry);
} else {
- cfs_message("ignore duplicate"); // fixme remove
+ cfs_message("ignore insert of duplicate cluster log");
}
- g_mutex_unlock(cl->mutex);
-};
+ g_mutex_unlock(&cl->mutex);
+}
void
clusterlog_add(