I want create a block device that get a bio with request for n sector and split it into n bio with 1 sector. I used bio_split but it doesn't work and reaches BUG_ON.
Is there any function to do such thing?
If there's not can anyone help me to write a function to do that? It's also fine to have a function that split a bio into 4k bios.
The split_bio() function only works for bios with a single page (when bi_vcnt field is exactly 1).
To deal with bios with multiple pages - and I suspect you deal with these most of the time - you have to create new bios and set them up so that they contain only a single sector.
Tip: If the sector size is the same as the page size (currently 4K), and your block driver tells the kernel to supply no less than this size, than you only have to put each page from the incoming bio to the new bio. If the sector size is less then the page size, than the logic will be a bit more complicated.
Use bio_kmalloc to allocate the new bios and copy the data onto the memory pages in them manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With