:: Re: [DNG] libudev-compat documentat…
Inizio della pagina
Delete this message
Reply to this message
Autore: aitor
Data:  
To: dng
Oggetto: Re: [DNG] libudev-compat documentation (Was: Remarks on vdev, Eudev, Mdev)
Hi,

On 11/6/22 14:07, aitor wrote:

> I started documenting libudev-compat in my website as part of the documentation about vdev:
> https://www.gnuinos.org/libudev-compat/ <https://www.gnuinos.org/libudev-compat/>
> This documentation is a work in progress.


Jude Nelson was wondering whether or not is possible to use `sendfile(2)`:

    *ssize_t sendfile(int */out_fd/*, int */in_fd/*, off_t **/offset/*, size_t */count/*); *


in the function:

    static int udev_monitor_fs_push_event( int fd, struct udev_monitor* monitor );


of the file:

https://github.com/jcnelson/vdev/blob/master/libudev-compat/libudev-fs.c <https://github.com/jcnelson/vdev/blob/master/libudev-compat/libudev-fs.c>

If you read his comment between the lines 759-771:


    // send the contents of a file containing a serialized packet to the libudev client:
    // * read the contents
    // * send it along to the receiving struct udev_monitor
    // NOTE: The file format is expected to be the same as a uevent packet:
    //       * all newlines (\n) will be converted to null (\0), since that's how
    //         the kernel sends it.
    //       * the buffer is expected to be at most 8192 bytes long.
    // return 0 on success
    // return -errno on failure
    // return -EMSGSIZE if the file is too big
    // return -EBADMSG if the file is invalid
    // return -EAGAIN if we'd block on send
    // TODO: can we use sendfile(2)?



The use of `sendfile` would imply to convert the function below (used by `udev_monitor_fs_push_event`):

    // send udev_device along
    // TODO: sendfile(2)?
    rc = udev_monitor_send_device( monitor, NULL, dev );
    if( rc < 0 ) {


      log_error("udev_monitor_send_device rc = %d", rc );

   }

   else {

      rc = 0;

   }

into something like this:

   off_t offset = 0;

   // send file descriptor
   rc = sendfile( monitor->sock_fs, fd, &offset, BUFSIZ );
   if( rc < 0 ) {

      rc = -errno;
      log_error("udev_monitor_send_device rc = %d", rc );
   }
   else {

      rc = 0;
   }

Other modifications would be required in the receiver side, of course.

According to the description in the Linux Man Page:

https://man7.org/linux/man-pages/man2/sendfile.2.html <https://man7.org/linux/man-pages/man2/sendfile.2.html>

*sendfile*() copies data between one file descriptor and another.
Because this copying is done within the kernel,*sendfile*() is
more efficient than the combination ofread(2) <https://man7.org/linux/man-pages/man2/read.2.html> andwrite(2) <https://man7.org/linux/man-pages/man2/write.2.html>,
which would require transferring data to and from user space.

Well, I've been trying to make such improvement in libudev-compat, and appearently it's working fine.
So, I'll update my git repository soon.

... And again: if you catch some inaccuracy or glaring error in my documentation,
please let me know and I'll update it.

Thanks in advance,

Aitor.