Add validation to the transfer step to make the adding step more simple
for easier cleanup paths.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_fd.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/src/qemu/qemu_fd.c b/src/qemu/qemu_fd.c
index 1af8932bdd..284e77ba2b 100644
--- a/src/qemu/qemu_fd.c
+++ b/src/qemu/qemu_fd.c
@@ -65,6 +65,30 @@ qemuFDPassFree(qemuFDPass *fdpass)
}
+static int
+qemuFDPassValidate(qemuFDPass *fdpass)
+{
+ size_t i;
+
+ if (!fdpass->useFDSet &&
+ fdpass->nfds > 1) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("direct FD passing supports only 1 file
descriptor"));
+ return -1;
+ }
+
+ for (i = 0; i < fdpass->nfds; i++) {
+ if (fdpass->fds[i].fd < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("invalid file descriptor"));
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+
/**
* qemuFDPassNew:
* @prefix: prefix used for naming the passed FDs
@@ -186,6 +210,9 @@ qemuFDPassTransferCommand(qemuFDPass *fdpass,
if (!fdpass)
return 0;
+ if (qemuFDPassValidate(fdpass) < 0)
+ return -1;
+
for (i = 0; i < fdpass->nfds; i++) {
virCommandPassFD(cmd, fdpass->fds[i].fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
@@ -229,6 +256,9 @@ qemuFDPassTransferMonitor(qemuFDPass *fdpass,
if (!fdpass)
return 0;
+ if (qemuFDPassValidate(fdpass) < 0)
+ return -1;
+
for (i = 0; i < fdpass->nfds; i++) {
if (fdpass->useFDSet) {
qemuMonitorAddFdInfo fdsetinfo;
@@ -274,6 +304,9 @@ 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 {
--
2.35.1