I'm working on Linux kernel version 2.6.39.1, and am developing a block device driver. In this regard, I want to combine multiple struct bio
s into a single struct request
, which is then added to the request_queue
for processing by the device driver, namely -- scsi_request_fn()
.
I tried using the ->bi_next
field of struct bio
to link multiple struct bio
s that I have composed, thereby creating a linked list of struct bio
s. When I call submit_bio()
to submit a bio to the block device layer for I/O, this BUG_ON()
is triggered because the code expects bio->bi_next
to be NULL
.
Is there a way to link several struct bio
s into a single struct request
before sending it to lower layers for servicing?
I'm not sure how to string multiple struct bio
together, but you might want to take a look at the "task collector" implementation in libsas and the aic94xx driver for an alternate approach. There isn't much documentation, but the libsas documentation describes it as
Some hardware (e.g. aic94xx) has the capability to DMA more than one task at a time (interrupt) from host memory. Task Collector Mode is an optional feature for HAs which support this in their hardware. (Again, it is completely optional even if your hardware supports it.)
In Task Collector Mode, the SAS Layer would do natural coalescing of tasks and at the appropriate moment it would call your driver to DMA more than one task in a single HA interrupt. DMBS may want to use this by insmod/modprobe setting the lldd_max_execute_num to something greater than 1.
Effectively, this lets the block layer (a.k.a. BIO) remain unchanged, but multiple requests are accumulated at the driver layer and submitted together.
Thanks for the reply, @ctuffli. I've decided to use a structure similar to the one described here. Basically, I allocate a struct packet_data
which would contain pointers to all struct bio
s that should be merged to form one single struct bio
(and later on, one single struct request
). In addition, I store some driver related information as well in this struct packet_data
. Next, I allocate a new struct bio
(lets call it "merged_bio"), copy all the pages from the list of original BIOs and then make the merged_bio->bi_private
point to the struct packet_data
. This last hack would allow me to keep track of the list of original BIOs, and also call bio_endio()
to end I/O on all individual BIOs once the merged_bio
has been successfully transferred.
Not sure if this is the smartest way to do this, but it does what I intended! :^)
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