The data being displayed on a loop device mount is incorrect when the data in the underlying file is changed.
Example:
$ mkdir drv
$ dd if=/dev/zero of=data.ext4 bs=1M count=10
$ mkfs.ext4 data.ext4
$ losetup /dev/loop0 data.ext4
$ mount /dev/loop0 drv
$ echo "abcdefg" > drv/test.txt
$ cat drv/test.txt
abcdefg
$ hexdump -C data.ext4 | grep abcd
00169000 61 62 63 64 65 66 67 0a 00 00 00 00 00 00 00 00 |abcdefg.........|
$ sed -i 's/abcd/zzzz/g' data.ext4
$ hexdump -C data.ext4 | grep zzzz
00169000 7a 7a 7a 7a 65 66 67 0a 00 00 00 00 00 00 00 00 |zzzzefg.........|
$ cat drv/test.txt
abcdefg
$ hexdump -C data.ext4 | grep abcd
$
The string "abcd" is no longer in the backing data.ext4 file, yet when the test.txt
file is cat, abcd
is still seen. How can I sync the loop to properly display what the backing file truly has?
Note: --direct-io=on
makes no difference to the above test.
There is absolutely some sort of caching going on, thats what I need to sync. I need the cache for /dev/loop0 to have the data from data.ext4 read into it somehow.
– Michael Mullin Dec 22 '20 at 21:28