Skip to contentSkip to conversation

asynchronous calls an the lack of --wait-for-completion options (e.g. modprobe, losetup, cryptsetup)

DISCUSSION Alexander Holler 4 participants 6 messages Jun 17, 2009 – Jun 23, 2009

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 7 lines · Alexander Holler

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..

#2 lore raw
Quoted 7 lines · Robert Hancock
Quoted 2 lines · Alexander Holler

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

#3 lore raw
Quoted 9 lines · Kay Sievers
Quoted 7 lines · Robert Hancock
Quoted 2 lines · Alexander Holler

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..

Quoted 8 lines

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

#4 lore raw
Quoted 7 lines · Alexander Holler

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

#5 lore raw
Quoted 11 lines · On Tue, 23 Jun 2009 13:35:07 +0200 Kay Sievers <[email protected]> wrote:
Quoted 7 lines · Alexander Holler

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