On Mon, Nov 30, 2009 at 10:11:10AM +0100, Paolo Bonzini wrote:
> This patch adds the --crash option (already present in "xm dump-core")
> to "virsh dump". virDomainCoreDump already has a flags argument, so
> the API/ABI is untouched.
>
> * include/libvirt/libvirt.h.in (virDomainCoreDumpFlags): New.
> * src/test/test_driver.c (testDomainCoreDump): Do not crash
> after dump unless VIR_DUMP_CRASH is given.
> * src/qemu/qemu_driver.c (qemudDomainCoreDump): Shutdown the domain
> instead of restarting it if --crash is passed.
> * src/xen/xend_internal.c (xenDaemonDomainCoreDump): Support --crash.
> * tools/virsh.c (opts_dump): Add --crash.
> (cmdDump): Map it to flags for virDomainCoreDump and pass them.
> ---
> include/libvirt/libvirt.h.in | 5 +++++
> src/qemu/qemu_driver.c | 17 ++++++++++++++++-
> src/test/test_driver.c | 19 ++++++++++---------
> src/xen/xend_internal.c | 6 ++++--
> tools/virsh.c | 7 ++++++-
> 5 files changed, 41 insertions(+), 13 deletions(-)
>
> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index 5bc7694..c04b552 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -334,6 +334,11 @@ struct _virDomainInterfaceStats {
> typedef virDomainInterfaceStatsStruct *virDomainInterfaceStatsPtr;
>
>
> +/* Domain core dump flags. */
> +typedef enum {
> + VIR_DUMP_CRASH = (1 << 0), /* crash after dump */
> +} virDomainCoreDumpFlags;
> +
> /* Domain migration flags. */
> typedef enum {
> VIR_MIGRATE_LIVE = (1 << 0), /* live migration */
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 92d4629..8e80144 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -3543,6 +3543,7 @@ static int qemudDomainCoreDump(virDomainPtr dom,
> virDomainObjPtr vm;
> int resume = 0, paused = 0;
> int ret = -1, fd = -1;
> + virDomainEventPtr event = NULL;
> const char *args[] = {
> "cat",
> NULL,
> @@ -3633,10 +3634,17 @@ static int qemudDomainCoreDump(virDomainPtr dom,
> goto endjob;
>
> endjob:
> + if ((ret == 0) && (flags & VIR_DUMP_CRASH)) {
> + qemudShutdownVMDaemon(dom->conn, driver, vm);
> + event = virDomainEventNewFromObj(vm,
> + VIR_DOMAIN_EVENT_STOPPED,
> + VIR_DOMAIN_EVENT_STOPPED_CRASHED);
> + }
> +
> /* Since the monitor is always attached to a pty for libvirt, it
> will support synchronous operations so we always get here after
> the migration is complete. */
> - if (resume && paused) {
> + else if (resume && paused) {
> qemuDomainObjEnterMonitor(vm);
> if (qemuMonitorStartCPUs(priv->mon, dom->conn) < 0) {
> if (virGetLastError() == NULL)
> @@ -3647,12 +3655,19 @@ endjob:
> }
>
> qemuDomainObjEndJob(vm);
> + if ((ret == 0) && (flags & VIR_DUMP_CRASH) && !vm->persistent) {
> + virDomainRemoveInactive(&driver->domains,
> + vm);
> + vm = NULL;
> + }
>
> cleanup:
> if (ret != 0)
> unlink(path);
> if (vm)
> virDomainObjUnlock(vm);
> + if (event)
> + qemuDomainEventQueue(driver, event);
> return ret;
> }
>
> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> index 35f7571..7db9a4c 100644
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c
> @@ -1911,15 +1911,16 @@ static int testDomainCoreDump(virDomainPtr domain,
> goto cleanup;
> }
>
> - testDomainShutdownState(domain, privdom);
> - event = virDomainEventNewFromObj(privdom,
> - VIR_DOMAIN_EVENT_STOPPED,
> - VIR_DOMAIN_EVENT_STOPPED_CRASHED);
> -
> - if (!privdom->persistent) {
> - virDomainRemoveInactive(&privconn->domains,
> - privdom);
> - privdom = NULL;
> + if (flags & VIR_DUMP_CRASH) {
> + testDomainShutdownState(domain, privdom);
> + event = virDomainEventNewFromObj(privdom,
> + VIR_DOMAIN_EVENT_STOPPED,
> + VIR_DOMAIN_EVENT_STOPPED_CRASHED);
> + if (!privdom->persistent) {
> + virDomainRemoveInactive(&privconn->domains,
> + privdom);
> + privdom = NULL;
> + }
> }
>
> ret = 0;
> diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
> index 66d2e7f..360390d 100644
> --- a/src/xen/xend_internal.c
> +++ b/src/xen/xend_internal.c
> @@ -3243,8 +3243,10 @@ xenDaemonDomainCoreDump(virDomainPtr domain, const
> char *filename,
> return(-1);
> }
>
> - return xend_op(domain->conn, domain->name, "op", "dump", "file",
> filename,
> - "live", "0", "crash", "0", NULL);
> + return xend_op(domain->conn, domain->name,
> + "op", "dump", "file", filename, "live", "0",
> + "crash", (flags & VIR_DUMP_CRASH ? "1" : "0"),
> + NULL);
> }
>
> /**
> diff --git a/tools/virsh.c b/tools/virsh.c
> index 9faac35..65eaa3b 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -1431,6 +1431,7 @@ static const vshCmdInfo info_dump[] = {
> };
>
> static const vshCmdOptDef opts_dump[] = {
> + {"crash", VSH_OT_BOOL, 0, gettext_noop("crash the domain after core
> dump")},
> {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or
> uuid")},
> {"file", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("where to dump the
> core")},
> {NULL, 0, 0, NULL}
> @@ -1443,6 +1444,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd)
> char *name;
> char *to;
> int ret = TRUE;
> + int flags = 0;
>
> if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
> return FALSE;
> @@ -1453,7 +1455,10 @@ cmdDump(vshControl *ctl, const vshCmd *cmd)
> if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
> return FALSE;
>
> - if (virDomainCoreDump(dom, to, 0) == 0) {
> + if (vshCommandOptBool (cmd, "crash"))
> + flags |= VIR_DUMP_CRASH;
> +
> + if (virDomainCoreDump(dom, to, flags) == 0) {
> vshPrint(ctl, _("Domain %s dumped to %s\n"), name, to);
> } else {
> vshError(ctl, _("Failed to core dump domain %s to %s"), name, to);
Looks fine to me, ACK, nice addition !
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
[email protected] | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
--
Libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list