]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: introduce qemuBuildFDSet
authorJán Tomko <jtomko@redhat.com>
Tue, 24 Nov 2020 13:42:58 +0000 (14:42 +0100)
committerJán Tomko <jtomko@redhat.com>
Tue, 1 Dec 2020 16:24:20 +0000 (17:24 +0100)
An alternative to qemuVirCommandGetFDSet that takes the index
into the passed FD set as an argument and does not try to look it up.

Use it as well ass virCommandPassFDIndex in qemuBuildChrChardevFileStr
and qemuBuildInterfaceCommandLine.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_command.c

index 479bcc0b0c8bc48fffd6621df763fc4273b52fd2..d9c6c4bc43c102be71616b08c3642129c4c92d12 100644 (file)
@@ -224,6 +224,23 @@ qemuBuildMasterKeyCommandLine(virCommandPtr cmd,
 }
 
 
+/**
+ * qemuBuildFDSet:
+ * @fd: fd to reassign to the child
+ * @idx: index in the fd set
+ *
+ * Format the parameters for the -add-fd command line option
+ * for the given file descriptor. The file descriptor must previously
+ * have been 'transferred' in a virCommandPassFDIndex() call,
+ * and @idx is the value returned by that call.
+ */
+static char *
+qemuBuildFDSet(int fd, size_t idx)
+{
+    return g_strdup_printf("set=%zu,fd=%d", idx, fd);
+}
+
+
 /**
  * qemuVirCommandGetFDSet:
  * @cmd: the command to modify
@@ -4614,6 +4631,7 @@ qemuBuildChrChardevFileStr(virLogManagerPtr logManager,
         g_autofree char *fdpath = NULL;
         int flags = 0;
         int logfd;
+        size_t idx;
 
         if (appendval == VIR_TRISTATE_SWITCH_ABSENT ||
             appendval == VIR_TRISTATE_SWITCH_OFF)
@@ -4628,9 +4646,8 @@ qemuBuildChrChardevFileStr(virLogManagerPtr logManager,
                                                     NULL, NULL)) < 0)
             return -1;
 
-        virCommandPassFD(cmd, logfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
-        if (!(fdset = qemuVirCommandGetFDSet(cmd, logfd)))
-            return -1;
+        virCommandPassFDIndex(cmd, logfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT, &idx);
+        fdset = qemuBuildFDSet(logfd, idx);
 
         virCommandAddArg(cmd, "-add-fd");
         virCommandAddArg(cmd, fdset);
@@ -8183,11 +8200,10 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
     if (vdpafd > 0) {
         g_autofree char *fdset = NULL;
         g_autofree char *addfdarg = NULL;
+        size_t idx;
 
-        virCommandPassFD(cmd, vdpafd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
-        fdset = qemuVirCommandGetFDSet(cmd, vdpafd);
-        if (!fdset)
-            goto cleanup;
+        virCommandPassFDIndex(cmd, vdpafd, VIR_COMMAND_PASS_FD_CLOSE_PARENT, &idx);
+        fdset = qemuBuildFDSet(vdpafd, idx);
         vdpafdName = qemuVirCommandGetDevSet(cmd, vdpafd);
         /* set opaque to the devicepath so that we can look up the fdset later
          * if necessary */