I'm trying to access a block device (say /dev/sdb) using libaio. I works correctly, but I was wondering how to perform FUA (Force Unit Access) using the API of libaio.
I must say the documentation I found on the subject is quite poor, hope one of you will be able to help me with this.
You can't, unfortunately. The interface is too limited. But what you should be able to do is use the SG_IO ioctl()
for SYNCHRONIZE CACHE (10)
or (16)
. That is, if your device supports the command. SYNCHRONIZE CACHE
lets you instruct the device to commit a range of logical blocks to the medium.
See the manpage for the sg_sync
command: http://manpages.ubuntu.com/manpages/trusty/man8/sg_sync.8.html
And download the latest sg3_utils
source here: http://sg.danny.cz/sg/sg3_utils.html (as of now, version 1.41 http://sg.danny.cz/sg/p/sg3_utils-1.41.tar.xz). Look at the sg_sync command source to see how the ioctl is invoked.
ioctl(SG_IO)
blocks, but there is a way to transact these commands with non-blocking I/O. Refer to the SCSI Generic HOWTO: http://sg.danny.cz/sg/p/sg_v3_ho.html