[PATCH 02/11] Introduce a virDomainOpenConsole API

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

 



To enable virsh console (or equivalent) to be used remotely
it is necessary to provide remote access to the /dev/pts/XXX
pseudo-TTY associated with the console/serial/parallel device
in the guest. The virStream API provide a bi-directional I/O
stream capability that can be used for this purpose. This
patch thus introduces a virDomainOpenConsole API that uses
the stream APIs.

* src/libvirt.c, src/libvirt_public.syms,
  include/libvirt/libvirt.h.in, src/driver.h: Define the
  new virDomainOpenConsole API
* src/esx/esx_driver.c, src/lxc/lxc_driver.c,
  src/opennebula/one_driver.c, src/openvz/openvz_driver.c,
  src/phyp/phyp_driver.c, src/qemu/qemu_driver.c,
  src/remote/remote_driver.c, src/test/test_driver.c,
  src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
  src/xen/xen_driver.c, src/xenapi/xenapi_driver.c: Stub
  API entry point
---
 include/libvirt/libvirt.h.in |    6 ++++
 src/driver.h                 |    6 ++++
 src/esx/esx_driver.c         |    1 +
 src/libvirt.c                |   53 ++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |    5 ++++
 src/lxc/lxc_driver.c         |    1 +
 src/opennebula/one_driver.c  |    1 +
 src/openvz/openvz_driver.c   |    1 +
 src/phyp/phyp_driver.c       |    1 +
 src/qemu/qemu_driver.c       |    1 +
 src/remote/remote_driver.c   |    1 +
 src/test/test_driver.c       |    1 +
 src/uml/uml_driver.c         |    1 +
 src/vbox/vbox_tmpl.c         |    1 +
 src/xen/xen_driver.c         |    1 +
 src/xenapi/xenapi_driver.c   |    1 +
 16 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 81db3a2..cc82e5c 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2400,6 +2400,12 @@ int                     virNWFilterGetUUIDString (virNWFilterPtr nwfilter,
 char *                  virNWFilterGetXMLDesc    (virNWFilterPtr nwfilter,
                                                   int flags);
 
+
+int virDomainOpenConsole(virDomainPtr dom,
+                         const char *devname,
+                         virStreamPtr st,
+                         unsigned int flags);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/driver.h b/src/driver.h
index 79a96c1..6417ee9 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -480,6 +480,11 @@ typedef int
     (*virDrvQemuDomainMonitorCommand)(virDomainPtr domain, const char *cmd,
                                       char **result, unsigned int flags);
 
+typedef int
+    (*virDrvDomainOpenConsole)(virDomainPtr dom,
+                               const char *devname,
+                               virStreamPtr st,
+                               unsigned int flags);
 
 
 /**
@@ -598,6 +603,7 @@ struct _virDriver {
     virDrvQemuDomainMonitorCommand qemuDomainMonitorCommand;
     virDrvDomainSetMemoryParameters domainSetMemoryParameters;
     virDrvDomainGetMemoryParameters domainGetMemoryParameters;
+    virDrvDomainOpenConsole domainOpenConsole;
 };
 
 typedef int
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index b3e1284..861247f 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -4253,6 +4253,7 @@ static virDriver esxDriver = {
     NULL,                            /* qemuDomainMonitorCommand */
     NULL,                            /* domainSetMemoryParameters */
     NULL,                            /* domainGetMemoryParameters */
+    NULL,                            /* domainOpenConsole */
 };
 
 
diff --git a/src/libvirt.c b/src/libvirt.c
index aebd3bc..4c2175e 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -13118,3 +13118,56 @@ virDomainSnapshotFree(virDomainSnapshotPtr snapshot)
     }
     return 0;
 }
