blkparse: split off the timestamp correction code in to a separate function
[blktrace.git] / blktrace.c
index e8f2f877352260504d103e6f19f4d212492acd64..d0d271f9add5106b4481321058787f1ba1aa82a4 100644 (file)
@@ -112,6 +112,7 @@ struct devpath {
        struct cl_host *ch;
        u32 cl_id;
        time_t cl_connect_time;
+       int setup_done; /* ioctl BLKTRACESETUP done */
        struct io_info *ios;
 };
 
@@ -1066,9 +1067,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;
@@ -1082,14 +1084,19 @@ static void setup_buts(void)
                if (ioctl(dpp->fd, BLKTRACESETUP, &buts) >= 0) {
                        dpp->ncpus = max_cpus;
                        dpp->buts_name = strdup(buts.name);
+                       dpp->setup_done = 1;
                        if (dpp->stats)
                                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)
@@ -1280,7 +1287,8 @@ static void rel_devpaths(void)
                struct devpath *dpp = list_entry(p, struct devpath, head);
 
                list_del(&dpp->head);
-               __stop_trace(dpp->fd);
+               if (dpp->setup_done)
+                       __stop_trace(dpp->fd);
                close(dpp->fd);
 
                if (dpp->heads)
@@ -2676,7 +2684,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())