]> git.lttng.org Git - lttng-tools.git/commitdiff
Fix: truncate the metadata file in shm-path
authorLiguang Li <liguang.li@windriver.com>
Mon, 28 Nov 2016 08:37:47 +0000 (16:37 +0800)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 29 Nov 2016 17:53:45 +0000 (12:53 -0500)
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 <liguang.li@windriver.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/cmd.c

index fed029443094a39fe395c15d549744f3e46fa6ec..ae0a56ac67e0d249953ec39d28718323484dbbad 100644 (file)
@@ -3436,6 +3436,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_metadata_regenerate(struct ltt_ust_session *usess)
 {
@@ -3457,6 +3478,15 @@ int ust_metadata_regenerate(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(&registry->lock);
+                               goto end;
+                       }
+               }
+
                ret = ust_metadata_session_statedump(registry, NULL,
                                registry->major, registry->minor);
                if (ret) {
This page took 0.031968 seconds and 4 git commands to generate.