iolog: get rid of ic->nofree
[fio.git] / iolog.c
diff --git a/iolog.c b/iolog.c
index 950670562f61045a4256adc28ca23ccdaed4821c..c3b42b3be1cf02f66bcea1a798276b087ff20418 100644 (file)
--- a/iolog.c
+++ b/iolog.c
 
 static const char iolog_ver2[] = "fio version 2 iolog";
 
-#ifdef CONFIG_ZLIB
-
-struct iolog_compress {
-       struct flist_head list;
-       void *buf;
-       size_t len;
-       unsigned int seq;
-       int nofree;
-};
-
-#define GZ_CHUNK       131072
-
-static struct iolog_compress *get_new_chunk(unsigned int seq)
-{
-       struct iolog_compress *c;
-
-       c = malloc(sizeof(*c));
-       INIT_FLIST_HEAD(&c->list);
-       c->buf = malloc(GZ_CHUNK);
-       c->len = 0;
-       c->seq = seq;
-       c->nofree = 0;
-       return c;
-}
-
-static void free_chunk(struct iolog_compress *ic)
-{
-       if (!ic->nofree) {
-               free(ic->buf);
-               free(ic);
-       }
-}
-
-#endif
-
 void queue_io_piece(struct thread_data *td, struct io_piece *ipo)
 {
        flist_add_tail(&ipo->list, &td->io_log_list);
@@ -685,6 +650,41 @@ static void flush_samples(FILE *f, void *samples, uint64_t sample_size)
 }
 
 #ifdef CONFIG_ZLIB
+
+struct iolog_flush_data {
+       struct tp_work work;
+       struct io_log *log;
+       void *samples;
+       uint64_t nr_samples;
+};
+
+struct iolog_compress {
+       struct flist_head list;
+       void *buf;
+       size_t len;
+       unsigned int seq;
+};
+
+#define GZ_CHUNK       131072
+
+static struct iolog_compress *get_new_chunk(unsigned int seq)
+{
+       struct iolog_compress *c;
+
+       c = malloc(sizeof(*c));
+       INIT_FLIST_HEAD(&c->list);
+       c->buf = malloc(GZ_CHUNK);
+       c->len = 0;
+       c->seq = seq;
+       return c;
+}
+
+static void free_chunk(struct iolog_compress *ic)
+{
+       free(ic->buf);
+       free(ic);
+}
+
 static int z_stream_init(z_stream *stream, int gz_hdr)
 {
        int wbits = 15;
@@ -770,7 +770,6 @@ static int flush_chunk(struct iolog_compress *ic, int gz_hdr, FILE *f,
                        break;
        }
 
-       free_chunk(ic);
        return 0;
 }
 
@@ -787,11 +786,12 @@ static void flush_gz_chunks(struct io_log *log, FILE *f)
                ic = flist_entry(node, struct iolog_compress, list);
                flist_del(&ic->list);
 
-               if (log->log_gz_store) {
+               if (log->log_gz_store)
                        fwrite(ic->buf, ic->len, 1, f);
-                       free_chunk(ic);
-               } else
+               else
                        flush_chunk(ic, log->log_gz_store, f, &stream, &iter);
+
+               free_chunk(ic);
        }
 
        if (iter.seq) {
@@ -806,23 +806,23 @@ int iolog_file_inflate(const char *file)
        struct iolog_compress ic;
        z_stream stream;
        struct stat sb;
-       size_t ret;
+       ssize_t ret;
        FILE *f;
 
-       if (stat(file, &sb) < 0) {
-               perror("stat");
-               return 1;
-       }
-
        f = fopen(file, "r");
        if (!f) {
                perror("fopen");
                return 1;
        }
 
+       if (stat(file, &sb) < 0) {
+               fclose(f);
+               perror("stat");
+               return 1;
+       }
+
        ic.buf = malloc(sb.st_size);
        ic.len = sb.st_size;
-       ic.nofree = 1;
        ic.seq = 1;
 
        ret = fread(ic.buf, ic.len, 1, f);
@@ -901,13 +901,6 @@ static int finish_log(struct thread_data *td, struct io_log *log, int trylock)
 
 #ifdef CONFIG_ZLIB
 
-struct iolog_flush_data {
-       struct tp_work work;
-       struct io_log *log;
-       void *samples;
-       uint64_t nr_samples;
-};
-
 static int gz_work(struct tp_work *work)
 {
        struct iolog_flush_data *data;
@@ -916,7 +909,7 @@ static int gz_work(struct tp_work *work)
        unsigned int seq;
        z_stream stream;
        size_t total = 0;
-       int ret, wbits;
+       int ret;
 
        INIT_FLIST_HEAD(&list);
 
@@ -926,19 +919,7 @@ static int gz_work(struct tp_work *work)
        stream.zfree = Z_NULL;
        stream.opaque = Z_NULL;
 
-       /*
-        * Store gz header if storing to a file
-        */
-#if 0
-       wbits = 15;
-       if (data->log->log_gz_store)
-               wbits += 16;
-
-       ret = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
-                               31, 8, Z_DEFAULT_STRATEGY);
-#else
        ret = deflateInit(&stream, Z_DEFAULT_COMPRESSION);
-#endif
        if (ret != Z_OK) {
                log_err("fio: failed to init gz stream\n");
                return 0;