[PATCH 6/9] ssh: Support BDRV_REQ_ZERO_WRITE for truncate

Eric Blake posted 9 patches 5 years, 9 months ago
Maintainers: Peter Lieven <pl@kamp.de>, "Denis V. Lunev" <den@openvz.org>, Stefan Weil <sw@weilnetz.de>, Jason Dillaman <dillaman@redhat.com>, Max Reitz <mreitz@redhat.com>, Jeff Cody <codyprime@gmail.com>, Kevin Wolf <kwolf@redhat.com>, Liu Yuan <namei.unix@gmail.com>, "Richard W.M. Jones" <rjones@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>
[PATCH 6/9] ssh: Support BDRV_REQ_ZERO_WRITE for truncate
Posted by Eric Blake 5 years, 9 months ago
Our .bdrv_has_zero_init_truncate can detect when the remote side
always zero fills; we can reuse that same knowledge to implement
BDRV_REQ_ZERO_WRITE by ignoring it when the server gives it to us for
free.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 block/ssh.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/block/ssh.c b/block/ssh.c
index 9eb33df8598c..f9e08a490069 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -883,6 +883,10 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
     /* Go non-blocking. */
     ssh_set_blocking(s->session, 0);

+    if (s->attrs->type == SSH_FILEXFER_TYPE_REGULAR) {
+        bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE;
+    }
+
     qapi_free_BlockdevOptionsSsh(opts);

     return 0;
-- 
2.26.2


Re: [PATCH 6/9] ssh: Support BDRV_REQ_ZERO_WRITE for truncate
Posted by Richard W.M. Jones 5 years, 9 months ago
On Tue, Apr 28, 2020 at 03:29:02PM -0500, Eric Blake wrote:
> Our .bdrv_has_zero_init_truncate can detect when the remote side
> always zero fills; we can reuse that same knowledge to implement
> BDRV_REQ_ZERO_WRITE by ignoring it when the server gives it to us for
> free.
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>  block/ssh.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/block/ssh.c b/block/ssh.c
> index 9eb33df8598c..f9e08a490069 100644
> --- a/block/ssh.c
> +++ b/block/ssh.c
> @@ -883,6 +883,10 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
>      /* Go non-blocking. */
>      ssh_set_blocking(s->session, 0);
> 
> +    if (s->attrs->type == SSH_FILEXFER_TYPE_REGULAR) {
> +        bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE;
> +    }
> +

As the libssh sftp API is written this is all fine, so ACK:

Reviewed-by: Richard W.M. Jones <rjones@redhat.com>

On the other hand the actual openssh / libssh code is a bit hairy.
Openssh simply copies the st_mode field onto the wire (with
byte-swapping).  Libssh assumes that S_IFREG == 0100000 and translates
this bit to SSH_FILEXFER_TYPE_REGULAR.  This happens to be true on
Linux and *BSD but as far as I can tell isn't defined in POSIX.
Anyway I guess it'll work in all places that we care about.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top