Rename list_* function and file to flist_ to avoid conflict with FreeBSD

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/blktrace.c b/blktrace.c
index 46dc13b..4469243 100644
--- a/blktrace.c
+++ b/blktrace.c
@@ -6,7 +6,7 @@
 #include <sys/stat.h>
 #include <dirent.h>
 
-#include "list.h"
+#include "flist.h"
 #include "fio.h"
 #include "blktrace_api.h"
 
@@ -157,7 +157,7 @@
 	ipo->ddir = DDIR_INVAL;
 	ipo->fileno = fileno;
 	ipo->file_action = FIO_LOG_OPEN_FILE;
-	list_add_tail(&ipo->list, &td->io_log_list);
+	flist_add_tail(&ipo->list, &td->io_log_list);
 }
 
 static void trace_add_file(struct thread_data *td, __u32 device)
@@ -201,7 +201,7 @@
 	struct io_piece *ipo = malloc(sizeof(*ipo));
 
 	memset(ipo, 0, sizeof(*ipo));
-	INIT_LIST_HEAD(&ipo->list);
+	INIT_FLIST_HEAD(&ipo->list);
 	/*
 	 * the 512 is wrong here, it should be the hardware sector size...
 	 */
diff --git a/diskutil.c b/diskutil.c
index 1815c4a..a38f4fa 100644
--- a/diskutil.c
+++ b/diskutil.c
@@ -11,7 +11,7 @@
 
 static int last_majdev, last_mindev;
 
