Fix cpumask setting/getting on older kernels

Don't call into the affinity functions, unless the user has
specified a mask.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/fio.c b/fio.c
index 0c297f7..6483e64 100644
--- a/fio.c
+++ b/fio.c
@@ -792,7 +792,7 @@
 	if (init_io_u(td))
 		goto err;
 
-	if (fio_setaffinity(td) == -1) {
+	if (td->o.cpumask_set && fio_setaffinity(td) == -1) {
 		td_verror(td, errno, "cpu_set_affinity");
 		goto err;
 	}
diff --git a/fio.h b/fio.h
index 2717f5d..9a43c6f 100644
--- a/fio.h
+++ b/fio.h
@@ -406,6 +406,7 @@
 	unsigned int new_group;
 	unsigned int numjobs;
 	os_cpu_mask_t cpumask;
+	unsigned int cpumask_set;
 	unsigned int iolog;
 	unsigned int rwmixcycle;
 	unsigned int rwmix[2];
diff --git a/init.c b/init.c
index 0df30a2..355de88 100644
--- a/init.c
+++ b/init.c
@@ -655,10 +655,7 @@
 {
 	memset(&def_thread, 0, sizeof(def_thread));
 
-	if (fio_getaffinity(getpid(), &def_thread.o.cpumask) == -1) {
-		perror("sched_getaffinity");
-		return 1;
-	}
+	fio_getaffinity(getpid(), &def_thread.o.cpumask);
 
 	/*
 	 * fill default options
diff --git a/options.c b/options.c
index 54ceaee..e67742d 100644
--- a/options.c
+++ b/options.c
@@ -117,6 +117,7 @@
 	struct thread_data *td = data;
 
 	fill_cpu_mask(td->o.cpumask, *val);
+	td->o.cpumask_set = 1;
 	return 0;
 }