From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Tejun Heo <tj@kernel.org>,
"Eric W. Biederman" <ebiederm@xmission.com>,
"David S. Miller" <davem@davemloft.net>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH 4/5] driver core: set up ownership of class devices in sysfs
Date: Tue, 16 Aug 2016 15:33:14 -0700 [thread overview]
Message-ID: <1471386795-32918-5-git-send-email-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <1471386795-32918-1-git-send-email-dmitry.torokhov@gmail.com>
Plumb in get_ownership() callback for devices belonging to a class so that
they can be created with uid/gid different from global root. This will
allow network devices in a container to belong to container's root and not
global root.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/base/core.c | 9 +++++++++
include/linux/device.h | 5 +++++
2 files changed, 14 insertions(+)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 0a8bdad..0f95454 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -263,10 +263,19 @@ static const void *device_namespace(struct kobject *kobj)
return ns;
}
+static void device_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
+{
+ struct device *dev = kobj_to_dev(kobj);
+
+ if (dev->class && dev->class->get_ownership)
+ dev->class->get_ownership(dev, uid, gid);
+}
+
static struct kobj_type device_ktype = {
.release = device_release,
.sysfs_ops = &dev_sysfs_ops,
.namespace = device_namespace,
+ .get_ownership = device_get_ownership,
};
diff --git a/include/linux/device.h b/include/linux/device.h
index 38f0281..da20b12 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -374,6 +374,9 @@ int subsys_virtual_register(struct bus_type *subsys,
* @resume: Used to bring the device from the sleep mode.
* @ns_type: Callbacks so sysfs can detemine namespaces.
* @namespace: Namespace of the device belongs to this class.
+ * @get_ownership: Allows class to specify uid/gid of the sysfs directories
+ * for the devices belonging to the class. Usually tied to
+ * device's namespace.
* @pm: The default device power management operations of this class.
* @p: The private data of the driver core, no one other than the
* driver core can touch this.
@@ -404,6 +407,8 @@ struct class {
const struct kobj_ns_type_operations *ns_type;
const void *(*namespace)(struct device *dev);
+ void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid);
+
const struct dev_pm_ops *pm;
struct subsys_private *p;
--
2.8.0.rc3.226.g39d4020
next prev parent reply other threads:[~2016-08-16 22:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-16 22:33 [PATCH 0/5] Make /sys/class/net per net namespace objects belong to container Dmitry Torokhov
2016-08-16 22:33 ` [PATCH 1/5] kernfs: allow creating kernfs objects with arbitrary uid/gid Dmitry Torokhov
2016-08-16 22:33 ` [PATCH 2/5] sysfs, kobject: allow creating kobject belonging to arbitrary users Dmitry Torokhov
2016-08-16 22:33 ` [PATCH 3/5] kobject: kset_create_and_add() - fetch ownership info from parent Dmitry Torokhov
2016-08-16 22:33 ` Dmitry Torokhov [this message]
2016-08-20 2:26 ` [PATCH 4/5] driver core: set up ownership of class devices in sysfs Stephen Hemminger
2016-08-16 22:33 ` [PATCH 5/5] net-sysfs: make sure objects belong to contrainer's owner Dmitry Torokhov
2016-08-22 6:03 ` kbuild test robot
2016-08-19 23:59 ` [PATCH 0/5] Make /sys/class/net per net namespace objects belong to container David Miller
2016-08-29 12:38 ` Eric W. Biederman
2016-09-15 3:24 ` Dmitry Torokhov
2016-09-15 23:26 ` Eric W. Biederman
2016-08-22 6:41 ` David Miller
2016-08-22 16:24 ` Dmitry Torokhov
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=1471386795-32918-5-git-send-email-dmitry.torokhov@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=tj@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.