From patchwork Tue Aug 16 22:33:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 659852 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3sDRy41wtdz9t0w for ; Wed, 17 Aug 2016 08:35:08 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=WcJH/nrC; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753952AbcHPWfA (ORCPT ); Tue, 16 Aug 2016 18:35:00 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:36515 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753510AbcHPWdW (ORCPT ); Tue, 16 Aug 2016 18:33:22 -0400 Received: by mail-pa0-f66.google.com with SMTP id ez1so5871543pab.3; Tue, 16 Aug 2016 15:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VYhTugU008/3Z7okWfaZ+nKbkLhvuou3+TZF+6Iumbg=; b=WcJH/nrCEIf3lx21mN1ilyj4icpRhdoKsuEdGPbDV8M9gvSixPRt3yLP2cUDvHFpa7 +9e9GuLj8Erg/eHoCwWzl0dPlFkKHHOwhCLrEqU1lJ+/L/6ztpKLT3PjMHlSQgli0uQs aAfmag5rgJz2d+2dYqNpWPIrjwNFnT+0HV5dbvXB5cAWC3bY0wUaGHciT7JXQCAt42By KjlMQmYtfqQoiO81zn1qUowQ+yTWIKMiySWeNqMVw46qtduD9kYuGjx4oZBkXW3gc97b Z6m/8i8T5ADLiR2+XfbZxDP251F8sMuyygKk+5KF3ntqEQAgCzGQhA5tNPuz24L0Zp+T 8tMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VYhTugU008/3Z7okWfaZ+nKbkLhvuou3+TZF+6Iumbg=; b=b/7JFS1OnSHbKqFHneOaawxO49MQt6pxECYmLaNpwBDXKxANZxN5EYZ3jF0SfL2UWV gXd3XSd+dAIojGe0+2JPcIhH8b08v8DnihuNUrDu34KWceQ7kYXoAy3fovAZlxji0ilN MUD9yKCJRz/+nxrqEgCfHofOziPiiP6jLcrva6P6oi/qWMkO8UVrXmPh7ezG2XFX59NF 8aGbo+5GoVPTZHZjxTBkXjWsYz9olUbaVokDs3AMcgNI3md8sUUFwlcMHxLW4NdSM2wu GonqUe0eLZz5aJUQQx+N6AjsU7TIRfgorLsag3zsiePZLxecPR8Q7a3met83Y095Ozt5 +pqQ== X-Gm-Message-State: AEkoouss087IUnDupNVHmvlmrJbJXkwj3SNq8YTVGesi1S6c2USQHvLaIYKaXtmAo5/Ocg== X-Received: by 10.66.54.132 with SMTP id j4mr68594414pap.110.1471386801178; Tue, 16 Aug 2016 15:33:21 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([172.22.152.21]) by smtp.gmail.com with ESMTPSA id cp11sm41819736pac.28.2016.08.16.15.33.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Aug 2016 15:33:20 -0700 (PDT) From: Dmitry Torokhov To: Tejun Heo , "Eric W. Biederman" , "David S. Miller" 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 Message-Id: <1471386795-32918-5-git-send-email-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1471386795-32918-1-git-send-email-dmitry.torokhov@gmail.com> References: <1471386795-32918-1-git-send-email-dmitry.torokhov@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- 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;