Move the function doing the fake setup of chardev backend for FD passing
into the collection of qemu test helpers so that it can be used in
qemumonitorjsontest.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
tests/qemuxml2argvtest.c | 93 +---------------------------------
tests/testutilsqemu.c | 106 +++++++++++++++++++++++++++++++++++++++
tests/testutilsqemu.h | 3 ++
3 files changed, 111 insertions(+), 91 deletions(-)
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index d4e518e3a1..1e1d9ee9a1 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -378,95 +378,6 @@ testCheckExclusiveFlags(int flags)
}
-static int
-testPrepareHostBackendChardevOne(virDomainDeviceDef *dev,
- virDomainChrSourceDef *chardev,
- void *opaque)
-{
- virDomainObj *vm = opaque;
- qemuDomainObjPrivate *priv = vm->privateData;
- qemuDomainChrSourcePrivate *charpriv = QEMU_DOMAIN_CHR_SOURCE_PRIVATE(chardev);
- int fakesourcefd = -1;
- const char *devalias = NULL;
- bool usefdset = true;
-
- if (dev) {
- virDomainDeviceInfo *info = virDomainDeviceGetInfo(dev);
- devalias = info->alias;
-
- /* vhost-user disk doesn't use FD passing */
- if (dev->type == VIR_DOMAIN_DEVICE_DISK)
- return 0;
-
- if (dev->type == VIR_DOMAIN_DEVICE_NET) {
- /* due to a historical bug in qemu we don't use FD passtrhough for
- * vhost-sockets for network devices */
- return 0;
- }
-
- /* TPMs FD passing setup is special and handled separately */
- if (dev->type == VIR_DOMAIN_DEVICE_TPM)
- return 0;
- } else {
- devalias = "monitor";
- }
-
- switch ((virDomainChrType) chardev->type) {
- case VIR_DOMAIN_CHR_TYPE_NULL:
- case VIR_DOMAIN_CHR_TYPE_VC:
- case VIR_DOMAIN_CHR_TYPE_PTY:
- case VIR_DOMAIN_CHR_TYPE_DEV:
- case VIR_DOMAIN_CHR_TYPE_PIPE:
- case VIR_DOMAIN_CHR_TYPE_STDIO:
- case VIR_DOMAIN_CHR_TYPE_UDP:
- case VIR_DOMAIN_CHR_TYPE_TCP:
- case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
- case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
- break;
-
- case VIR_DOMAIN_CHR_TYPE_FILE:
- fakesourcefd = 1750;
- break;
-
- case VIR_DOMAIN_CHR_TYPE_UNIX:
- if (chardev->data.nix.listen &&
- virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_CHARDEV_FD_PASS_COMMANDLINE))
- fakesourcefd = 1729;
-
- usefdset = false;
- break;
-
- case VIR_DOMAIN_CHR_TYPE_NMDM:
- case VIR_DOMAIN_CHR_TYPE_LAST:
- break;
- }
-
- if (fakesourcefd != -1) {
- if (fcntl(fakesourcefd, F_GETFD) != -1)
- abort();
-
- charpriv->sourcefd = qemuFDPassNew(devalias, priv, usefdset);
-
- if (qemuFDPassAddFD(charpriv->sourcefd, &fakesourcefd,
"-source") < 0)
- return -1;
- }
-
- if (chardev->logfile) {
- int fd = 1751;
-
- if (fcntl(fd, F_GETFD) != -1)
- abort();
-
- charpriv->logfd = qemuFDPassNew(devalias, priv, true);
-
- if (qemuFDPassAddFD(charpriv->logfd, &fd, "-log") < 0)
- return -1;
- }
-
- return 0;
-}
-
-
static virCommand *
testCompareXMLToArgvCreateArgs(virQEMUDriver *drv,
virDomainObj *vm,
@@ -483,11 +394,11 @@ testCompareXMLToArgvCreateArgs(virQEMUDriver *drv,
return NULL;
if (qemuDomainDeviceBackendChardevForeach(vm->def,
- testPrepareHostBackendChardevOne,
+ testQemuPrepareHostBackendChardevOne,
vm) < 0)
return NULL;
- if (testPrepareHostBackendChardevOne(NULL, priv->monConfig, vm) < 0)
+ if (testQemuPrepareHostBackendChardevOne(NULL, priv->monConfig, vm) < 0)
return NULL;
for (i = 0; i < vm->def->ndisks; i++) {
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 646ef415d1..c156a89413 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -13,6 +13,9 @@
# include "virstring.h"
# include "virfilecache.h"
+# include <sys/types.h>
+# include <fcntl.h>
+
# define VIR_FROM_THIS VIR_FROM_QEMU
virCPUDef *cpuDefault;
@@ -979,3 +982,106 @@ testQemuInfoClear(struct testQemuInfo *info)
virObjectUnref(info->qemuCaps);
g_clear_pointer(&info->args.fakeCaps, virObjectUnref);
}
+
+
+/**
+ * testQemuPrepareHostBackendChardevOne:
+ * @dev: device definition object
+ * @chardev: chardev source object
+ * @opaque: Caller is expected to pass pointer to virDomainObj or NULL
+ *
+ * This helper sets up a chardev source backend for FD passing with fake
+ * file descriptros. It's expected to be used as callback for
+ * 'qemuDomainDeviceBackendChardevForeach', thus the VM object is passed via
+ * @opaque. Callers may pass NULL if the test scope is limited.
+ */
+int
+testQemuPrepareHostBackendChardevOne(virDomainDeviceDef *dev,
+ virDomainChrSourceDef *chardev,
+ void *opaque)
+{
+ virDomainObj *vm = opaque;
+ qemuDomainObjPrivate *priv = NULL;
+ qemuDomainChrSourcePrivate *charpriv = QEMU_DOMAIN_CHR_SOURCE_PRIVATE(chardev);
+ int fakesourcefd = -1;
+ const char *devalias = NULL;
+ bool usefdset = true;
+
+ if (vm)
+ priv = vm->privateData;
+
+ if (dev) {
+ virDomainDeviceInfo *info = virDomainDeviceGetInfo(dev);
+ devalias = info->alias;
+
+ /* vhost-user disk doesn't use FD passing */
+ if (dev->type == VIR_DOMAIN_DEVICE_DISK)
+ return 0;
+
+ if (dev->type == VIR_DOMAIN_DEVICE_NET) {
+ /* due to a historical bug in qemu we don't use FD passtrhough for
+ * vhost-sockets for network devices */
+ return 0;
+ }
+
+ /* TPMs FD passing setup is special and handled separately */
+ if (dev->type == VIR_DOMAIN_DEVICE_TPM)
+ return 0;
+ } else {
+ devalias = "monitor";
+ }
+
+ switch ((virDomainChrType) chardev->type) {
+ case VIR_DOMAIN_CHR_TYPE_NULL:
+ case VIR_DOMAIN_CHR_TYPE_VC:
+ case VIR_DOMAIN_CHR_TYPE_PTY:
+ case VIR_DOMAIN_CHR_TYPE_DEV:
+ case VIR_DOMAIN_CHR_TYPE_PIPE:
+ case VIR_DOMAIN_CHR_TYPE_STDIO:
+ case VIR_DOMAIN_CHR_TYPE_UDP:
+ case VIR_DOMAIN_CHR_TYPE_TCP:
+ case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+ case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+ break;
+
+ case VIR_DOMAIN_CHR_TYPE_FILE:
+ fakesourcefd = 1750;
+ break;
+
+ case VIR_DOMAIN_CHR_TYPE_UNIX:
+ if (chardev->data.nix.listen &&
+ virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_CHARDEV_FD_PASS_COMMANDLINE))
+ fakesourcefd = 1729;
+
+ usefdset = false;
+ break;
+
+ case VIR_DOMAIN_CHR_TYPE_NMDM:
+ case VIR_DOMAIN_CHR_TYPE_LAST:
+ break;
+ }
+
+ if (fakesourcefd != -1) {
+ if (fcntl(fakesourcefd, F_GETFD) != -1)
+ abort();
+
+ charpriv->sourcefd = qemuFDPassNew(devalias, priv, usefdset);
+
+ if (qemuFDPassAddFD(charpriv->sourcefd, &fakesourcefd,
"-source") < 0)
+ return -1;
+ }
+
+ if (chardev->logfile) {
+ int fd = 1751;
+
+ if (fcntl(fd, F_GETFD) != -1)
+ abort();
+
+ charpriv->logfd = qemuFDPassNew(devalias, priv, true);
+
+ if (qemuFDPassAddFD(charpriv->logfd, &fd, "-log") < 0)
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index 51139e6a97..187f9b7cd3 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -143,4 +143,7 @@ void testQemuInfoSetArgs(struct testQemuInfo *info,
int testQemuInfoInitArgs(struct testQemuInfo *info);
void testQemuInfoClear(struct testQemuInfo *info);
+int testQemuPrepareHostBackendChardevOne(virDomainDeviceDef *dev,
+ virDomainChrSourceDef *chardev,
+ void *opaque);
#endif
--
2.34.1