Put the ->real_file_size handling into fio

Then we can remove it from the io engines, where the disk-less IO
engines provided a ->setup() hook just to set that.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/engines/cpu.c b/engines/cpu.c
index dd69ced..14ad971 100644
--- a/engines/cpu.c
+++ b/engines/cpu.c
@@ -13,21 +13,6 @@
 	return FIO_Q_COMPLETED;
 }
 
-static int fio_cpuio_setup(struct thread_data fio_unused *td)
-{
-	struct fio_file *f;
-	unsigned int i;
-
-	for_each_file(td, f, i) {
-		if (td->o.size)
-			f->real_file_size = td->o.size / td->o.nr_files;
-		else
-			f->real_file_size = -1ULL;
-	}
-
-	return 0;
-}
-
 static int fio_cpuio_init(struct thread_data *td)
 {
 	struct thread_options *o = &td->o;
@@ -62,7 +47,6 @@
 	.version	= FIO_IOOPS_VERSION,
 	.queue		= fio_cpuio_queue,
 	.init		= fio_cpuio_init,
-	.setup		= fio_cpuio_setup,
 	.open_file	= fio_cpuio_open,
 	.flags		= FIO_SYNCIO | FIO_DISKLESSIO,
 };
diff --git a/engines/net.c b/engines/net.c
index cc707db..2b48b0a 100644
--- a/engines/net.c
+++ b/engines/net.c
@@ -269,8 +269,6 @@
 static int fio_netio_setup(struct thread_data *td)
 {
 	struct netio_data *nd;
-	struct fio_file *f;
-	unsigned int i;
 
 	if (!td->io_ops->data) {
 		nd = malloc(sizeof(*nd));;
@@ -278,13 +276,6 @@
 		memset(nd, 0, sizeof(*nd));
 		nd->listenfd = -1;
 		td->io_ops->data = nd;
-
-		for_each_file(td, f, i) {
-			if (td->o.size)
-				f->real_file_size = td->o.size / td->o.nr_files;
-			else
-				f->real_file_size = -1ULL;
-		}
 	}
 
 	return 0;
diff --git a/engines/null.c b/engines/null.c
index 318952c..823d40d 100644
--- a/engines/null.c
+++ b/engines/null.c
@@ -65,21 +65,6 @@
 	return FIO_Q_QUEUED;
 }
 
-static int fio_null_setup(struct thread_data *td)
-{
-	struct fio_file *f;
-	unsigned int i;
-
-	for_each_file(td, f, i) {
-		if (td->o.size)
-			f->real_file_size = td->o.size / td->o.nr_files;
-		else
-			f->real_file_size = -1ULL;
-	}
-
-	return 0;
-}
-
 static int fio_null_open(struct thread_data fio_unused *td,
 			 struct fio_file fio_unused *f)
 {
@@ -117,7 +102,6 @@
 static struct ioengine_ops ioengine = {
 	.name		= "null",
 	.version	= FIO_IOOPS_VERSION,
-	.setup		= fio_null_setup,
 	.queue		= fio_null_queue,
 	.commit		= fio_null_commit,
 	.getevents	= fio_null_getevents,
diff --git a/filesetup.c b/filesetup.c
index 62d048e..bd975d8 100644
--- a/filesetup.c
+++ b/filesetup.c
@@ -288,8 +288,10 @@
 				err = 1;
 			}
 			clear_error(td);
-		} else
-			td->io_ops->close_file(td, f);
+		} else {
+			if (td->io_ops->close_file)
+				td->io_ops->close_file(td, f);
+		}
 
 		if (f->real_file_size == -1ULL && td->o.size)
 			f->real_file_size = td->o.size / td->o.nr_files;
@@ -499,6 +501,12 @@
 	memset(f, 0, sizeof(*f));
 	f->fd = -1;
 
+	/*
+	 * init function, io engine may not be loaded yet
+	 */
+	if (td->io_ops && (td->io_ops->flags & FIO_DISKLESSIO))
+		f->real_file_size = -1ULL;
+
 	if (td->o.directory)
 		len = sprintf(file_name, "%s/", td->o.directory);
 
diff --git a/init.c b/init.c
index 0151c9b..bc33f4f 100644
--- a/init.c
+++ b/init.c
@@ -427,6 +427,13 @@
 	if (fixup_options(td))
 		goto err;
 
+	if (td->io_ops->flags & FIO_DISKLESSIO) {
+		struct fio_file *f;
+
+		for_each_file(td, f, i)
+			f->real_file_size = -1ULL;
+	}
+
 	td->mutex = fio_sem_init(0);
 
 	td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX;