[PATCH 07/10] virsh: add support for VIR_DOMAIN_CONSOLE_FORCE flag

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

 



This patch adds support for the newly introduced VIR_DOMAIN_CONSOLE
flag. The console command now has an optional parameter --force that
specifies that the user wants to forcibly interrupt an ongoing console
session and create a new one. The behaviour to this point was, that the
daemon openend two streams to the console, that competed for data from
the pipe and the result was, that both of the consoles ended up
scrambled.
---
 tools/console.c |    6 ++++--
 tools/console.h |    2 +-
 tools/virsh.c   |   18 +++++++++++++-----
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/tools/console.c b/tools/console.c
index 3913c42..814eacb 100644
--- a/tools/console.c
+++ b/tools/console.c
@@ -282,7 +282,9 @@ virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED,
 }


-int vshRunConsole(virDomainPtr dom, const char *dev_name)
+int vshRunConsole(virDomainPtr dom,
+                  const char *dev_name,
+                  unsigned int flags)
 {
     int ret = -1;
     struct termios ttyattr, rawattr;
@@ -335,7 +337,7 @@ int vshRunConsole(virDomainPtr dom, const char *dev_name)
     if (!con->st)
         goto cleanup;

-    if (virDomainOpenConsole(dom, dev_name, con->st, 0) < 0)
+    if (virDomainOpenConsole(dom, dev_name, con->st, flags) < 0)
         goto cleanup;

     con->stdinWatch = virEventAddHandle(STDIN_FILENO,
diff --git a/tools/console.h b/tools/console.h
index 9b05ff1..1b4b158 100644
--- a/tools/console.h
+++ b/tools/console.h
@@ -25,7 +25,7 @@

 # ifndef WIN32

-int vshRunConsole(virDomainPtr dom, const char *dev_name);
+int vshRunConsole(virDomainPtr dom, const char *dev_name, unsigned int flags);

 # endif /* !WIN32 */

diff --git a/tools/virsh.c b/tools/virsh.c
index bcf0603..3933b8f 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -774,11 +774,14 @@ static const vshCmdInfo info_console[] = {
 static const vshCmdOptDef opts_console[] = {
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
     {"devname", VSH_OT_STRING, 0, N_("character device name")},
+    {"force", VSH_OT_BOOL, 0, N_("force console connection (disconnect already connected sessions)")},
     {NULL, 0, 0, NULL}
 };

 static bool
-cmdRunConsole(vshControl *ctl, virDomainPtr dom, const char *name)
+cmdRunConsole(vshControl *ctl, virDomainPtr dom,
+              const char *name,
+              unsigned int flags)
 {
     bool ret = false;
     int state;
@@ -795,7 +798,7 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom, const char *name)

     vshPrintExtra(ctl, _("Connected to domain %s\n"), virDomainGetName(dom));
     vshPrintExtra(ctl, "%s", _("Escape character is ^]\n"));
-    if (vshRunConsole(dom, name) == 0)
+    if (vshRunConsole(dom, name, flags) == 0)
         ret = true;

  cleanup:
@@ -808,6 +811,8 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom;
     bool ret = false;
+    bool force = vshCommandOptBool(cmd, "force");
+    unsigned int flags = 0;
     const char *name = NULL;

     if (!vshConnectionUsability(ctl, ctl->conn))
@@ -821,7 +826,10 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }

-    ret = cmdRunConsole(ctl, dom, name);
+    if (force)
+        flags = VIR_DOMAIN_CONSOLE_FORCE;
+
+    ret = cmdRunConsole(ctl, dom, name, flags);

 cleanup:
     virDomainFree(dom);
@@ -1838,7 +1846,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
                  virDomainGetName(dom), from);
 #ifndef WIN32
         if (console)
-            cmdRunConsole(ctl, dom, NULL);
+            cmdRunConsole(ctl, dom, NULL, 0);
 #endif
         virDomainFree(dom);
     } else {
@@ -2161,7 +2169,7 @@ started:
     vshPrint(ctl, _("Domain %s started\n"),
              virDomainGetName(dom));
 #ifndef WIN32
-    if (console && !cmdRunConsole(ctl, dom, NULL))
+    if (console && !cmdRunConsole(ctl, dom, NULL, 0))
         goto cleanup;
 #endif

-- 
1.7.3.4

--
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]