Fix: sync buffer file metadata on buffer allocation
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 23 Aug 2017 15:17:48 +0000 (08:17 -0700)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 23 Aug 2017 15:17:48 +0000 (08:17 -0700)
Synchronizing the file metadata on disk after zeroing the whole file (on
buffer allocation) will make the crash extraction feature (--shm-path
create option) more robust. It ensures the content of the file metadata
backing the buffers does not have to be updated while tracing into the
memory map. Therefore, the on-disk metadata will never be out of sync at
the point where a system crash occurs.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
libringbuffer/shm.c

index c4c651e4b925543e373e9b016398636be4c03293..8ac321e3931906888f79dd9e2419a7dbca8225de 100644 (file)
@@ -39,6 +39,9 @@
  * Ensure we have the required amount of space available by writing 0
  * into the entire buffer. Not doing so can trigger SIGBUS when going
  * beyond the available shm space.
+ *
+ * Also ensure the file metadata is synced with the storage by using
+ * fsync(2).
  */
 static
 int zero_file(int fd, size_t len)
@@ -67,6 +70,11 @@ int zero_file(int fd, size_t len)
                }
                written += retlen;
        }
+       ret = fsync(fd);
+       if (ret) {
+               ret = (int) -errno;
+               goto error;
+       }
        ret = 0;
 error:
        free(zeropage);
This page took 0.025002 seconds and 4 git commands to generate.