Skip to content

Commit 1b0b283

Browse files
mcgrofaxboe
authored andcommitted
blktrace: break out of blktrace setup on concurrent calls
We use one blktrace per request_queue, that means one per the entire disk. So we cannot run one blktrace on say /dev/vda and then /dev/vda1, or just two calls on /dev/vda. We check for concurrent setup only at the very end of the blktrace setup though. If we try to run two concurrent blktraces on the same block device the second one will fail, and the first one seems to go on. However when one tries to kill the first one one will see things like this: The kernel will show these: ``` debugfs: File 'dropped' in directory 'nvme1n1' already present! debugfs: File 'msg' in directory 'nvme1n1' already present! debugfs: File 'trace0' in directory 'nvme1n1' already present! `` And userspace just sees this error message for the second call: ``` blktrace /dev/nvme1n1 BLKTRACESETUP(2) /dev/nvme1n1 failed: 5/Input/output error ``` The first userspace process #1 will also claim that the files were taken underneath their nose as well. The files are taken away form the first process given that when the second blktrace fails, it will follow up with a BLKTRACESTOP and BLKTRACETEARDOWN. This means that even if go-happy process #1 is waiting for blktrace data, we *have* been asked to take teardown the blktrace. This can easily be reproduced with break-blktrace [0] run_0005.sh test. Just break out early if we know we're already going to fail, this will prevent trying to create the files all over again, which we know still exist. [0] https://github.com/mcgrof/break-blktrace Signed-off-by: Luis Chamberlain <[email protected]> Signed-off-by: Jan Kara <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 2d3a8e2 commit 1b0b283

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

kernel/trace/blktrace.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright (C) 2006 Jens Axboe <[email protected]>
44
*
55
*/
6+
7+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8+
69
#include <linux/kernel.h>
710
#include <linux/blkdev.h>
811
#include <linux/blktrace_api.h>
@@ -494,6 +497,16 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
494497
*/
495498
strreplace(buts->name, '/', '_');
496499

500+
/*
501+
* bdev can be NULL, as with scsi-generic, this is a helpful as
502+
* we can be.
503+
*/
504+
if (q->blk_trace) {
505+
pr_warn("Concurrent blktraces are not allowed on %s\n",
506+
buts->name);
507+
return -EBUSY;
508+
}
509+
497510
bt = kzalloc(sizeof(*bt), GFP_KERNEL);
498511
if (!bt)
499512
return -ENOMEM;

0 commit comments

Comments
 (0)