#include "filelock.h"
#include "smalloc.h"
+static int iolog_flush(struct io_log *log);
+
static const char iolog_ver2[] = "fio version 2 iolog";
void queue_io_piece(struct thread_data *td, struct io_piece *ipo)
{
struct io_log *l;
- l = smalloc(sizeof(*l));
- l->nr_samples = 0;
+ l = scalloc(1, sizeof(*l));
+ INIT_FLIST_HEAD(&l->io_logs);
l->log_type = p->log_type;
l->log_offset = p->log_offset;
l->log_gz = p->log_gz;
void free_log(struct io_log *log)
{
- free(log->log);
+ while (!flist_empty(&log->io_logs)) {
+ struct io_logs *cur_log;
+
+ cur_log = flist_first_entry(&log->io_logs, struct io_logs, list);
+ flist_del_init(&cur_log->list);
+ free(cur_log->log);
+ }
+
free(log->filename);
sfree(log);
}
struct workqueue_work work;
struct io_log *log;
void *samples;
- uint64_t nr_samples;
+ uint32_t nr_samples;
+ bool free;
};
#define GZ_CHUNK 131072
{
size_t ret;
- dprint(FD_COMPRESS, "inflate chunk size=%lu, seq=%u",
+ dprint(FD_COMPRESS, "inflate chunk size=%lu, seq=%u\n",
(unsigned long) ic->len, ic->seq);
if (ic->seq != iter->seq) {
inflate_gz_chunks(log, f);
- flush_samples(f, log->log, log->nr_samples * log_entry_sz(log));
+ while (!flist_empty(&log->io_logs)) {
+ struct io_logs *cur_log;
+
+ cur_log = flist_first_entry(&log->io_logs, struct io_logs, list);
+ flist_del_init(&cur_log->list);
+ flush_samples(f, cur_log->log, cur_log->nr_samples * log_entry_sz(log));
+ }
fclose(f);
clear_file_buffer(buf);
static int finish_log(struct thread_data *td, struct io_log *log, int trylock)
{
if (td->flags & TD_F_COMPRESS_LOG)
- iolog_flush(log, 1);
+ iolog_flush(log);
if (trylock) {
if (fio_trylock_file(log->filename))
INIT_FLIST_HEAD(&list);
+ memset(&stream, 0, sizeof(stream));
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
ret = 0;
done:
- free(data);
+ if (data->free)
+ free(data);
return ret;
err:
while (!flist_empty(&list)) {
* Queue work item to compress the existing log entries. We reset the
* current log to a small size, and reference the existing log in the
* data that we queue for compression. Once compression has been done,
- * this old log is freed. If called with wait == 1, will not return until
- * the log compression has completed.
+ * this old log is freed. If called with finish == true, will not return
+ * until the log compression has completed, and will flush all previous
+ * logs too
*/
-int iolog_flush(struct io_log *log, int wait)
+static int iolog_flush(struct io_log *log)
{
struct iolog_flush_data *data;
- io_u_quiesce(log->td);
-
data = malloc(sizeof(*data));
if (!data)
return 1;
data->log = log;
+ data->free = false;
- data->samples = log->log;
- data->nr_samples = log->nr_samples;
+ while (!flist_empty(&log->io_logs)) {
+ struct io_logs *cur_log;
- log->nr_samples = 0;
- log->max_samples = DEF_LOG_ENTRIES;
- log->log = malloc(log->max_samples * log_entry_sz(log));
+ cur_log = flist_first_entry(&log->io_logs, struct io_logs, list);
+ flist_del_init(&cur_log->list);
+
+ data->samples = cur_log->log;
+ data->nr_samples = cur_log->nr_samples;
+
+ cur_log->nr_samples = 0;
+ cur_log->max_samples = 0;
+ cur_log->log = NULL;
- if (!wait)
- workqueue_enqueue(&log->td->log_compress_wq, &data->work);
- else
gz_work(data);
+ }
+ free(data);
return 0;
}
+int iolog_cur_flush(struct io_log *log, struct io_logs *cur_log)
+{
+ struct iolog_flush_data *data;
+
+ data = malloc(sizeof(*data));
+ if (!data)
+ return 1;
+
+ data->log = log;
+
+ data->samples = cur_log->log;
+ data->nr_samples = cur_log->nr_samples;
+ data->free = true;
+
+ cur_log->nr_samples = cur_log->max_samples = 0;
+ cur_log->log = NULL;
+
+ workqueue_enqueue(&log->td->log_compress_wq, &data->work);
+ return 0;
+}
#else
-int iolog_flush(struct io_log *log, int wait)
+static int iolog_flush(struct io_log *log)
+{
+ return 1;
+}
+
+int iolog_cur_flush(struct io_log *log, struct io_logs *cur_log)
{
return 1;
}
#endif
+struct io_logs *iolog_cur_log(struct io_log *log)
+{
+ if (flist_empty(&log->io_logs))
+ return NULL;
+
+ return flist_last_entry(&log->io_logs, struct io_logs, list);
+}
+
+uint64_t iolog_nr_samples(struct io_log *iolog)
+{
+ struct flist_head *entry;
+ uint64_t ret = 0;
+
+ flist_for_each(entry, &iolog->io_logs) {
+ struct io_logs *cur_log;
+
+ cur_log = flist_entry(entry, struct io_logs, list);
+ ret += cur_log->nr_samples;
+ }
+
+ return ret;
+}
+
static int __write_log(struct thread_data *td, struct io_log *log, int try)
{
if (log)