[PATCH 5/5] virsh: Implement virConnectCrash

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tools/virsh-host.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod    |  9 +++++++
 2 files changed, 84 insertions(+)

diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 80ac4bd..8635386 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -1137,6 +1137,75 @@ cmdCPUModelNames(vshControl *ctl, const vshCmd *cmd)
 }
 
 /*
+ * "crash" command
+ */
+static const vshCmdInfo info_crash[] = {
+    {.name = "help",
+     .data = N_("Crash either daemon or client")
+    },
+    {.name = "desc",
+     .data = N_("Crash either daemon or client")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_crash[] = {
+    {.name = "mode",
+     .type = VSH_OT_STRING,
+     .help = N_("mode of crash (write, null, stack)")
+    },
+    {.name = "side",
+     .type = VSH_OT_STRING,
+     .help = N_("side of crash (client, server)")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdCrash(vshControl *ctl, const vshCmd *cmd)
+{
+    const char *modeStr = NULL, *sideStr = NULL;
+    int mode = VIR_CONNECT_CRASH_NULL_DEREF;
+    int side = VIR_CONNECT_CRASH_SERVER;
+    virshControlPtr priv = ctl->privData;
+    const unsigned int flags = 0;
+
+    if (vshCommandOptStringReq(ctl, cmd, "mode", &modeStr) < 0 ||
+        vshCommandOptStringReq(ctl, cmd, "side", &sideStr) < 0)
+        return false;
+
+    if (modeStr) {
+        if (STREQ(modeStr, "write")) {
+            mode = VIR_CONNECT_CRASH_WRITE_RO;
+        } else if (STREQ(modeStr, "null")) {
+            mode = VIR_CONNECT_CRASH_NULL_DEREF;
+        } else if (STREQ(modeStr, "stack")) {
+            mode = VIR_CONNECT_CRASH_STACK_OVERFLOW;
+        } else {
+            vshError(ctl, _("Unknown crash mode: %s"), modeStr);
+            return false;
+        }
+    }
+
+    if (sideStr) {
+        if (STREQ(sideStr, "server")) {
+            side = VIR_CONNECT_CRASH_SERVER;
+        } else if (STREQ(sideStr, "client")) {
+            side = VIR_CONNECT_CRASH_CLIENT;
+        } else {
+            vshError(ctl, _("Unknown crash side: %s"), sideStr);
+            return false;
+        }
+    }
+
+    if (virConnectCrash(priv->conn, side, mode, flags) < 0)
+        return false;
+
+    return true;
+}
+
+
+/*
  * "version" command
  */
 static const vshCmdInfo info_version[] = {
@@ -1372,6 +1441,12 @@ const vshCmdDef hostAndHypervisorCmds[] = {
      .info = info_cpu_models,
      .flags = 0
     },
+    {.name = "crash",
+     .handler = cmdCrash,
+     .opts = opts_crash,
+     .info = info_crash,
+     .flags = 0
+    },
     {.name = "domcapabilities",
      .handler = cmdDomCapabilities,
      .opts = opts_domcapabilities,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index d2cc5b2..bc28d3a 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -243,6 +243,15 @@ This command is only available in interactive mode.
 
 Will print the current directory.
 
+=item B<crash> [I<mode>] [I<side>]
+
+Crash either daemon or client. Depending on I<mode> selected
+preferred way of crashing can be performed: "write" for
+attempting to write to read-only memory, "null" for dereferencing
+a NULL pointer, or "stack" for stack overflow. Moreover, I<side>
+on which the crash occurs can be chosen from "server" and
+"client". B<Use this command with extreme caution!>
+
 =item B<connect> [I<URI>] [I<--readonly>]
 
 (Re)-Connect to the hypervisor. When the shell is first started, this
-- 
2.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]