From nobody Thu Apr 25 05:52:04 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=1605293580; cv=none; d=zohomail.com; s=zohoarc; b=P4ynrd4SllNMsb7opWtR4DCS+LretrTvqHtKZlxCRPPNFkUj3NEuvdQoAodSJ9d7IP6vJjW+MsP6iPG6XKg8z9uNRteapnYPhuoKBUxmnIulAmbXgxIor7C6EC5z4LI2fLoPlvuNyzqVX0CCrYgvF7OTOtiA7VHvl8rC0u/ekzM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605293580; 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=FocOIJ3x6LVRHXF7MUy/rtns4Vaz7YsH4ZLEcbVXvRM=; b=EWbqJCDLjhEobEv9yMMPJ1AnEn+c0xRzEz1CyTHqknFSGptsAFXHlQTXyryKZMzdnCn6icx/ugJfbVlYb0C6IZ74MUDw20cUP60XiHrgsm5olbjZTrZ9Un76OnHVmtbqIwz+w6pRAYDz1BPOqCNe80MqE3LuXPw9nBOfefWM+g4= 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 1605293580758643.1371713112791; Fri, 13 Nov 2020 10:53:00 -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-229-FUsIlZS3OV2w7SVYUA_ypQ-1; Fri, 13 Nov 2020 13:52:57 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC0E06D240; Fri, 13 Nov 2020 18:52:49 +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 DC86C1002D70; Fri, 13 Nov 2020 18:52:47 +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 02F41181A870; Fri, 13 Nov 2020 18:52:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0ADIqfWN011859 for ; Fri, 13 Nov 2020 13:52:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 31342110EAC; Fri, 13 Nov 2020 18:52:41 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C2C2110EB2 for ; Fri, 13 Nov 2020 18:52:38 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.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 D9238858290 for ; Fri, 13 Nov 2020 18:52:38 +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-586-GRKhQwPGNHSO454AGlnheQ-1; Fri, 13 Nov 2020 13:52:36 -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 0ADIqYbl038867 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Nov 2020 12:52:34 -0600 Received: (from rgahagan@localhost) by ginger.cs.utexas.edu (8.15.2/8.15.2/Submit) id 0ADIqYQg019802; Fri, 13 Nov 2020 12:52:34 -0600 X-MC-Unique: FUsIlZS3OV2w7SVYUA_ypQ-1 X-MC-Unique: GRKhQwPGNHSO454AGlnheQ-1 From: Ryan Gahagan To: libvir-list@redhat.com Subject: [PATCH] virsh: Added attach-disk support for network disk Date: Fri, 13 Nov 2020 12:52:32 -0600 Message-Id: <20201113185232.19744-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]); Fri, 13 Nov 2020 12:52:34 -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.79 on 10.11.54.5 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.84 on 10.5.11.22 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 | 26 ++++++++++--- tools/virsh-domain.c | 85 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 100 insertions(+), 11 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index bfd26e3120..a4d70e9211 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -4500,14 +4500,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 @@ -4541,6 +4545,16 @@ 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 also wishes to provide host information. +Host information can be provided using any of 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. 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 12b35c037d..4c43da7a2c 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, @@ -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, @@ -567,6 +583,12 @@ 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_name_copy =3D NULL; + char *host_port =3D NULL; struct DiskAddress diskAddr; bool isFile =3D false, functionReturn =3D false; int ret; @@ -604,7 +626,11 @@ 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) { @@ -632,6 +658,13 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) if (wwn && !virValidateWWN(wwn)) goto cleanup; =20 + if (!source_protocol && (host_name || host_socket || host_transport)) { + /* Error: cannot use network host without a source protocol */ + vshError(ctl, "%s", + _("Cannot use --source-host-* parameters without a --sour= ce-protocol")); + goto cleanup; + } + /* 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 */ + virBufferAsprintf(&buf, " %s=3D'%s'", + isFile ? "file" : "dev", source); + virBufferAddLit(&buf, "/>\n"); + } + } + virBufferAsprintf(&buf, "