Commit 9944e894 authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by David S. Miller

driver core: set up ownership of class devices in sysfs

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: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: default avatarTyler Hicks <tyhicks@canonical.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d028b6f7
...@@ -866,10 +866,19 @@ static const void *device_namespace(struct kobject *kobj) ...@@ -866,10 +866,19 @@ static const void *device_namespace(struct kobject *kobj)
return ns; 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 = { static struct kobj_type device_ktype = {
.release = device_release, .release = device_release,
.sysfs_ops = &dev_sysfs_ops, .sysfs_ops = &dev_sysfs_ops,
.namespace = device_namespace, .namespace = device_namespace,
.get_ownership = device_get_ownership,
}; };
......
...@@ -384,6 +384,9 @@ int subsys_virtual_register(struct bus_type *subsys, ...@@ -384,6 +384,9 @@ int subsys_virtual_register(struct bus_type *subsys,
* @shutdown_pre: Called at shut-down time before driver shutdown. * @shutdown_pre: Called at shut-down time before driver shutdown.
* @ns_type: Callbacks so sysfs can detemine namespaces. * @ns_type: Callbacks so sysfs can detemine namespaces.
* @namespace: Namespace of the device belongs to this class. * @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. * @pm: The default device power management operations of this class.
* @p: The private data of the driver core, no one other than the * @p: The private data of the driver core, no one other than the
* driver core can touch this. * driver core can touch this.
...@@ -413,6 +416,8 @@ struct class { ...@@ -413,6 +416,8 @@ struct class {
const struct kobj_ns_type_operations *ns_type; const struct kobj_ns_type_operations *ns_type;
const void *(*namespace)(struct device *dev); const void *(*namespace)(struct device *dev);
void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid);
const struct dev_pm_ops *pm; const struct dev_pm_ops *pm;
struct subsys_private *p; struct subsys_private *p;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment