Received: from eggs.gnu.org ([2001:4830:134:3::10]:42307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCTlh-0003BW-Jk for qemu-devel@nongnu.org; Thu, 22 Aug 2013 08:13:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VCTlb-0003cS-HS for qemu-devel@nongnu.org; Thu, 22 Aug 2013 08:13:37 -0400 Received: from mail-ee0-x235.google.com ([2a00:1450:4013:c00::235]:44720) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCTlb-0003aU-AU for qemu-devel@nongnu.org; Thu, 22 Aug 2013 08:13:31 -0400 Received: by mail-ee0-f53.google.com with SMTP id b15so863532eek.26 for ; Thu, 22 Aug 2013 05:13:30 -0700 (PDT) Date: Thu, 22 Aug 2013 14:13:28 +0200 From: Stefan Hajnoczi Message-ID: <20130822121328.GG27613@stefanha-thinkpad.redhat.com> References: <20130805124110.GI2654@dhcp-200-207.str.redhat.com> <1375754020-20545-1-git-send-email-asias@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1375754020-20545-1-git-send-email-asias@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2] block: Produce zeros when protocols reading beyond end of file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Asias He Cc: Kevin Wolf , Stefan Hajnoczi , qemu-devel@nongnu.org, MORITA Kazutaka On Tue, Aug 06, 2013 at 09:53:40AM +0800, Asias He wrote: > From: MORITA Kazutaka > > While Asias is debugging an issue creating qcow2 images on top of > non-file protocols. It boils down to this example using NBD: > > $ qemu-io -c 'open -g nbd+unix:///?socket=/tmp/nbd.sock' -c 'read -v 0 512' > > Notice the open -g option to set bs->growable. This means you can > read/write beyond end of file. Reading beyond end of file is supposed > to produce zeroes. > > We rely on this behavior in qcow2_create2() during qcow2 image > creation. We create a new file and then write the qcow2 header > structure using bdrv_pwrite(). Since QCowHeader is not a multiple of > sector size, block.c first uses bdrv_read() on the empty file to fetch > the first sector (should be all zeroes). > > Here is the output from the qemu-io NBD example above: > > $ qemu-io -c 'open -g nbd+unix:///?socket=/tmp/nbd.sock' -c 'read -v 0 512' > 00000000: ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ................ > 00000010: ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ................ > 00000020: ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ................ > ... > > We are not zeroing the buffer! As a result qcow2 image creation on top > of protocols is not guaranteed to work even when file creation is > supported by the protocol. > > Signed-off-by: MORITA Kazutaka > Signed-off-by: Asias He > --- > block.c | 30 +++++++++++++++++++++++++++++- > 1 file changed, 29 insertions(+), 1 deletion(-) Applied again on top of Asias' fix so qcow2 vmstate doesn't break. Thanks, applied to my block tree: https://github.com/stefanha/qemu/commits/block Stefan