From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH] trace-cmd: Write the actual size of compressed block in the trace file
Date: Mon, 11 Apr 2022 07:10:38 +0300 [thread overview]
Message-ID: <20220411041038.132453-1-tz.stoyanov@gmail.com> (raw)
Before a data block is compressed using the chosen compression
algorithm, a hook function is called to calculate the size of the
required buffer to compress the data. In most cases that size is bigger
than the actual size of the compressed data. The current logic writes
into the trace file that buffer with its calculated size, even though
part of it is not used. In the trace file should be written only the
compressed data block, with its real size.
fixes: 3f8447b1 ("trace-cmd library: Add support for compression algorithms")
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
lib/trace-cmd/trace-compress.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/lib/trace-cmd/trace-compress.c b/lib/trace-cmd/trace-compress.c
index aa03d17c..a63295e6 100644
--- a/lib/trace-cmd/trace-compress.c
+++ b/lib/trace-cmd/trace-compress.c
@@ -303,7 +303,7 @@ error:
*/
int tracecmd_compress_block(struct tracecmd_compression *handle)
{
- unsigned int size;
+ unsigned int size, real_size;
char *buf;
int endian4;
int ret;
@@ -318,12 +318,14 @@ int tracecmd_compress_block(struct tracecmd_compression *handle)
if (!buf)
return -1;
- ret = handle->proto->compress_block(handle->context, handle->buffer, handle->pointer, buf, size);
- if (ret < 0)
+ real_size = handle->proto->compress_block(handle->context, handle->buffer, handle->pointer, buf, size);
+ if (real_size < 0) {
+ ret = real_size;
goto out;
+ }
/* Write compressed data size */
- endian4 = tep_read_number(handle->tep, &ret, 4);
+ endian4 = tep_read_number(handle->tep, &real_size, 4);
ret = do_write(handle, &endian4, 4);
if (ret != 4)
goto out;
@@ -337,8 +339,8 @@ int tracecmd_compress_block(struct tracecmd_compression *handle)
}
/* Write compressed data */
- ret = do_write(handle, buf, size);
- if (ret != size) {
+ ret = do_write(handle, buf, real_size);
+ if (ret != real_size) {
ret = -1;
goto out;
}
--
2.35.1
reply other threads:[~2022-04-11 4:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220411041038.132453-1-tz.stoyanov@gmail.com \
--to=tz.stoyanov@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).