From nobody Fri Oct 24 09:45:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519415700037319.92260016517014; Fri, 23 Feb 2018 11:55:00 -0800 (PST) Received: from localhost ([::1]:46879 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epJQo-0000T5-Eu for importer@patchew.org; Fri, 23 Feb 2018 14:54:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epIzo-0001Ru-8h for qemu-devel@nongnu.org; Fri, 23 Feb 2018 14:27:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epIzm-0005Rk-TJ for qemu-devel@nongnu.org; Fri, 23 Feb 2018 14:27:04 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33938 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1epIzh-0005Kj-V9; Fri, 23 Feb 2018 14:26:58 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8CD91EAEB8; Fri, 23 Feb 2018 19:26:57 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-118.ams2.redhat.com [10.36.117.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id F13242024CAC; Fri, 23 Feb 2018 19:26:55 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 23 Feb 2018 20:25:45 +0100 Message-Id: <20180223192549.26666-33-kwolf@redhat.com> In-Reply-To: <20180223192549.26666-1-kwolf@redhat.com> References: <20180223192549.26666-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 23 Feb 2018 19:26:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 23 Feb 2018 19:26:57 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 32/36] ssh: Support .bdrv_co_create X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, jdurgin@redhat.com, pkrempa@redhat.com, mitake.hitoshi@lab.ntt.co.jp, jcody@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, namei.unix@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This adds the .bdrv_co_create driver callback to ssh, which enables image creation over QMP. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- qapi/block-core.json | 16 ++++++++- block/ssh.c | 92 +++++++++++++++++++++++++++++-------------------= ---- 2 files changed, 67 insertions(+), 41 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 431d4a4fb2..2f7fab46eb 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3593,6 +3593,20 @@ '*object-size': 'size' } } =20 ## +# @BlockdevCreateOptionsSsh: +# +# Driver specific image creation options for SSH. +# +# @location Where to store the new image file +# @size Size of the virtual disk in bytes +# +# Since: 2.12 +## +{ 'struct': 'BlockdevCreateOptionsSsh', + 'data': { 'location': 'BlockdevOptionsSsh', + 'size': 'size' } } + +## # @BlockdevCreateNotSupported: # # This is used for all drivers that don't support creating images. @@ -3644,7 +3658,7 @@ 'rbd': 'BlockdevCreateOptionsRbd', 'replication': 'BlockdevCreateNotSupported', 'sheepdog': 'BlockdevCreateOptionsSheepdog', - 'ssh': 'BlockdevCreateNotSupported', + 'ssh': 'BlockdevCreateOptionsSsh', 'throttle': 'BlockdevCreateNotSupported', 'vdi': 'BlockdevCreateNotSupported', 'vhdx': 'BlockdevCreateNotSupported', diff --git a/block/ssh.c b/block/ssh.c index 77bc20041f..bd3044e5f6 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -826,64 +826,75 @@ static QemuOptsList ssh_create_opts =3D { } }; =20 -static int ssh_create(const char *filename, QemuOpts *opts, Error **errp) +static int ssh_co_create(BlockdevCreateOptions *options, Error **errp) { - int r, ret; - int64_t total_size =3D 0; - QDict *uri_options =3D NULL; - BlockdevOptionsSsh *ssh_opts =3D NULL; + BlockdevCreateOptionsSsh *opts =3D &options->u.ssh; BDRVSSHState s; - ssize_t r2; char c[1] =3D { '\0' }; + int ret; + + assert(options->driver =3D=3D BLOCKDEV_DRIVER_SSH); =20 ssh_state_init(&s); =20 + ret =3D connect_to_ssh(&s, opts->location, + LIBSSH2_FXF_READ|LIBSSH2_FXF_WRITE| + LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC, + 0644, errp); + if (ret < 0) { + goto fail; + } + + if (opts->size > 0) { + libssh2_sftp_seek64(s.sftp_handle, opts->size - 1); + ret =3D libssh2_sftp_write(s.sftp_handle, c, 1); + if (ret < 0) { + sftp_error_setg(errp, &s, "truncate failed"); + ret =3D -EINVAL; + goto fail; + } + s.attrs.filesize =3D opts->size; + } + + ret =3D 0; +fail: + ssh_state_free(&s); + return ret; +} + +static int ssh_create(const char *filename, QemuOpts *opts, Error **errp) +{ + BlockdevCreateOptions *create_options; + BlockdevCreateOptionsSsh *ssh_opts; + int ret; + QDict *uri_options =3D NULL; + + create_options =3D g_new0(BlockdevCreateOptions, 1); + create_options->driver =3D BLOCKDEV_DRIVER_SSH; + ssh_opts =3D &create_options->u.ssh; + /* Get desired file size. */ - total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), - BDRV_SECTOR_SIZE); - DPRINTF("total_size=3D%" PRIi64, total_size); + ssh_opts->size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE= , 0), + BDRV_SECTOR_SIZE); + DPRINTF("total_size=3D%" PRIi64, ssh_opts->size); =20 uri_options =3D qdict_new(); - r =3D parse_uri(filename, uri_options, errp); - if (r < 0) { - ret =3D r; + ret =3D parse_uri(filename, uri_options, errp); + if (ret < 0) { goto out; } =20 - ssh_opts =3D ssh_parse_options(uri_options, errp); - if (ssh_opts =3D=3D NULL) { + ssh_opts->location =3D ssh_parse_options(uri_options, errp); + if (ssh_opts->location =3D=3D NULL) { ret =3D -EINVAL; goto out; } =20 - r =3D connect_to_ssh(&s, ssh_opts, - LIBSSH2_FXF_READ|LIBSSH2_FXF_WRITE| - LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC, - 0644, errp); - if (r < 0) { - ret =3D r; - goto out; - } - - if (total_size > 0) { - libssh2_sftp_seek64(s.sftp_handle, total_size-1); - r2 =3D libssh2_sftp_write(s.sftp_handle, c, 1); - if (r2 < 0) { - sftp_error_setg(errp, &s, "truncate failed"); - ret =3D -EINVAL; - goto out; - } - s.attrs.filesize =3D total_size; - } - - ret =3D 0; + ret =3D ssh_co_create(create_options, errp); =20 out: - ssh_state_free(&s); - if (uri_options !=3D NULL) { - QDECREF(uri_options); - } - qapi_free_BlockdevOptionsSsh(ssh_opts); + QDECREF(uri_options); + qapi_free_BlockdevCreateOptions(create_options); return ret; } =20 @@ -1223,6 +1234,7 @@ static BlockDriver bdrv_ssh =3D { .bdrv_parse_filename =3D ssh_parse_filename, .bdrv_file_open =3D ssh_file_open, .bdrv_create =3D ssh_create, + .bdrv_co_create =3D ssh_co_create, .bdrv_close =3D ssh_close, .bdrv_has_zero_init =3D ssh_has_zero_init, .bdrv_co_readv =3D ssh_co_readv, --=20 2.13.6