
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@linux.vnet.ibm.com> Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com> Tested-by: Corey Bryant <coreyb@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, '/'); 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; } Thank you. Stefan