All domainSendSysrq related API should be manageable from
the virsh command line. So, expose 'virsh sysrq' command.
Signed-off-by: Chunyan Liu <cyliu(a)suse.com>
---
Changes:
* adjust code to follow general format and fix a memory leak
tools/virsh-domain.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 750411b..43fa1d8 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -12289,6 +12289,57 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
return ret >= 0;
}
+/*
+ * "sysrq" command
+ */
+static const vshCmdInfo info_sysrq[] = {
+ {.name = "help",
+ .data = N_("Send SysRq key to the guest")
+ },
+ {.name = "desc",
+ .data = N_("Send SysRq key to the guest")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_sysrq[] = {
+ {.name = "domain",
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("domain name, id or uuid")
+ },
+ {.name = "key",
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("the SysRq key")
+ },
+ {.name = NULL}
+};
+
+static bool
+cmdSysrq(vshControl *ctl, const vshCmd *cmd)
+{
+ virDomainPtr dom;
+ bool ret = false;
+ const char *key = NULL;
+
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+ return false;
+
+ if (vshCommandOptStringReq(ctl, cmd, "key", &key) < 0)
+ goto cleanup;
+
+ if (virDomainSendSysrq(dom, key[0], 0) < 0)
+ goto cleanup;
+
+ ret = true;
+
+ cleanup:
+ virDomainFree(dom);
+ return ret;
+}
+
+
const vshCmdDef domManagementCmds[] = {
{.name = "attach-device",
.handler = cmdAttachDevice,
@@ -12808,5 +12859,11 @@ const vshCmdDef domManagementCmds[] = {
.info = info_vncdisplay,
.flags = 0
},
+ {.name = "sysrq",
+ .handler = cmdSysrq,
+ .opts = opts_sysrq,
+ .info = info_sysrq,
+ .flags = 0
+ },
{.name = NULL}
};
--
1.8.4.5