I am thinking of a way for Linux kernel driver to communicate with
Erlang node. The purpose is send binary blobs and have some logic:
* The blob has been ack'ed by erlang node
* Some business operation has been completed with the blob (by node)
C node seems to be the perfect match. Is there anything I should know
before starting messing around? Any possible gotchas running Erlang node
in kernel space? Has anybody tried that?
What I am trying to do
======================
I am thinking of implementing NBD stack with Erlang and C. NBD server is
easy (100% userspace), the client is more tricky, since device driver
code has to be kernel space.
NBD-client would consist of two parts:
* nbd.c that implements block device interface and talks to Erlang node
* Erlang node that communicates with another Erlang node nbd-server
(which does the "business" part with the blob -- writes to disk)
RFC
===
For me distinction between "client" and "server" is unclear in the
tutorial: http://www.erlang.org/doc/tutorial/cnode.html Could somebody
explain it from the higher perspective?
I have never mixed C and Erlang before, and would appreciate some light
on C nodes generally. What is a C node from the system point of view?
Does it use sockets, pipes? What OS processes/threads does it spawn?
Many thanks,
Motiejus
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
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