[lttng-dev] [PATCH] Fix: truncate the metadata file in shm-path

Liguang Li liguang.li at windriver.com
Mon Nov 28 08:37:47 UTC 2016


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 ust_metadata_truncate() to truncate and regenerate the
metadata file.

Signed-off-by: Liguang Li <liguang.li at windriver.com>
---
 src/bin/lttng-sessiond/cmd.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c
index 325ffd2..ba83226 100644
--- a/src/bin/lttng-sessiond/cmd.c
+++ b/src/bin/lttng-sessiond/cmd.c
@@ -3378,6 +3378,25 @@ end:
 }
 
 static
+int ust_metadata_truncate(int fd, size_t length)
+{
+	int ret;
+
+	ret = lseek(fd, length, SEEK_SET);
+	if (ret < 0) {
+		PERROR("lseek");
+		goto out;
+	}
+
+	ret = ftruncate(fd, length);
+	if (ret < 0)
+		PERROR("ftruncate");
+
+out:
+	return ret;
+}
+
+static
 int ust_regenerate_metadata(struct ltt_ust_session *usess)
 {
 	int ret = 0;
@@ -3398,6 +3417,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++;
+		/*truncate the metadata file*/
+		if (registry->metadata_fd > 0) {
+			ret = ust_metadata_truncate(registry->metadata_fd, 0);
+			if (ret) {
+				pthread_mutex_unlock(&registry->lock);
+				goto end;
+			}
+		}
+
 		ret = ust_metadata_session_statedump(registry, NULL,
 				registry->major, registry->minor);
 		if (ret) {
-- 
2.7.4



More information about the lttng-dev mailing list