Re: [PATCH] tpm: adapt sysfs cancel path for new TPM driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Nov 17, 2015 at 09:18:29AM -0500, Stefan Berger wrote:
> On 11/16/2015 10:12 PM, Stefan Berger wrote:
> >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.
> >
> >Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxxxxxxxxxx>
> >---
> >  src/util/virtpm.c                                   | 21 +++++++++++++++++++--
> >  .../qemuxml2argv-tpm-passthrough.args               |  2 +-
> >  2 files changed, 20 insertions(+), 3 deletions(-)
> >
> >diff --git a/src/util/virtpm.c b/src/util/virtpm.c
> >index 88f8361..40a758b 100644
> >--- a/src/util/virtpm.c
> >+++ b/src/util/virtpm.c
> >@@ -23,9 +23,12 @@
> >  #include <config.h>
> >
> >  #include <sys/stat.h>
> >+#include <fcntl.h>
> >
> >  #include "virstring.h"
> >  #include "virerror.h"
> >+#include "viralloc.h"
> >+#include "virfile.h"
> >  #include "virtpm.h"
> >
> >  #define VIR_FROM_THIS VIR_FROM_NONE
> >@@ -41,13 +44,27 @@ virTPMCreateCancelPath(const char *devpath)
> >  {
> >      char *path = NULL;
> >      const char *dev;
> >+    const char *prefix[] = {"misc/", "tpm/"};
> >+    int i, fd;
> >
> >      if (devpath) {
> >          dev = strrchr(devpath, '/');
> >          if (dev) {
> >              dev++;
> >-            if (virAsprintf(&path, "/sys/class/misc/%s/device/cancel",
> >-                            dev) < 0)
> >+            for (i = 0; i < ARRAY_CARDINALITY(prefix); i++) {
> >+                if (virAsprintf(&path, "/sys/class/%s%s/device/cancel",
> >+                                prefix[i], dev) < 0)
> >+                     goto cleanup;
> >+
> >+                fd = open(path, O_WRONLY);
> 
> To get that path right we need to test it's availability by opening it.
> Unfortunately there's  problem with that now related to the test case below
> where, if the test is run as non-root, /dev/null will be returned, and if
> run as root possibly one of those constructed paths will be returned. What's
> the best way to fix this ?

The unit tests should never depend on host state, so we should
not run this code at all.

You sould mock override the virTPMCreateCancelPath method entirely
I guess to return a fixed filename.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]