blktrace: abort if device ioctl setup fails
authorJens Axboe <axboe@kernel.dk>
Sun, 5 Nov 2017 04:10:00 +0000 (22:10 -0600)
committerJens Axboe <axboe@kernel.dk>
Sun, 5 Nov 2017 04:10:00 +0000 (22:10 -0600)
If we fail doing the BLKTRACESETUP ioctl, blktrace still marches on
and sets up the rest. This results in errors like the below:

blktrace /dev/sdf
BLKTRACESETUP(2) /dev/sdf failed: 5/Input/output error
Thread 1 failed open /sys/kernel/debug/block/(null)/trace1: 2/No such file or directory
Thread 3 failed open /sys/kernel/debug/block/(null)/trace3: 2/No such file or directory
Thread 2 failed open /sys/kernel/debug/block/(null)/trace2: 2/No such file or directory
[...]
FAILED to start thread on CPU 0: 1/Operation not permitted
FAILED to start thread on CPU 1: 1/Operation not permitted
FAILED to start thread on CPU 2: 1/Operation not permitted

and blktrace continues to run, though it can't do anything in this
state.

If the ioctl setup fails, just abort.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
blktrace.c

index e8f2f877352260504d103e6f19f4d212492acd64..e048f687c4feb7822718b8f24edea3e7b0295c9b 100644 (file)
@@ -1066,9 +1066,10 @@ static void close_client_connections(void)
        }
 }
 
-static void setup_buts(void)
+static int setup_buts(void)
 {
        struct list_head *p;
+       int ret = 0;
 
        __list_for_each(p, &devpaths) {
                struct blk_user_trace_setup buts;
@@ -1086,10 +1087,14 @@ static void setup_buts(void)
                                free(dpp->stats);
                        dpp->stats = calloc(dpp->ncpus, sizeof(*dpp->stats));
                        memset(dpp->stats, 0, dpp->ncpus * sizeof(*dpp->stats));
-               } else
+               } else {
                        fprintf(stderr, "BLKTRACESETUP(2) %s failed: %d/%s\n",
                                dpp->path, errno, strerror(errno));
+                       ret++;
+               }
        }
+
+       return ret;
 }
 
 static void start_buts(void)
@@ -2676,7 +2681,8 @@ static int run_tracers(void)
        if (net_mode == Net_client)
                printf("blktrace: connecting to %s\n", hostname);
 
-       setup_buts();
+       if (setup_buts())
+               return 1;
 
        if (use_tracer_devpaths()) {
                if (setup_tracer_devpaths())