[PATCH 003/003] Attempt to cope with device changes and delayed kobject deallocation

From: Richard Watts
Date: Tue May 19 2015 - 11:15:52 EST


Avoid issuing duplicate name errors when a kobject's sysfs directory is
scheduled for deletion but has not yet been deleted, and a directory
with the same name is created.

Signed-off-by: Richard Watts <rrw@xxxxxxxxxxxxx>
---
fs/sysfs/dir.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 0b45ff4..e85de14 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -49,6 +49,21 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
else
parent = sysfs_root_kn;

+ kn = kernfs_find_and_get_ns(parent, kobject_name(kobj),
+ ns);
+ /* This check is non-atomic, but that is OK - the worst thing
+ * that can happen is a concurrent removal of the sysfs dir,
+ * which is exactly what we want anyway.
+ */
+ if (kn) {
+ struct kobject *kobj_exist = (struct kobject *)kn->priv;
+
+ if (kobject_get_unless_zero(kobj_exist))
+ kobject_put(kobj_exist);
+ else
+ sysfs_remove_dir(kobj_exist);
+ }
+
if (!parent)
return -ENOENT;

--
1.9.1

--
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/