From 7802bae326824ecb116cb0d782bb7472eaa6f6e4 Mon Sep 17 00:00:00 2001 From: Liguang Li Date: Mon, 28 Nov 2016 16:37:47 +0800 Subject: [PATCH] Fix: truncate the metadata file in shm-path MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In the shm-path mode, the metadata will be backuped to a metadata file, when run the lttng command "lttng metadata regenerate" to resample the wall time following a major NTP correction, the metadata file will not be truncated and regenerated. Add the function clear_metadata_file() to truncate and regenerate the metadata file. Signed-off-by: Liguang Li Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/cmd.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 325ffd2cf..cc81906b6 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -3377,6 +3377,27 @@ end: return ret; } +static +int clear_metadata_file(int fd) +{ + int ret; + + ret = lseek(fd, 0, SEEK_SET); + if (ret < 0) { + PERROR("lseek"); + goto end; + } + + ret = ftruncate(fd, 0); + if (ret < 0) { + PERROR("ftruncate"); + goto end; + } + +end: + return ret; +} + static int ust_regenerate_metadata(struct ltt_ust_session *usess) { @@ -3398,6 +3419,15 @@ int ust_regenerate_metadata(struct ltt_ust_session *usess) memset(registry->metadata, 0, registry->metadata_alloc_len); registry->metadata_len = 0; registry->metadata_version++; + if (registry->metadata_fd > 0) { + /* Clear the metadata file's content. */ + ret = clear_metadata_file(registry->metadata_fd); + if (ret) { + pthread_mutex_unlock(®istry->lock); + goto end; + } + } + ret = ust_metadata_session_statedump(registry, NULL, registry->major, registry->minor); if (ret) { -- 2.34.1