[PATCH 05/26] sysfs: Improve sysfs directory deletion debugging.

From: Eric W. Biederman
Date: Fri May 29 2009 - 16:20:59 EST


From: Eric W. Biederman <ebiederm@xxxxxxxxxxxx>

We have found several cases where directories are deleted without
removing all of their subdirectories. That case isn't valid so
warn anyone who makes that mistake, and continue to leak dirents
to keep the system as operational as possible.

Move the debug message when a directory is deleted into remove_dir
so we are told when subdirectories are deleted as well as full
fledge kobject directories.

Signed-off-by: Eric W. Biederman <ebiederm@xxxxxxxxxxxxxxxxxx>
---
fs/sysfs/dir.c | 23 +++++++++++++++++++----
1 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index a55e1d4..60482be 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -732,12 +732,28 @@ const struct inode_operations sysfs_dir_inode_operations = {
.setattr = sysfs_setattr,
};

-static void remove_dir(struct sysfs_dirent *sd)
+static void remove_dir(struct sysfs_dirent *dir_sd)
{
struct sysfs_addrm_cxt acxt;

- sysfs_addrm_start(&acxt, sd->s_parent);
- sysfs_remove_one(&acxt, sd);
+ pr_debug("sysfs %s: removing dir\n", dir_sd->s_name);
+
+ /* Removing non-empty directories is not valid complain! */
+ if (unlikely(dir_sd->s_dir.children)) {
+ struct sysfs_dirent *sd;
+
+ WARN(1, KERN_WARNING "sysfs: removing non-empty dir: %s\n",
+ dir_sd->s_name);
+
+ mutex_lock(&sysfs_mutex);
+ for (sd = dir_sd->s_dir.children; sd; sd = sd->s_sibling)
+ printk(KERN_WARNING "%s/%s\n",
+ dir_sd->s_name, sd->s_name);
+ mutex_unlock(&sysfs_mutex);
+ }
+
+ sysfs_addrm_start(&acxt, dir_sd->s_parent);
+ sysfs_remove_one(&acxt, dir_sd);
sysfs_addrm_finish(&acxt);
}

@@ -752,7 +768,6 @@ static void __sysfs_remove_dir(struct sysfs_dirent *dir_sd)
struct sysfs_addrm_cxt acxt;
struct sysfs_dirent **pos;

- pr_debug("sysfs %s: removing dir\n", dir_sd->s_name);
sysfs_addrm_start(&acxt, dir_sd);
pos = &dir_sd->s_dir.children;
while (*pos) {
--
1.6.3.1.54.g99dd.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/