Generic I/O
Kai Meyer
kai at gnukai.com
Mon Nov 14 14:15:14 EST 2011
I'm finding it's really simple to write generic I/O functions for block
devices (via a "struct block_device") to mimic the posix read() and
write() functions (I have to supply the position, since I don't have a
fd to keep a position for me, but that's perfectly ok).
I've got a little hack that allows me to run synchronously or
asynchronously, relying on submit_bio() to create the threads for me. My
caller function has an atomic_t value that I set equal to the number of
bios I want to submit. Then I pass a pointer to that atomic_t around to
each of the bios which decrement it in the endio function for that bio.
Then the caller does this:
while(atomic_read(numbios) > 0)
msleep(1);
I'm finding the msleep(1) is a really really really long time,
relatively. It seems to work ok if I just have an empty loop, but it
also seems to me like I'm re-inventing a wheel here. Are there
mechanisms that are better suited for waiting for tasks to complete? Or
even for generic block I/O functions?
-Kai Meyer
More information about the Kernelnewbies
mailing list