If we use our own fdset ID when hot-adding a fdset we can vastly
simplify our internals.
As a stop-gap when a fdset would be added behind libvirt's back we'll
validated that the fdset to be added is not yet used.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_fd.c | 61 +++++++++++++++----------------------
src/qemu/qemu_fd.h | 3 --
tests/qemuhotplugtest.c | 1 +
tests/qemumonitorjsontest.c | 7 -----
4 files changed, 25 insertions(+), 47 deletions(-)
diff --git a/src/qemu/qemu_fd.c b/src/qemu/qemu_fd.c
index 84e9d2bfdf..fe81cc650f 100644
--- a/src/qemu/qemu_fd.c
+++ b/src/qemu/qemu_fd.c
@@ -111,8 +111,12 @@ qemuFDPassNew(const char *prefix,
fdpass->prefix = g_strdup(prefix);
fdpass->useFDSet = true;
- if (priv)
+ if (priv) {
fdpass->fdSetID = qemuDomainFDSetIDNew(priv);
+ fdpass->path = g_strdup_printf("/dev/fdset/%u",
fdpass->fdSetID);
+ } else {
+ fdpass->path = g_strdup_printf("/dev/fdset/monitor-fake");
+ }
return fdpass;
}
@@ -171,6 +175,9 @@ qemuFDPassAddFD(qemuFDPass *fdpass,
newfd.opaque = g_strdup_printf("%s%s", fdpass->prefix,
NULLSTR_EMPTY(suffix));
+ if (!fdpass->useFDSet)
+ fdpass->path = g_strdup(newfd.opaque);
+
VIR_APPEND_ELEMENT(fdpass->fds, fdpass->nfds, newfd);
}
@@ -232,7 +239,6 @@ int
qemuFDPassTransferMonitor(qemuFDPass *fdpass,
qemuMonitor *mon)
{
- int fdsetid = -1;
size_t i;
if (!fdpass)
@@ -240,6 +246,21 @@ qemuFDPassTransferMonitor(qemuFDPass *fdpass,
if (qemuFDPassValidate(fdpass) < 0)
return -1;
+ if (fdpass->useFDSet) {
+ g_autoptr(qemuMonitorFdsets) fdsets = NULL;
+
+ if (qemuMonitorQueryFdsets(mon, &fdsets) < 0)
+ return -1;
+
+ for (i = 0; i < fdsets->nfdsets; i++) {
+ if (fdsets->fdsets[i].id == fdpass->fdSetID) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("fdset '%u' is already in use by
qemu"),
+ fdpass->fdSetID);
+ return -1;
+ }
+ }
+ }
for (i = 0; i < fdpass->nfds; i++) {
if (fdpass->useFDSet) {
@@ -247,22 +268,15 @@ qemuFDPassTransferMonitor(qemuFDPass *fdpass,
if (qemuMonitorAddFileHandleToSet(mon,
fdpass->fds[i].fd,
- fdsetid,
+ fdpass->fdSetID,
fdpass->fds[i].opaque,
&fdsetinfo) < 0)
return -1;
-
- if (fdsetid == -1) {
- fdpass->fdSetID = fdsetid = fdsetinfo.fdset;
- fdpass->path = g_strdup_printf("/dev/fdset/%u", fdsetid);
- }
} else {
if (qemuMonitorSendFileHandle(mon,
fdpass->fds[i].opaque,
fdpass->fds[i].fd) < 0)
return -1;
-
- fdpass->path = g_strdup(fdpass->fds[i].opaque);
}
fdpass->passed = true;
@@ -272,33 +286,6 @@ qemuFDPassTransferMonitor(qemuFDPass *fdpass,
}
-/**
- * qemuFDPassTransferMonitorFake:
- * @fdpass: The fd passing helper struct
- *
- * Simulate as if @fdpass was passed via monitor for callers which don't
- * actually wish to test that code path.
- */
-int
-qemuFDPassTransferMonitorFake(qemuFDPass *fdpass)
-{
-
- if (!fdpass)
- return 0;
-
- if (qemuFDPassValidate(fdpass) < 0)
- return -1;
-
- if (fdpass->useFDSet) {
- fdpass->path = g_strdup_printf("/dev/fdset/monitor-fake");
- } else {
- fdpass->path = g_strdup(fdpass->fds[0].opaque);
- }
-
- return 0;
-}
-
-
/**
* qemuFDPassTransferMonitorRollback:
* @fdpass: The fd passing helper struct
diff --git a/src/qemu/qemu_fd.h b/src/qemu/qemu_fd.h
index ef35daba8c..d078d4ce5d 100644
--- a/src/qemu/qemu_fd.h
+++ b/src/qemu/qemu_fd.h
@@ -47,9 +47,6 @@ int
qemuFDPassTransferMonitor(qemuFDPass *fdpass,
qemuMonitor *mon);
-int
-qemuFDPassTransferMonitorFake(qemuFDPass *fdpass);
-
void
qemuFDPassTransferMonitorRollback(qemuFDPass *fdpass,
qemuMonitor *mon);
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 21302e0fce..fe8f0b58db 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -834,6 +834,7 @@ mymain(void)
"device_del", QMP_DEVICE_DELETED("hostdev0")
QMP_OK);
DO_TEST_ATTACH("base-live", "interface-vdpa", false, true,
+ "query-fdsets",
"{\"return\":[{\"fdset-id\":99999}]}",
"add-fd", "{ \"return\": {
\"fdset-id\": 1, \"fd\": 95 }}",
"netdev_add", QMP_OK, "device_add", QMP_OK);
DO_TEST_DETACH("base-live", "interface-vdpa", false, false,
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index e15c8533f6..c3ee771cbb 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -725,7 +725,6 @@ qemuMonitorJSONTestAttachChardev(virDomainXMLOption *xmlopt,
{
g_autoptr(virDomainChrSourceDef) chr = virDomainChrSourceDefNew(xmlopt);
- qemuDomainChrSourcePrivate *charpriv = QEMU_DOMAIN_CHR_SOURCE_PRIVATE(chr);
chr->data.file.path = g_strdup("/test/path");
@@ -743,12 +742,6 @@ qemuMonitorJSONTestAttachChardev(virDomainXMLOption *xmlopt,
chrdev.source = chr;
ignore_value(testQemuPrepareHostBackendChardevOne(&dev, chr, NULL));
- if (qemuFDPassTransferMonitorFake(charpriv->sourcefd) < 0)
- ret = -1;
-
- if (qemuFDPassTransferMonitorFake(charpriv->logfd) < 0)
- ret = -1;
-
CHECK("file", false,
"{'id':'alias','backend':{'type':'file','data':{'out':'/dev/fdset/monitor-fake',"
"'append':true,"
--
2.35.1