virsh: add --graceful switch to destroy command

This allows virsh to use the new VIR_DOMAIN_DESTROY_GRACEUL flag for
virDomainDestroyFlags.
This commit is contained in:
Laine Stump 2012-02-03 14:14:36 -05:00
parent 72f8a7f197
commit 3e952ecc52
2 changed files with 17 additions and 2 deletions

View File

@ -4265,6 +4265,7 @@ static const vshCmdInfo info_destroy[] = {
static const vshCmdOptDef opts_destroy[] = { static const vshCmdOptDef opts_destroy[] = {
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
{"graceful", VSH_OT_BOOL, VSH_OFLAG_NONE, N_("terminate gracefully")},
{NULL, 0, 0, NULL} {NULL, 0, 0, NULL}
}; };
@ -4274,6 +4275,8 @@ cmdDestroy(vshControl *ctl, const vshCmd *cmd)
virDomainPtr dom; virDomainPtr dom;
bool ret = true; bool ret = true;
const char *name; const char *name;
unsigned int flags = 0;
int result;
if (!vshConnectionUsability(ctl, ctl->conn)) if (!vshConnectionUsability(ctl, ctl->conn))
return false; return false;
@ -4281,7 +4284,15 @@ cmdDestroy(vshControl *ctl, const vshCmd *cmd)
if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return false; return false;
if (virDomainDestroy(dom) == 0) { if (vshCommandOptBool(cmd, "graceful"))
flags |= VIR_DOMAIN_DESTROY_GRACEFUL;
if (flags)
result = virDomainDestroyFlags(dom, VIR_DOMAIN_DESTROY_GRACEFUL);
else
result = virDomainDestroy(dom);
if (result == 0) {
vshPrint(ctl, _("Domain %s destroyed\n"), name); vshPrint(ctl, _("Domain %s destroyed\n"), name);
} else { } else {
vshError(ctl, _("Failed to destroy domain %s"), name); vshError(ctl, _("Failed to destroy domain %s"), name);

View File

@ -458,7 +458,7 @@ Flag I<--title> selects operation on the title field instead of description.
If neither of I<--edit> and I<--new_desc> are specified the note or description If neither of I<--edit> and I<--new_desc> are specified the note or description
is displayed instead of being modified. is displayed instead of being modified.
=item B<destroy> I<domain-id> =item B<destroy> I<domain-id> [I<--graceful>]
Immediately terminate the domain domain-id. This doesn't give the domain Immediately terminate the domain domain-id. This doesn't give the domain
OS any chance to react, and it's the equivalent of ripping the power OS any chance to react, and it's the equivalent of ripping the power
@ -472,6 +472,10 @@ be lost once the guest stops running, but the snapshot contents still
exist, and a new domain with the same name and UUID can restore the exist, and a new domain with the same name and UUID can restore the
snapshot metadata with B<snapshot-create>. snapshot metadata with B<snapshot-create>.
If I<--graceful> is specified, don't resort to extreme measures
(e.g. SIGKILL) when the guest doesn't stop after a reasonable timeout;
return an error instead.
=item B<domblkstat> I<domain> I<block-device> [I<--human>] =item B<domblkstat> I<domain> I<block-device> [I<--human>]
Get device block stats for a running domain. A I<block-device> corresponds Get device block stats for a running domain. A I<block-device> corresponds