Bug 2148853

Summary: [virtiofs] file size is increasing when writing to the same address with mmap() on virtiofs backed paths
Product: Red Hat Enterprise Linux 9 Reporter: xiagao
Component: virtiofsdAssignee: German Maglione <gmaglione>
Status: CLOSED ERRATA QA Contact: xiagao
Severity: medium Docs Contact:
Priority: medium    
Version: 9.2CC: coli, gmaglione, jinzhao, juzhang, kwolf, lijin, vgoyal, virt-maint
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: virtiofsd-1.5.0-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-09 07:46:45 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 2123070    
Bug Blocks:    

Description xiagao 2022-11-28 07:30:04 UTC
Description of problem:
This bug comes from an upstream issue and can be reproduced downstream.
https://gitlab.com/virtio-fs/virtiofsd/-/issues/67

'''
When using python and writing to a mmap file, I am seeing with cache mode auto and always that the file is increasing in size each time I write to it.
'''

Version-Release number of selected component (if applicable):
qemu-kvm-7.1.0-3.el9.x86_64
virtiofsd-1.4.0-1.el9.x86_64
kernel-5.14.0-178.el9.x86_64

How reproducible:
100%

Steps to Reproduce:
1. start virtiofsd
# /usr/libexec/virtiofsd -o source=/home/test  --socket-path=/tmp/sock1 --cache auto
2. boot up a rhel920 guest
3. in guest, mount virtiofs
# mount -t virtiofs myfs /mnt/test
4. write to the same space of a file with mmap 
```

[root@vm-74-75 test]# cat mmap_test.py 
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())

```

Actual results:
# python3 mmap_test.py 
2048
4096


Expected results:
The file size will not be changed.

Additional info:

Comment 5 xiagao 2022-12-29 07:27:24 UTC
Test passed with the fixed virtiofsd version, file size is NOT increasing when writing to the same address with mmap() on virtiofs backed paths, so verify the bug.

[root@bootp-73-75-32 mm]# python3 mmap_test.py 
1024
1024
1024
1024


pkg:
virtiofsd-1.5.0-1.el9.x86_64
qemu-kvm-7.2.0-1.el9
5.14.0-219.el9.x86_64(host)
5.14.0-226.el9.x86_64(guest)

Comment 7 errata-xmlrpc 2023-05-09 07:46:45 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (virtiofsd bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2334