]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Helper functions for host TPM support
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Fri, 12 Apr 2013 20:55:45 +0000 (16:55 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Fri, 12 Apr 2013 20:55:45 +0000 (16:55 -0400)
Implement helper function to create the TPM's sysfs cancel file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Tested-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
po/POTFILES.in
src/Makefile.am
src/libvirt_private.syms
src/util/virtpm.c [new file with mode: 0644]
src/util/virtpm.h [new file with mode: 0644]

index 91e5c025c5844dbfe79d3f48701813d111225000..bf5a864199faf5e964216cb19ecfc79318696352 100644 (file)
@@ -181,6 +181,7 @@ src/util/virsysinfo.c
 src/util/virerror.c
 src/util/virerror.h
 src/util/virtime.c
+src/util/virtpm.c
 src/util/virtypedparam.c
 src/util/viruri.c
 src/util/virusb.c
index fc6b8467e79635d7ea14bce3bf8c285372c67b13..0323f430899b21dd574cdefbb55590ea074d6693 100644 (file)
@@ -122,6 +122,7 @@ UTIL_SOURCES =                                                      \
                util/virthreadwin32.h                           \
                util/virthreadpool.c util/virthreadpool.h       \
                util/virtime.h util/virtime.c                   \
+               util/virtpm.h util/virtpm.c                     \
                util/virtypedparam.c util/virtypedparam.h       \
                util/virusb.c util/virusb.h                     \
                util/viruri.h util/viruri.c                     \
index 64a6e3d0c4a90b1aae8bf58cdeb6884c0d4f997c..8a7dfcf867125d70e21143f7e16683cccb8904b2 100644 (file)
@@ -1781,6 +1781,10 @@ virTimeStringThen;
 virTimeStringThenRaw;
 
 
+# util/virtpm.h
+virTPMCreateCancelPath;
+
+
 # util/virtypedparam.h
 virTypedParameterArrayValidate;
 virTypedParameterAssign;
diff --git a/src/util/virtpm.c b/src/util/virtpm.c
new file mode 100644 (file)
index 0000000..fbe5e9d
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * virtpm.c: TPM support
+ *
+ * Copyright (C) 2013 IBM Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Stefan Berger <stefanb@linux.vnet.ibm.com>
+ */
+
+#include <config.h>
+
+#include <sys/stat.h>
+
+#include "virutil.h"
+#include "virerror.h"
+#include "virtpm.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+/**
+ * virTPMCreateCancelPath:
+ * @devpath: Path to the TPM device
+ *
+ * Create the cancel path given the path to the TPM device
+ */
+char *
+virTPMCreateCancelPath(const char *devpath)
+{
+    char *path = NULL;
+    const char *dev;
+
+    if (devpath) {
+        dev = strrchr(devpath, '/');
+        if (dev) {
+            dev++;
+            if (virAsprintf(&path, "/sys/class/misc/%s/device/cancel",
+                            dev) < 0) {
+                virReportOOMError();
+                goto cleanup;
+            }
+        } else {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("TPM device path %s is invalid"), devpath);
+        }
+    } else {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Missing TPM device path"));
+    }
+
+cleanup:
+    return path;
+}
diff --git a/src/util/virtpm.h b/src/util/virtpm.h
new file mode 100644 (file)
index 0000000..fe71307
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * virtpm.h: TPM support
+ *
+ * Copyright (C) 2013 IBM Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Stefan Berger <stefanb@linux.vnet.ibm.com>
+ */
+#ifndef __VIR_TPM_H__
+# define __VIR_TPM_H__
+
+char *virTPMCreateCancelPath(const char *devpath);
+
+#endif /* __VIR_TPM_H__ */