-static struct list_head disk_list = LIST_HEAD_INIT(disk_list);
+static struct flist_head disk_list = FLIST_HEAD_INIT(disk_list);
 
 static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus)
 {
@@ -76,24 +76,24 @@
 
 void update_io_ticks(void)
 {
-	struct list_head *entry;
+	struct flist_head *entry;
 	struct disk_util *du;
 
 	dprint(FD_DISKUTIL, "update io ticks\n");
 
-	list_for_each(entry, &disk_list) {
-		du = list_entry(entry, struct disk_util, list);
+	flist_for_each(entry, &disk_list) {
+		du = flist_entry(entry, struct disk_util, list);
 		update_io_tick_disk(du);
 	}
 }
 
 static struct disk_util *disk_util_exists(int major, int minor)
 {
-	struct list_head *entry;
+	struct flist_head *entry;
 	struct disk_util *du;
 
-	list_for_each(entry, &disk_list) {
-		du = list_entry(entry, struct disk_util, list);
+	flist_for_each(entry, &disk_list) {
+		du = flist_entry(entry, struct disk_util, list);
 
 		if (major == du->major && minor == du->minor)
 			return du;
@@ -105,21 +105,21 @@
 static void disk_util_add(int majdev, int mindev, char *path)
 {
 	struct disk_util *du, *__du;
-	struct list_head *entry;
+	struct flist_head *entry;
 
 	dprint(FD_DISKUTIL, "add maj/min %d/%d: %s\n", majdev, mindev, path);
 
 	du = malloc(sizeof(*du));
 	memset(du, 0, sizeof(*du));
-	INIT_LIST_HEAD(&du->list);
+	INIT_FLIST_HEAD(&du->list);
 	sprintf(du->path, "%s/stat", path);
 	du->name = strdup(basename(path));
 	du->sysfs_root = path;
 	du->major = majdev;
 	du->minor = mindev;
 
-	list_for_each(entry, &disk_list) {
-		__du = list_entry(entry, struct disk_util, list);
+	flist_for_each(entry, &disk_list) {
+		__du = flist_entry(entry, struct disk_util, list);
 
 		dprint(FD_DISKUTIL, "found %s in list\n", __du->name);
 
@@ -135,7 +135,7 @@
 	fio_gettime(&du->time, NULL);
 	get_io_ticks(du, &du->last_dus);
 
-	list_add_tail(&du->list, &disk_list);
+	flist_add_tail(&du->list, &disk_list);
 }
 
 static int check_dev_match(int majdev, int mindev, char *path)
@@ -319,17 +319,17 @@
 void show_disk_util(void)
 {
 	struct disk_util_stat *dus;
-	struct list_head *entry, *next;
+	struct flist_head *entry, *next;
 	struct disk_util *du;
 	double util;
 
-	if (list_empty(&disk_list))
+	if (flist_empty(&disk_list))
 		return;
 
 	log_info("\nDisk stats (read/write):\n");
 
-	list_for_each(entry, &disk_list) {
-		du = list_entry(entry, struct disk_util, list);
+	flist_for_each(entry, &disk_list) {
+		du = flist_entry(entry, struct disk_util, list);
 		dus = &du->dus;
 
 		util = (double) 100 * du->dus.io_ticks / (double) du->msec;
@@ -347,9 +347,9 @@
 	/*
 	 * now free the list
 	 */
-	list_for_each_safe(entry, next, &disk_list) {
-		list_del(entry);
-		du = list_entry(entry, struct disk_util, list);
+	flist_for_each_safe(entry, next, &disk_list) {
+		flist_del(entry);
+		du = flist_entry(entry, struct disk_util, list);
 		free(du->name);
 		free(du);
 	}
diff --git a/engines/posixaio.c b/engines/posixaio.c
index acd215c..4aa1842 100644
--- a/engines/posixaio.c
+++ b/engines/posixaio.c
@@ -83,7 +83,7 @@
 {
 	struct posixaio_data *pd = td->io_ops->data;
 	struct aiocb *suspend_list[SUSPEND_ENTRIES];
-	struct list_head *entry;
+	struct flist_head *entry;
 	struct timespec start;
 	int have_timeout = 0;
 	int suspend_entries = 0;
@@ -95,8 +95,8 @@
 	r = 0;
 	memset(suspend_list, 0, sizeof(*suspend_list));
 restart:
-	list_for_each(entry, &td->io_u_busylist) {
-		struct io_u *io_u = list_entry(entry, struct io_u, list);
+	flist_for_each(entry, &td->io_u_busylist) {
+		struct io_u *io_u = flist_entry(entry, struct io_u, list);
 		int err;
 
 		if (io_u->seen)
diff --git a/filehash.c b/filehash.c
index 54cea99..a00ac78 100644
--- a/filehash.c
+++ b/filehash.c
@@ -2,15 +2,15 @@
 #include <assert.h>
 
 #include "fio.h"
-#include "list.h"
+#include "flist.h"
 #include "crc/crc16.h"
 
 #define HASH_BUCKETS	512
 #define HASH_MASK	(HASH_BUCKETS - 1)
 
-unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct list_head);
+unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct flist_head);
 
-static struct list_head *file_hash;
+static struct flist_head *file_hash;
 static struct fio_mutex *hash_lock;
 
 static unsigned short hash(const char *name)
@@ -23,8 +23,8 @@
 	fio_mutex_down(hash_lock);
 
 	if (f->flags & FIO_FILE_HASHED) {
-		assert(!list_empty(&f->hash_list));
-		list_del_init(&f->hash_list);
+		assert(!flist_empty(&f->hash_list));
+		flist_del_init(&f->hash_list);
 		f->flags &= ~FIO_FILE_HASHED;
 	}
 
@@ -33,11 +33,11 @@
 
 static struct fio_file *__lookup_file_hash(const char *name)
 {
-	struct list_head *bucket = &file_hash[hash(name)];
-	struct list_head *n;
+	struct flist_head *bucket = &file_hash[hash(name)];
+	struct flist_head *n;
 
-	list_for_each(n, bucket) {
-		struct fio_file *f = list_entry(n, struct fio_file, hash_list);
+	flist_for_each(n, bucket) {
+		struct fio_file *f = flist_entry(n, struct fio_file, hash_list);
 
 		if (!strcmp(f->file_name, name)) {
 			assert(f->fd != -1);
@@ -65,14 +65,14 @@
 	if (f->flags & FIO_FILE_HASHED)
 		return NULL;
 
-	INIT_LIST_HEAD(&f->hash_list);
+	INIT_FLIST_HEAD(&f->hash_list);
 
 	fio_mutex_down(hash_lock);
 
 	alias = __lookup_file_hash(f->file_name);
 	if (!alias) {
 		f->flags |= FIO_FILE_HASHED;
-		list_add_tail(&f->hash_list, &file_hash[hash(f->file_name)]);
+		flist_add_tail(&f->hash_list, &file_hash[hash(f->file_name)]);
 	}
 
 	fio_mutex_up(hash_lock);
@@ -85,7 +85,7 @@
 
 	fio_mutex_down(hash_lock);
 	for (i = 0; i < HASH_BUCKETS; i++)
-		has_entries += !list_empty(&file_hash[i]);
+		has_entries += !flist_empty(&file_hash[i]);
 	fio_mutex_up(hash_lock);
 
 	if (has_entries)
@@ -102,7 +102,7 @@
 
 	file_hash = ptr;
 	for (i = 0; i < HASH_BUCKETS; i++)
-		INIT_LIST_HEAD(&file_hash[i]);
+		INIT_FLIST_HEAD(&file_hash[i]);
 
 	hash_lock = fio_mutex_init(1);
 }
diff --git a/fio.c b/fio.c
index bcabe33..43197b7 100644
--- a/fio.c
+++ b/fio.c
@@ -243,7 +243,7 @@
  */
 static void cleanup_pending_aio(struct thread_data *td)
 {
-	struct list_head *entry, *n;
+	struct flist_head *entry, *n;
 	struct io_u *io_u;
 	int r;
 
@@ -258,8 +258,8 @@
 	 * now cancel remaining active events
 	 */
 	if (td->io_ops->cancel) {
-		list_for_each_safe(entry, n, &td->io_u_busylist) {
-			io_u = list_entry(entry, struct io_u, list);
+		flist_for_each_safe(entry, n, &td->io_u_busylist) {
+			io_u = flist_entry(entry, struct io_u, list);
 
 			/*
 			 * if the io_u isn't in flight, then that generally
@@ -653,13 +653,13 @@
 
 static void cleanup_io_u(struct thread_data *td)
 {
-	struct list_head *entry, *n;
+	struct flist_head *entry, *n;
 	struct io_u *io_u;
 
-	list_for_each_safe(entry, n, &td->io_u_freelist) {
-		io_u = list_entry(entry, struct io_u, list);
+	flist_for_each_safe(entry, n, &td->io_u_freelist) {
+		io_u = flist_entry(entry, struct io_u, list);
 
-		list_del(&io_u->list);
+		flist_del(&io_u->list);
 		free(io_u);
 	}
 
@@ -703,7 +703,7 @@
 			return 1;
 		io_u = malloc(sizeof(*io_u));
 		memset(io_u, 0, sizeof(*io_u));
-		INIT_LIST_HEAD(&io_u->list);
+		INIT_FLIST_HEAD(&io_u->list);
 
 		if (!(td->io_ops->flags & FIO_NOIO)) {
 			io_u->buf = p + max_bs * i;
@@ -714,7 +714,7 @@
 
 		io_u->index = i;
 		io_u->flags = IO_U_F_FREE;
-		list_add(&io_u->list, &td->io_u_freelist);
+		flist_add(&io_u->list, &td->io_u_freelist);
 	}
 
 	io_u_init_timeout();
@@ -850,11 +850,11 @@
 
 	dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
 
-	INIT_LIST_HEAD(&td->io_u_freelist);
-	INIT_LIST_HEAD(&td->io_u_busylist);
-	INIT_LIST_HEAD(&td->io_u_requeues);
-	INIT_LIST_HEAD(&td->io_log_list);
-	INIT_LIST_HEAD(&td->io_hist_list);
+	INIT_FLIST_HEAD(&td->io_u_freelist);
+	INIT_FLIST_HEAD(&td->io_u_busylist);
+	INIT_FLIST_HEAD(&td->io_u_requeues);
+	INIT_FLIST_HEAD(&td->io_log_list);
+	INIT_FLIST_HEAD(&td->io_hist_list);
 	td->io_hist_tree = RB_ROOT;
 
 	td_set_runstate(td, TD_INITIALIZED);
diff --git a/fio.h b/fio.h
index b1792ab..25318ae 100644
--- a/fio.h
+++ b/fio.h
@@ -16,7 +16,7 @@
 #include <assert.h>
 
 #include "compiler/compiler.h"
-#include "list.h"
+#include "flist.h"
 #include "fifo.h"
 #include "rbtree.h"
 #include "arch/arch.h"
@@ -92,7 +92,7 @@
 struct io_piece {
 	union {
 		struct rb_node rb_node;
-		struct list_head list;
+		struct flist_head list;
 	};
 	union {
 		int fileno;
@@ -170,7 +170,7 @@
 
 	struct fio_file *file;
 
-	struct list_head list;
+	struct flist_head list;
 
 	/*
 	 * Callback for io completion
@@ -295,7 +295,7 @@
  * this structure holds state information for a single file.
  */
 struct fio_file {
-	struct list_head hash_list;
+	struct flist_head hash_list;
 	enum fio_filetype filetype;
 
 	/*
@@ -572,9 +572,9 @@
 	 */
 	unsigned int cur_depth;
 	unsigned int io_u_queued;
-	struct list_head io_u_freelist;
-	struct list_head io_u_busylist;
-	struct list_head io_u_requeues;
+	struct flist_head io_u_freelist;
+	struct flist_head io_u_busylist;
+	struct flist_head io_u_requeues;
 
 	/*
 	 * Rate state
@@ -619,12 +619,12 @@
 	 * if we are overwriting. Otherwise just use a fifo.
 	 */
 	struct rb_root io_hist_tree;
-	struct list_head io_hist_list;
+	struct flist_head io_hist_list;
 
 	/*
 	 * For IO replaying
 	 */
-	struct list_head io_log_list;
+	struct flist_head io_log_list;
 
 	/*
 	 * timeout handling
@@ -746,7 +746,7 @@
  * Per-device disk util management
  */
 struct disk_util {
-	struct list_head list;
+	struct flist_head list;
 
 	char *name;
 	char *sysfs_root;
@@ -904,7 +904,7 @@
 /*
  * io unit handling
  */
-#define queue_full(td)	list_empty(&(td)->io_u_freelist)
+#define queue_full(td)	flist_empty(&(td)->io_u_freelist)
 extern struct io_u *__get_io_u(struct thread_data *);
 extern struct io_u *get_io_u(struct thread_data *);
 extern void put_io_u(struct thread_data *, struct io_u *);
@@ -941,7 +941,7 @@
 #endif
 
 struct ioengine_ops {
-	struct list_head list;
+	struct flist_head list;
 	char name[16];
 	int version;
 	int flags;
diff --git a/flist.h b/flist.h
new file mode 100644
index 0000000..f28a5ab
--- /dev/null
+++ b/flist.h
@@ -0,0 +1,146 @@
+#ifndef _LINUX_FLIST_H
+#define _LINUX_FLIST_H
+
+#undef offsetof
+#ifdef __compiler_offsetof
+#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
+#else
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
+#define container_of(ptr, type, member) ({			\
+	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
+	(type *)( (char *)__mptr - offsetof(type,member) );})
+
+/*
+ * Simple doubly linked list implementation.
+ *
+ * Some of the internal functions ("__xxx") are useful when
+ * manipulating whole lists rather than single entries, as
+ * sometimes we already know the next/prev entries and we can
+ * generate better code by using them directly rather than
+ * using the generic single-entry routines.
+ */
+
+struct flist_head {
+	struct flist_head *next, *prev;
+};
+
+#define FLIST_HEAD_INIT(name) { &(name), &(name) }
+
+#define FLIST_HEAD(name) \
+	struct flist_head name = FLIST_HEAD_INIT(name)
+
+#define INIT_FLIST_HEAD(ptr) do { \
+	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
+} while (0)
+
+/*
+ * Insert a new entry between two known consecutive entries.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __flist_add(struct flist_head *new,
+			       struct flist_head *prev,
+			       struct flist_head *next)
+{
+	next->prev = new;
+	new->next = next;
+	new->prev = prev;
+	prev->next = new;
+}
+
+/**
+ * flist_add - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it after
+ *
+ * Insert a new entry after the specified head.
+ * This is good for implementing stacks.
+ */
+static inline void flist_add(struct flist_head *new, struct flist_head *head)
+{
+	__flist_add(new, head, head->next);
+}
+
+static inline void flist_add_tail(struct flist_head *new,
+				  struct flist_head *head)
+{
+	__flist_add(new, head->prev, head);
+}
+
+/*
+ * Delete a list entry by making the prev/next entries
+ * point to each other.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __flist_del(struct flist_head *prev,
+			       struct flist_head * next)
+{
+	next->prev = prev;
+	prev->next = next;
+}
+
+/**
+ * flist_del - deletes entry from list.
+ * @entry: the element to delete from the list.
+ * Note: flist_empty on entry does not return true after this, the entry is
+ * in an undefined state.
+ */
+static inline void flist_del(struct flist_head *entry)
+{
+	__flist_del(entry->prev, entry->next);
+	entry->next = NULL;
+	entry->prev = NULL;
+}
+
+/**
+ * flist_del_init - deletes entry from list and reinitialize it.
+ * @entry: the element to delete from the list.
+ */
+static inline void flist_del_init(struct flist_head *entry)
+{
+	__flist_del(entry->prev, entry->next);
+	INIT_FLIST_HEAD(entry);
+}
+
+/**
+ * flist_empty - tests whether a list is empty
+ * @head: the list to test.
+ */
+static inline int flist_empty(const struct flist_head *head)
+{
+	return head->next == head;
+}
+
+/**
+ * flist_entry - get the struct for this entry
+ * @ptr:	the &struct flist_head pointer.
+ * @type:	the type of the struct this is embedded in.
+ * @member:	the name of the flist_struct within the struct.
+ */
+#define flist_entry(ptr, type, member) \
+	container_of(ptr, type, member)
+
+/**
+ * flist_for_each	-	iterate over a list
+ * @pos:	the &struct flist_head to use as a loop counter.
+ * @head:	the head for your list.
+ */
+#define flist_for_each(pos, head) \
+	for (pos = (head)->next; pos != (head); pos = pos->next)
+
+/**
+ * flist_for_each_safe	-	iterate over a list safe against removal of list entry
+ * @pos:	the &struct flist_head to use as a loop counter.
+ * @n:		another &struct flist_head to use as temporary storage
+ * @head:	the head for your list.
+ */
+#define flist_for_each_safe(pos, n, head) \
+	for (pos = (head)->next, n = pos->next; pos != (head); \
+		pos = n, n = pos->next)
+
+#endif
diff --git a/gettime.c b/gettime.c
index d78cf6d..2753fae 100644
--- a/gettime.c
+++ b/gettime.c
@@ -16,11 +16,11 @@
 #define HASH_BITS	8
 #define HASH_SIZE	(1 << HASH_BITS)
 
-static struct list_head hash[HASH_SIZE];
+static struct flist_head hash[HASH_SIZE];
 static int gtod_inited;
 
 struct gtod_log {
-	struct list_head list;
+	struct flist_head list;
 	void *caller;
 	unsigned long calls;
 };
@@ -28,10 +28,11 @@
 static struct gtod_log *find_hash(void *caller)
 {
 	unsigned long h = hash_ptr(caller, HASH_BITS);
-	struct list_head *entry;
+	struct flist_head *entry;
 
-	list_for_each(entry, &hash[h]) {
-		struct gtod_log *log = list_entry(entry, struct gtod_log, list);
+	flist_for_each(entry, &hash[h]) {
+		struct gtod_log *log = flist_entry(entry, struct gtod_log,
+									list);
 
 		if (log->caller == caller)
 			return log;
@@ -48,12 +49,12 @@
 		unsigned long h;
 
 		log = malloc(sizeof(*log));
-		INIT_LIST_HEAD(&log->list);
+		INIT_FLIST_HEAD(&log->list);
 		log->caller = caller;
 		log->calls = 0;
 
 		h = hash_ptr(caller, HASH_BITS);
-		list_add_tail(&log->list, &hash[h]);
+		flist_add_tail(&log->list, &hash[h]);
 	}
 
 	return log;
@@ -74,11 +75,11 @@
 	int i;
 
 	for (i = 0; i < HASH_SIZE; i++) {
-		struct list_head *entry;
+		struct flist_head *entry;
 		struct gtod_log *log;
 
-		list_for_each(entry, &hash[i]) {
-			log = list_entry(entry, struct gtod_log, list);
+		flist_for_each(entry, &hash[i]) {
+			log = flist_entry(entry, struct gtod_log, list);
 
 			printf("function %p, calls %lu\n", log->caller,
 								log->calls);
@@ -94,7 +95,7 @@
 	int i;
 
 	for (i = 0; i < HASH_SIZE; i++)
-		INIT_LIST_HEAD(&hash[i]);
+		INIT_FLIST_HEAD(&hash[i]);
 
 	gtod_inited = 1;
 }
diff --git a/io_u.c b/io_u.c
index 927e161..57b991a 100644
--- a/io_u.c
+++ b/io_u.c
@@ -354,8 +354,8 @@
 		put_file_log(td, io_u->file);
 
 	io_u->file = NULL;
-	list_del(&io_u->list);
-	list_add(&io_u->list, &td->io_u_freelist);
+	flist_del(&io_u->list);
+	flist_add(&io_u->list, &td->io_u_freelist);
 	td->cur_depth--;
 }
 
@@ -371,8 +371,8 @@
 
 	__io_u->flags &= ~IO_U_F_FLIGHT;
 
-	list_del(&__io_u->list);
-	list_add_tail(&__io_u->list, &td->io_u_requeues);
+	flist_del(&__io_u->list);
+	flist_add_tail(&__io_u->list, &td->io_u_requeues);
 	td->cur_depth--;
 	*io_u = NULL;
 }
@@ -764,10 +764,10 @@
 {
 	struct io_u *io_u = NULL;
 
-	if (!list_empty(&td->io_u_requeues))
-		io_u = list_entry(td->io_u_requeues.next, struct io_u, list);
+	if (!flist_empty(&td->io_u_requeues))
+		io_u = flist_entry(td->io_u_requeues.next, struct io_u, list);
 	else if (!queue_full(td)) {
-		io_u = list_entry(td->io_u_freelist.next, struct io_u, list);
+		io_u = flist_entry(td->io_u_freelist.next, struct io_u, list);
 
 		io_u->buflen = 0;
 		io_u->resid = 0;
@@ -780,8 +780,8 @@
 		io_u->flags &= ~IO_U_F_FREE;
 
 		io_u->error = 0;
-		list_del(&io_u->list);
-		list_add(&io_u->list, &td->io_u_busylist);
+		flist_del(&io_u->list);
+		flist_add(&io_u->list, &td->io_u_busylist);
 		td->cur_depth++;
 	}
 
@@ -1060,7 +1060,7 @@
 {
 	struct thread_data *td, *__td;
 	pid_t pid = getpid();
-	struct list_head *entry;
+	struct flist_head *entry;
 	struct io_u *io_u;
 	int i;
 
@@ -1089,8 +1089,8 @@
 
 	log_err("fio: io_u timeout: job=%s, pid=%d\n", td->o.name, td->pid);
 
-	list_for_each(entry, &td->io_u_busylist) {
-		io_u = list_entry(entry, struct io_u, list);
+	flist_for_each(entry, &td->io_u_busylist) {
+		io_u = flist_entry(entry, struct io_u, list);
 
 		io_u_dump(io_u);
 	}
diff --git a/ioengines.c b/ioengines.c
index dd70e1d..3e17897 100644
--- a/ioengines.c
+++ b/ioengines.c
@@ -18,7 +18,7 @@
 
 #include "fio.h"
 
-static LIST_HEAD(engine_list);
+static FLIST_HEAD(engine_list);
 
 static int check_engine_ops(struct ioengine_ops *ops)
 {
@@ -58,24 +58,24 @@
 void unregister_ioengine(struct ioengine_ops *ops)
 {
 	dprint(FD_IO, "ioengine %s unregistered\n", ops->name);
-	list_del(&ops->list);
-	INIT_LIST_HEAD(&ops->list);
+	flist_del(&ops->list);
+	INIT_FLIST_HEAD(&ops->list);
 }
 
 void register_ioengine(struct ioengine_ops *ops)
 {
 	dprint(FD_IO, "ioengine %s registered\n", ops->name);
-	INIT_LIST_HEAD(&ops->list);
-	list_add_tail(&ops->list, &engine_list);
+	INIT_FLIST_HEAD(&ops->list);
+	flist_add_tail(&ops->list, &engine_list);
 }
 
 static struct ioengine_ops *find_ioengine(const char *name)
 {
 	struct ioengine_ops *ops;
-	struct list_head *entry;
+	struct flist_head *entry;
 
-	list_for_each(entry, &engine_list) {
-		ops = list_entry(entry, struct ioengine_ops, list);
+	flist_for_each(entry, &engine_list) {
+		ops = flist_entry(entry, struct ioengine_ops, list);
 		if (!strcmp(name, ops->name))
 			return ops;
 	}
diff --git a/list.h b/list.h
deleted file mode 100644
index 172fa48..0000000
--- a/list.h
+++ /dev/null
@@ -1,144 +0,0 @@
-#ifndef _LINUX_LIST_H
-#define _LINUX_LIST_H
-
-#undef offsetof
-#ifdef __compiler_offsetof
-#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
-#else
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-#endif
-
-#define container_of(ptr, type, member) ({			\
-	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
-	(type *)( (char *)__mptr - offsetof(type,member) );})
-
-/*
- * Simple doubly linked list implementation.
- *
- * Some of the internal functions ("__xxx") are useful when
- * manipulating whole lists rather than single entries, as
- * sometimes we already know the next/prev entries and we can
- * generate better code by using them directly rather than
- * using the generic single-entry routines.
- */
-
-struct list_head {
-	struct list_head *next, *prev;
-};
-
-#define LIST_HEAD_INIT(name) { &(name), &(name) }
-
-#define LIST_HEAD(name) \
-	struct list_head name = LIST_HEAD_INIT(name)
-
-#define INIT_LIST_HEAD(ptr) do { \
-	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
-} while (0)
-
-/*
- * Insert a new entry between two known consecutive entries.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static inline void __list_add(struct list_head *new,
-			      struct list_head *prev,
-			      struct list_head *next)
-{
-	next->prev = new;
-	new->next = next;
-	new->prev = prev;
-	prev->next = new;
-}
-
-/**
- * list_add - add a new entry
- * @new: new entry to be added
- * @head: list head to add it after
- *
- * Insert a new entry after the specified head.
- * This is good for implementing stacks.
- */
-static inline void list_add(struct list_head *new, struct list_head *head)
-{
-	__list_add(new, head, head->next);
-}
-
-static inline void list_add_tail(struct list_head *new, struct list_head *head)
-{
-	__list_add(new, head->prev, head);
-}
-
-/*
- * Delete a list entry by making the prev/next entries
- * point to each other.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static inline void __list_del(struct list_head * prev, struct list_head * next)
-{
-	next->prev = prev;
-	prev->next = next;
-}
-
-/**
- * list_del - deletes entry from list.
- * @entry: the element to delete from the list.
- * Note: list_empty on entry does not return true after this, the entry is
- * in an undefined state.
- */
-static inline void list_del(struct list_head *entry)
-{
-	__list_del(entry->prev, entry->next);
-	entry->next = NULL;
-	entry->prev = NULL;
-}
-
-/**
- * list_del_init - deletes entry from list and reinitialize it.
- * @entry: the element to delete from the list.
- */
-static inline void list_del_init(struct list_head *entry)
-{
-	__list_del(entry->prev, entry->next);
-	INIT_LIST_HEAD(entry);
-}
-
-/**
- * list_empty - tests whether a list is empty
- * @head: the list to test.
- */
-static inline int list_empty(const struct list_head *head)
-{
-	return head->next == head;
-}
-
-/**
- * list_entry - get the struct for this entry
- * @ptr:	the &struct list_head pointer.
- * @type:	the type of the struct this is embedded in.
- * @member:	the name of the list_struct within the struct.
- */
-#define list_entry(ptr, type, member) \
-	container_of(ptr, type, member)
-
-/**
- * list_for_each	-	iterate over a list
- * @pos:	the &struct list_head to use as a loop counter.
- * @head:	the head for your list.
- */
-#define list_for_each(pos, head) \
-	for (pos = (head)->next; pos != (head); pos = pos->next)
-
-/**
- * list_for_each_safe	-	iterate over a list safe against removal of list entry
- * @pos:	the &struct list_head to use as a loop counter.
- * @n:		another &struct list_head to use as temporary storage
- * @head:	the head for your list.
- */
-#define list_for_each_safe(pos, n, head) \
-	for (pos = (head)->next, n = pos->next; pos != (head); \
-		pos = n, n = pos->next)
-
-#endif
diff --git a/log.c b/log.c
index 191f806..5c468ad 100644
--- a/log.c
+++ b/log.c
@@ -6,14 +6,14 @@
 #include <stdlib.h>
 #include <libgen.h>
 #include <assert.h>
-#include "list.h"
+#include "flist.h"
 #include "fio.h"
 
 static const char iolog_ver2[] = "fio version 2 iolog";
 
 void queue_io_piece(struct thread_data *td, struct io_piece *ipo)
 {
-	list_add_tail(&ipo->list, &td->io_log_list);
+	flist_add_tail(&ipo->list, &td->io_log_list);
 	td->total_io_size += ipo->len;
 }
 
@@ -109,11 +109,11 @@
 {
 	struct io_piece *ipo;
 
-	while (!list_empty(&td->io_log_list)) {
+	while (!flist_empty(&td->io_log_list)) {
 		int ret;
 
-		ipo = list_entry(td->io_log_list.next, struct io_piece, list);
-		list_del(&ipo->list);
+		ipo = flist_entry(td->io_log_list.next, struct io_piece, list);
+		flist_del(&ipo->list);
 
 		ret = ipo_special(td, ipo);
 		if (ret < 0) {
@@ -155,9 +155,9 @@
 		free(ipo);
 	}
 
-	while (!list_empty(&td->io_hist_list)) {
-		ipo = list_entry(td->io_hist_list.next, struct io_piece, list);
-		list_del(&ipo->list);
+	while (!flist_empty(&td->io_hist_list)) {
+		ipo = flist_entry(td->io_hist_list.next, struct io_piece, list);
+		flist_del(&ipo->list);
 		free(ipo);
 	}
 }
@@ -185,8 +185,8 @@
 	 * wrote it out is the fastest.
 	 */
 	if (!td_random(td) || !td->o.overwrite) {
-		INIT_LIST_HEAD(&ipo->list);
-		list_add_tail(&ipo->list, &td->io_hist_list);
+		INIT_FLIST_HEAD(&ipo->list);
+		flist_add_tail(&ipo->list, &td->io_hist_list);
 		return;
 	}
 
@@ -307,7 +307,7 @@
 		 */
 		ipo = malloc(sizeof(*ipo));
 		memset(ipo, 0, sizeof(*ipo));
-		INIT_LIST_HEAD(&ipo->list);
+		INIT_FLIST_HEAD(&ipo->list);
 		ipo->offset = offset;
 		ipo->len = bytes;
 		ipo->ddir = rw;
diff --git a/verify.c b/verify.c
index d602534..680e491 100644
--- a/verify.c
+++ b/verify.c
@@ -639,9 +639,9 @@
 
 		ipo = rb_entry(n, struct io_piece, rb_node);
 		rb_erase(n, &td->io_hist_tree);
-	} else if (!list_empty(&td->io_hist_list)) {
-		ipo = list_entry(td->io_hist_list.next, struct io_piece, list);
-		list_del(&ipo->list);
+	} else if (!flist_empty(&td->io_hist_list)) {
+		ipo = flist_entry(td->io_hist_list.next, struct io_piece, list);
+		flist_del(&ipo->list);
 	}
 
 	if (ipo) {