Skip to content

passthrough: Set `RWF_APPEND` on non-cached writes on append only files

German Maglione requested to merge ghm-virtio-fs/virtiofsd:fix-append-mmap into main

Writing to a mem mapped area of a file that was open with O_APPEND, will always write at the end of the file. We can test this with running virtiofsd with --cache=auto|always:

    import mmap
    import struct
    l = 1024
    f = open("./test.db", "a+b")
    f.truncate(l)
    m = mmap.mmap(f.fileno(), 1024, access=mmap.ACCESS_WRITE)
    m[0:4] = b"0000"
    m.flush()
    print(m.size())
    m[0:4] = b"0000"
    m.flush()
    print(m.size())

After each write the size of the file is increased. This is because, even though the guest kernel sends the correct offsets, the mem mapped writes in the guest translate into write() operations in the host so that if the file was opened/created with O_APPEND the offset is ignored.

For more details see: #67 (closed) https://github.com/kata-containers/kata-containers/issues/5634

closes #67 (closed)

Merge request reports