Re: [libvirt] [PATCH v2 03/12] virsh: Expose virDomainDetachDeviceAlias
On Thu, May 24, 2018 at 01:13:30PM +0200, Michal Privoznik wrote: Signed-off-by: Michal Privoznik--- tools/virsh-domain.c | 72 tools/virsh.pod | 12 + 2 files changed, 84 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index cfbbf5a7bc..26f7983540 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11878,6 +11878,72 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd) return funcRet; } + +/* + * "detach-device-alias" command + */ +static const vshCmdInfo info_detach_device_alias[] = { +{.name = "help", + .data = N_("detach device from an alias") +}, +{.name = "desc", + .data = N_("Detach device from domain using given alias to identify device") "from a domain" feels better. Or even: Detach device identified by the given alias from a domain +}, +{.name = NULL} +}; + [...] +static bool +cmdDetachDeviceAlias(vshControl *ctl, const vshCmd *cmd) +{ +virDomainPtr dom = NULL; +const char *alias = NULL; +bool current = vshCommandOptBool(cmd, "current"); +bool config = vshCommandOptBool(cmd, "config"); +bool live = vshCommandOptBool(cmd, "live"); +unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; +bool ret = false; + +VSH_EXCLUSIVE_OPTIONS_VAR(current, live); +VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + +if (config) +flags |= VIR_DOMAIN_AFFECT_CONFIG; +if (live) +flags |= VIR_DOMAIN_AFFECT_LIVE; + +if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) +return false; + +if (vshCommandOptStringReq(ctl, cmd, "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")); Or, to match the semantics of the API more closely: "Device detach request sent successfully\n" +ret = true; + + cleanup: +virshDomainFree(dom); +return ret; +} + + /* * "update-device" command */ @@ -13999,6 +14065,12 @@ const vshCmdDef domManagementCmds[] = { .info = info_detach_device, .flags = 0 }, +{.name = "detach-device-alias", + .handler = cmdDetachDeviceAlias, + .opts = opts_detach_device_alias, + .info = info_detach_device_alias, + .flags = 0 +}, {.name = "detach-disk", .handler = cmdDetachDisk, .opts = opts_detach_disk, diff --git a/tools/virsh.pod b/tools/virsh.pod index 929958a953..45c1a3f271 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3112,6 +3112,18 @@ an offline domain, and like I<--live> I<--config> for a running domain. Note that older versions of virsh used I<--config> as an alias for I<--persistent>. +=item 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 domain. +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 depends +on the hypervisor driver. + Drop this sentence, it is not relevant for the new API. Reviewed-by: Ján Tomko Jano signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 03/12] virsh: Expose virDomainDetachDeviceAlias
Signed-off-by: Michal Privoznik--- tools/virsh-domain.c | 72 tools/virsh.pod | 12 + 2 files changed, 84 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index cfbbf5a7bc..26f7983540 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11878,6 +11878,72 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd) return funcRet; } + +/* + * "detach-device-alias" command + */ +static const vshCmdInfo info_detach_device_alias[] = { +{.name = "help", + .data = N_("detach device from an alias") +}, +{.name = "desc", + .data = N_("Detach device from domain using given alias to identify device") +}, +{.name = NULL} +}; + +static const vshCmdOptDef opts_detach_device_alias[] = { +VIRSH_COMMON_OPT_DOMAIN_FULL(0), +{.name = "alias", + .type = VSH_OT_DATA, + .flags = VSH_OFLAG_REQ, + .help = N_("device alias") +}, +VIRSH_COMMON_OPT_DOMAIN_CONFIG, +VIRSH_COMMON_OPT_DOMAIN_LIVE, +VIRSH_COMMON_OPT_DOMAIN_CURRENT, +{.name = NULL} +}; + +static bool +cmdDetachDeviceAlias(vshControl *ctl, const vshCmd *cmd) +{ +virDomainPtr dom = NULL; +const char *alias = NULL; +bool current = vshCommandOptBool(cmd, "current"); +bool config = vshCommandOptBool(cmd, "config"); +bool live = vshCommandOptBool(cmd, "live"); +unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; +bool ret = false; + +VSH_EXCLUSIVE_OPTIONS_VAR(current, live); +VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + +if (config) +flags |= VIR_DOMAIN_AFFECT_CONFIG; +if (live) +flags |= VIR_DOMAIN_AFFECT_LIVE; + +if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) +return false; + +if (vshCommandOptStringReq(ctl, cmd, "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 = true; + + cleanup: +virshDomainFree(dom); +return ret; +} + + /* * "update-device" command */ @@ -13999,6 +14065,12 @@ const vshCmdDef domManagementCmds[] = { .info = info_detach_device, .flags = 0 }, +{.name = "detach-device-alias", + .handler = cmdDetachDeviceAlias, + .opts = opts_detach_device_alias, + .info = info_detach_device_alias, + .flags = 0 +}, {.name = "detach-disk", .handler = cmdDetachDisk, .opts = opts_detach_disk, diff --git a/tools/virsh.pod b/tools/virsh.pod index 929958a953..45c1a3f271 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3112,6 +3112,18 @@ an offline domain, and like I<--live> I<--config> for a running domain. Note that older versions of virsh used I<--config> as an alias for I<--persistent>. +=item 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 domain. +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 depends +on the hypervisor driver. + =item B I I [[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]] [I<--print-xml>] -- 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list