* Re: [PATCH] Fix: truncate the metadata file in shm-path
[not found] <1480322267-12997-1-git-send-email-liguang.li@windriver.com>
@ 2016-11-28 22:00 ` Jérémie Galarneau
[not found] ` <CA+jJMxv_JgJou-Ppn_1+_HOi3SK1fQMJ0Q_cwO9YDJH2Er=58Q@mail.gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Jérémie Galarneau @ 2016-11-28 22:00 UTC (permalink / raw)
To: Liguang Li; +Cc: lttng-dev
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@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@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(®istry->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@lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
--
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix: truncate the metadata file in shm-path
[not found] ` <CA+jJMxv_JgJou-Ppn_1+_HOi3SK1fQMJ0Q_cwO9YDJH2Er=58Q@mail.gmail.com>
@ 2016-11-29 2:22 ` Liguang Li
0 siblings, 0 replies; 3+ messages in thread
From: Liguang Li @ 2016-11-29 2:22 UTC (permalink / raw)
To: Jérémie Galarneau; +Cc: lttng-dev
Hi Jérémie,
Thanks for your review, i agree with your modification.
Regards,
Liguang
On 11/29/2016 06:00 AM, Jérémie Galarneau wrote:
> 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@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@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(®istry->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@lists.lttng.org
>> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>
>
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] Fix: truncate the metadata file in shm-path
@ 2016-11-28 8:37 Liguang Li
0 siblings, 0 replies; 3+ messages in thread
From: Liguang Li @ 2016-11-28 8:37 UTC (permalink / raw)
To: lttng-dev
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@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(®istry->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@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-11-29 3:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1480322267-12997-1-git-send-email-liguang.li@windriver.com>
2016-11-28 22:00 ` [PATCH] Fix: truncate the metadata file in shm-path Jérémie Galarneau
[not found] ` <CA+jJMxv_JgJou-Ppn_1+_HOi3SK1fQMJ0Q_cwO9YDJH2Er=58Q@mail.gmail.com>
2016-11-29 2:22 ` Liguang Li
2016-11-28 8:37 Liguang Li
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.