blktrace: fix a race when creating blk_tree_root in debugfs
authorLi Zefan <lizf@cn.fujitsu.com>
Wed, 25 Mar 2009 09:19:33 +0000 (17:19 +0800)
committerIngo Molnar <mingo@elte.hu>
Tue, 31 Mar 2009 15:26:59 +0000 (17:26 +0200)
t1                                t2
------                            ------
do_blk_trace_setup()              do_blk_trace_setup()
  if (!blk_tree_root) {
                                    if (!blk_tree_root)
    blk_tree_root = create_dir()
                                      blk_tree_root = create_dir();
                                      (now blk_tree_root == NULL)
  ...
  dir = create_dir(name, blk_tree_root);

Due to this race, t1 will create 'dir' in /debugfs but not /debugfs/block.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
kernel/trace/blktrace.c

index ee7a8bb8b1e8e292d733f20f1c398c7a30b1a2c1..95f89faca73eba6998b334ee75960c6f7c27d8d9 100644 (file)
@@ -426,11 +426,15 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
 
        ret = -ENOENT;
 
+       mutex_lock(&blk_tree_mutex);
        if (!blk_tree_root) {
                blk_tree_root = debugfs_create_dir("block", NULL);
-               if (!blk_tree_root)
+               if (!blk_tree_root) {
+                       mutex_unlock(&blk_tree_mutex);
                        goto err;
+               }
        }
+       mutex_unlock(&blk_tree_mutex);
 
        dir = debugfs_create_dir(buts->name, blk_tree_root);