From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNlu6-0004k0-9H for qemu-devel@nongnu.org; Tue, 17 Feb 2015 12:25:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNlu2-0006W7-Ol for qemu-devel@nongnu.org; Tue, 17 Feb 2015 12:25:46 -0500 Received: from indium.canonical.com ([91.189.90.7]:49191) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNlu2-0006Vp-HG for qemu-devel@nongnu.org; Tue, 17 Feb 2015 12:25:42 -0500 Received: from loganberry.canonical.com ([91.189.90.37]) by indium.canonical.com with esmtp (Exim 4.76 #1 (Debian)) id 1YNlu1-0000Eh-Ly for ; Tue, 17 Feb 2015 17:25:41 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 91F782E80C2 for ; Tue, 17 Feb 2015 17:25:41 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Date: Tue, 17 Feb 2015 17:18:59 -0000 From: Max Reitz <1422307@bugs.launchpad.net> Sender: bounces@canonical.com References: <20150216100528.10277.20713.malonedeb@chaenomeles.canonical.com> Message-Id: <20150217171859.20817.82424.malone@wampee.canonical.com> Errors-To: bounces@canonical.com Subject: [Qemu-devel] [Bug 1422307] Re: qemu-nbd corrupts files Reply-To: Bug 1422307 <1422307@bugs.launchpad.net> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org For whatever reason, using an empty image now works for me, too: $ ./qemu-img create -f vdi test.vdi 64M; ./qemu-nbd -c /dev/nbd0 test.vdi; = dd if=3D/dev/urandom of=3D/dev/nbd0 bs=3D1K count=3D16384; md5sum /dev/nbd0= ; sync; echo 1 > /proc/sys/vm/drop_caches; md5sum /dev/nbd0; ./qemu-nbd -d = /dev/nbd0 Formatting 'test.vdi', fmt=3Dvdi size=3D67108864 static=3Doff 16384+0 records in 16384+0 records out 16777216 bytes (17 MB) copied, 0.982225 s, 17.1 MB/s 216f7abbf90bf2539163396bdb7fd7b9 /dev/nbd0 a42faf71124c1f6102fa39cea82a1c86 /dev/nbd0 /dev/nbd0 disconnected Writing less than 16384 kB, the issue is not always reproducible; for me, it disappears around 16160 kB (it's fuzzy, sometimes it appears, sometimes it doesn't). So far I was only able to reproduce the issue by connecting qemu-nbd to the the Linux NBD interface; connecting to qemu-nbd via TCP worked fine. So, a couple of test cases: VDI and NBD over /dev/nbd0: # for i in $(seq 0 9); do ./qemu-img create -f vdi test.vdi 64M > /dev/null= ; ./qemu-nbd -c /dev/nbd0 test.vdi; sleep 1; ./qemu-img convert -n blob.raw= /dev/nbd0; ./qemu-img convert /dev/nbd0 test1.raw; sync; echo 1 > /proc/sy= s/vm/drop_caches; ./qemu-img convert /dev/nbd0 test2.raw; ./qemu-nbd -d /de= v/nbd0 > /dev/null; if ! ./qemu-img compare -q test1.raw test2.raw; then md= 5sum test1.raw test2.raw; echo "$i failed"; break; fi; done; echo 'done' e5185b807948d65bb4e837d992cea429 test1.raw 9907ca700f6ee4d4cdb136bb90fd8df1 test2.raw 6 failed done VDI and NBD over TCP: # for i in $(seq 0 9); do ./qemu-img create -f vdi test.vdi 64M > /dev/null= ; (./qemu-nbd -t test.vdi &); sleep 1; ./qemu-img convert -n blob.raw nbd:/= /localhost; ./qemu-img convert nbd://localhost test1.raw; sync; echo 1 > /p= roc/sys/vm/drop_caches; ./qemu-img convert nbd://localhost test2.raw; killa= ll qemu-nbd; if ! ./qemu-img compare -q test1.raw test2.raw; then md5sum te= st1.raw test2.raw; echo "$i failed"; break; fi; done; echo 'done' = done VDI and NBD over a Unix socket: # for i in $(seq 0 9); do ./qemu-img create -f vdi test.vdi 64M > /dev/null= ; (./qemu-nbd -k /tmp/nbd -t test.vdi &); sleep 1; ./qemu-img convert -n bl= ob.raw nbd+unix:///\?socket=3D/tmp/nbd; ./qemu-img convert nbd+unix:///\?so= cket=3D/tmp/nbd test1.raw; sync; echo 1 > /proc/sys/vm/drop_caches; ./qemu-= img convert nbd+unix:///\?socket=3D/tmp/nbd test2.raw; killall qemu-nbd; if= ! ./qemu-img compare -q test1.raw test2.raw; then md5sum test1.raw test2.r= aw; echo "$i failed"; break; fi; done; echo 'done' = = done VDI without NBD: # for i in $(seq 0 9); do ./qemu-img create -f vdi test.vdi 64M > /dev/null= ; ./qemu-img convert -n -O vdi blob.raw test.vdi; ./qemu-img convert test.v= di test1.raw; sync; echo 1 > /proc/sys/vm/drop_caches; ./qemu-img convert t= est.vdi test2.raw; if ! ./qemu-img compare -q test1.raw test2.raw; then md5= sum test1.raw test2.raw; echo "$i failed"; break; fi; done; echo 'done' done qcow2 and NBD over /dev/nbd0: # for i in $(seq 0 9); do ./qemu-img create -f qcow2 test.qcow2 64M > /dev/= null; ./qemu-nbd -c /dev/nbd0 test.qcow2; sleep 1; ./qemu-img convert -n bl= ob.raw /dev/nbd0; ./qemu-img convert /dev/nbd0 test1.raw; sync; echo 1 > /p= roc/sys/vm/drop_caches; ./qemu-img convert /dev/nbd0 test2.raw; ./qemu-nbd = -d /dev/nbd0 > /dev/null; if ! ./qemu-img compare -q test1.raw test2.raw; t= hen md5sum test1.raw test2.raw; echo "$i failed"; break; fi; done; echo 'do= ne' done raw and NBD over /dev/nbd0: # for i in $(seq 0 9); do ./qemu-img create -f raw test.raw 64M > /dev/null= ; ./qemu-nbd -f raw -c /dev/nbd0 test.raw; sleep 1; ./qemu-img convert -n b= lob.raw /dev/nbd0; ./qemu-img convert /dev/nbd0 test1.raw; sync; echo 1 > /= proc/sys/vm/drop_caches; ./qemu-img convert /dev/nbd0 test2.raw; ./qemu-nbd= -d /dev/nbd0 > /dev/null; if ! ./qemu-img compare -q test1.raw test2.raw; = then md5sum test1.raw test2.raw; echo "$i failed"; break; fi; done; echo 'd= one' done In conclusion, the only combination I can reproduce the issue with is VDI with NBD over the Linux NBD interface. It doesn't seem to be the kernel's fault because other file formats work fine; it doesn't seem to be qemu-nbd's fault because not using the kernel interface works fine; and it doesn't seem to be VDI's fault because not using NBD or at least using NBD over TCP or Unix sockets works fine, too. I'll keep looking into it. Max -- = You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1422307 Title: qemu-nbd corrupts files Status in QEMU: New Bug description: Dear all, On Trusty, in certain situations, try to copy files over a qemu-nbd mounted file system leads to write errors (and thus, file corruption). Here is the last example I tried: -> virtual disk is a VDI disk -> It has only one partition, in FAT Here is my mount process: # modprobe nbd max_part=3D63 # qemu-nbd -c /dev/nbd0 "virtual_disk.vdi" # partprobe /dev/nbd0 # mount /dev/nbd0p1 /tmp/mnt/ Partition is properly mounted at that point: /dev/nbd0p1 on /tmp/mnt type vfat (rw) Now, when I copy a file (rather big, ~28MB): # cp file_to_copy /tmp/mnt/ ; sync # md5sum /tmp/mnt/file_to_copy 2efc9f32e4267782b11d63d2f128a363 /tmp/mnt/file_to_copy # umount /tmp/mnt = # mount /dev/nbd0p1 /tmp/mnt/ # md5sum /tmp/mnt/file_to_copy 42b0a3bf73f704d03ce301716d7654de /tmp/mnt/file_to_copy The first hash was obviously the right one. On a previous attempt I did, I spotted thanks to vbindiff that parts of t= he file were just filed with 0s instead of actual data. It will randomly work after several attempts to write. Version information: # qemu-nbd --version qemu-nbd version 0.0.1 Written by Anthony Liguori. Cheers, To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1422307/+subscriptions