From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrS0Z-0000za-Rv for qemu-devel@nongnu.org; Tue, 25 Jun 2013 08:06:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UrS0U-0003QR-Oq for qemu-devel@nongnu.org; Tue, 25 Jun 2013 08:06:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrS0U-0003Px-G8 for qemu-devel@nongnu.org; Tue, 25 Jun 2013 08:05:58 -0400 Date: Tue, 25 Jun 2013 13:05:33 +0100 From: "Richard W.M. Jones" Message-ID: <20130625120533.GP1882@redhat.com> References: <20130625113911.GD3539@dhcp-200-207.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130625113911.GD3539@dhcp-200-207.str.redhat.com> Subject: Re: [Qemu-devel] block: Review of .has_zero_init use List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: josh.durgin@dreamhost.com, tailai.ly@taobao.com, Peter Lieven , qemu-devel@nongnu.org, stefanha@redhat.com, bharata@linux.vnet.ibm.com, morita.kazutaka@lab.ntt.co.jp On Tue, Jun 25, 2013 at 01:39:11PM +0200, Kevin Wolf wrote: > * ssh - currently has_zero_init = 1 (is this correct?) [...] > It might be possible that the correct value depends on the backend on > the server side for some protocols - for example, I think for SSH it > depends on whether you access a regular file or a block device on the > other host (if accessing a block device is even possible). This seems to depend on the behaviour of O_TRUNC on block devices. The man page says it's unspecified, but I tested it on Linux, and Linux ignores it (for logical volumes anyway). When the ssh driver is asked to do bdrv_create it does on the remote end: - open (filename, O_RDWR|O_CREAT|O_TRUNC, 0644) [1] - lseek (fd, size-1, SEEK_SET) [2] - write (fd, &'\0', 1) In other words for regular files, it creates a sparse file. For block devices, I tested the sequence above, and it doesn't fail. So .. I guess that has_zero_init = 0 would be correct? Unless we fstat the fd after opening it and return some conditional value from bdrv_has_zero_init eg if it's a block device. Is that possible? Rich. [1] Mode 0644 is hard-coded :-( [2] I realize now it's actually possible to use ftruncate, although it's not obvious. There is no explicit truncate operation in sftp. But there is a "setattr" operation, which if you try to set the size attr in fact does a truncate at the remote end. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones 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/