From nobody Sat May 4 04:43:36 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=1605135677; cv=none; d=zohomail.com; s=zohoarc; b=bpXbb2oEbS7lQlGkIjwLT81MsRS99QdpEVWHSHO3fSWvddZa699J2sdzJyX0zjS8NL4elpvO6LkS37EZAbF6o2Xvesx0io3QXzWx7AQQ0eNZXg68FJHMWOQWrx8M/aKNow4MB3UmYP6cccSM9n7tvjzv9phz39uZag7vsJ+yLiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605135677; 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=7B+Y/NHsdDLZW9tqQ0vhe2E/EWyOqm68Sb//JKIQa1E=; b=Tb4Ot75wUN0ZwSjIeyMAFUbtbY6wiRGtYSQ/u4Q4mSmIEGmszooMuy2qfwSkmtbe7WCE8jildlLVnK9DTxw+MFJeJzuFRXfUPTMO2BCSKgafODfMRBhhjebBICUo+e09qcGjNmBKoh+mQQKun6zv1HzQdh75+UPhh0Ct8erNfrc= 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 1605135677773602.7511286849191; Wed, 11 Nov 2020 15:01:17 -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-143-pUBoKn3MNI2zRsMhfnTpaA-1; Wed, 11 Nov 2020 18:01:14 -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 158821882FB6; Wed, 11 Nov 2020 23:01:07 +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 C38B86198C; Wed, 11 Nov 2020 23:01:06 +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 196AB180610F; Wed, 11 Nov 2020 23:01:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0ABN107W011892 for ; Wed, 11 Nov 2020 18:01:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3E6922157F45; Wed, 11 Nov 2020 23:01:00 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 387542166BDD for ; Wed, 11 Nov 2020 23:00:58 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (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 0498A1021F8C for ; Wed, 11 Nov 2020 23:00:58 +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-354-SwztEQrrMzOtzU31l-HkKA-1; Wed, 11 Nov 2020 18:00:54 -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 0ABN0rq4046978 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Nov 2020 17:00:53 -0600 Received: (from rgahagan@localhost) by ginger.cs.utexas.edu (8.15.2/8.15.2/Submit) id 0ABN0qZB012280; Wed, 11 Nov 2020 17:00:52 -0600 X-MC-Unique: pUBoKn3MNI2zRsMhfnTpaA-1 X-MC-Unique: SwztEQrrMzOtzU31l-HkKA-1 From: Ryan Gahagan To: libvir-list@redhat.com Subject: [PATCH] Added attach-disk parameters for network disk support Date: Wed, 11 Nov 2020 17:00:51 -0600 Message-Id: <20201111230051.12221-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, 11 Nov 2020 17:00:53 -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.6 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-name --source-protocol --source-host-name --source-host-socket --source-host-transport Allowed for multiple hosts to be added to a single source. Multiple hosts can be defined by providing multiple instances of --source-host-name, followed by optional transport and socket parameters. Using a single host does not require a host name. Added documentation to virsh.rst specifying usage. Signed-off-by: Ryan Gahagan --- docs/manpages/virsh.rst | 24 +++++++- tools/virsh-domain.c | 125 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 138 insertions(+), 11 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index bfd26e3120..60e5f5ebe4 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -4500,9 +4500,11 @@ 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-name name] + [--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 @@ -4541,6 +4543,22 @@ 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 +If *--source-protocol* or *--source-name* is specified, then the parameters +will be inserted into the XML that is generated for the source. +If any of *--source-host-name*, *--source-host-transport*, or +*--source-host-socket* are specified, then a ```` tag +will be generated under the ```` tag containing whichever +parameters were provided. If needed, the user can provide multiple hosts +by providing each host with a *--source-host-name*. Each host will +receive the host parameters which come between it and the next instance +of *--source-host-name* or between it and the end of the command. +If a user tries to provide multiple of the same host parameter +for any single host, only the first one will be generated as +part of the XML output. + +--source-host-name me --source-host-transport t1 --source-host-transport t= 2 --source-host-transport t3 --soure-host-name you + + 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 12b35c037d..609189e398 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -224,6 +224,26 @@ static const vshCmdOptDef opts_attach_disk[] =3D { .flags =3D VSH_OFLAG_REQ | VSH_OFLAG_EMPTY_OK, .help =3D N_("source of disk device") }, + {.name =3D "source-protocol", + .type =3D VSH_OT_STRING, + .help =3D N_("protocol used by disk device source") + }, + {.name =3D "source-name", + .type =3D VSH_OT_STRING, + .help =3D N_("name of 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") + }, {.name =3D "target", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -558,15 +578,68 @@ static int str2DiskAddress(const char *str, struct Di= skAddress *diskAddr) return -1; } =20 +static void attachDiskHostGen(virBufferPtr buf, const vshCmd *cmd) +{ + // Can be multiple hosts so we have to scan + // the cmd options to find all the host params + // opts; + char *host_name =3D NULL, *host_port =3D NULL; + int close_tag =3D 0, seen_socket =3D 0, seen_transport =3D 0; + + while (candidate) { + // Iterate candidates to find each host-name + if (STREQ(candidate->def->name, "source-host-name")) { + // After the first host-name, we need to terminate + // the \n"); + else + close_tag =3D 1; + + host_name =3D candidate->data; + host_port =3D strchr(host_name, ':'); + + if (!host_port) { + // If port isn't provided, only print name + virBufferAsprintf(buf, "def->name, "source-hos= t-socket")) { + seen_socket =3D 1; + virBufferAsprintf(buf, " socket=3D'%s'", candidate->data); + } else if (!seen_transport && STREQ(candidate->def->name, "source-= host-transport")) { + seen_transport =3D 1; + virBufferAsprintf(buf, " transport=3D'%s'", candidate->data); + } + + candidate =3D candidate->next; + } + // Close final \n"); +} + static bool cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom =3D NULL; - const char *source =3D NULL, *target =3D NULL, *driver =3D NULL, - *subdriver =3D NULL, *type =3D NULL, *mode =3D NULL, - *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 =3D NULL, *source_name =3D NULL, *source_protocol = =3D NULL, + *target =3D NULL, *driver =3D NULL, *subdriver =3D NULL, *= type =3D NULL, + *mode =3D NULL, *iothread =3D NULL, *cache =3D NULL, + *io =3D NULL, *serial =3D NULL, *straddr =3D NULL, + *wwn =3D NULL, *targetbus =3D NULL, *alias =3D NULL, + *host_transport =3D NULL, *host_name =3D NULL, *host_socke= t =3D NULL; struct DiskAddress diskAddr; bool isFile =3D false, functionReturn =3D false; int ret; @@ -591,6 +664,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_DOMAIN_AFFECT_LIVE; =20 if (vshCommandOptStringReq(ctl, cmd, "source", &source) < 0 || + vshCommandOptStringReq(ctl, cmd, "source-name", &source_name) < 0 = || + vshCommandOptStringReq(ctl, cmd, "source-protocol", &source_protoc= ol) < 0 || vshCommandOptStringReq(ctl, cmd, "target", &target) < 0 || vshCommandOptStringReq(ctl, cmd, "driver", &driver) < 0 || vshCommandOptStringReq(ctl, cmd, "subdriver", &subdriver) < 0 || @@ -604,7 +679,10 @@ 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-host-name", (const char *= *) &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) { @@ -659,9 +737,40 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) virBufferAddLit(&buf, "/>\n"); } =20 - if (source) - virBufferAsprintf(&buf, "\n", + if (source || source_protocol || source_name || + host_name || host_transport || host_socket) { + virBufferAddLit(&buf, "\n"); + } else if (!host_name) { + // If no host name is provided but there is a host, + // we have a single host with params + virBufferAddLit(&buf, ">\n\n\n"); + } else { + // May have multiple hosts, use helper method + virBufferAddLit(&buf, ">\n"); + attachDiskHostGen(&buf, cmd); + virBufferAddLit(&buf, "\n"); + } + } + virBufferAsprintf(&buf, "