Messages in this thread Patch in this message | | | Date | Tue, 19 May 2015 16:15:48 +0100 | From | Richard Watts <> | Subject | [PATCH 003/003] Attempt to cope with device changes and delayed kobject deallocation |
| |
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@kynesim.co.uk> --- 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
| |