openzfs / zfs

OpenZFS on Linux and FreeBSD
https://openzfs.github.io/openzfs-docs
Other
10.66k stars 1.76k forks source link

ZFS may cause file corrupt with guestmount #6115

Closed sunzhaoyang closed 7 years ago

sunzhaoyang commented 7 years ago

System information

Type Version/Name
Distribution Name Redhat
Distribution Version 7.2
Linux Kernel 3.10.0-327.el7.x86_64
Architecture
ZFS Version 0.6.4.2
SPL Version 0.6.4.2

Describe the problem you're observing

There is an os qcow2 file in zfs.

It will be cloned and be guestmounted for modify(copy file,change config file,eg.)

But md5sum check mismatch after copy file into qcow2 and boot up.

Here is my test script:

# mount zfs block device and guestmount os.qcow2 inside.
zfs clone qbackup/redhat-6.7@test qbackup/sun_3;sleep 3;
mount /dev/qbackup/sun_3 /tmp/1;
guestmount -a /tmp/1/os.qcow2 -w -i /tmp/2;

# copy testfile(14M) into qcow2
cp /root/testfile /tmp/2/usr/local/bin/;

# guestmount again ,and check md5
umount /tmp/2/;
guestmount -a /tmp/1/os.qcow2 -w -i /tmp/2;
md5sum /tmp/2/usr/local/bin/testfile
umount /tmp/2

# guestmount agagin ,and check md5
guestmount -a /tmp/1/os.qcow2 -w -i /tmp/2
md5sum /tmp/2/usr/local/bin/testfile
umount /tmp/2

result

14b80a29535342a242ef9b61e4883472  /tmp/2/usr/local/bin/testfile # Wrong md5 result
1fd08ffc62181a31068dbde11aacd60f  /tmp/2/usr/local/bin/testfile      # Right md5 result

Then I copy os.qcow2 out of zfs ,use normal filesystem instead.

new test script

# copy an new os.qcow2
rm /tmp/1/os.qcow2 ;  #/tmp/1/ based lvm and xfs now.
cp os.qcow2 /tmp/1/ ;
guestmount -a /tmp/1/os.qcow2 -w -i /tmp/2;
cp /root/testfile /tmp/2/usr/local/bin/;
umount /tmp/2/;

# guestmount os.qcow2 and check md5
guestmount -a /tmp/1/os.qcow2 -w -i /tmp/2;
md5sum /tmp/2/usr/local/bin/testfile
umount /tmp/2

# guestmount again and  check md5
guestmount -a /tmp/1/os.qcow2 -w -i /tmp/2
md5sum /tmp/2/usr/local/bin/testfile
umount /tmp/2

result

1fd08ffc62181a31068dbde11aacd60f  /tmp/2/usr/local/bin/testfile # Right value
1fd08ffc62181a31068dbde11aacd60f  /tmp/2/usr/local/bin/testfile # Right value

I tried zfs set sync=always , did not work....

$rpm -qa |grep guestfs
libguestfs-tools-c-1.28.1-1.55.el7.x86_64
libguestfs-winsupport-7.2-1.el7.x86_64
libguestfs-tools-1.28.1-1.55.el7.noarch
libguestfs-xfs-1.28.1-1.55.el7.x86_64
libguestfs-1.28.1-1.55.el7.x86_64
libguestfs-java-1.28.1-1.55.el7.x86_64

Describe how to reproduce the problem

Include any warning/errors/backtraces from the system logs

sunzhaoyang commented 7 years ago

Can't upload my testfile.......