]> git.proxmox.com Git - pve-cluster.git/blobdiff - data/src/logger.c
logger: drop fixme comment and add context to clusterlog duplicate log
[pve-cluster.git] / data / src / logger.c
index c0c61fbe1a4a18c98962e25ffdf1775b4b9996cf..1ba3c8b347dbd537aefb20f62a9fed59b381c9d5 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  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
@@ -27,6 +27,7 @@
 
 #include <unistd.h>
 #include <stdio.h>
+#include <inttypes.h>
 #include <stdint.h>
 #include <glib.h>
 #include <string.h>
@@ -121,7 +122,7 @@ clog_dump_entry(clog_entry_t *cur, uint32_t cpos)
        char tbuf[256];
        strftime(tbuf, sizeof(tbuf), "%F %T", localtime(&lt));
        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);
        
 }
 
@@ -135,6 +136,11 @@ clog_dump(clog_base_t *clog)
        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;
        }
 }
@@ -164,6 +170,11 @@ clog_dump_json(
        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)
@@ -219,7 +230,7 @@ clog_copy(
        clog_entry_t *new;
        if ((new = clog_alloc_entry(clog, size)))
                memcpy((char *)new + 8, (char *)entry + 8, size - 8);
-};
+}
 
 uint32_t
 clog_pack(
@@ -357,6 +368,11 @@ clog_sort(clog_base_t *clog)
 
                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;
        }
 
@@ -508,10 +524,12 @@ clusterlog_merge(
                                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;
@@ -608,11 +626,11 @@ clusterlog_insert(
        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);
-};
+}
 
 void
 clusterlog_add(