Asynchronous Block I/O request

In the Linux kernel, Block I/O request are asynchronous. It means that when you call submit_bio(READ/WRITE, bio); or generic_make_request(…), the function will (most probably) return directly, and of course, the read is not done. So after calling bio_submit(READ…); you absolutely cannot read the content of a page added by bio_add_page().

So, how to know when it is finished? You have to use bio->bi_end_io pointer function. You have to set this pointer to a function which will be called when the read has been done.

void myReadIsFinished(struct bio* bio, int error) {
//Read is finished, do something with the bio content
}

...

bio->bi_end_io = &myReadIsFinished;
bio_submit(READ, bio);

bio->bi_private allows you to store some pointer with the bio. Use it to know what you tried to read.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.