CPU set creation and destruction can fail on some platforms
authorJens Axboe <jens.axboe@oracle.com>
Fri, 12 Dec 2008 19:51:40 +0000 (20:51 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 12 Dec 2008 19:51:40 +0000 (20:51 +0100)
Check for that and error out if necessary.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
fio.c
options.c
os/os-linux.h
os/os-solaris.h

diff --git a/fio.c b/fio.c
index 2a468b134de5bb02ed3ee4dece8b8ea9b645b2b8..30b40cc7e27d8be1e9940695ed2c36c92bba2c46 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -1116,8 +1116,11 @@ err:
        close_ioengine(td);
        cleanup_io_u(td);
 
        close_ioengine(td);
        cleanup_io_u(td);
 
-       if (td->o.cpumask_set)
-               fio_cpuset_exit(td);
+       if (td->o.cpumask_set) {
+               int ret = fio_cpuset_exit(&td->o.cpumask);
+
+               td_verror(td, ret, "fio_cpuset_exit");
+       }
 
        /*
         * do this very late, it will log file closing as well
 
        /*
         * do this very late, it will log file closing as well
index 8e11227c6e0ff2917fbb0307fcbabb601286ec53..f5bc9c073c6f9f1e62a5674fbecd82b62aabe681 100644 (file)
--- a/options.c
+++ b/options.c
@@ -247,8 +247,15 @@ static int str_cpumask_cb(void *data, unsigned int *val)
        struct thread_data *td = data;
        unsigned int i;
        long max_cpu;
        struct thread_data *td = data;
        unsigned int i;
        long max_cpu;
+       int ret;
+
+       ret = fio_cpuset_init(&td->o.cpumask);
+       if (ret < 0) {
+               log_err("fio: cpuset_init failed\n");
+               td_verror(td, ret, "fio_cpuset_init");
+               return 1;
+       }
 
 
-       fio_cpuset_init(td);
        max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
 
        for (i = 0; i < sizeof(int) * 8; i++) {
        max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
 
        for (i = 0; i < sizeof(int) * 8; i++) {
@@ -274,7 +281,12 @@ static int str_cpus_allowed_cb(void *data, const char *input)
        long max_cpu;
        int ret = 0;
 
        long max_cpu;
        int ret = 0;
 
-       fio_cpuset_init(td);
+       ret = fio_cpuset_init(&td->o.cpumask);
+       if (ret < 0) {
+               log_err("fio: cpuset_init failed\n");
+               td_verror(td, ret, "fio_cpuset_init");
+               return 1;
+       }
 
        p = str = strdup(input);
 
 
        p = str = strdup(input);
 
index 33380461f19c0c8fe122b9577e324f22ebe66a23..03d2450cf5f9388199ec227743eb9172807d71c9 100644 (file)
@@ -65,8 +65,17 @@ typedef struct drand48_data os_random_state_t;
 
 #define fio_cpu_clear(mask, cpu)       CPU_CLR((cpu), (mask))
 #define fio_cpu_set(mask, cpu)         CPU_SET((cpu), (mask))
 
 #define fio_cpu_clear(mask, cpu)       CPU_CLR((cpu), (mask))
 #define fio_cpu_set(mask, cpu)         CPU_SET((cpu), (mask))
-#define fio_cpuset_init(td)            CPU_ZERO(&(td)->o.cpumask)
-#define fio_cpuset_exit(td)            do { } while (0)
+
+static inline int fio_cpuset_init(os_cpu_mask_t *mask)
+{
+       CPU_ZERO(mask);
+       return 0;
+}
+
+static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
+{
+       return 0;
+}
 
 #define FIO_MAX_CPUS                   CPU_SETSIZE
 
 
 #define FIO_MAX_CPUS                   CPU_SETSIZE
 
index de948952f866541acf41cad840efc8fff0529769..6b44ec09b7dc9766967d0c38b71a808ed8091346 100644 (file)
@@ -74,8 +74,30 @@ static inline int fio_set_odirect(int fd)
 
 #define fio_cpu_clear(mask, cpu)       pset_assign(*(mask), (cpu), PS_NONE)
 #define fio_cpu_set(mask, cpu)         pset_assign(*(mask), (cpu), PS_MYID)
 
 #define fio_cpu_clear(mask, cpu)       pset_assign(*(mask), (cpu), PS_NONE)
 #define fio_cpu_set(mask, cpu)         pset_assign(*(mask), (cpu), PS_MYID)
-#define fio_cpuset_init(td)            pset_create(&(td)->o.cpumask)
-#define fio_cpuset_exit(td)            pset_destroy((td)->o.cpumask)
+
+static inline int fio_cpuset_init(os_cpu_mask_t *mask)
+{
+       int ret;
+
+       if (pset_create(mask) < 0) {
+               ret = errno;
+               return -1;
+       }
+
+       return 0;
+}
+
+static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
+{
+       int ret;
+
+       if (pset_destroy(*mask) < 0) {
+               ret = errno;
+               return -1;
+       }
+
+       return 0;
+}
 
 /*
  * Should be enough, not aware of what (if any) restrictions Solaris has
 
 /*
  * Should be enough, not aware of what (if any) restrictions Solaris has