Skip to contentSkip to conversation

blktrace: don't stop tracer if not setup trace successfully

PATCH In review weiping zhang 3 participants 3 messages Jan 15, 2018 – Jan 24, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blktrace: don't stop tracer if not setup trace successfully

if we run blktrace on same device twice, the second time will failed to ioctl(BLKTRACESETUP), then it will call __stop_tracer, which lead the first blktrace failed to access debugfs entries. So this patch add a check to handle this case, to avoid stop tracer uncondionally.

---
 blktrace.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
blktrace.c +4 -1
index e048f68..d0d271f 100644
@@ -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;
 };
 
@@ -1083,6 +1084,7 @@ static int 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));
@@ -1285,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)
Signature · 1 line
1.8.3.1
#1 lore raw

Hi Jens,

Will you consider this patch ?

Thanks

2018-01-15 23:53 GMT+08:00 weiping zhang <[email protected]>:

Quoted 47 lines

if we run blktrace on same device twice, the second time will failed to ioctl(BLKTRACESETUP), then it will call __stop_tracer, which lead the first blktrace failed to access debugfs entries. So this patch add a check to handle this case, to avoid stop tracer uncondionally.

---
 blktrace.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
blktrace.c +4 -2
index e048f68..d0d271f 100644
@@ -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;
 };
 
@@ -1083,6 +1084,7 @@ static int 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));
@@ -1285,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)
--

1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-btrace" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to weiping zhang
Quoted 4 lines · weiping zhang

if we run blktrace on same device twice, the second time will failed to ioctl(BLKTRACESETUP), then it will call __stop_tracer, which lead the first blktrace failed to access debugfs entries. So this patch add a check to handle this case, to avoid stop tracer uncondionally.

Thanks, looks good to me, applied.

Signature · 1 line
Jens Axboe