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

Jérémie Galarneau jeremie.galarneau at efficios.com
Mon Nov 28 22:00:07 UTC 2016


Hi Liguang,

Good catch, thanks for the fix!
I have slightly modified the patch prior to merging it, read on.

Jérémie

On 28 November 2016 at 03:37, Liguang Li <liguang.li at windriver.com> wrote:
> 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)

Changed the name of this function to clear_metadata_file(...) which
only takes an "fd" as parameter. There are no other users of this
utility yet, so I'm keeping it specific to its current use.

> +{
> +       int ret;
> +
> +       ret = lseek(fd, length, SEEK_SET);

length replaced by 0

> +       if (ret < 0) {
> +               PERROR("lseek");
> +               goto out;
> +       }
> +
> +       ret = ftruncate(fd, length);

length replaced by 0

> +       if (ret < 0)
> +               PERROR("ftruncate");

We use curly-braces even on single-line conditionals in this codebase.

> +
> +out:

Changed the "out" label to "end" to remain consistent with the rest of the code.

> +       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
>
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list