options: move ioprio/ioprio_class into thread_options space

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/backend.c b/backend.c
index ad92313..968b522 100644
--- a/backend.c
+++ b/backend.c
@@ -958,10 +958,12 @@
 {
 	unsigned long long elapsed;
 	struct thread_data *td = data;
+	struct thread_options *o = &td->o;
 	pthread_condattr_t attr;
 	int clear_state;
+	int ret;
 
-	if (!td->o.use_thread) {
+	if (!o->use_thread) {
 		setsid();
 		td->pid = getpid();
 	} else
@@ -1004,11 +1006,11 @@
 	 * A new gid requires privilege, so we need to do this before setting
 	 * the uid.
 	 */
-	if (td->o.gid != -1U && setgid(td->o.gid)) {
+	if (o->gid != -1U && setgid(o->gid)) {
 		td_verror(td, errno, "setgid");
 		goto err;
 	}
-	if (td->o.uid != -1U && setuid(td->o.uid)) {
+	if (o->uid != -1U && setuid(o->uid)) {
 		td_verror(td, errno, "setuid");
 		goto err;
 	}
@@ -1017,16 +1019,19 @@
 	 * If we have a gettimeofday() thread, make sure we exclude that
 	 * thread from this job
 	 */
-	if (td->o.gtod_cpu)
-		fio_cpu_clear(&td->o.cpumask, td->o.gtod_cpu);
+	if (o->gtod_cpu)
+		fio_cpu_clear(&o->cpumask, o->gtod_cpu);
 
 	/*
 	 * Set affinity first, in case it has an impact on the memory
 	 * allocations.
 	 */
-	if (td->o.cpumask_set && fio_setaffinity(td->pid, td->o.cpumask) == -1) {
-		td_verror(td, errno, "cpu_set_affinity");
-		goto err;
+	if (o->cpumask_set) {
+		ret = fio_setaffinity(td->pid, o->cpumask);
+		if (ret == -1) {
+			td_verror(td, errno, "cpu_set_affinity");
+			goto err;
+		}
 	}
 
 	if (fio_pin_memory(td))
@@ -1042,29 +1047,30 @@
 	if (init_io_u(td))
 		goto err;
 
-	if (td->o.verify_async && verify_async_init(td))
+	if (o->verify_async && verify_async_init(td))
 		goto err;
 
-	if (td->ioprio_set) {
-		if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
+	if (o->ioprio) {
+		ret = ioprio_set(IOPRIO_WHO_PROCESS, 0, o->ioprio_class, o->ioprio);
+		if (ret == -1) {
 			td_verror(td, errno, "ioprio_set");
 			goto err;
 		}
 	}
 
-	if (td->o.cgroup_weight && cgroup_setup(td, cgroup_list, &cgroup_mnt))
+	if (o->cgroup_weight && cgroup_setup(td, cgroup_list, &cgroup_mnt))
 		goto err;
 
 	errno = 0;
-	if (nice(td->o.nice) == -1 && errno != 0) {
+	if (nice(o->nice) == -1 && errno != 0) {
 		td_verror(td, errno, "nice");
 		goto err;
 	}
 
-	if (td->o.ioscheduler && switch_ioscheduler(td))
+	if (o->ioscheduler && switch_ioscheduler(td))
 		goto err;
 
-	if (!td->o.create_serialize && setup_files(td))
+	if (!o->create_serialize && setup_files(td))
 		goto err;
 
 	if (td_io_init(td))
@@ -1073,12 +1079,10 @@
 	if (init_random_map(td))
 		goto err;
 
-	if (td->o.exec_prerun) {
-		if (exec_string(td->o.exec_prerun))
-			goto err;
-	}
+	if (o->exec_prerun && exec_string(o->exec_prerun))
+		goto err;
 
-	if (td->o.pre_read) {
+	if (o->pre_read) {
 		if (pre_read_files(td) < 0)
 			goto err;
 	}
@@ -1206,8 +1210,8 @@
 	cleanup_io_u(td);
 	cgroup_shutdown(td, &cgroup_mnt);
 
-	if (td->o.cpumask_set) {
-		int ret = fio_cpuset_exit(&td->o.cpumask);
+	if (o->cpumask_set) {
+		int ret = fio_cpuset_exit(&o->cpumask);
 
 		td_verror(td, ret, "fio_cpuset_exit");
 	}
diff --git a/cconv.c b/cconv.c
index d94502b..285db4e 100644
--- a/cconv.c
+++ b/cconv.c
@@ -153,6 +153,8 @@
 	o->iolog = le32_to_cpu(top->iolog);
 	o->rwmixcycle = le32_to_cpu(top->rwmixcycle);
 	o->nice = le32_to_cpu(top->nice);
+	o->ioprio = le32_to_cpu(top->ioprio);
+	o->ioprio_class = le32_to_cpu(top->ioprio_class);
 	o->file_service_type = le32_to_cpu(top->file_service_type);
 	o->group_reporting = le32_to_cpu(top->group_reporting);
 	o->fadvise_hint = le32_to_cpu(top->fadvise_hint);
@@ -291,6 +293,8 @@
 	top->iolog = cpu_to_le32(o->iolog);
 	top->rwmixcycle = cpu_to_le32(o->rwmixcycle);
 	top->nice = cpu_to_le32(o->nice);
+	top->ioprio = cpu_to_le32(o->ioprio);
+	top->ioprio_class = cpu_to_le32(o->ioprio_class);
 	top->file_service_type = cpu_to_le32(o->file_service_type);
 	top->group_reporting = cpu_to_le32(o->group_reporting);
 	top->fadvise_hint = cpu_to_le32(o->fadvise_hint);
diff --git a/fio.h b/fio.h
index e37e5ae..9994ccd 100644
--- a/fio.h
+++ b/fio.h
@@ -105,8 +105,6 @@
 	size_t orig_buffer_size;
 	volatile int terminate;
 	volatile int runstate;
-	unsigned int ioprio;
-	unsigned int ioprio_set;
 	unsigned int last_was_sync;
 	enum fio_ddir last_ddir;
 
diff --git a/options.c b/options.c
index 5b668e5..962ca19 100644
--- a/options.c
+++ b/options.c
@@ -269,40 +269,6 @@
 	return 0;
 }
 
-#ifdef FIO_HAVE_IOPRIO
-static int str_prioclass_cb(void *data, unsigned long long *val)
-{
-	struct thread_data *td = data;
-	unsigned short mask;
-
-	/*
-	 * mask off old class bits, str_prio_cb() may have set a default class
-	 */
-	mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
-	td->ioprio &= mask;
-
-	td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
-	td->ioprio_set = 1;
-	return 0;
-}
-
-static int str_prio_cb(void *data, unsigned long long *val)
-{
-	struct thread_data *td = data;
-
-	td->ioprio |= *val;
-
-	/*
-	 * If no class is set, assume BE
-	 */
-	if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
-		td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
-
-	td->ioprio_set = 1;
-	return 0;
-}
-#endif
-
 static int str_exitall_cb(void)
 {
 	exitall_on_terminate = 1;
@@ -2176,7 +2142,7 @@
 		.name	= "prio",
 		.lname	= "I/O nice priority",
 		.type	= FIO_OPT_INT,
-		.cb	= str_prio_cb,
+		.off1	= td_var_offset(ioprio),
 		.help	= "Set job IO priority value",
 		.minval	= 0,
 		.maxval	= 7,
@@ -2188,7 +2154,7 @@
 		.name	= "prioclass",
 		.lname	= "I/O nice priority class",
 		.type	= FIO_OPT_INT,
-		.cb	= str_prioclass_cb,
+		.off1	= td_var_offset(ioprio_class),
 		.help	= "Set job IO priority class",
 		.minval	= 0,
 		.maxval	= 3,
diff --git a/os/os-linux.h b/os/os-linux.h
index d5c3f76..3f5b2d8 100644
--- a/os/os-linux.h
+++ b/os/os-linux.h
@@ -111,8 +111,31 @@
 
 #define FIO_MAX_CPUS			CPU_SETSIZE
 
-static inline int ioprio_set(int which, int who, int ioprio)
+enum {
+	IOPRIO_CLASS_NONE,
+	IOPRIO_CLASS_RT,
+	IOPRIO_CLASS_BE,
+	IOPRIO_CLASS_IDLE,
+};
+
+enum {
+	IOPRIO_WHO_PROCESS = 1,
+	IOPRIO_WHO_PGRP,
+	IOPRIO_WHO_USER,
+};
+
+#define IOPRIO_BITS		16
+#define IOPRIO_CLASS_SHIFT	13
+
+static inline int ioprio_set(int which, int who, int ioprio_class, int ioprio)
 {
+	/*
+	 * If no class is set, assume BE
+	 */
+	if (!ioprio_class)
+		ioprio_class = IOPRIO_CLASS_BE;
+
+	ioprio |= ioprio_class << IOPRIO_CLASS_SHIFT;
 	return syscall(__NR_ioprio_set, which, who, ioprio);
 }
 
@@ -186,22 +209,6 @@
 }
 #endif /* FIO_HAVE_SYSLET */
 
-enum {
-	IOPRIO_CLASS_NONE,
-	IOPRIO_CLASS_RT,
-	IOPRIO_CLASS_BE,
-	IOPRIO_CLASS_IDLE,
-};
-
-enum {
-	IOPRIO_WHO_PROCESS = 1,
-	IOPRIO_WHO_PGRP,
-	IOPRIO_WHO_USER,
-};
-
-#define IOPRIO_BITS		16
-#define IOPRIO_CLASS_SHIFT	13
-
 #ifndef BLKGETSIZE64
 #define BLKGETSIZE64	_IOR(0x12,114,size_t)
 #endif
diff --git a/os/os.h b/os/os.h
index 8d2a6ae..dc798c3 100644
--- a/os/os.h
+++ b/os/os.h
@@ -84,7 +84,7 @@
 #endif
 
 #ifndef FIO_HAVE_IOPRIO
-#define ioprio_set(which, who, prio)	(0)
+#define ioprio_set(which, who, prioclass, prio)	(0)
 #endif
 
 #ifndef FIO_HAVE_ODIRECT
diff --git a/thread_options.h b/thread_options.h
index 5a296c7..4b5f957 100644
--- a/thread_options.h
+++ b/thread_options.h
@@ -141,6 +141,8 @@
 	unsigned int rwmixcycle;
 	unsigned int rwmix[2];
 	unsigned int nice;
+	unsigned int ioprio;
+	unsigned int ioprio_class;
 	unsigned int file_service_type;
 	unsigned int group_reporting;
 	unsigned int fadvise_hint;
@@ -326,6 +328,8 @@
 	uint32_t rwmixcycle;
 	uint32_t rwmix[2];
 	uint32_t nice;
+	uint32_t ioprio;
+	uint32_t ioprio_class;
 	uint32_t file_service_type;
 	uint32_t group_reporting;
 	uint32_t fadvise_hint;