]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
tpm: adapt sysfs cancel path for new TPM driver
authorStefan Berger <stefanb@us.ibm.com>
Wed, 18 Nov 2015 00:44:13 +0000 (19:44 -0500)
committerCole Robinson <crobinso@redhat.com>
Wed, 18 Nov 2015 01:52:13 +0000 (20:52 -0500)
This patch addresses BZ 1244895.

Adapt the sysfs TPM command cancel path for the TPM driver that
does not use a miscdevice anymore since Linux 4.0. Support old
and new paths and check their availability.

Add a mockup for the test cases to avoid the testing for
availability of the cancel path.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
src/util/virtpm.c
tests/qemuxml2argvmock.c

index 88f8361967a4a59a87d9dfd6fb87bbf50bf8bb9b..6d9b0657a66a00d513d59a0e0ecfa6b27d959d90 100644 (file)
@@ -26,6 +26,8 @@
 
 #include "virstring.h"
 #include "virerror.h"
+#include "viralloc.h"
+#include "virfile.h"
 #include "virtpm.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
@@ -41,14 +43,27 @@ virTPMCreateCancelPath(const char *devpath)
 {
     char *path = NULL;
     const char *dev;
+    const char *prefix[] = {"misc/", "tpm/"};
+    size_t i;
 
     if (devpath) {
         dev = strrchr(devpath, '/');
         if (dev) {
             dev++;
-            if (virAsprintf(&path, "/sys/class/misc/%s/device/cancel",
-                            dev) < 0)
-                goto cleanup;
+            for (i = 0; i < ARRAY_CARDINALITY(prefix); i++) {
+                if (virAsprintf(&path, "/sys/class/%s%s/device/cancel",
+                                prefix[i], dev) < 0)
+                     goto cleanup;
+
+                if (virFileExists(path))
+                    break;
+
+                VIR_FREE(path);
+            }
+            if (!path)
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                               _("No usable sysfs TPM cancel file could be "
+                                 "found"));
         } else {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("TPM device path %s is invalid"), devpath);
index d24725ed3802b53e82b394014c952cf6da817976..e58b8ce8b565825a4b9d767823ca3b04a2a49c42 100644 (file)
 #include "virnuma.h"
 #include "virmock.h"
 #include "virutil.h"
+#include "virstring.h"
+#include "virtpm.h"
 #include <time.h>
 #include <unistd.h>
 
+#define VIR_FROM_THIS VIR_FROM_NONE
+
 long virGetSystemPageSize(void)
 {
     return 4096;
@@ -59,3 +63,14 @@ virNumaNodeIsAvailable(int node)
     return node >= 0 && node <= virNumaGetMaxNode();
 }
 #endif /* WITH_NUMACTL && HAVE_NUMA_BITMASK_ISBITSET */
+
+char *
+virTPMCreateCancelPath(const char *devpath)
+{
+    char *path;
+    (void)devpath;
+
+    ignore_value(VIR_STRDUP(path, "/sys/class/misc/tpm0/device/cancel"));
+
+    return path;
+}