<tt><font size=2>Cole Robinson <crobinso@redhat.com> wrote on 11/17/2015
04:37:56 PM:<br><br>> From: Cole Robinson <crobinso@redhat.com></font></tt><br><tt><font size=2>> To: Stefan Berger/Watson/IBM@IBMUS, libvir-list@redhat.com,
<br>> berrange@redhat.com</font></tt><br><tt><font size=2>> Cc: Stefan Berger <stefanb@linux.vnet.ibm.com></font></tt><br><tt><font size=2>> Date: 11/17/2015 04:38 PM</font></tt><br><tt><font size=2>> Subject: Re: [PATCH v2] tpm: adapt sysfs cancel
path for new TPM driver</font></tt><br><tt><font size=2>> <br>> On 11/17/2015 10:46 AM, Stefan Berger wrote:<br>> > Adapt the sysfs TPM command cancel path for the TPM driver that<br>> > does not use a miscdevice anymore since Linux 4.0. Support old<br>> > and new paths and check their availability.<br>> > <br>> > Add a mockup for the test cases to avoid the testing for<br>> > availability of the cancel path.<br>> > <br>> > Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com><br>> > ---<br>> >  src/util/virtpm.c        | 22 ++++++++++++++++++++--<br>> >  tests/qemuxml2argvmock.c | 15 +++++++++++++++<br>> >  2 files changed, 35 insertions(+), 2 deletions(-)<br>> > <br>> > diff --git a/src/util/virtpm.c b/src/util/virtpm.c<br>> > index 88f8361..3872a31 100644<br>> > --- a/src/util/virtpm.c<br>> > +++ b/src/util/virtpm.c<br>> > @@ -23,9 +23,12 @@<br>> >  #include <config.h><br>> >  <br>> >  #include <sys/stat.h><br>> > +#include <fcntl.h><br>> >  <br>> >  #include "virstring.h"<br>> >  #include "virerror.h"<br>> > +#include "viralloc.h"<br>> > +#include "virfile.h"<br>> >  #include "virtpm.h"<br>> >  <br>> >  #define VIR_FROM_THIS VIR_FROM_NONE<br>> > @@ -41,13 +44,28 @@ virTPMCreateCancelPath(const char *devpath)<br>> >  {<br>> >      char *path = NULL;<br>> >      const char *dev;<br>> > +    const char *prefix[] = {"misc/", "tpm/"};<br>> > +    size_t i;<br>> > +    int fd;<br>> >  <br>> >      if (devpath) {<br>> >          dev = strrchr(devpath, '/');<br>> >          if (dev) {<br>> >              dev++;<br>> > -            if (virAsprintf(&path,
"/sys/class/misc/%s/device/cancel",<br>> > -                  
         dev) < 0)<br>> > +            for (i = 0; i <
ARRAY_CARDINALITY(prefix); i++) {<br>> > +                if (virAsprintf(&path,
"/sys/class/%s%s/device/cancel",<br>> > +                  
             prefix[i], dev) < 0)<br>> > +                  
  goto cleanup;<br>> > +<br>> > +                fd =
open(path, O_WRONLY);<br>> > +                if (fd
>= 0) {<br>> > +                  
 VIR_FORCE_CLOSE(fd);<br>> > +                  
 break;<br>> > +                }<br>> > +                VIR_FREE(path);<br>> > +            }<br>> <br>> You can use virFileExists(path) to simplify this</font></tt><br><br><tt><font size=2>Right.</font></tt><br><tt><font size=2><br>> <br>> > +            /* /dev/null does
not allow to cancel cmds but it canbe used */<br>> > +            if (!path &&
virAsprintf(&path, "/dev/null") < 0)<br>> >                  goto
cleanup;<br>> >          } else {<br>> <br>> Hmm, does this mean we might selinux relabel /dev/null? Maybe just
fall back<br>> to no cancel-path if we want this to be non-fatal</font></tt><br><br><tt><font size=2>We have to pass something on the command line otherwise
QEMU will try to find a path and SELinux will not allow it to open the
file. Basically either one of these sysfs files has to be there.</font></tt><br><br><tt><font size=2>I'll resort to displaying an error instead.</font></tt><br><br><tt><font size=2>Regards,</font></tt><br><tt><font size=2>   Stefan</font></tt><br><BR>