[erlang-questions] Linux device driver communication with Erlang node
Motiejus Jakštys
desired.mta@REDACTED
Fri Dec 2 22:31:42 CET 2011
On Fri, Dec 02, 2011 at 10:21:51AM -0600, Daniel Goertzen wrote:
> Sanya is correct.
>
> You would need to write a device driver that implements the block device
> interface and also provides a conduit to userspace; probably a character
> device node which Erlang could read and write. After being spoiled by
> Erlang, writing linux device drivers in C will make you want to rip your
> hair out. :)
Yes, I get it. So it's quite clear that it will not be a C node. It
will be either home-made port driver, or wrapped in Erl_interface. I
will have a look.
> Incidentally, people abuse the existing NBD client driver to write their
> own userspace block devices. You could easily do the same without having
> to touch kernel code at all.
But as far as I see nbd-client.c sets up the socket:
262 void finish_sock(int sock, int nbd, int swap) {
263 if (ioctl(nbd, NBD_SET_SOCK, sock) < 0)
drivers/block/nbd.c fetches the socket:
602 case NBD_SET_SOCK: {
and sends/receives packets to the nbd server:
191 result = kernel_sendmsg(sock, &msg, &iov, 1, size);
195 result = kernel_recvmsg(sock, &msg, &iov, 1, size,
196 msg.msg_flags);
Transferring data from kernel to nbd-client.c would not make sense,
because it would make +2 context switches per buffer while sending data.
How it would work then:
1) userspace calls write(), and sends data to kernel-space
2) kernel driver nbd.c sends data to nbd-client.c (again to userspace)
3) nbd-client.c sends the blob to kernel space to send it to NIC
Now second step is skipped.
Mentioning NBD was misleading here... It would be better to name it
"ErlBD". Since I will implement neither nbd client, nor server. Just the
idea is similar.
Thanks for help, now I have an image how it should look like.
For the curious:
https://github.com/Motiejus/ErlBD
Motiejus
More information about the erlang-questions
mailing list