Support sending sysrq key to guest.
Signed-off-by: Chunyan Liu <cyliu(a)suse.com>
---
src/xen/xen_driver.c | 21 +++++++++++++++++++++
src/xen/xend_internal.c | 26 ++++++++++++++++++++++++++
src/xen/xend_internal.h | 1 +
3 files changed, 48 insertions(+)
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index c9f4159..4a56b69 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2738,6 +2738,26 @@ xenUnifiedNodeSuspendForDuration(virConnectPtr conn,
return nodeSuspendForDuration(target, duration, flags);
}
+static int
+xenUnifiedDomainSendSysrq(virDomainPtr dom, char key, unsigned int flags)
+{
+ int ret = -1;
+ virDomainDefPtr def = NULL;
+
+ virCheckFlags(0, -1);
+
+ if (!(def = xenGetDomainDefForDom(dom)))
+ goto cleanup;
+
+ if (virDomainSendSysrqEnsureACL(dom->conn, def) < 0)
+ goto cleanup;
+
+ ret = xenDaemonDomainSysrq(dom->conn, def, key);
+
+ cleanup:
+ virDomainDefFree(def);
+ return ret;
+}
/*----- Register with libvirt.c, and initialize Xen drivers. -----*/
@@ -2836,6 +2856,7 @@ static virHypervisorDriver xenUnifiedDriver = {
.nodeSuspendForDuration = xenUnifiedNodeSuspendForDuration, /* 0.9.8 */
.nodeGetMemoryParameters = xenUnifiedNodeGetMemoryParameters, /* 0.10.2 */
.nodeSetMemoryParameters = xenUnifiedNodeSetMemoryParameters, /* 0.10.2 */
+ .domainSendSysrq = xenUnifiedDomainSendSysrq, /* 1.2.12 */
};
/**
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index b233b6b..16532ad 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -3300,6 +3300,32 @@ xenDaemonDomainBlockPeek(virConnectPtr conn,
return ret;
}
+/*
+ * xenDaemonDomainSysrq:
+ * <at> conn: the connection object
+ * <at> def: the domain to destroy
+ * <at> key: SysRq key
+ *
+ * Send a sysrq to a domain.
+ *
+ * Returns 0 in case of success, -1 (with errno) in case of error.
+ */
+int
+xenDaemonDomainSysrq(virConnectPtr conn, virDomainDefPtr def, char key)
+{
+ char *buf;
+
+ if (def->id < 0) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("Domain %s isn't running."), def->name);
+ return -1;
+ }
+
+ if (virAsprintf(&buf, "%c", key) < 0)
+ return -1;
+
+ return xend_op(conn, def->name, "op", "sysrq",
"key", buf, NULL);
+}
/**
* virDomainXMLDevID:
diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h
index 814330d..02f9d9b 100644
--- a/src/xen/xend_internal.h
+++ b/src/xen/xend_internal.h
@@ -213,5 +213,6 @@ int xenDaemonSetSchedulerParameters(virConnectPtr conn,
virDomainDefPtr def,
virTypedParameterPtr params,
int nparams);
+int xenDaemonDomainSysrq(virConnectPtr conn, virDomainDefPtr def, char key);
#endif /* __XEND_INTERNAL_H_ */
--
1.8.4.5