iolog: fix bug with ret != Z_STREAM_END
authorJens Axboe <axboe@fb.com>
Thu, 19 May 2016 21:35:18 +0000 (15:35 -0600)
committerJens Axboe <axboe@fb.com>
Thu, 19 May 2016 21:35:18 +0000 (15:35 -0600)
Before adding more chunks, adjust the previous chunk size. This
fixes an inflate issue, where we'd get Z_DATA_ERROR because the
middle chunk did not have the correct length.

Signed-off-by: Jens Axboe <axboe@fb.com>
iolog.c

diff --git a/iolog.c b/iolog.c
index 234910ae84cf70620d7e446b1561a44fad15b47a..e2300a528e4759bb9dedaba5fc6a9fb8f4a46337 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -1023,7 +1023,7 @@ size_t log_chunk_sizes(struct io_log *log)
 
 static int gz_work(struct iolog_flush_data *data)
 {
-       struct iolog_compress *c;
+       struct iolog_compress *c = NULL;
        struct flist_head list;
        unsigned int seq;
        z_stream stream;
@@ -1052,6 +1052,8 @@ static int gz_work(struct iolog_flush_data *data)
                                (unsigned long) stream.avail_in, seq,
                                data->log->filename);
        do {
+               if (c)
+                       dprint(FD_COMPRESS, "seq=%d, chunk=%lu\n", seq, c->len);
                c = get_new_chunk(seq);
                stream.avail_out = GZ_CHUNK;
                stream.next_out = c->buf;
@@ -1077,6 +1079,11 @@ static int gz_work(struct iolog_flush_data *data)
                total += c->len;
                dprint(FD_COMPRESS, "seq=%d, chunk=%lu\n", seq, c->len);
        } else {
+               total -= c->len;
+               c->len = GZ_CHUNK - stream.avail_out;
+               total += c->len;
+               dprint(FD_COMPRESS, "seq=%d, chunk=%lu\n", seq, c->len);
+
                do {
                        c = get_new_chunk(seq);
                        stream.avail_out = GZ_CHUNK;