On Fri, Apr 12, 2013 at 08:40:18AM -0400, Stefan Berger wrote:
On 04/12/2013 06:24 AM, Daniel P. Berrange wrote:
>On Thu, Apr 11, 2013 at 04:04:46PM -0400, Stefan Berger wrote:
>>Implement helper functions to find the TPM's sysfs cancel file.
>>
>>Signed-off-by: Stefan Berger <stefanb(a)linux.vnet.ibm.com>
>>Reviewed-by: Corey Bryant <coreyb(a)linux.vnet.ibm.com>
>>Tested-by: Corey Bryant <coreyb(a)linux.vnet.ibm.com>
>>
>>Hmm, actually on second thoughts the entirely approach for this
>>method is just flawed.
>>
>>In the XML description you have:
>>
>> <device path='/dev/tpm0'/>
>>
>>So we should not be iterating over /sys/fs/misc/tpmNNN at all.
>>We know exactly which TPM device we want - it is 'tpm0'. Just
>>kill all this pointless readdir code & pass in the device name
>>we want to get the cancel path for.
Indeed, the following is better:
/**
* virTPMFindCancelPath:
* @devpath: Path to the TPM device
*
* Find the cancel path given the path to the TPM device
*/
char *
virTPMFindCancelPath(const char *devpath)
{
char *basepath = NULL;
char *path = NULL;
const char *dev;
if (devpath) {
dev = rindex(devpath, '/');
rindex is deprecated by POSIX - strrchr is preferred.
if (dev) {
dev++;
if (virAsprintf(&basepath, "/sys/class/misc/%s/device",
dev) < 0) {
virReportOOMError();
goto cleanup;
}
path = virTPMCheckSysfsCancel(basepath);
} 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:
VIR_FREE(basepath);
return path;
}
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 :|