I've encountered a race condition with LVM and a disk driver I'm working on. It looks like things like vgcreate and lvcreate do their IO in O_DIRECT mode. I discovered this when running those commands with -vvv.
Clearing start of logical volume "test"
/dev/Finance-PG-vg/test: Added to device cache
Opened /dev/Finance-PG-vg/test RW O_DIRECT
Wiping /dev/Finance-PG-vg/test at sector 0 length 8 sectors
/dev/Finance-PG-vg/test: block size is 4096 bytes
Closed /dev/Finance-PG-vg/test
Specifically, I suspect that our reads are hitting the cache, and not getting the latest disk contents.
If something is written with O_DIRECT, my understanding is that this bypasses the cache. Therefore any reads to that sector are going to recieve the old data from cache, at least until the cache is invalidated. So if I want to read whatever O_DIRECT just wrote within a few seconds, I should be dropping the cache first?
Correct?