[PATCH 3/9] kobject: kset_create_and_add() - fetch ownership info from parent

Tyler Hicks tyhicks at canonical.com
Wed Oct 31 00:55:19 UTC 2018

From: Dmitry Torokhov <dmitry.torokhov at gmail.com>

BugLink: https://launchpad.net/bugs/1784501

This change implements get_ownership() for ksets created with
kset_create_and_add() call by fetching ownership data from parent kobject.
This is done mostly for benefit of "queues" attribute of net devices so
that corresponding directory belongs to container's root instead of global
root for network devices in a container.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov at gmail.com>
Reviewed-by: Tyler Hicks <tyhicks at canonical.com>
Signed-off-by: David S. Miller <davem at davemloft.net>
(cherry picked from commit d028b6f703209dbe96201b2714ff46625877128e)
Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
 lib/kobject.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 4a530e93a0ce..65edcc833431 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -891,9 +891,16 @@ static void kset_release(struct kobject *kobj)
+void kset_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
+	if (kobj->parent)
+		kobject_get_ownership(kobj->parent, uid, gid);
 static struct kobj_type kset_ktype = {
 	.sysfs_ops	= &kobj_sysfs_ops,
-	.release = kset_release,
+	.release	= kset_release,
+	.get_ownership	= kset_get_ownership,

More information about the kernel-team mailing list