]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Move qemuBuildTPMBackendStr
authorJohn Ferlan <jferlan@redhat.com>
Mon, 15 Feb 2016 14:26:41 +0000 (09:26 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 16 Feb 2016 16:07:47 +0000 (11:07 -0500)
Move function closer to where it's called in qemuBuildTPMCommandLine

Also adjust function header to fit current coding guidelines

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_command.c

index 3331f7018bcee0be0fe535505960a210a4885c02..8018662887412095472ede7c23d7c725487e9d02 100644 (file)
@@ -6859,95 +6859,6 @@ qemuBuildRNGDevStr(virDomainDefPtr def,
 }
 
 
-static char *qemuBuildTPMBackendStr(const virDomainDef *def,
-                                    virCommandPtr cmd,
-                                    virQEMUCapsPtr qemuCaps,
-                                    const char *emulator,
-                                    int *tpmfd, int *cancelfd)
-{
-    const virDomainTPMDef *tpm = def->tpm;
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
-    const char *type = virDomainTPMBackendTypeToString(tpm->type);
-    char *cancel_path = NULL, *devset = NULL;
-    const char *tpmdev;
-
-    *tpmfd = -1;
-    *cancelfd = -1;
-
-    virBufferAsprintf(&buf, "%s,id=tpm-%s", type, tpm->info.alias);
-
-    switch (tpm->type) {
-    case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
-        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_PASSTHROUGH))
-            goto no_support;
-
-        tpmdev = tpm->data.passthrough.source.data.file.path;
-        if (!(cancel_path = virTPMCreateCancelPath(tpmdev)))
-            goto error;
-
-        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_ADD_FD)) {
-            *tpmfd = open(tpmdev, O_RDWR);
-            if (*tpmfd < 0) {
-                virReportSystemError(errno, _("Could not open TPM device %s"),
-                                     tpmdev);
-                goto error;
-            }
-
-            virCommandPassFD(cmd, *tpmfd,
-                             VIR_COMMAND_PASS_FD_CLOSE_PARENT);
-            devset = qemuVirCommandGetDevSet(cmd, *tpmfd);
-            if (devset == NULL)
-                goto error;
-
-            *cancelfd = open(cancel_path, O_WRONLY);
-            if (*cancelfd < 0) {
-                virReportSystemError(errno,
-                                     _("Could not open TPM device's cancel "
-                                       "path %s"), cancel_path);
-                goto error;
-            }
-            VIR_FREE(cancel_path);
-
-            virCommandPassFD(cmd, *cancelfd,
-                             VIR_COMMAND_PASS_FD_CLOSE_PARENT);
-            cancel_path = qemuVirCommandGetDevSet(cmd, *cancelfd);
-            if (cancel_path == NULL)
-                goto error;
-        }
-        virBufferAddLit(&buf, ",path=");
-        virBufferEscape(&buf, ',', ",", "%s", devset ? devset : tpmdev);
-
-        virBufferAddLit(&buf, ",cancel-path=");
-        virBufferEscape(&buf, ',', ",", "%s", cancel_path);
-
-        VIR_FREE(devset);
-        VIR_FREE(cancel_path);
-
-        break;
-    case VIR_DOMAIN_TPM_TYPE_LAST:
-        goto error;
-    }
-
-    if (virBufferCheckError(&buf) < 0)
-        goto error;
-
-    return virBufferContentAndReset(&buf);
-
- no_support:
-    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                   _("The QEMU executable %s does not support TPM "
-                     "backend type %s"),
-                   emulator, type);
-
- error:
-    VIR_FREE(devset);
-    VIR_FREE(cancel_path);
-
-    virBufferFreeAndReset(&buf);
-    return NULL;
-}
-
-
 static char *qemuBuildTPMDevStr(const virDomainDef *def,
                                 virQEMUCapsPtr qemuCaps,
                                 const char *emulator)
@@ -9023,6 +8934,98 @@ qemuBuildDomainLoaderCommandLine(virCommandPtr cmd,
     return ret;
 }
 
+
+static char *
+qemuBuildTPMBackendStr(const virDomainDef *def,
+                       virCommandPtr cmd,
+                       virQEMUCapsPtr qemuCaps,
+                       const char *emulator,
+                       int *tpmfd,
+                       int *cancelfd)
+{
+    const virDomainTPMDef *tpm = def->tpm;
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+    const char *type = virDomainTPMBackendTypeToString(tpm->type);
+    char *cancel_path = NULL, *devset = NULL;
+    const char *tpmdev;
+
+    *tpmfd = -1;
+    *cancelfd = -1;
+
+    virBufferAsprintf(&buf, "%s,id=tpm-%s", type, tpm->info.alias);
+
+    switch (tpm->type) {
+    case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_PASSTHROUGH))
+            goto no_support;
+
+        tpmdev = tpm->data.passthrough.source.data.file.path;
+        if (!(cancel_path = virTPMCreateCancelPath(tpmdev)))
+            goto error;
+
+        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_ADD_FD)) {
+            *tpmfd = open(tpmdev, O_RDWR);
+            if (*tpmfd < 0) {
+                virReportSystemError(errno, _("Could not open TPM device %s"),
+                                     tpmdev);
+                goto error;
+            }
+
+            virCommandPassFD(cmd, *tpmfd,
+                             VIR_COMMAND_PASS_FD_CLOSE_PARENT);
+            devset = qemuVirCommandGetDevSet(cmd, *tpmfd);
+            if (devset == NULL)
+                goto error;
+
+            *cancelfd = open(cancel_path, O_WRONLY);
+            if (*cancelfd < 0) {
+                virReportSystemError(errno,
+                                     _("Could not open TPM device's cancel "
+                                       "path %s"), cancel_path);
+                goto error;
+            }
+            VIR_FREE(cancel_path);
+
+            virCommandPassFD(cmd, *cancelfd,
+                             VIR_COMMAND_PASS_FD_CLOSE_PARENT);
+            cancel_path = qemuVirCommandGetDevSet(cmd, *cancelfd);
+            if (cancel_path == NULL)
+                goto error;
+        }
+        virBufferAddLit(&buf, ",path=");
+        virBufferEscape(&buf, ',', ",", "%s", devset ? devset : tpmdev);
+
+        virBufferAddLit(&buf, ",cancel-path=");
+        virBufferEscape(&buf, ',', ",", "%s", cancel_path);
+
+        VIR_FREE(devset);
+        VIR_FREE(cancel_path);
+
+        break;
+    case VIR_DOMAIN_TPM_TYPE_LAST:
+        goto error;
+    }
+
+    if (virBufferCheckError(&buf) < 0)
+        goto error;
+
+    return virBufferContentAndReset(&buf);
+
+ no_support:
+    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                   _("The QEMU executable %s does not support TPM "
+                     "backend type %s"),
+                   emulator, type);
+
+ error:
+    VIR_FREE(devset);
+    VIR_FREE(cancel_path);
+
+    virBufferFreeAndReset(&buf);
+    return NULL;
+}
+
+
 static int
 qemuBuildTPMCommandLine(virDomainDefPtr def,
                         virCommandPtr cmd,