+
+/**
+ * virDomainOpenConsole:
+ * @dom: a domain object
+ * @devname: the console, serial or parallel port device alias, or NULL
+ * @st: a stream to associate with the console
+ * @flags: unused, pass 0
+ *
+ * This opens the backend associated with a console, serial or
+ * parallel port device on a guest, if the backend is supported.
+ * If the @devname is omitted, then the first console or serial
+ * device is opened. The console is associated with the passed
+ * in @st stream, which should have been opened in non-blocking
+ * mode for bi-directional I/O.
+ *
+ * returns 0 if the console was opened, -1 on error
+ */
+int virDomainOpenConsole(virDomainPtr dom,
+                         const char *devname,
+                         virStreamPtr st,
+                         unsigned int flags)
+{
+    virConnectPtr conn;
+    DEBUG("dom=%p devname=%s, st=%p flags=%u", dom, NULLSTR(devname), st, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_DOMAIN(dom)) {
+        virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    conn = dom->conn;
+    if (conn->flags & VIR_CONNECT_RO) {
+        virLibDomainError(dom, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        goto error;
+    }
+
+    if (conn->driver->domainOpenConsole) {
+        int ret;
+        ret = conn->driver->domainOpenConsole(dom, devname, st, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index a8091b1..4ef4c5a 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -413,4 +413,9 @@ LIBVIRT_0.8.5 {
         virDomainSetVcpusFlags;
 } LIBVIRT_0.8.2;
 
+LIBVIRT_0.8.6 {
+    global:
+        virDomainOpenConsole;
+} LIBVIRT_0.8.5;
+
 # .... define new API here using predicted next version number ....
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index d39b60e..48a38d1 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2844,6 +2844,7 @@ static virDriver lxcDriver = {
     NULL, /* qemuDomainMonitorCommand */
     lxcDomainSetMemoryParameters, /* domainSetMemoryParameters */
     lxcDomainGetMemoryParameters, /* domainGetMemoryParameters */
+    NULL, /* domainOpenConsole */
 };
 
 static virStateDriver lxcStateDriver = {
diff --git a/src/opennebula/one_driver.c b/src/opennebula/one_driver.c
index 199fca3..43a2847 100644
--- a/src/opennebula/one_driver.c
+++ b/src/opennebula/one_driver.c
@@ -822,6 +822,7 @@ static virDriver oneDriver = {
     NULL, /* qemuDomainMonitorCommand */
     NULL, /* domainSetMemoryParameters */
     NULL, /* domainGetMemoryParameters */
+    NULL, /* domainOpenConsole */
 };
 
 static virStateDriver oneStateDriver = {
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index b7c2754..e2fb281 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1690,6 +1690,7 @@ static virDriver openvzDriver = {
     NULL, /* qemuDomainMonitorCommand */
     NULL, /* domainSetMemoryParameters */
     NULL, /* domainGetMemoryParameters */
+    NULL, /* domainOpenConsole */
 };
 
 int openvzRegister(void) {
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 3d0ed11..bf55581 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -4036,6 +4036,7 @@ static virDriver phypDriver = {
     NULL,                       /* qemuMonitorCommand */
     NULL,                       /* domainSetMemoryParameters */
     NULL,                       /* domainGetMemoryParameters */
+    NULL, /* domainOpenConsole */
 };
 
 static virStorageDriver phypStorageDriver = {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4e590e3..d70ae8b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13409,6 +13409,7 @@ static virDriver qemuDriver = {
     qemuDomainMonitorCommand, /* qemuDomainMonitorCommand */
     qemuDomainSetMemoryParameters, /* domainSetMemoryParameters */
     qemuDomainGetMemoryParameters, /* domainGetMemoryParameters */
+    NULL, /* domainOpenConsole */
 };
 
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 61da8ff..2ad5ef7 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -10697,6 +10697,7 @@ static virDriver remote_driver = {
     remoteQemuDomainMonitorCommand, /* qemuDomainMonitorCommand */
     remoteDomainSetMemoryParameters, /* domainSetMemoryParameters */
     remoteDomainGetMemoryParameters, /* domainGetMemoryParameters */
+    NULL, /* domainOpenConsole */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index a9d3d89..23f79a5 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5447,6 +5447,7 @@ static virDriver testDriver = {
     NULL, /* qemuDomainMonitorCommand */
     NULL, /* domainSetMemoryParameters */
     NULL, /* domainGetMemoryParameters */
+    NULL, /* domainOpenConsole */
 };
 
 static virNetworkDriver testNetworkDriver = {
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 5161012..e0bb4e5 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -2200,6 +2200,7 @@ static virDriver umlDriver = {
     NULL, /* qemuDomainMonitorCommand */
     NULL, /* domainSetMemoryParamters */
     NULL, /* domainGetMemoryParamters */
+    NULL, /* domainOpenConsole */
 };
 
 static int
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index ddbca97..78f945c 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -8464,6 +8464,7 @@ virDriver NAME(Driver) = {
     NULL, /* qemuDomainMonitorCommand */
     NULL, /* domainSetMemoryParameters */
     NULL, /* domainGetMemoryParameters */
+    NULL, /* domainOpenConsole */
 };
 
 virNetworkDriver NAME(NetworkDriver) = {
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 66e8518..9cc46ae 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2087,6 +2087,7 @@ static virDriver xenUnifiedDriver = {
     NULL, /* qemuDomainMonitorCommand */
     NULL, /* domainSetMemoryParameters */
     NULL, /* domainGetMemoryParameters */
+    NULL, /* domainOpenConsole */
 };
 
 /**
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 5ccdede..03b0a6a 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -1869,6 +1869,7 @@ static virDriver xenapiDriver = {
     NULL, /* qemuDomainMonitorCommand */
     NULL, /* domainSetMemoryParameters */
     NULL, /* domainGetMemoryParameters */
+    NULL, /* domainOpenConsole */
 };
 
 /**
-- 
1.7.2.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]