All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] package/busybox: update S10mdev
@ 2019-05-29 14:25 Titouan Christophe
       [not found] ` <20190614172647.GA32315@smile.fi.intel.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Titouan Christophe @ 2019-05-29 14:25 UTC (permalink / raw)
  To: buildroot

Avoid race conditions in mdev invocations
* use the uevent daemon if possible
* fallback to hotplug (as before) and initialize /dev/mdev.seq
* otherwise print an error message and do nothing else

Signed-off-by: Titouan Christophe <titouan.christophe@railnova.eu>
---
 package/busybox/S10mdev | 66 +++++++++++++++++++++++++++++++++++------
 1 file changed, 57 insertions(+), 9 deletions(-)

diff --git a/package/busybox/S10mdev b/package/busybox/S10mdev
index 7075b77016..f1a836da32 100644
--- a/package/busybox/S10mdev
+++ b/package/busybox/S10mdev
@@ -1,20 +1,68 @@
 #!/bin/sh
 #
-# Start mdev....
+# Start mdev, using the uevent daemon whereas possible
 #
 
-case "$1" in
-  start)
-	echo "Starting mdev..."
-	echo /sbin/mdev >/proc/sys/kernel/hotplug
+DAEMON="uevent"
+PIDFILE="/var/run/$DAEMON.pid"
+
+has_uevent_and_netlink() {
+	[ -f /proc/net/netlink ] && [ -x /sbin/uevent ]
+}
+
+has_hotplug() {
+	[ -w /proc/sys/kernel/hotplug ]
+}
+
+
+start() {
+	if has_uevent_and_netlink; then
+		echo -n "Starting mdev within uevent... "
+		start-stop-daemon -S -b -m -p $PIDFILE -x /sbin/uevent -- /sbin/mdev
+		[ $? -eq 0 ] && echo "OK" || echo "FAIL"
+	elif has_hotplug; then
+		echo "Installing mdev as hotplug helper"
+		# Initialize the seq counter to prevent plug/unplug races
+		touch /dev/mdev.seq
+		echo /sbin/mdev > /proc/sys/kernel/hotplug
+	else
+		echo "ERROR: neither netlink+uevent nor hotplug are available"
+		echo "       Unable to start mdev !"
+		exit 1
+	fi
+
+	# Run boot time /sys scan
 	/sbin/mdev -s
+
 	# coldplug modules
 	find /sys/ -name modalias -print0 | xargs -0 sort -u | tr '\n' '\0' | \
 	    xargs -0 modprobe -abq
-	;;
-  stop)
-	;;
-  restart|reload)
+}
+
+stop() {
+	if has_uevent_and_netlink; then
+		echo -n "Stopping mdev within uevent... "
+		start-stop-daemon -K -p $PIDFILE
+		[ $? -eq 0 ] && echo "OK" || echo "FAIL"
+	elif has_hotplug; then
+		echo "Uninstalling mdev from hotplug helper"
+		echo > /proc/sys/kernel/hotplug
+	else
+		echo "ERROR: neither netlink+uevent nor hotplug are available"
+		echo "       Unable to stop mdev !"
+		exit 1
+	fi
+}
+
+restart() {
+	stop
+	start
+}
+
+
+case "$1" in
+  start|stop|restart)
+	$1
 	;;
   *)
 	echo "Usage: $0 {start|stop|restart}"
-- 
2.21.0

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

* [Buildroot] [PATCH 1/1] package/busybox: update S10mdev
       [not found] <mailman.4931.1560533212.86899.buildroot@busybox.net>
@ 2019-06-15 16:34 ` Andy Shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2019-06-15 16:34 UTC (permalink / raw)
  To: buildroot

> On Wed, May 29, 2019 at 04:25:28PM +0200, Titouan Christophe wrote:
> > Avoid race conditions in mdev invocations
> > * use the uevent daemon if possible
> > * fallback to hotplug (as before) and initialize /dev/mdev.seq
> > * otherwise print an error message and do nothing else

