Re: Working with user space file descriptor in kernel thread

[email protected] (Michael van Elst)
Newsgroups gmane.os.netbsd.devel.kernel
Organization Serpens User Group
Message-ID <[email protected]>
[email protected] (Mouse) writes:

>> My question is:
>> Can I use such retrieved file_fd or struct socket* so in separate
>> kernel thread ?

>I see no reason why not - but that is not at all the same as "yes".  I
>do not work with multiple threads often enough to feel confident of my
>answer here.


The kernel iSCSI initiator takes a file descriptor from
userland and then uses the socket in two separate threads,
one sending, one receiving.

While the two threads use a rwlock to protect the socket,
they acquire it in shared ("READER") mode for I/O and
in exclusive ("WRITER") mode for closing and replacing
during error recovery.

The socket operations themselves are protected by the
socket lock. In case of PF_INET that's a global lock
(even with NET_MPSAFE). In case of PF_LOCAL, each
socket has a private lock.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.