Wire up SIGUSR2 to kill blocking threads
authorJens Axboe <axboe@kernel.dk>
Fri, 30 Nov 2012 20:46:06 +0000 (21:46 +0100)
committerJens Axboe <axboe@kernel.dk>
Fri, 30 Nov 2012 20:46:06 +0000 (21:46 +0100)
Get rid of io engine ops SIGTERM flag, it didn't really
work.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c
engines/net.c
fio.h
ioengine.h
libfio.c

index f901503a6d347bf23e0e57fd3daca83feeb7544a..faa861cf64d303e993d3fe2c3044dcda2b3367a4 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1385,7 +1385,7 @@ static void reap_threads(unsigned int *nr_running, unsigned int *t_rate,
                        if (WIFSIGNALED(status)) {
                                int sig = WTERMSIG(status);
 
                        if (WIFSIGNALED(status)) {
                                int sig = WTERMSIG(status);
 
-                               if (sig != SIGTERM)
+                               if (sig != SIGTERM && sig != SIGUSR2)
                                        log_err("fio: pid=%d, got signal=%d\n",
                                                        (int) td->pid, sig);
                                td->sig = sig;
                                        log_err("fio: pid=%d, got signal=%d\n",
                                                        (int) td->pid, sig);
                                td->sig = sig;
index 8957545546b459e60bf3503bdbc73160fd3db0a5..81e173ccbffd82f2ca92e4857238ffeb435d4bc6 100644 (file)
@@ -881,6 +881,11 @@ static int fio_netio_setup(struct thread_data *td)
        return 0;
 }
 
        return 0;
 }
 
+static void fio_netio_terminate(struct thread_data *td)
+{
+       kill(td->pid, SIGUSR2);
+}
+
 #ifdef FIO_HAVE_SPLICE
 static int fio_netio_setup_splice(struct thread_data *td)
 {
 #ifdef FIO_HAVE_SPLICE
 static int fio_netio_setup_splice(struct thread_data *td)
 {
@@ -909,11 +914,12 @@ static struct ioengine_ops ioengine_splice = {
        .init                   = fio_netio_init,
        .cleanup                = fio_netio_cleanup,
        .open_file              = fio_netio_open_file,
        .init                   = fio_netio_init,
        .cleanup                = fio_netio_cleanup,
        .open_file              = fio_netio_open_file,
-       .close_file             = generic_close_file,
+       .close_file             = fio_netio_close_file,
+       .terminate              = fio_netio_terminate,
        .options                = options,
        .option_struct_size     = sizeof(struct netio_options),
        .flags                  = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
        .options                = options,
        .option_struct_size     = sizeof(struct netio_options),
        .flags                  = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
-                                 FIO_SIGTERM | FIO_PIPEIO,
+                                 FIO_PIPEIO,
 };
 #endif
 
 };
 #endif
 
@@ -927,10 +933,11 @@ static struct ioengine_ops ioengine_rw = {
        .cleanup                = fio_netio_cleanup,
        .open_file              = fio_netio_open_file,
        .close_file             = fio_netio_close_file,
        .cleanup                = fio_netio_cleanup,
        .open_file              = fio_netio_open_file,
        .close_file             = fio_netio_close_file,
+       .terminate              = fio_netio_terminate,
        .options                = options,
        .option_struct_size     = sizeof(struct netio_options),
        .flags                  = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
        .options                = options,
        .option_struct_size     = sizeof(struct netio_options),
        .flags                  = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
-                                 FIO_SIGTERM | FIO_PIPEIO,
+                                 FIO_PIPEIO,
 };
 
 static int str_hostname_cb(void *data, const char *input)
 };
 
 static int str_hostname_cb(void *data, const char *input)
diff --git a/fio.h b/fio.h
index d7cb4ab842f26b7a5563d7c3176097d794a0c6fe..58364aaf5c74c8338885cd0a59214ee9c1cc01ff 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -694,8 +694,8 @@ enum {
        TD_NOT_CREATED = 0,
        TD_CREATED,
        TD_INITIALIZED,
        TD_NOT_CREATED = 0,
        TD_CREATED,
        TD_INITIALIZED,
-       TD_SETTING_UP,
        TD_RAMP,
        TD_RAMP,
+       TD_SETTING_UP,
        TD_RUNNING,
        TD_PRE_READING,
        TD_VERIFYING,
        TD_RUNNING,
        TD_PRE_READING,
        TD_VERIFYING,
index e27dab1c1785ea1ac7af9b4f84361efe331082d8..997f90afcfe605feee231da08822289364be20dc 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef FIO_IOENGINE_H
 #define FIO_IOENGINE_H
 
 #ifndef FIO_IOENGINE_H
 #define FIO_IOENGINE_H
 
-#define FIO_IOOPS_VERSION      13
+#define FIO_IOOPS_VERSION      14
 
 enum {
        IO_U_F_FREE             = 1 << 0,
 
 enum {
        IO_U_F_FREE             = 1 << 0,
@@ -120,6 +120,7 @@ struct ioengine_ops {
        int (*open_file)(struct thread_data *, struct fio_file *);
        int (*close_file)(struct thread_data *, struct fio_file *);
        int (*get_file_size)(struct thread_data *, struct fio_file *);
        int (*open_file)(struct thread_data *, struct fio_file *);
        int (*close_file)(struct thread_data *, struct fio_file *);
        int (*get_file_size)(struct thread_data *, struct fio_file *);
+       void (*terminate)(struct thread_data *);
        int option_struct_size;
        struct fio_option *options;
        void *data;
        int option_struct_size;
        struct fio_option *options;
        void *data;
@@ -134,10 +135,9 @@ enum fio_ioengine_flags {
        FIO_NODISKUTIL  = 1 << 4,       /* diskutil can't handle filename */
        FIO_UNIDIR      = 1 << 5,       /* engine is uni-directional */
        FIO_NOIO        = 1 << 6,       /* thread does only pseudo IO */
        FIO_NODISKUTIL  = 1 << 4,       /* diskutil can't handle filename */
        FIO_UNIDIR      = 1 << 5,       /* engine is uni-directional */
        FIO_NOIO        = 1 << 6,       /* thread does only pseudo IO */
-       FIO_SIGTERM     = 1 << 7,       /* needs SIGTERM to exit */
-       FIO_PIPEIO      = 1 << 8,       /* input/output no seekable */
-       FIO_BARRIER     = 1 << 9,       /* engine supports barriers */
-       FIO_MEMALIGN    = 1 << 10,      /* engine wants aligned memory */
+       FIO_PIPEIO      = 1 << 7,       /* input/output no seekable */
+       FIO_BARRIER     = 1 << 8,       /* engine supports barriers */
+       FIO_MEMALIGN    = 1 << 9,       /* engine wants aligned memory */
 };
 
 /*
 };
 
 /*
index ee5a0ead1707f66fc7418c2b0b964d72727912ee..96ae8146b8cc16e62defedbfe3baa1a4050487e9 100644 (file)
--- a/libfio.c
+++ b/libfio.c
@@ -177,15 +177,15 @@ void fio_terminate_threads(int group_id)
                        /*
                         * if the thread is running, just let it exit
                         */
                        /*
                         * if the thread is running, just let it exit
                         */
-                       if (!td->pid)
+                       if (!td->pid || pid == td->pid)
                                continue;
                        else if (td->runstate < TD_RAMP)
                                kill(td->pid, SIGTERM);
                                continue;
                        else if (td->runstate < TD_RAMP)
                                kill(td->pid, SIGTERM);
-                       else if (pid != td->pid) {
+                       else {
                                struct ioengine_ops *ops = td->io_ops;
 
                                struct ioengine_ops *ops = td->io_ops;
 
-                               if (ops && (ops->flags & FIO_SIGTERM))
-                                       kill(td->pid, SIGTERM);
+                               if (ops && ops->terminate)
+                                       ops->terminate(td);
                        }
                }
        }
                        }
                }
        }