Add option to select how to service multiple files

Right now we just round robin the open files, but sometimes you
just want to randomly go through the files. Add a 'file_service'
option for that, default to round robin still.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/io_u.c b/io_u.c
index ab85193..6fb754e 100644
--- a/io_u.c
+++ b/io_u.c
@@ -325,7 +325,27 @@
 	td->io_u_lat[index]++;
 }
 
-static struct fio_file *get_next_file(struct thread_data *td)
+/*
+ * Get next file to service by choosing one at random
+ */
+static struct fio_file *get_next_file_rand(struct thread_data *td)
+{
+	long r = os_random_long(&td->next_file_state);
+	unsigned int fileno;
+	struct fio_file *f;
+
+	do {
+		fileno = (unsigned int) ((double) (td->nr_files - 1) * r / (RAND_MAX + 1.0));
+		f = &td->files[fileno];
+		if (f->fd != -1)
+			return f;
+	} while (1);
+}
+
+/*
+ * Get next file to service by doing round robin between all available ones
+ */
+static struct fio_file *get_next_file_rr(struct thread_data *td)
 {
 	unsigned int old_next_file = td->next_file;
 	struct fio_file *f;
@@ -393,7 +413,11 @@
 	if (io_u->file)
 		goto out;
 
-	f = get_next_file(td);
+	if (td->file_service_type == FIO_FSERVICE_RR)
+		f = get_next_file_rr(td);
+	else
+		f = get_next_file_rand(td);
+
 	if (!f) {
 		put_io_u(td, io_u);
 		return NULL;