Remove the last code path using hardcoded fdsets.

Signed-off-by: Peter Krempa <pkre...@redhat.com>
---
 src/qemu/qemu_command.c                       | 140 +++++-------------
 .../tpm-passthrough-crb.x86_64-latest.args    |   6 +-
 .../tpm-passthrough.x86_64-latest.args        |   6 +-
 3 files changed, 45 insertions(+), 107 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7169b8ff90..9649ba3701 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -301,56 +301,6 @@ qemuBuildMasterKeyCommandLine(virCommand *cmd,
 }


-/**
- * qemuVirCommandGetFDSet:
- * @cmd: the command to modify
- * @fd: fd to reassign to the child
- *
- * Get the parameters for the QEMU -add-fd command line option
- * for the given file descriptor. The file descriptor must previously
- * have been 'transferred' in a virCommandPassFD() call.
- * This function for example returns "set=10,fd=20".
- */
-static char *
-qemuVirCommandGetFDSet(virCommand *cmd, int fd)
-{
-    int idx = virCommandPassFDGetFDIndex(cmd, fd);
-
-    if (idx < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("file descriptor %d has not been transferred"), fd);
-        return NULL;
-    }
-
-    return g_strdup_printf("set=%d,fd=%d", idx, fd);
-}
-
-
-/**
- * qemuVirCommandGetDevSet:
- * @cmd: the command to modify
- * @fd: fd to reassign to the child
- *
- * Get the parameters for the QEMU path= parameter where a file
- * descriptor is accessed via a file descriptor set, for example
- * /dev/fdset/10. The file descriptor must previously have been
- * 'transferred' in a virCommandPassFD() call.
- */
-static char *
-qemuVirCommandGetDevSet(virCommand *cmd, int fd)
-{
-    int idx = virCommandPassFDGetFDIndex(cmd, fd);
-
-    if (idx < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("file descriptor %d has not been transferred"), fd);
-        return NULL;
-    }
-
-    return g_strdup_printf("/dev/fdset/%d", idx);
-}
-
-
 static char *
 qemuBuildDeviceAddressPCIGetBus(const virDomainDef *domainDef,
                                 const virDomainDeviceInfo *info)
