Move it closer to its new user. Left exported because it needs to be mocked and it might be used for hotplug in the future. Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx> --- src/qemu/qemu_command.c | 57 ---------------------------------------------- src/qemu/qemu_command.h | 4 ---- src/qemu/qemu_process.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++- src/qemu/qemu_process.h | 3 +++ tests/qemuxml2argvmock.c | 3 ++- 5 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 94bb5d184d..0b2d8d29fa 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4991,63 +4991,6 @@ qemuBuildChrChardevReconnectStr(virBufferPtr buf, } -int -qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev) -{ - struct sockaddr_un addr; - socklen_t addrlen = sizeof(addr); - int fd; - - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - virReportSystemError(errno, "%s", - _("Unable to create UNIX socket")); - goto error; - } - - memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_UNIX; - if (virStrcpyStatic(addr.sun_path, dev->data.nix.path) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("UNIX socket path '%s' too long"), - dev->data.nix.path); - goto error; - } - - if (unlink(dev->data.nix.path) < 0 && errno != ENOENT) { - virReportSystemError(errno, - _("Unable to unlink %s"), - dev->data.nix.path); - goto error; - } - - if (bind(fd, (struct sockaddr *)&addr, addrlen) < 0) { - virReportSystemError(errno, - _("Unable to bind to UNIX socket path '%s'"), - dev->data.nix.path); - goto error; - } - - if (listen(fd, 1) < 0) { - virReportSystemError(errno, - _("Unable to listen to UNIX socket path '%s'"), - dev->data.nix.path); - goto error; - } - - /* We run QEMU with umask 0002. Compensate for the umask - * libvirtd might be running under to get the same permission - * QEMU would have. */ - if (virFileUpdatePerm(dev->data.nix.path, 0002, 0664) < 0) - goto error; - - return fd; - - error: - VIR_FORCE_CLOSE(fd); - return -1; -} - - enum { QEMU_BUILD_CHARDEV_TCP_NOWAIT = (1 << 0), QEMU_BUILD_CHARDEV_FILE_LOGD = (1 << 1), diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 3f4a660e87..96cfa563bb 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -72,10 +72,6 @@ int qemuBuildTLSx509BackendProps(const char *tlspath, virQEMUCapsPtr qemuCaps, virJSONValuePtr *propsret); -/* Open a UNIX socket for chardev FD passing */ -int -qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev); - /* Generate '-device' string for chardev device */ int qemuBuildChrDeviceStr(char **deviceStr, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 9519178603..ae1bac8ecb 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6136,6 +6136,63 @@ qemuProcessOpenVhostVsock(virDomainVsockDefPtr vsock) } +int +qemuProcessOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev) +{ + struct sockaddr_un addr; + socklen_t addrlen = sizeof(addr); + int fd; + + if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + virReportSystemError(errno, "%s", + _("Unable to create UNIX socket")); + goto error; + } + + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + if (virStrcpyStatic(addr.sun_path, dev->data.nix.path) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("UNIX socket path '%s' too long"), + dev->data.nix.path); + goto error; + } + + if (unlink(dev->data.nix.path) < 0 && errno != ENOENT) { + virReportSystemError(errno, + _("Unable to unlink %s"), + dev->data.nix.path); + goto error; + } + + if (bind(fd, (struct sockaddr *)&addr, addrlen) < 0) { + virReportSystemError(errno, + _("Unable to bind to UNIX socket path '%s'"), + dev->data.nix.path); + goto error; + } + + if (listen(fd, 1) < 0) { + virReportSystemError(errno, + _("Unable to listen to UNIX socket path '%s'"), + dev->data.nix.path); + goto error; + } + + /* We run QEMU with umask 0002. Compensate for the umask + * libvirtd might be running under to get the same permission + * QEMU would have. */ + if (virFileUpdatePerm(dev->data.nix.path, 0002, 0664) < 0) + goto error; + + return fd; + + error: + VIR_FORCE_CLOSE(fd); + return -1; +} + + static int qemuProcessMaybeOpenChrSource(virDomainObjPtr vm, const virDomainChrSourceDef *src) @@ -6158,7 +6215,7 @@ qemuProcessMaybeOpenChrSource(virDomainObjPtr vm, if (qemuSecuritySetSocketLabel(driver->securityManager, vm->def) < 0) goto cleanup; - fd = qemuOpenChrChardevUNIXSocket(src); + fd = qemuProcessOpenChrChardevUNIXSocket(src); if (qemuSecurityClearSocketLabel(driver->securityManager, vm->def) < 0) goto cleanup; diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index c2f7c2b5d2..1135556a5a 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -116,6 +116,9 @@ int qemuProcessPrepareDomain(virQEMUDriverPtr driver, unsigned int flags); int qemuProcessOpenVhostVsock(virDomainVsockDefPtr vsock); +/* Open a UNIX socket for chardev FD passing */ +int qemuProcessOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev); + int qemuProcessPrepareHost(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index 79152d928e..dadf0f0a62 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -38,6 +38,7 @@ #include "virutil.h" #include "qemu/qemu_interface.h" #include "qemu/qemu_command.h" +#include "qemu/qemu_process.h" #include <time.h> #include <unistd.h> #include <fcntl.h> @@ -233,7 +234,7 @@ qemuInterfaceOpenVhostNet(virDomainDefPtr def ATTRIBUTE_UNUSED, int -qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev ATTRIBUTE_UNUSED) +qemuProcessOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev ATTRIBUTE_UNUSED) { /* We need to return an FD number for a UNIX listener socket, -- 2.16.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list