From: Mathieu Desnoyers Date: Wed, 23 Aug 2017 15:27:16 +0000 (-0700) Subject: Fix: move fsync after ftruncate X-Git-Tag: v2.11.0-rc1~48 X-Git-Url: http://git.lttng.org/?p=lttng-ust.git;a=commitdiff_plain;h=d0f6cf574ef992620b09c183cb3a0ea771070ea5 Fix: move fsync after ftruncate Move fsync after ftruncate to ensure we sync up all metadata after the entire initialization of the buffer. Signed-off-by: Mathieu Desnoyers --- diff --git a/libringbuffer/shm.c b/libringbuffer/shm.c index 8ac321e3..ea946ea3 100644 --- a/libringbuffer/shm.c +++ b/libringbuffer/shm.c @@ -39,9 +39,6 @@ * 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) @@ -70,11 +67,6 @@ 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); @@ -142,6 +134,15 @@ struct shm_object *_shm_object_table_alloc_shm(struct shm_object_table *table, PERROR("ftruncate"); goto error_ftruncate; } + /* + * Also ensure the file metadata is synced with the storage by using + * fsync(2). + */ + ret = fsync(shmfd); + if (ret) { + PERROR("fsync"); + goto error_fsync; + } obj->shm_fd_ownership = 0; obj->shm_fd = shmfd; @@ -161,6 +162,7 @@ struct shm_object *_shm_object_table_alloc_shm(struct shm_object_table *table, return obj; error_mmap: +error_fsync: error_ftruncate: error_zero_file: error_fcntl: