backend: if we can't grab stat_mutex, report a deadlock error and exit
authorTheodore Ts'o <tytso@mit.edu>
Sun, 23 Oct 2016 14:35:14 +0000 (08:35 -0600)
committerJens Axboe <axboe@fb.com>
Sun, 23 Oct 2016 14:35:14 +0000 (08:35 -0600)
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Jens Axboe <axboe@fb.com>
backend.c

index fb2a8551e396227fc01ed5849e95fbd0e15c38a8..093b6a3a290e25e406fa15026d1cca055f6e0816 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1471,6 +1471,7 @@ static void *thread_main(void *data)
        struct thread_data *td = fd->td;
        struct thread_options *o = &td->o;
        struct sk_out *sk_out = fd->sk_out;
        struct thread_data *td = fd->td;
        struct thread_options *o = &td->o;
        struct sk_out *sk_out = fd->sk_out;
+       int deadlock_loop_cnt;
        int clear_state;
        int ret;
 
        int clear_state;
        int ret;
 
@@ -1731,11 +1732,17 @@ static void *thread_main(void *data)
                 * the rusage_sem, which would never get upped because
                 * this thread is waiting for the stat mutex.
                 */
                 * the rusage_sem, which would never get upped because
                 * this thread is waiting for the stat mutex.
                 */
+               deadlock_loop_cnt = 0;
                do {
                        check_update_rusage(td);
                        if (!fio_mutex_down_trylock(stat_mutex))
                                break;
                        usleep(1000);
                do {
                        check_update_rusage(td);
                        if (!fio_mutex_down_trylock(stat_mutex))
                                break;
                        usleep(1000);
+                       if (deadlock_loop_cnt++ > 5000) {
+                               log_err("fio seems to be stuck grabbing stat_mutex, forcibly exiting\n");
+                               td->error = EDEADLOCK;
+                               goto err;
+                       }
                } while (1);
 
                if (td_read(td) && td->io_bytes[DDIR_READ])
                } while (1);
 
                if (td_read(td) && td->io_bytes[DDIR_READ])