This also changes the function signature to take a
virDomainChrSourceDefPtr instead of just a path, since it needs to
differentiate behavior based on source->type.
---
src/conf/virchrdev.c | 38 +++++++++++++++++++++++++++++++++-----
src/conf/virchrdev.h | 5 +++--
src/qemu/qemu_driver.c | 2 +-
3 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c
index dcb064f..1802324 100644
--- a/src/conf/virchrdev.c
+++ b/src/conf/virchrdev.c
@@ -324,7 +324,7 @@ void virChrdevFree(virChrdevsPtr devs)
* same FD by two processes.
*
* @devs Pointer to private structure holding data about device streams.
- * @path Path to the character device to be opened.
+ * @source Pointer to private structure holding data about device source.
* @st Stream the client wishes to use for the device connection.
* @force On true, close active device streams for the selected character
* device before opening this connection.
@@ -334,14 +334,29 @@ void virChrdevFree(virChrdevsPtr devs)
* error and 1 if the device stream is open and busy.
*/
int virChrdevOpen(virChrdevsPtr devs,
- const char *path,
- virStreamPtr st,
- bool force)
+ virDomainChrSourceDefPtr source,
+ virStreamPtr st,
+ bool force)
{
virChrdevStreamInfoPtr cbdata = NULL;
virStreamPtr savedStream;
+ const char *path;
int ret;
+ switch (source->type) {
+ case VIR_DOMAIN_CHR_TYPE_PTY:
+ path = source->data.file.path;
+ break;
+ case VIR_DOMAIN_CHR_TYPE_UNIX:
+ path = source->data.nix.path;
+ break;
+ default:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Unsupported device type '%s'"),
+ virDomainChrTypeToString(source->type));
+ return -1;
+ }
+
virMutexLock(&devs->lock);
if ((savedStream = virHashLookup(devs->hash, path))) {
@@ -391,8 +406,21 @@ int virChrdevOpen(virChrdevsPtr devs,
}
/* open the character device */
- if (virFDStreamOpenFile(st, path, 0, 0, O_RDWR) < 0)
+ switch (source->type) {
+ case VIR_DOMAIN_CHR_TYPE_PTY:
+ if (virFDStreamOpenFile(st, path, 0, 0, O_RDWR) < 0)
+ goto error;
+ break;
+ case VIR_DOMAIN_CHR_TYPE_UNIX:
+ if (virFDStreamConnectUNIX(st, path, false) < 0)
+ goto error;
+ break;
+ default:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Unsupported device type '%s'"),
+ virDomainChrTypeToString(source->type));
goto error;
+ }
/* add cleanup callback */
virFDStreamSetInternalCloseCb(st,
diff --git a/src/conf/virchrdev.h b/src/conf/virchrdev.h
index 57d7576..e1990e8 100644
--- a/src/conf/virchrdev.h
+++ b/src/conf/virchrdev.h
@@ -24,6 +24,7 @@
# define __VIR_CHRDEV_H__
# include "internal.h"
+# include "domain_conf.h"
typedef struct _virChrdevs virChrdevs;
typedef virChrdevs *virChrdevsPtr;
@@ -31,6 +32,6 @@ typedef virChrdevs *virChrdevsPtr;
virChrdevsPtr virChrdevAlloc(void);
void virChrdevFree(virChrdevsPtr devs);
-int virChrdevOpen(virChrdevsPtr devs, const char *path,
- virStreamPtr st, bool force);
+int virChrdevOpen(virChrdevsPtr devs, virDomainChrSourceDefPtr source,
+ virStreamPtr st, bool force);
#endif /*__VIR_CHRDEV_H__*/
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 992af02..20e2001 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12577,7 +12577,7 @@ qemuDomainOpenConsole(virDomainPtr dom,
/* handle mutually exclusive access to console devices */
ret = virChrdevOpen(priv->devs,
- chr->source.data.file.path,
+ &chr->source,
st,
(flags & VIR_DOMAIN_CONSOLE_FORCE) != 0);
--
1.7.11.7