From nobody Wed May 14 06:58:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1526918927119735.3376826296446; Mon, 21 May 2018 09:08:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5278634ADEF; Mon, 21 May 2018 16:08:45 +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 29794977B2; Mon, 21 May 2018 16:08:45 +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 DA9C61801255; Mon, 21 May 2018 16:08:44 +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 w4LG8LYX030459 for ; Mon, 21 May 2018 12:08:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id C641885778; Mon, 21 May 2018 16:08:21 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B8FAC1FB4 for ; Mon, 21 May 2018 16:08:21 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 21 May 2018 18:08:02 +0200 Message-Id: <4cdbf233a93cf3ad46d3aa4c2909e98dba5732cd.1526918751.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/5] virsh: Expose virDomainDetachDeviceAlias 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 21 May 2018 16:08:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- tools/virsh-domain.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ tools/virsh.pod | 15 ++++++++++ 2 files changed, 94 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index cfbbf5a7bc..b41e76b3d8 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11878,6 +11878,79 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd) return funcRet; } =20 + +/* + * "detach-device-alias" command + */ +static const vshCmdInfo info_detach_device_alias[] =3D { + {.name =3D "help", + .data =3D N_("detach device from an alias") + }, + {.name =3D "desc", + .data =3D N_("Detach device from domain using given alias to identify= device") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_detach_device_alias[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "alias", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("device alias") + }, + VIRSH_COMMON_OPT_DOMAIN_PERSISTENT, + VIRSH_COMMON_OPT_DOMAIN_CONFIG, + VIRSH_COMMON_OPT_DOMAIN_LIVE, + VIRSH_COMMON_OPT_DOMAIN_CURRENT, + {.name =3D NULL} +}; + +static bool +cmdDetachDeviceAlias(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + const char *alias =3D NULL; + bool current =3D vshCommandOptBool(cmd, "current"); + bool config =3D vshCommandOptBool(cmd, "config"); + bool live =3D vshCommandOptBool(cmd, "live"); + bool persistent =3D vshCommandOptBool(cmd, "persistent"); + unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; + bool ret =3D false; + + VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (config || persistent) + flags |=3D VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |=3D VIR_DOMAIN_AFFECT_LIVE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (persistent && + virDomainIsActive(dom) =3D=3D 1) + flags |=3D VIR_DOMAIN_AFFECT_LIVE; + + if (vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0) + goto cleanup; + + if (virDomainDetachDeviceAlias(dom, alias, flags) < 0) { + vshError(ctl, _("Failed to detach device with alias %s"), alias); + goto cleanup; + } + + vshPrintExtra(ctl, "%s", _("Device detached successfully\n")); + ret =3D true; + + cleanup: + virshDomainFree(dom); + return ret; +} + + /* * "update-device" command */ @@ -13999,6 +14072,12 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_detach_device, .flags =3D 0 }, + {.name =3D "detach-device-alias", + .handler =3D cmdDetachDeviceAlias, + .opts =3D opts_detach_device_alias, + .info =3D info_detach_device_alias, + .flags =3D 0 + }, {.name =3D "detach-disk", .handler =3D cmdDetachDisk, .opts =3D opts_detach_disk, diff --git a/tools/virsh.pod b/tools/virsh.pod index 929958a953..b6e60ce2f7 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3112,6 +3112,21 @@ an offline domain, and like I<--live> I<--config> fo= r a running domain. Note that older versions of virsh used I<--config> as an alias for I<--persistent>. =20 +=3Ditem B I I +[[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]] + +Detach a device with given I from the I. + +If I<--live> is specified, affect a running domain. +If I<--config> is specified, affect the next startup of a persistent domai= n. +If I<--current> is specified, affect the current domain state. +Both I<--live> and I<--config> flags may be given, but I<--current> is +exclusive. When no flag is specified legacy API is used whose behavior dep= ends +on the hypervisor driver. + +For compatibility purposes, I<--persistent> behaves like I<--config> for +an offline domain, and like I<--live> I<--config> for a running domain. + =3Ditem B I I [[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]] [I<--print-xml>] --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list