6

I am writing a Linux block device driver that receives requests via a function registered with blk_init_queue().

My hardware device reorders requests and as such to avoid read-after-write conflicts it is required to wait for the completion of write(lba x) before issuing read(lba x).

My question: Does the Linux block layer keep track of RaW conflicts and it will not issue read(lba x) until it has received a request completion (via __blk_end_request_all(req r) ) for a preceding write(lba x), or do I have to do that in my driver?

hlitz
  • 635
  • 6
  • 24

1 Answers1

0

According to the article below, Linux block device drivers are now free to reorder requests arbitrarily, the filesystem layer is responsible for avoiding hazards and implementing barriers. https://lwn.net/Articles/400541/

The only exception are REQ_FLUSH and REQ_FUA requests for devices that implement write-back caches. In the case these flags are set certain ordering requirements need to be enforced by the blk device driver. https://www.kernel.org/doc/Documentation/block/writeback_cache_control.txt

In particular, the following ordering requirements exist:

  • No write data, REQ_FLUSH - doesn't have any ordering constraint other than the inherent FLUSH requirement (previously completed WRITEs should be on the media on FLUSH completion).

  • Write data, REQ_FLUSH - FLUSH must be completed before write data is issued. ie. write data must not be written to the media before all previous writes are on the media.

  • Write data, REQ_FUA - Write should be completed before FLUSH is issued - ie. the write data should be on platter along with previously completed writes on bio completion.

  • Write data, REQ_FLUSH | REQ_FUA - Write data must not be written to the media before all previous writes are on the media && the write data must be on the media on bio completion. This is usually sequenced as FLUSH write FLUSH.

[from the linux-fsdevel mailinglist: http://www.spinics.net/lists/linux-fsdevel/msg45616.html]

hlitz
  • 635
  • 6
  • 24