mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
virPerfReadEvent: Refactor to return -errno on failure
The function didn't comply with libvirt's error reporting scheme as it reported libvirt errors only sometimes. As callers may want to ignore errors convert it to returning -errno on failure instead. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
a4c0c6fd9f
commit
613901baec
@ -17581,9 +17581,13 @@ qemuDomainGetStatsPerfOneEvent(virPerf *perf,
|
||||
virTypedParamList *params)
|
||||
{
|
||||
uint64_t value = 0;
|
||||
int rv;
|
||||
|
||||
if (virPerfReadEvent(perf, type, &value) < 0)
|
||||
if ((rv = virPerfReadEvent(perf, type, &value)) < 0) {
|
||||
virReportSystemError(-rv, "%s",
|
||||
_("Unable to read cache data"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
virTypedParamListAddULLong(params, value, "perf.%s", virPerfEventTypeToString(type));
|
||||
|
||||
|
@ -290,6 +290,12 @@ bool virPerfEventIsEnabled(virPerf *perf,
|
||||
return perf && perf->events[type].enabled;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virPerfReadEvent:
|
||||
*
|
||||
* Returns 0 on success -ERRNO on failure.
|
||||
*/
|
||||
int
|
||||
virPerfReadEvent(virPerf *perf,
|
||||
virPerfEventType type,
|
||||
@ -297,13 +303,10 @@ virPerfReadEvent(virPerf *perf,
|
||||
{
|
||||
struct virPerfEvent *event = &perf->events[type];
|
||||
if (!event->enabled)
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
|
||||
if (saferead(event->fd, value, sizeof(uint64_t)) < 0) {
|
||||
virReportSystemError(errno, "%s",
|
||||
_("Unable to read cache data"));
|
||||
return -1;
|
||||
}
|
||||
if (saferead(event->fd, value, sizeof(uint64_t)) < 0)
|
||||
return -errno;
|
||||
|
||||
if (type == VIR_PERF_EVENT_CMT)
|
||||
*value *= event->efields.cmt.scale;
|
||||
@ -350,9 +353,7 @@ virPerfReadEvent(virPerf *perf G_GNUC_UNUSED,
|
||||
virPerfEventType type G_GNUC_UNUSED,
|
||||
uint64_t *value G_GNUC_UNUSED)
|
||||
{
|
||||
virReportSystemError(ENXIO, "%s",
|
||||
_("Perf not supported on this platform"));
|
||||
return -1;
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user