提交 5ed7afa9 编写于 作者: S Stefan Berger 提交者: Cole Robinson

tpm: adapt sysfs cancel path for new TPM driver

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: NStefan Berger <stefanb@linux.vnet.ibm.com>
上级 b6e19cf4
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include "virstring.h" #include "virstring.h"
#include "virerror.h" #include "virerror.h"
#include "viralloc.h"
#include "virfile.h"
#include "virtpm.h" #include "virtpm.h"
#define VIR_FROM_THIS VIR_FROM_NONE #define VIR_FROM_THIS VIR_FROM_NONE
...@@ -41,14 +43,27 @@ virTPMCreateCancelPath(const char *devpath) ...@@ -41,14 +43,27 @@ virTPMCreateCancelPath(const char *devpath)
{ {
char *path = NULL; char *path = NULL;
const char *dev; const char *dev;
const char *prefix[] = {"misc/", "tpm/"};
size_t i;
if (devpath) { if (devpath) {
dev = strrchr(devpath, '/'); dev = strrchr(devpath, '/');
if (dev) { if (dev) {
dev++; dev++;
if (virAsprintf(&path, "/sys/class/misc/%s/device/cancel", for (i = 0; i < ARRAY_CARDINALITY(prefix); i++) {
dev) < 0) if (virAsprintf(&path, "/sys/class/%s%s/device/cancel",
goto cleanup; 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 { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("TPM device path %s is invalid"), devpath); _("TPM device path %s is invalid"), devpath);
......
...@@ -24,9 +24,13 @@ ...@@ -24,9 +24,13 @@
#include "virnuma.h" #include "virnuma.h"
#include "virmock.h" #include "virmock.h"
#include "virutil.h" #include "virutil.h"
#include "virstring.h"
#include "virtpm.h"
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#define VIR_FROM_THIS VIR_FROM_NONE
long virGetSystemPageSize(void) long virGetSystemPageSize(void)
{ {
return 4096; return 4096;
...@@ -59,3 +63,14 @@ virNumaNodeIsAvailable(int node) ...@@ -59,3 +63,14 @@ virNumaNodeIsAvailable(int node)
return node >= 0 && node <= virNumaGetMaxNode(); return node >= 0 && node <= virNumaGetMaxNode();
} }
#endif /* WITH_NUMACTL && HAVE_NUMA_BITMASK_ISBITSET */ #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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册