From: Mathieu Desnoyers Date: Wed, 23 Aug 2017 15:17:48 +0000 (-0700) Subject: Fix: sync buffer file metadata on buffer allocation X-Git-Tag: v2.9.2~7 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=1e88ac269f04995e989f7fda1eb93e0c7f2ed600;p=lttng-ust.git Fix: sync buffer file metadata on buffer allocation 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 --- diff --git a/libringbuffer/shm.c b/libringbuffer/shm.c index c4c651e4..8ac321e3 100644 --- a/libringbuffer/shm.c +++ b/libringbuffer/shm.c @@ -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);