:: Re: [DNG] vdev status update in dae…
Etusivu
Poista viesti
Vastaa
Lähettäjä: aitor
Päiväys:  
Vastaanottaja: dng
Vanhat otsikot: Re: [DNG] vdev status update in daedalus
Aihe: Re: [DNG] vdev status update in daedalus
Hi,

After updating the iso images with the lastest version of vdev, I've decided to try to solve another issue existent in vdev. I'll
try to explain in the best way.

When vdev starts running, the first thing it will do is to find all the devices shown by the kernel in the userspace by searching
all the uevent files in the sysfs filesystem, ending up in a poll() system call that will wait for new events, triggered every time
a hotpluggable device is added/removed.

The problem is that processing all the coldplugged devices requires a considerable time and, if a new device arises in the meantime,
it won't be functional for several seconds. In the worst of the cases, it may be possible that vdev misses it depending on the followed
runs of search within the sysfs's directory hierarchy.

On the other hand, I haven't found a way to wait on the file descriptor -i.e. the poll() system call- in a non-blocking mode while all
this is going on. We could think about forking a child process in order to carry out the coldplugged device processing and wait for new
events in the parent process. But, in doing so, there is a high risk of breaking the eventfs filesystem (monitored by libudev clients),
as it is receiving synthetic events from different sources at the same time.

None the less, I'm considering to use the async.h library:

https://github.com/naasking/async.h

The idea is to define two asynchronous tasks during the coldplug phase. The first task will process the coldplugged devices in batches.
During the batch processing, a second task will interrumpt the first task in order to detect possible new devices (by searching again in
the sysfs), devices that will be consumed in the latter task before going ahead with the next batch of devices in the earlier.

This asynchronous diagram can be controled by semaphores, as you can see in the example bellow:

https://github.com/naasking/async.h/blob/master/async/example-buffer.c

Today I've developed a simple example and it seems to work. The idea behind this scheme is to detect arising devices by searching in the
sysfs filesystem as well, while cannot otherwise be done. The list of devices processed in the first task remains constant, it's not updated
by the second task. From batch to batch, the latter gives first priority to new arising devices, say a keyboard or a mouse or a usb stick...
And so on until the last batch of devices is processed in the first task, ending up again in the poll() system call, and waiting forever.

Cheers,

Aitor.