From: Richard Watts <rrw@kynesim.co.uk>
To: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org
Subject: [PATCH 003/003] Attempt to cope with device changes and delayed kobject deallocation
Date: Tue, 19 May 2015 16:15:48 +0100 [thread overview]
Message-ID: <555B53A4.3070907@kynesim.co.uk> (raw)
In-Reply-To: <555B5305.9050506@kynesim.co.uk>
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
prev parent reply other threads:[~2015-05-19 15:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-19 15:13 [PATCH 000/003] Attempt to cope with device changes and delayed kobject deallocation Richard Watts
2015-05-19 15:14 ` [PATCH 001/003] " Richard Watts
2015-06-10 6:46 ` Alex Bennée
2015-05-19 15:15 ` [PATCH 002/003] " Richard Watts
2015-05-19 15:15 ` Richard Watts [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=555B53A4.3070907@kynesim.co.uk \
--to=rrw@kynesim.co.uk \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox