Skip to content

Commit

Permalink
blktrace: Make sure BLKTRACETEARDOWN does the full cleanup.
Browse files Browse the repository at this point in the history
if blktrace program segfault it will not be able
to call BLKTRACETEARDOWN. Now if we run the blktrace
again that would result in a failure to create the
block/<device> debugfs directory.This will result
in blk_remove_root() to be called which will set
blk_tree_root to NULL. But the  debugfs block dir
still exist because it contain subdirectory.

Now if we try to fix it using BLKTRACETEARDOWN
it won't work because blk_tree_root is NULL.

Fix the same.

Tested as below

root@qemu-image:/home/kvaneesh/blktrace# ./blktrace  -d /dev/hdc
Segmentation fault
root@qemu-image:/home/kvaneesh/blktrace# ./blktrace  -d /dev/hdc
BLKTRACESETUP: No such file or directory
Failed to start trace on /dev/hdc
root@qemu-image:/home/kvaneesh/blktrace# ./blktrace  -k /dev/hdc
root@qemu-image:/home/kvaneesh/blktrace# ./blktrace  -d /dev/hdc

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
  • Loading branch information
Aneesh Kumar K.V authored and Jens Axboe committed Nov 27, 2007
1 parent 8c27eba commit 35fc51e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions block/blktrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,25 @@ static void blk_remove_tree(struct dentry *dir)
static struct dentry *blk_create_tree(const char *blk_name)
{
struct dentry *dir = NULL;
int created = 0;

mutex_lock(&blk_tree_mutex);

if (!blk_tree_root) {
blk_tree_root = debugfs_create_dir("block", NULL);
if (!blk_tree_root)
goto err;
created = 1;
}

dir = debugfs_create_dir(blk_name, blk_tree_root);
if (dir)
root_users++;
else
blk_remove_root();
else {
/* Delete root only if we created it */
if (created)
blk_remove_root();
}

err:
mutex_unlock(&blk_tree_mutex);
Expand Down

0 comments on commit 35fc51e

Please sign in to comment.