> Thanks!
> 
> Tested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> 
> What are we going to do with this?
> As of today Buildroot can not be used with mdev in current state.

-- 
With Best Regards,
Andy Shevchenko

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

* [Buildroot] [PATCH 1/1] package/busybox: update S10mdev
       [not found] ` <20190614172647.GA32315@smile.fi.intel.com>
@ 2019-06-16 20:15   ` Titouan Christophe
  2019-06-18 19:33     ` Peter Korsgaard
  0 siblings, 1 reply; 5+ messages in thread
From: Titouan Christophe @ 2019-06-16 20:15 UTC (permalink / raw)
  To: buildroot

Hello Andy,

Thank you for following up !

On 6/14/19 7:26 PM, Andy Shevchenko wrote:
> On Wed, May 29, 2019 at 04:25:28PM +0200, Titouan Christophe wrote:
>> Avoid race conditions in mdev invocations
>> * use the uevent daemon if possible
>> * fallback to hotplug (as before) and initialize /dev/mdev.seq
>> * otherwise print an error message and do nothing else
>>
> 
> Thanks!
> 
> Tested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> 
> What are we going to do with this?
> As of today Buildroot can not be used with mdev in current state.

In the meantime Busybox did introduce the daemon mode for mdev, which 
renders this patch obsolete (see the thread "linux: enable UEVENT_HELPER 
when mdev is used" over there 
http://lists.busybox.net/pipermail/buildroot/2019-June/251744.html).

I discussed this with Arnout on IRC, and the outcome is that we will 
adapt the S10mdev script to use the new daemon mode as soon as the next 
Busybox release is available.

In the meantime, I guess the best option is to keep this patched script 
out of tree (this is what I'm doing right now).

Best regards,

Titouan

> 
>> Signed-off-by: Titouan Christophe <titouan.christophe@railnova.eu>
>> ---
>>   package/busybox/S10mdev | 66 +++++++++++++++++++++++++++++++++++------
>>   1 file changed, 57 insertions(+), 9 deletions(-)
>>
>> diff --git a/package/busybox/S10mdev b/package/busybox/S10mdev
>> index 7075b77016..f1a836da32 100644
>> --- a/package/busybox/S10mdev
>> +++ b/package/busybox/S10mdev
>> @@ -1,20 +1,68 @@
>>   #!/bin/sh
>>   #
>> -# Start mdev....
>> +# Start mdev, using the uevent daemon whereas possible
>>   #
>>   
>> -case "$1" in
>> -  start)
>> -	echo "Starting mdev..."
>> -	echo /sbin/mdev >/proc/sys/kernel/hotplug
>> +DAEMON="uevent"
>> +PIDFILE="/var/run/$DAEMON.pid"
>> +
>> +has_uevent_and_netlink() {
>> +	[ -f /proc/net/netlink ] && [ -x /sbin/uevent ]
>> +}
>> +
>> +has_hotplug() {
>> +	[ -w /proc/sys/kernel/hotplug ]
>> +}
>> +
>> +
>> +start() {
>> +	if has_uevent_and_netlink; then
>> +		echo -n "Starting mdev within uevent... "
>> +		start-stop-daemon -S -b -m -p $PIDFILE -x /sbin/uevent -- /sbin/mdev
>> +		[ $? -eq 0 ] && echo "OK" || echo "FAIL"
>> +	elif has_hotplug; then
>> +		echo "Installing mdev as hotplug helper"
>> +		# Initialize the seq counter to prevent plug/unplug races
>> +		touch /dev/mdev.seq
>> +		echo /sbin/mdev > /proc/sys/kernel/hotplug
>> +	else
>> +		echo "ERROR: neither netlink+uevent nor hotplug are available"
>> +		echo "       Unable to start mdev !"
>> +		exit 1
>> +	fi
>> +
>> +	# Run boot time /sys scan
>>   	/sbin/mdev -s
>> +
>>   	# coldplug modules
>>   	find /sys/ -name modalias -print0 | xargs -0 sort -u | tr '\n' '\0' | \
>>   	    xargs -0 modprobe -abq
>> -	;;
>> -  stop)
>> -	;;
>> -  restart|reload)
>> +}
>> +
>> +stop() {
>> +	if has_uevent_and_netlink; then
>> +		echo -n "Stopping mdev within uevent... "
>> +		start-stop-daemon -K -p $PIDFILE
>> +		[ $? -eq 0 ] && echo "OK" || echo "FAIL"
>> +	elif has_hotplug; then
>> +		echo "Uninstalling mdev from hotplug helper"
>> +		echo > /proc/sys/kernel/hotplug
>> +	else
>> +		echo "ERROR: neither netlink+uevent nor hotplug are available"
>> +		echo "       Unable to stop mdev !"
>> +		exit 1
>> +	fi
>> +}
>> +
>> +restart() {
>> +	stop
>> +	start
>> +}
>> +
>> +
>> +case "$1" in
>> +  start|stop|restart)
>> +	$1
>>   	;;
>>     *)
>>   	echo "Usage: $0 {start|stop|restart}"
> 

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

* [Buildroot] [PATCH 1/1] package/busybox: update S10mdev
  2019-06-16 20:15   ` Titouan Christophe
