]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ring: archive a previous file-backed ring on startup
authorWilly Tarreau <w@1wt.eu>
Fri, 12 Aug 2022 13:38:20 +0000 (15:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 12 Aug 2022 13:40:19 +0000 (15:40 +0200)
In order to ensure that an instant restart of the process will not wipe
precious debugging information, and to leave time for an admin to archive
a copy of a ring, now upon startup, any previously existing file will be
renamed with the extra suffix ".bak", and any previously existing file
with suffix ".bak" will be removed.

doc/configuration.txt
src/sink.c

index 678d0af32d91c1405af46efdf40ce2cb4974f4f7..aa167a8264a089228316e064e61db6c089268e5e 100644 (file)
@@ -3593,7 +3593,12 @@ backing-file <path>
   the "struct ring" that starts at the beginning of the area, and that is
   required to recover the area's contents. The file will be created with the
   starting user's ownership, with mode 0600 and will be of the size configured
-  by the "size" directive.
+  by the "size" directive. Any previously existing file will be renamed with
+  the extra suffix ".bak", and any previously existing file with suffix ".bak"
+  will be removed. This ensures that instant restart of the process will not
+  wipe precious debugging information, and will leave time for an admin to spot
+  this new ".bak" file and to archive it if needed. This means that the total
+  storage capacity required will be double of the ring size.
 
   WARNING: there are stability and security implications in using this feature.
   First, backing the ring to a slow device (e.g. physical hard drive) may cause
index ffb6cf1f97912c74527b887cfbf57cfc38e766a1..806eb1706c28652a27a3c99f0462e52ecd296200 100644 (file)
@@ -846,6 +846,7 @@ int cfg_parse_ring(const char *file, int linenum, char **args, int kwm)
                 * for ring <ring>. Existing data are delete. NULL is returned on error.
                 */
                const char *backing = args[1];
+               char *oldback;
                size_t size;
                void *area;
                int fd;
@@ -862,6 +863,19 @@ int cfg_parse_ring(const char *file, int linenum, char **args, int kwm)
                        goto err;
                }
 
+               oldback = NULL;
+               memprintf(&oldback, "%s.bak", backing);
+               if (oldback) {
+                       /* try to rename any possibly existing ring file to
+                        * ".bak" and delete remains of older ones. This will
+                        * ensure we don't wipe useful debug info upon restart.
+                        */
+                       unlink(oldback);
+                       if (rename(backing, oldback) < 0)
+                               unlink(oldback);
+                       ha_free(&oldback);
+               }
+
                fd = open(backing, O_RDWR | O_CREAT, 0600);
                if (fd < 0) {
                        ha_alert("parsing [%s:%d] : cannot open backing-file '%s' for ring '%s': %s.\n", file, linenum, backing, cfg_sink->name, strerror(errno));