From: Eric Sandeen <sandeen@redhat.com> Date: Tue, 12 May 2009 17:39:34 -0400 Subject: [block] blktrace: only tear down our own debug/block Message-id: <4A09B456.1000805@redhat.com> Patchwork-id: 19994 O-Subject: [PATCH RHEL5.4] blktrace: don't tear down debug/block unless we created it Bugzilla: 498489 RH-Acked-by: Jeff Moyer <jmoyer@redhat.com> For Bug 498489 - blktrace stops working after a trace-file-directory replacement Not sure if this'll make the 5.4 beta cut or not but putting it out there. It's a pretty simple fix to be sure that blktrace isn't cleaning up things it didn't create, which stops blktrace from working properly from that point ... Backport of upstream patch: From: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Date: Wed, 21 Nov 2007 11:25:41 +0000 (+0100) Subject: blktrace: Make sure BLKTRACETEARDOWN does the full cleanup. X-Git-Tag: v2.6.24-rc4~87^2~5 X-Git-Url: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=35fc51e7a5056889421270c1fb63d8ec45fbccf4 blktrace: Make sure BLKTRACETEARDOWN does the full cleanup. 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> diff --git a/block/blktrace.c b/block/blktrace.c index f7dc5c6..4493aa2 100644 --- a/block/blktrace.c +++ b/block/blktrace.c @@ -179,6 +179,7 @@ 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); @@ -186,13 +187,17 @@ static struct dentry *blk_create_tree(const char *blk_name) 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);