linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] driver core: emit uevents when device is bound to a driver
@ 2017-02-13  0:36 Dmitry Torokhov
  2017-02-13  0:36 ` [PATCH 2/2] sysfs: add devm_sysfs_create_group() and friends Dmitry Torokhov
  2017-02-13 12:07 ` [PATCH 1/2] driver core: emit uevents when device is bound to a driver Greg Kroah-Hartman
  0 siblings, 2 replies; 14+ messages in thread
From: Dmitry Torokhov @ 2017-02-13  0:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-kernel, Guenter Roeck

Majority of standard for a subsystem device attributes are created at the
same time devices are created, before KOBJECT_ADD uevent is emitted by the
driver core. This means that attributes are there when userspace is
notified about new device appearance.

However many drivers create additional driver-specific device attributes
when binding to the device, to provide userspace with additional controls,
and such attributes may not be there yet when userpsace receives
KOBJECT_ADD event. Changing the drivers to introduce intermediate "dummy"
device as a container for such attributes would be wasteful, and in many
cases, braking our sysfs ABI. Let's add a new event, KOBJECT_BIND (and its
counterpart, KOBJECT_UNBIND) that is emitted after a driver is bound to a
device. It can be used by userspace wishing to use driver-specific
attributes of a device.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/base/dd.c       | 4 ++++
 include/linux/kobject.h | 2 ++
 lib/kobject_uevent.c    | 2 ++
 3 files changed, 8 insertions(+)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index a1fbf55c4d3a..a9a5cc0560e5 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -258,6 +258,8 @@ static void driver_bound(struct device *dev)
 	if (dev->bus)
 		blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
 					     BUS_NOTIFY_BOUND_DRIVER, dev);
+
+	kobject_uevent(&dev->kobj, KOBJ_BIND);
 }
 
 static int driver_sysfs_add(struct device *dev)
@@ -839,6 +841,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)
 			blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
 						     BUS_NOTIFY_UNBOUND_DRIVER,
 						     dev);
+
+		kobject_uevent(&dev->kobj, KOBJ_UNBIND);
 	}
 }
 
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index e6284591599e..07292df4776e 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -57,6 +57,8 @@ enum kobject_action {
 	KOBJ_MOVE,
 	KOBJ_ONLINE,
 	KOBJ_OFFLINE,
+	KOBJ_BIND,
+	KOBJ_UNBIND,
 	KOBJ_MAX
 };
 
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 9a2b811966eb..4682e8545b5c 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -50,6 +50,8 @@ static const char *kobject_actions[] = {
 	[KOBJ_MOVE] =		"move",
 	[KOBJ_ONLINE] =		"online",
 	[KOBJ_OFFLINE] =	"offline",
+	[KOBJ_BIND] =		"bind",
+	[KOBJ_UNBIND] =		"unbind",
 };
 
 /**
-- 
2.11.0.483.g087da7b7c-goog

^ permalink raw reply related	[flat|nested] 14+ messages in thread
* [PATCH 0/2] New bind/unbingd uevents
@ 2017-07-18 19:30 Dmitry Torokhov
  2017-07-18 19:30 ` [PATCH 2/2] sysfs: add devm_sysfs_create_group() and friends Dmitry Torokhov
  0 siblings, 1 reply; 14+ messages in thread
From: Dmitry Torokhov @ 2017-07-18 19:30 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: htejun, linux-kernel, Guenter Roeck

Hi Greg,

I am resending the bind/unbind and devm_sysfs_create_group() patches,
as you requested. The new bind/unbind will allow triggering firmware
update through udev, and the new sysfs API will cut down on some
boilerplate code in drivers.

Below is also a patch to systemd to stop dropping the new attributes
(why they think they need to inspect and discard the data they do not
understand is beyond me).

Thanks,
Dmitry

Dmitry Torokhov (2):
  driver core: emit uevents when device is bound to a driver
  sysfs: add devm_sysfs_create_group() and friends

 drivers/base/dd.c       |   4 ++
 fs/sysfs/group.c        | 124 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/kobject.h |   2 +
 include/linux/sysfs.h   |  10 ++++
 lib/kobject_uevent.c    |   2 +
 5 files changed, 142 insertions(+)

-- >8 --

>From 6d10e621578dffcca0ad785e4a73196aa25350f6 Mon Sep 17 00:00:00 2001
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: Mon, 17 Jul 2017 20:10:17 -0700
Subject: [PATCH] Add handling for bind/unbind actions

Newer kernels will emit uevents with "bind" and "unbind" actions. These
uevents will be issued when driver is bound to or unbound from a device.
"Bind" events are helpful when device requires a firmware to operate
properly, and driver is unable to create a child device before firmware
is properly loaded.

For some reason systemd validates actions and drops the ones it does not
know, instead of passing them on through as old udev did, so we need to
explicitly teach it about them.
---
 src/libsystemd/sd-device/device-internal.h | 2 ++
 src/libsystemd/sd-device/device-private.c  | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/src/libsystemd/sd-device/device-internal.h b/src/libsystemd/sd-device/device-internal.h
index f4783deef..0505a2730 100644
--- a/src/libsystemd/sd-device/device-internal.h
+++ b/src/libsystemd/sd-device/device-internal.h
@@ -104,6 +104,8 @@ typedef enum DeviceAction {
         DEVICE_ACTION_MOVE,
         DEVICE_ACTION_ONLINE,
         DEVICE_ACTION_OFFLINE,
+        DEVICE_ACTION_BIND,
+        DEVICE_ACTION_UNBIND,
         _DEVICE_ACTION_MAX,
         _DEVICE_ACTION_INVALID = -1,
 } DeviceAction;
diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c
index b4cd676c1..8839c3266 100644
--- a/src/libsystemd/sd-device/device-private.c
+++ b/src/libsystemd/sd-device/device-private.c
@@ -466,6 +466,8 @@ static const char* const device_action_table[_DEVICE_ACTION_MAX] = {
         [DEVICE_ACTION_MOVE] = "move",
         [DEVICE_ACTION_ONLINE] = "online",
         [DEVICE_ACTION_OFFLINE] = "offline",
+        [DEVICE_ACTION_BIND] = "bind",
+        [DEVICE_ACTION_UNBIND] = "unbind",
 };
 
 DEFINE_STRING_TABLE_LOOKUP(device_action, DeviceAction);
-- 
2.13.2.932.g7449e964c-goog

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2017-07-19  7:34 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-13  0:36 [PATCH 1/2] driver core: emit uevents when device is bound to a driver Dmitry Torokhov
2017-02-13  0:36 ` [PATCH 2/2] sysfs: add devm_sysfs_create_group() and friends Dmitry Torokhov
2017-03-27 17:53   ` Dmitry Torokhov
2017-03-27 19:35     ` Greg Kroah-Hartman
2017-06-07 17:04       ` Dmitry Torokhov
2017-06-17 19:27         ` Greg Kroah-Hartman
2017-02-13 12:07 ` [PATCH 1/2] driver core: emit uevents when device is bound to a driver Greg Kroah-Hartman
2017-02-13 18:46   ` Dmitry Torokhov
2017-02-14  0:52     ` Greg Kroah-Hartman
2017-02-14  4:22       ` Dmitry Torokhov
2017-07-18 19:30 [PATCH 0/2] New bind/unbingd uevents Dmitry Torokhov
2017-07-18 19:30 ` [PATCH 2/2] sysfs: add devm_sysfs_create_group() and friends Dmitry Torokhov
2017-07-18 20:03   ` Greg Kroah-Hartman
2017-07-18 20:26     ` Dmitry Torokhov
2017-07-19  7:34       ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).