From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4477-0000Y5-F9 for qemu-devel@nongnu.org; Tue, 08 Nov 2016 05:58:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c4472-0001d9-L9 for qemu-devel@nongnu.org; Tue, 08 Nov 2016 05:58:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49584) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c4472-0001cq-GB for qemu-devel@nongnu.org; Tue, 08 Nov 2016 05:58:44 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED78261BB0 for ; Tue, 8 Nov 2016 10:58:42 +0000 (UTC) Received: from localhost (ovpn-204-128.brq.redhat.com [10.40.204.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA8AwfZ6021631 for ; Tue, 8 Nov 2016 05:58:42 -0500 Date: Tue, 8 Nov 2016 10:58:40 +0000 From: "Richard W.M. Jones" Message-ID: <20161108105840.GF27578@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] qemu-img create doesn't always replace the existing file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org When using 'qemu-img create', if the file being created already exists, then qemu-img tries to read it first. This has some unexpected effects: $ rm test.qcow2 $ qemu-img create -f qcow2 -o compat=1.1,preallocation=off test.qcow2 1G Formatting 'test.qcow2', fmt=qcow2 size=1073741824 compat=1.1 encryption=off cluster_size=65536 preallocation=off lazy_refcounts=off refcount_bits=16 $ du -sh test.qcow2 196K test.qcow2 $ rm test.qcow2 $ qemu-img create -f qcow2 -o compat=1.1,preallocation=falloc test.qcow2 1G Formatting 'test.qcow2', fmt=qcow2 size=1073741824 compat=1.1 encryption=off cluster_size=65536 preallocation=falloc lazy_refcounts=off refcount_bits=16 $ qemu-img create -f qcow2 -o compat=1.1,preallocation=off test.qcow2 1G Formatting 'test.qcow2', fmt=qcow2 size=1073741824 compat=1.1 encryption=off cluster_size=65536 preallocation=off lazy_refcounts=off refcount_bits=16 $ du -sh test.qcow2 256K test.qcow2 # would expect this to be the same as above $ rm test.qcow2 $ mkfifo test.qcow2 $ qemu-img create -f qcow2 -o compat=1.1 test.qcow2 64M Formatting 'test.qcow2', fmt=qcow2 size=67108864 compat=1.1 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16 qemu-img: test.qcow2: Could not resize file: Invalid argument Is this a bug or is my understanding of 'qemu-img create' wrong? Currently libguestfs uses 'qemu-img create' to create empty files. However we don't unlink the target file first. Should we be doing that? Tested with: qemu-img-2.6.0-3.fc24.x86_64 qemu-img-2.7.0-1.fc25.x86_64 Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/