From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrWpx-0004pV-9j for qemu-devel@nongnu.org; Tue, 25 Jun 2013 13:15:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UrWpv-00048n-NL for qemu-devel@nongnu.org; Tue, 25 Jun 2013 13:15:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57325) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrWpv-00048a-FN for qemu-devel@nongnu.org; Tue, 25 Jun 2013 13:15:23 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5PHFMrh015737 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 25 Jun 2013 13:15:22 -0400 From: "Richard W.M. Jones" Date: Tue, 25 Jun 2013 18:15:18 +0100 Message-Id: <1372180518-26888-1-git-send-email-rjones@redhat.com> Subject: [Qemu-devel] [PATCH] block/ssh: Set bdrv_has_zero_init according to the file type. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, rjones@redhat.com From: "Richard W.M. Jones" If the remote is a regular file, set it to true (ie. reads of uninitialized areas in a newly created file will return zeroes). If we can't prove that, return false (a safe default). Tested by adding a debugging print statement [not part of this commit] and creating a remote file and a remote block device: $ ./qemu-img create ssh://localhost/tmp/new 100M Formatting 'ssh://localhost/tmp/new', fmt=raw size=104857600 filename ssh://localhost/tmp/new: has_zero_init = 1 $ sudo lvcreate -L 1G -n tmp /dev/fedora Logical volume "tmp" created $ ./qemu-img create ssh://localhost/dev/fedora/tmp 1G Formatting 'ssh://localhost/dev/fedora/tmp', fmt=raw size=1073741824 filename ssh://localhost/dev/fedora/tmp: has_zero_init = 0 Cc: Kevin Wolf Signed-off-by: Richard W.M. Jones --- block/ssh.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/block/ssh.c b/block/ssh.c index 246a70d..d7e7bf8 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -716,6 +716,21 @@ static void ssh_close(BlockDriverState *bs) ssh_state_free(s); } +static int ssh_has_zero_init(BlockDriverState *bs) +{ + BDRVSSHState *s = bs->opaque; + /* Assume false, unless we can positively prove it's true. */ + int has_zero_init = 0; + + if (s->attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) { + if (s->attrs.permissions & LIBSSH2_SFTP_S_IFREG) { + has_zero_init = 1; + } + } + + return has_zero_init; +} + static void restart_coroutine(void *opaque) { Coroutine *co = opaque; @@ -1037,6 +1052,7 @@ static BlockDriver bdrv_ssh = { .bdrv_file_open = ssh_file_open, .bdrv_create = ssh_create, .bdrv_close = ssh_close, + .bdrv_has_zero_init = ssh_has_zero_init, .bdrv_co_readv = ssh_co_readv, .bdrv_co_writev = ssh_co_writev, .bdrv_getlength = ssh_getlength, -- 1.8.2.1