提交 66a06649 编写于 作者: J John Eckersberg 提交者: Eric Blake

conf: Add unix socket support to virChrdevOpen

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.
上级 3c971c67
......@@ -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,
......
......@@ -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__*/
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册