:: Re: [DNG] vdev status update in dae…
Top Page
Delete this message
Reply to this message
Author: aitor
Date:  
To: dng
Subject: Re: [DNG] vdev status update in daedalus
Hi Didier,

On 13/7/25 11:13, Didier Kryn wrote:
>
> AFAIU, your issue is that the sysfs tree may change while you scan it
> and before you start polling for new events. I don't know if this
> problem is real and if it has a solution.
>

In such hypothetical case, a possible solution might be to start a
separate process listening to netlink and keeping track of new devices.
When vdev starts polling, the other process unbinds the devices that
were found, but binding them again afterwards. This "unbind/bind"
process emulates the hotplug events that could have been missed while
the coldplug processing. However, I did further testing and I do not
think this is required at all.

>     However, if your issue is to poll() new events in the same time
> you scan sysfs, I could imagine to do these two things with two
> threads. The thread which scans sysfs would feed a pipe with the
> uevents it finds and the thread which polls() new events might poll()
> not only the uevent netlink but also your pipe, in the same time,
> hence reading two sources of uevents.
>

For a long time the "struct pollfd pfd" defined in the line 56 of
linux.c: https://github.com/jcnelson/vdev/blob/master/vdevd/os/linux.h
consists of a poll dealing with several file descriptors. I'll add
another one to handle the pipe you mentioned above. For example: /*
------------------ CODE ---------------------------- */

// Enumerate list of FDs to poll
enum {
        FD_POLL_SIGNAL = 0,
        FD_POLL_PIPE,
        FD_POLL_NETLINK,
        FD_POLL_MAX
};

// The poller:
struct pollfd pfd[FD_POLL_MAX];

//The pid and the pipe used in the fork
pid_t pid;
int pipe[2];

// Fork
pid = fork();

// Parent process
if (pid > 0) {

        close(pipe[0]);

        /* Setup the polling part concerning to the pipe, and the rest
as well */
        pfd[FD_POLL_PIPE].fd = pipe[1];
        pfd[FD_POLL_PIPE].events = POLLIN;
        ( .... )

        // Wait forever:
        rc = poll(pfd, FD_POLL_MAX, -1);


        /* linux signal received */
        if (pfd[FD_POLL_SIGNAL].revents & POLLIN) {

               ( ..... )

        /* Message received from the child */
        } else if (pfd[FD_POLL_PIPE].revents & POLLIN) {

                ( ...... )

        /* Netlink event received */
        } else if (pfd[FD_POLL_NETLINK].revents & POLLIN) {

                ( ...... )
        }

        // Process received device, if any:

        ( .... )

// Child process
} else if (pid == 0) {

        close(pipe[1]);

        // Coldplug processing

        ( ..... )
}

/* ------------------- END -------------------- */


>     Might be simpler than using async.
>

Indeed, async.h is not what I was looking for :)

Cheers, and thanks for your suggestions

Aitor.