@@ -9764,40 +9714,22 @@ qemuBuildTPMOpenBackendFDs(const char *tpmdev,


 static char *
-qemuBuildTPMBackendStr(virCommand *cmd,
-                       virDomainTPMDef *tpm,
-                       int *tpmfd,
-                       int *cancelfd)
+qemuBuildTPMBackendStr(virDomainTPMDef *tpm,
+                       qemuFDPass *passtpm,
+                       qemuFDPass *passcancel)
 {
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-    g_autofree char *devset = NULL;
-    g_autofree char *cancelset = NULL;
-
-    *tpmfd = -1;
-    *cancelfd = -1;

     virBufferAsprintf(&buf, "%s", virDomainTPMBackendTypeToString(tpm->type));
     virBufferAsprintf(&buf, ",id=tpm-%s", tpm->info.alias);

     switch (tpm->type) {
     case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
-        if 
(qemuBuildTPMOpenBackendFDs(tpm->data.passthrough.source->data.file.path,
-                                       tpmfd, cancelfd) < 0)
-            return NULL;
-
-        virCommandPassFD(cmd, *tpmfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
-        virCommandPassFD(cmd, *cancelfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
-
-        if (!(devset = qemuVirCommandGetDevSet(cmd, *tpmfd)) ||
-            !(cancelset = qemuVirCommandGetDevSet(cmd, *cancelfd)))
-            return NULL;
-
         virBufferAddLit(&buf, ",path=");
-        virQEMUBuildBufferEscapeComma(&buf, devset);
+        virQEMUBuildBufferEscapeComma(&buf, qemuFDPassGetPath(passtpm));

         virBufferAddLit(&buf, ",cancel-path=");
-        virQEMUBuildBufferEscapeComma(&buf, cancelset);
-
+        virQEMUBuildBufferEscapeComma(&buf, qemuFDPassGetPath(passcancel));
         break;
     case VIR_DOMAIN_TPM_TYPE_EMULATOR:
         virBufferAddLit(&buf, ",chardev=chrtpm");
@@ -9814,42 +9746,49 @@ static int
 qemuBuildTPMCommandLine(virCommand *cmd,
                         const virDomainDef *def,
                         virDomainTPMDef *tpm,
-                        virQEMUCaps *qemuCaps)
+                        qemuDomainObjPrivate *priv)
 {
     g_autofree char *tpmdevstr = NULL;
-    int tpmfd = -1;
-    int cancelfd = -1;
-    char *fdset;
+    g_autoptr(qemuFDPass) passtpm = NULL;
+    g_autoptr(qemuFDPass) passcancel = NULL;

-    if (tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
-        if (qemuBuildChardevCommand(cmd, tpm->data.emulator.source, "chrtpm", 
qemuCaps) < 0)
-            return -1;
-    }
+    switch ((virDomainTPMBackendType) tpm->type) {
+    case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: {
+        VIR_AUTOCLOSE fdtpm = -1;
+        VIR_AUTOCLOSE fdcancel = -1;

-    if (!(tpmdevstr = qemuBuildTPMBackendStr(cmd, tpm, &tpmfd, &cancelfd)))
-        return -1;
+        if 
(qemuBuildTPMOpenBackendFDs(tpm->data.passthrough.source->data.file.path,
+                                       &fdtpm, &fdcancel) < 0)
+            return -1;

-    virCommandAddArgList(cmd, "-tpmdev", tpmdevstr, NULL);
+        passtpm = qemuFDPassNew(tpm->info.alias, priv, true);
+        passcancel = qemuFDPassNew(tpm->info.alias, priv, true);

-    if (tpmfd >= 0) {
-        fdset = qemuVirCommandGetFDSet(cmd, tpmfd);
-        if (!fdset)
+        if (qemuFDPassAddFD(passtpm, &fdtpm, "-tpm") < 0 ||
+            qemuFDPassAddFD(passcancel, &fdcancel, "-cancel") < 0)
             return -1;
-
-        virCommandAddArgList(cmd, "-add-fd", fdset, NULL);
-        VIR_FREE(fdset);
     }
+        break;

-    if (cancelfd >= 0) {
-        fdset = qemuVirCommandGetFDSet(cmd, cancelfd);
-        if (!fdset)
+    case VIR_DOMAIN_TPM_TYPE_EMULATOR:
+        if (qemuBuildChardevCommand(cmd, tpm->data.emulator.source, "chrtpm", 
priv->qemuCaps) < 0)
             return -1;
+        break;

-        virCommandAddArgList(cmd, "-add-fd", fdset, NULL);
-        VIR_FREE(fdset);
+    case VIR_DOMAIN_TPM_TYPE_LAST:
+        virReportEnumRangeError(virDomainTPMBackendType, tpm->type);
+        return -1;
     }

-    if (qemuBuildTPMDevCmd(cmd, def, tpm, qemuCaps) < 0)
+    qemuFDPassTransferCommand(passtpm, cmd);
+    qemuFDPassTransferCommand(passcancel, cmd);
+
+    if (!(tpmdevstr = qemuBuildTPMBackendStr(tpm, passtpm, passcancel)))
+        return -1;
+
+    virCommandAddArgList(cmd, "-tpmdev", tpmdevstr, NULL);
+
+    if (qemuBuildTPMDevCmd(cmd, def, tpm, priv->qemuCaps) < 0)
         return -1;

     return 0;
@@ -9880,16 +9819,15 @@ qemuBuildTPMProxyCommandLine(virCommand *cmd,
 static int
 qemuBuildTPMsCommandLine(virCommand *cmd,
                          const virDomainDef *def,
-                         virQEMUCaps *qemuCaps)
+                         qemuDomainObjPrivate *priv)
 {
     size_t i;

     for (i = 0; i < def->ntpms; i++) {
         if (def->tpms[i]->model == VIR_DOMAIN_TPM_MODEL_SPAPR_PROXY) {
-            if (qemuBuildTPMProxyCommandLine(cmd, def->tpms[i], qemuCaps) < 0)
+            if (qemuBuildTPMProxyCommandLine(cmd, def->tpms[i], 
priv->qemuCaps) < 0)
                 return -1;
-        } else if (qemuBuildTPMCommandLine(cmd, def,
-                                           def->tpms[i], qemuCaps) < 0) {
+        } else if (qemuBuildTPMCommandLine(cmd, def, def->tpms[i], priv) < 0) {
             return -1;
         }
     }
@@ -10633,7 +10571,7 @@ qemuBuildCommandLine(virQEMUDriver *driver,
     if (qemuBuildConsoleCommandLine(cmd, def, qemuCaps) < 0)
         return NULL;

-    if (qemuBuildTPMsCommandLine(cmd, def, qemuCaps) < 0)
+    if (qemuBuildTPMsCommandLine(cmd, def, priv) < 0)
         return NULL;

     if (qemuBuildInputCommandLine(cmd, def, qemuCaps) < 0)
diff --git a/tests/qemuxml2argvdata/tpm-passthrough-crb.x86_64-latest.args 
b/tests/qemuxml2argvdata/tpm-passthrough-crb.x86_64-latest.args
index e099cf0fa1..b9f22188c2 100644
--- a/tests/qemuxml2argvdata/tpm-passthrough-crb.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/tpm-passthrough-crb.x86_64-latest.args
@@ -27,9 +27,9 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-TPM-VM/.config \
 -no-shutdown \
 -boot menu=on,strict=on \
 -device 
'{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
--tpmdev passthrough,id=tpm-tpm0,path=/dev/fdset/0,cancel-path=/dev/fdset/1 \
--add-fd set=0,fd=1730 \
--add-fd set=1,fd=1731 \
+-add-fd set=1,fd=1730,opaque=tpm0-tpm \
+-add-fd set=2,fd=1731,opaque=tpm0-cancel \
+-tpmdev passthrough,id=tpm-tpm0,path=/dev/fdset/1,cancel-path=/dev/fdset/2 \
 -device '{"driver":"tpm-crb","tpmdev":"tpm-tpm0","id":"tpm0"}' \
 -audiodev '{"id":"audio1","driver":"none"}' \
 -device 
'{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \
diff --git a/tests/qemuxml2argvdata/tpm-passthrough.x86_64-latest.args 
b/tests/qemuxml2argvdata/tpm-passthrough.x86_64-latest.args
index beb6a307cb..da042d3b2b 100644
--- a/tests/qemuxml2argvdata/tpm-passthrough.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/tpm-passthrough.x86_64-latest.args
@@ -27,9 +27,9 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-TPM-VM/.config \
 -no-shutdown \
 -boot menu=on,strict=on \
 -device 
'{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
--tpmdev passthrough,id=tpm-tpm0,path=/dev/fdset/0,cancel-path=/dev/fdset/1 \
--add-fd set=0,fd=1730 \
--add-fd set=1,fd=1731 \
+-add-fd set=1,fd=1730,opaque=tpm0-tpm \
+-add-fd set=2,fd=1731,opaque=tpm0-cancel \
+-tpmdev passthrough,id=tpm-tpm0,path=/dev/fdset/1,cancel-path=/dev/fdset/2 \
 -device '{"driver":"tpm-tis","tpmdev":"tpm-tpm0","id":"tpm0"}' \
 -audiodev '{"id":"audio1","driver":"none"}' \
 -device 
'{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \
-- 
2.34.1

Reply via email to