* [Qemu-devel] [PATCH] block/ssh: Set bdrv_has_zero_init according to the file type.
@ 2013-06-25 17:15 Richard W.M. Jones
2013-06-26 7:39 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: Richard W.M. Jones @ 2013-06-25 17:15 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, rjones
From: "Richard W.M. Jones" <rjones@redhat.com>
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 <kwolf@redhat.com>
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] block/ssh: Set bdrv_has_zero_init according to the file type.
2013-06-25 17:15 [Qemu-devel] [PATCH] block/ssh: Set bdrv_has_zero_init according to the file type Richard W.M. Jones
@ 2013-06-26 7:39 ` Kevin Wolf
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2013-06-26 7:39 UTC (permalink / raw)
To: Richard W.M. Jones; +Cc: qemu-devel, qemu-stable
Am 25.06.2013 um 19:15 hat Richard W.M. Jones geschrieben:
> From: "Richard W.M. Jones" <rjones@redhat.com>
>
> 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 <kwolf@redhat.com>
> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
Thanks, applied to the block branch, and CCed qemu-stable.
Kevin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-06-26 7:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-25 17:15 [Qemu-devel] [PATCH] block/ssh: Set bdrv_has_zero_init according to the file type Richard W.M. Jones
2013-06-26 7:39 ` Kevin Wolf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).