2009-06-17 14:08:44

by Alexander Holler

[permalink] [raw]
Subject: asynchronous calls an the lack of --wait-for-completion options (e.g. modprobe, losetup, cryptsetup)

Hello,

during the last kernel versions I've got more and more problems with
scripts which are calling modprobe, losetup or e.g. cryptsetup.

The problem is that when I'm e.g. calling modprobe loop, loop might not
has finished it's initialization, when modprobe returns.

This leads me to such ugly scripts like
-----------------------------
if [ ! -b /dev/loop0 ]; then
modprobe loop
for i in $(seq 1 10) ; do
if [ -b /dev/loop0 ]; then
break;
fi
sleep 1
done
fi
do something with /dev/loop0
-----------------------------

which leaves me in doubt if /dev/loop0 really is usable (or if the
module really has finished it's initialization) if /dev/loop0 appeared
(besides the unecessary seconds spended to sleep).

So I'm awaiting the time, when cp in "mkdir foo; cp bar foo" will fail,
because mkdir hasn't completed it's operation (but just started it).

My suggestion would be that all those tools should either offer an
option like --wait-for-completion, or, my prefered solution (which I
naively assume as how those userland-tools should behave), they should
by default wait for completion and could offer an option like
--asynchronous for the rare moments one really doesn't care if the
operation has completed when the appropriate userland-tool returns.

Another question could be, how to be sure if, e.g., modprobe loop
succeeded, if it returns while the operation hasn't finished.

Kind regards,

Alexander Holler


2009-06-19 00:52:43

by Robert Hancock

[permalink] [raw]
Subject: Re: asynchronous calls an the lack of --wait-for-completion options (e.g. modprobe, losetup, cryptsetup)

On 06/17/2009 07:39 AM, Alexander Holler wrote:
> Hello,
>
> during the last kernel versions I've got more and more problems with
> scripts which are calling modprobe, losetup or e.g. cryptsetup.
>
> The problem is that when I'm e.g. calling modprobe loop, loop might not
> has finished it's initialization, when modprobe returns.

It will have. Just that udev won't have received the events and created
the device node yet. So the solution would likely be on the udev side..

2009-06-20 19:20:35

by Kay Sievers

[permalink] [raw]
Subject: Re: asynchronous calls an the lack of --wait-for-completion options (e.g. modprobe, losetup, cryptsetup)

On Fri, Jun 19, 2009 at 02:52, Robert Hancock<[email protected]> wrote:
> On 06/17/2009 07:39 AM, Alexander Holler wrote:

>> The problem is that when I'm e.g. calling modprobe loop, loop might not
>> has finished it's initialization, when modprobe returns.
>
> It will have. Just that udev won't have received the events and created the
> device node yet. So the solution would likely be on the udev side..

The brutal method to do this is to call:
udevadm settle
after loading the module. It will block until all currently pending
events for udev are fully handled.

Recent udevadm versions also have a:
--exit-if-exists=<filename>
option, which will make "settle" stop waiting if a given file exists.

Kay

2009-06-22 12:08:59

by Alexander Holler

[permalink] [raw]
Subject: Re: asynchronous calls an the lack of --wait-for-completion options (e.g. modprobe, losetup, cryptsetup)

On 20.06.2009 21:20, Kay Sievers wrote:
> On Fri, Jun 19, 2009 at 02:52, Robert Hancock<[email protected]> wrote:
>> On 06/17/2009 07:39 AM, Alexander Holler wrote:
>
>>> The problem is that when I'm e.g. calling modprobe loop, loop might not
>>> has finished it's initialization, when modprobe returns.
>>
>> It will have. Just that udev won't have received the events and created the
>> device node yet. So the solution would likely be on the udev side..
>
> The brutal method to do this is to call:
> udevadm settle
> after loading the module. It will block until all currently pending
> events for udev are fully handled.
>
> Recent udevadm versions also have a:
> --exit-if-exists=<filename>
> option, which will make "settle" stop waiting if a given file exists.

Thanks a lot, I already thought it might be udev, but I haven't known
about udevadm.

Anyway, I still think, that the creation of the device-node is (seen
from a user-point) part of the module-initialization or part of the
operation of the userland-tool (like modprobe, losetup or cryptsetup).
So in my point of view, they should at least offer an option to wait
until udev finished that operation and should not rely on the user to
call udevadm.

But I don't want to extend that discussion. I know this is a complex
subject where many parts are involved and many people are having
different views (e.g. at boot time such asynchronous completion is often
wanted).

It would be nice, if at least the userland-tools would document (e.g. in
there examples-section), that a call to udevadm is necessary before
going on and using the (should already created) device-node (at least if
a stable operation on all systems is needed). The problem is, that it
heavily depends on the system how long udev needs and it might often
work without a call to udevadm so many people could miss the need to
call udevadm.

Kind regards,

Alexander Holler

2009-06-23 11:35:29

by Kay Sievers

[permalink] [raw]
Subject: Re: asynchronous calls an the lack of --wait-for-completion options (e.g. modprobe, losetup, cryptsetup)

On Mon, Jun 22, 2009 at 14:08, Alexander Holler<[email protected]> wrote:
> On 20.06.2009 21:20, Kay Sievers wrote:

> Anyway, I still think, that the creation of the device-node is (seen from a
> user-point) part of the module-initialization or part of the operation of
> the userland-tool (like modprobe, losetup or cryptsetup). So in my point of
> view, they should at least offer an option to wait until udev finished that
> operation and should not rely on the user to call udevadm.

That would be all solved properly by "devtmpfs":
http://lkml.org/lkml/2009/4/30/182

You might want to talk to the people who are delaying its adoption.

Thanks,
Kay

2009-06-23 16:00:31

by Alan

[permalink] [raw]
Subject: Re: asynchronous calls an the lack of --wait-for-completion options (e.g. modprobe, losetup, cryptsetup)

On Tue, 23 Jun 2009 13:35:07 +0200
Kay Sievers <[email protected]> wrote:

> On Mon, Jun 22, 2009 at 14:08, Alexander Holler<[email protected]> wrote:
> > On 20.06.2009 21:20, Kay Sievers wrote:
>
> > Anyway, I still think, that the creation of the device-node is (seen from a
> > user-point) part of the module-initialization or part of the operation of
> > the userland-tool (like modprobe, losetup or cryptsetup). So in my point of
> > view, they should at least offer an option to wait until udev finished that
> > operation and should not rely on the user to call udevadm.
>
> That would be all solved properly by "devtmpfs":
> http://lkml.org/lkml/2009/4/30/182

which unsolves lots of other problems and has good reasons why people
object to it.

Sorting out waiting behaviour and fixing udev to do jobs once is a user
space problem and while it might benefit from some tiny bits of kernel
help re-implementing devfs (which we've been through before thank you) is
not the cure but replacing a minor ailment with a nasty disease