@ 2019-06-18 19:33     ` Peter Korsgaard
  2019-06-19 17:15       ` Titouan Christophe
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Korsgaard @ 2019-06-18 19:33 UTC (permalink / raw)
  To: buildroot

>>>>> "Titouan" == Titouan Christophe <titouan.christophe@railnova.eu> writes:

Hi,

 > In the meantime Busybox did introduce the daemon mode for mdev, which
 > renders this patch obsolete (see the thread "linux: enable
 > UEVENT_HELPER when mdev is used" over there
 > http://lists.busybox.net/pipermail/buildroot/2019-June/251744.html).

 > I discussed this with Arnout on IRC, and the outcome is that we will
 > adapt the S10mdev script to use the new daemon mode as soon as the
 > next Busybox release is available.

Busybox 1.31.0 was released last week with this new daemon option:

https://busybox.net/

-- 
Bye, Peter Korsgaard

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

* [Buildroot] [PATCH 1/1] package/busybox: update S10mdev
  2019-06-18 19:33     ` Peter Korsgaard
@ 2019-06-19 17:15       ` Titouan Christophe
  0 siblings, 0 replies; 5+ messages in thread
From: Titouan Christophe @ 2019-06-19 17:15 UTC (permalink / raw)
  To: buildroot

Hello Peter,

On 6/18/19 9:33 PM, Peter Korsgaard wrote:
>>>>>> "Titouan" == Titouan Christophe <titouan.christophe@railnova.eu> writes:
> 
> Hi,
> 
>   > In the meantime Busybox did introduce the daemon mode for mdev, which
>   > renders this patch obsolete (see the thread "linux: enable
>   > UEVENT_HELPER when mdev is used" over there
>   > http://lists.busybox.net/pipermail/buildroot/2019-June/251744.html).
> 
>   > I discussed this with Arnout on IRC, and the outcome is that we will
>   > adapt the S10mdev script to use the new daemon mode as soon as the
>   > next Busybox release is available.
> 
> Busybox 1.31.0 was released last week with this new daemon option:
> 
> https://busybox.net/


Thank you for the heads up.

I submitted a patch series for the aforementioned changes, see 
http://patchwork.ozlabs.org/project/buildroot/list/?series=114874

Best regards,

Titouan

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

end of thread, other threads:[~2019-06-19 17:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.4931.1560533212.86899.buildroot@busybox.net>
2019-06-15 16:34 ` [Buildroot] [PATCH 1/1] package/busybox: update S10mdev Andy Shevchenko
2019-05-29 14:25 Titouan Christophe
     [not found] ` <20190614172647.GA32315@smile.fi.intel.com>
2019-06-16 20:15   ` Titouan Christophe
2019-06-18 19:33     ` Peter Korsgaard
2019-06-19 17:15       ` Titouan Christophe

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.