From nobody Thu Mar 28 12:54:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=cs.utexas.edu ARC-Seal: i=1; a=rsa-sha256; t=1605743315; cv=none; d=zohomail.com; s=zohoarc; b=VgPLU3UGSV0FJwjEJEonG/6alj1hCxRN9Ljh54sDxbMyoNjKDTwUTf+dLwLxaC72mzppIeMrN886KLSqBbOXdlG3QgR8bg2GIRRq+xT8K0badSRksZQT/uDQtXXdrYwJdXK+F5csK4Mm+snk0utIz19B78NHUdq6MKDXtI55yIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605743315; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Y3lexG5rtbJwtgJ+ePgMr383wpbD/u4Kbr4C4DDzUGo=; b=oEfHE+PnoF66CXUKVc9QzqjKl7389UI0QW+cbZTJF8iadW186bIG1zgEw6W8xBIRwRI5Dh4U/b0/3oDDhRdgwZB+DymHM5Yby6oO7KquIpg1+RhZJyacZC5yT3TwoCEG9+ebzZeitkB0q/4t+DRqfK4MasvZ4bEZs0gsl2uOR0c= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 16057433154915.720828493362774; Wed, 18 Nov 2020 15:48:35 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-577-dhfVxh0GN0aquUdJI_nYAA-1; Wed, 18 Nov 2020 18:48:32 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F1378049CA; Wed, 18 Nov 2020 23:48:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B1BCB60C05; Wed, 18 Nov 2020 23:48:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EB23618095C7; Wed, 18 Nov 2020 23:48:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AINmLDE026523 for ; Wed, 18 Nov 2020 18:48:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 522A8201E75E; Wed, 18 Nov 2020 23:48:21 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D4912022796 for ; Wed, 18 Nov 2020 23:48:19 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ED3D6811E86 for ; Wed, 18 Nov 2020 23:48:18 +0000 (UTC) Received: from newman.cs.utexas.edu (newman.cs.utexas.edu [128.83.139.110]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-480-zUx_zwoJM_mNYfepZO9U3g-1; Wed, 18 Nov 2020 18:48:16 -0500 Received: from ginger.cs.utexas.edu (ginger.cs.utexas.edu [128.83.144.229]) by newman.cs.utexas.edu (8.14.4/8.14.4/Debian-4.1ubuntu1.1) with ESMTP id 0AINmEiV039985 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Nov 2020 17:48:14 -0600 Received: (from rgahagan@localhost) by ginger.cs.utexas.edu (8.15.2/8.15.2/Submit) id 0AINmEGb028439; Wed, 18 Nov 2020 17:48:14 -0600 X-MC-Unique: dhfVxh0GN0aquUdJI_nYAA-1 X-MC-Unique: zUx_zwoJM_mNYfepZO9U3g-1 From: Ryan Gahagan To: libvir-list@redhat.com Subject: [PATCH] virsh: Added attach-disk support for network disk Date: Wed, 18 Nov 2020 17:48:13 -0600 Message-Id: <20201118234813.28384-1-rgahagan@cs.utexas.edu> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (newman.cs.utexas.edu [128.83.139.110]); Wed, 18 Nov 2020 17:48:15 -0600 (CST) X-Virus-Scanned: clamav-milter 0.100.3 at newman X-Virus-Status: Clean X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Related issue: https://gitlab.com/libvirt/libvirt/-/issues/16 Added in support for the following parameters in attach-disk: --source-protocol --source-host-name --source-host-socket --source-host-transport Added documentation to virsh.rst specifying usage. Signed-off-by: Ryan Gahagan --- docs/manpages/virsh.rst | 31 ++++++--- tools/virsh-domain.c | 135 +++++++++++++++++++++++++++++++++++----- 2 files changed, 145 insertions(+), 21 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 1ae6d1a0d4..36c868a3e6 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -4538,14 +4538,18 @@ attach-disk [--current]] | [--persistent]] [--targetbus bus] [--driver driver] [--subdriver subdriver] [--iothread iothread] [--cache cache] [--io io] [--type type] [--alias alias] - [--mode mode] [--sourcetype sourcetype] [--serial serial] - [--wwn wwn] [--rawio] [--address address] [--multifunction] - [--print-xml] + [--mode mode] [--sourcetype sourcetype] + [--source-protocol protocol] [--source-host-name hostname:port] + [--source-host-transport transport] [--source-host-socket socket] + [--serial serial] [--wwn wwn] [--rawio] [--address address] + [--multifunction] [--print-xml] =20 Attach a new disk device to the domain. -*source* is path for the files and devices. *target* controls the bus or -device under which the disk is exposed to the guest OS. It indicates the -"logical" device name; the optional *targetbus* attribute specifies the ty= pe +*source* is path for the files and devices unless *--source-protocol* +is specified, in which case *source* is the name of a network disk. +*target* controls the bus or device under which the disk is exposed +to the guest OS. It indicates the "logical" device name; +the optional *targetbus* attribute specifies the type of disk device to emulate; possible values are driver specific, with typic= al values being *ide*, *scsi*, *virtio*, *xen*, *usb*, *sata*, or *sd*, if omitted, the bus type is inferred from the style of the device name (e.g. = a @@ -4563,7 +4567,7 @@ within the existing virtual cdrom or floppy device; c= onsider using ``update-device`` for this usage instead. *alias* can set user supplied alias. *mode* can specify the two specific mode *readonly* or *shareable*. -*sourcetype* can indicate the type of source (block|file) +*sourcetype* can indicate the type of source (block|file|network) *cache* can be one of "default", "none", "writethrough", "writeback", "directsync" or "unsafe". *io* controls specific policies on I/O; QEMU guests support "threads", @@ -4579,6 +4583,19 @@ ccw:cssid.ssid.devno. Virtio-ccw devices must have t= heir cssid set to 0xfe. *multifunction* indicates specified pci address is a multifunction pci dev= ice address. =20 +There is also support for using a network disk. As specified, the user can +provide a *--source-protocol* in which case the *source* parameter will +be interpreted as the source name. *--source-protocol* must be provided +if the user intends to provide a network disk or host information. +Host information can be provided using the tags +*--source-host-name*, *--source-host-transport*, and *--source-host-socket= *, +which respectively denote the name of the host, the host's transport metho= d, +and the socket that the host uses. *--source-host-socket* and +*--source-host-name* cannot both be provided, and the user must provide a +*--source-host-transport* if they want to provide a *--source-host-socket*. +The *--source-host-name* parameter supports host:port syntax +if the user wants to provide a port as well. + If *--print-xml* is specified, then the XML of the disk that would be atta= ched is printed instead. =20 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index c999458d72..1303676c33 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -222,7 +222,7 @@ static const vshCmdOptDef opts_attach_disk[] =3D { {.name =3D "source", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ | VSH_OFLAG_EMPTY_OK, - .help =3D N_("source of disk device") + .help =3D N_("source of disk device or name of network disk") }, {.name =3D "target", .type =3D VSH_OT_DATA, @@ -268,7 +268,7 @@ static const vshCmdOptDef opts_attach_disk[] =3D { }, {.name =3D "sourcetype", .type =3D VSH_OT_STRING, - .help =3D N_("type of source (block|file)") + .help =3D N_("type of source (block|file|network)") }, {.name =3D "serial", .type =3D VSH_OT_STRING, @@ -298,6 +298,22 @@ static const vshCmdOptDef opts_attach_disk[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("print XML document rather than attach the disk") }, + {.name =3D "source-protocol", + .type =3D VSH_OT_STRING, + .help =3D N_("protocol used by disk device source") + }, + {.name =3D "source-host-name", + .type =3D VSH_OT_STRING, + .help =3D N_("host name for source of disk device") + }, + {.name =3D "source-host-transport", + .type =3D VSH_OT_STRING, + .help =3D N_("host transport for source of disk device") + }, + {.name =3D "source-host-socket", + .type =3D VSH_OT_STRING, + .help =3D N_("host socket for source of disk device") + }, VIRSH_COMMON_OPT_DOMAIN_PERSISTENT, VIRSH_COMMON_OPT_DOMAIN_CONFIG, VIRSH_COMMON_OPT_DOMAIN_LIVE, @@ -558,6 +574,13 @@ static int str2DiskAddress(const char *str, struct Dis= kAddress *diskAddr) return -1; } =20 +typedef enum { + VIRSH_SOURCE_TYPE_FILE, + VIRSH_SOURCE_TYPE_BLOCK, + VIRSH_SOURCE_TYPE_NETWORK, + VIRSH_SOURCE_TYPE_UNKNOWN, +} virshAttachDiskSourceType; + static bool cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) { @@ -567,8 +590,14 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) *iothread =3D NULL, *cache =3D NULL, *io =3D NULL, *serial =3D NULL, *straddr =3D NULL, *wwn =3D NULL, *targetbus =3D NULL, *alias =3D NULL; + const char *source_protocol =3D NULL; + const char *host_name =3D NULL; + const char *host_transport =3D NULL; + const char *host_socket =3D NULL; + char *host_port =3D NULL; struct DiskAddress diskAddr; - bool isFile =3D false, functionReturn =3D false; + virshAttachDiskSourceType disk_type =3D VIRSH_SOURCE_TYPE_UNKNOWN; + bool functionReturn =3D false; int ret; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; const char *stype =3D NULL; @@ -585,6 +614,13 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); =20 + VSH_REQUIRE_OPTION("source-host-name", "source-protocol"); + VSH_REQUIRE_OPTION("source-host-transport", "source-protocol"); + VSH_REQUIRE_OPTION("source-host-socket", "source-protocol"); + VSH_REQUIRE_OPTION("source-host-socket", "source-host-transport"); + + VSH_EXCLUSIVE_OPTIONS("source-host-name", "source-host-socket"); + if (config || persistent) flags |=3D VIR_DOMAIN_AFFECT_CONFIG; if (live) @@ -604,23 +640,45 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "address", &straddr) < 0 || vshCommandOptStringReq(ctl, cmd, "targetbus", &targetbus) < 0 || vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 || - vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0) + vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0 || + vshCommandOptStringReq(ctl, cmd, "source-protocol", &source_protoc= ol) < 0 || + vshCommandOptStringReq(ctl, cmd, "source-host-name", &host_name) <= 0 || + vshCommandOptStringReq(ctl, cmd, "source-host-transport", &host_tr= ansport) < 0 || + vshCommandOptStringReq(ctl, cmd, "source-host-socket", &host_socke= t) < 0) goto cleanup; =20 if (!stype) { if (driver && (STREQ(driver, "file") || STREQ(driver, "tap"))) { - isFile =3D true; + disk_type =3D VIRSH_SOURCE_TYPE_FILE; } else { - if (source && !stat(source, &st)) - isFile =3D S_ISREG(st.st_mode) ? true : false; + if (source && !stat(source, &st)) { + if (S_ISREG(st.st_mode)) + disk_type =3D VIRSH_SOURCE_TYPE_FILE; + else + disk_type =3D VIRSH_SOURCE_TYPE_BLOCK; + } } } else if (STREQ(stype, "file")) { - isFile =3D true; - } else if (STRNEQ(stype, "block")) { + disk_type =3D VIRSH_SOURCE_TYPE_FILE; + } else if (STREQ(stype, "block")) { + disk_type =3D VIRSH_SOURCE_TYPE_BLOCK; + } else if (STREQ(stype, "network")) { + /* The user must provide a protocol for a network disk */ + if (!source_protocol) { + vshError(ctl, _("A source-protocol must be provided for a netw= ork disk")); + goto cleanup; + } + } else { vshError(ctl, _("Unknown source type: '%s'"), stype); goto cleanup; } =20 + /* If a protocol is provided, the disk is assumed to be a network disk. + * This overwrites other disk types, such as an explicit + * 'sourcetype=3Dfile' or comparable parameter. */ + if (source_protocol) + disk_type =3D VIRSH_SOURCE_TYPE_NETWORK; + if (mode) { if (STRNEQ(mode, "readonly") && STRNEQ(mode, "shareable")) { vshError(ctl, _("No support for %s in command 'attach-disk'"), @@ -633,8 +691,13 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) goto cleanup; =20 /* Make XML of disk */ - virBufferAsprintf(&buf, "\n"); } =20 - if (source) - virBufferAsprintf(&buf, "\n", - isFile ? "file" : "dev", source); + if (source || source_protocol) { + virBufferAddLit(&buf, " tag */ + virBufferAddLit(&buf, ">\n"); + virBufferAdjustIndent(&buf, 2); + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); + } + } else { + /* Using a local disk; source is file or dev */ + if (disk_type =3D=3D VIRSH_SOURCE_TYPE_FILE) + virBufferAsprintf(&buf, " file=3D'%s'", source); + else + virBufferAsprintf(&buf, " dev=3D'%s'", source); + virBufferAddLit(&buf, "/>\n"); + } + } + virBufferAsprintf(&buf, "