<div dir="auto">I just realized after sending this patch that I made the change in the Linux version of the function. It may not be applicable for FreeBSD . </div><div dir="auto">In any case I simply don’t understand if errors on the logs is a problem. If it is maybe we need a FreeBSD version of this function as well not just a larger bucket on non Linux flavours that report error .</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 11, 2022 at 23:43 Ani Sinha <<a href="mailto:ani@anisinha.ca">ani@anisinha.ca</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">Currently virProcessGetStatInfo() always returns success and only logs error<br>
when it is unable to parse the data. Make this function actually report the<br>
error and return a negative value in this error scenario.<br>
<br>
Fix the callers so that they do not override the error generated.<br>
Also fix non-linux implementation of this function so as to report error.<br>
<br>
Signed-off-by: Ani Sinha <<a href="mailto:ani@anisinha.ca" target="_blank">ani@anisinha.ca</a>><br>
---<br>
src/ch/ch_driver.c | 2 --<br>
src/qemu/qemu_driver.c | 7 +------<br>
src/util/virprocess.c | 17 +++++++++++++----<br>
3 files changed, 14 insertions(+), 12 deletions(-)<br>
<br>
changelog:<br>
v4: on freebsd error on the logs is a problem appaently. try to fix<br>
that.<br>
v3: fix non linux implementation<br>
v2: fix callers<br>
<br>
diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c<br>
index 53e0872207..3cbc668489 100644<br>
--- a/src/ch/ch_driver.c<br>
+++ b/src/ch/ch_driver.c<br>
@@ -1073,8 +1073,6 @@ chDomainHelperGetVcpus(virDomainObj *vm,<br>
if (virProcessGetStatInfo(&vcpuinfo->cpuTime,<br>
&vcpuinfo->cpu, NULL,<br>
vm->pid, vcpupid) < 0) {<br>
- virReportSystemError(errno, "%s",<br>
- _("cannot get vCPU placement & pCPU time"));<br>
return -1;<br>
}<br>
}<br>
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c<br>
index d3d76c003f..65ac5ef367 100644<br>
--- a/src/qemu/qemu_driver.c<br>
+++ b/src/qemu/qemu_driver.c<br>
@@ -1359,8 +1359,6 @@ qemuDomainHelperGetVcpus(virDomainObj *vm,<br>
if (virProcessGetStatInfo(&vcpuinfo->cpuTime,<br>
&vcpuinfo->cpu, NULL,<br>
vm->pid, vcpupid) < 0) {<br>
- virReportSystemError(errno, "%s",<br>
- _("cannot get vCPU placement & pCPU time"));<br>
return -1;<br>
}<br>
}<br>
@@ -2521,8 +2519,6 @@ qemuDomainGetInfo(virDomainPtr dom,<br>
if (virDomainObjIsActive(vm)) {<br>
if (virProcessGetStatInfo(&(info->cpuTime), NULL, NULL,<br>
vm->pid, 0) < 0) {<br>
- virReportError(VIR_ERR_OPERATION_FAILED, "%s",<br>
- _("cannot read cputime for domain"));<br>
goto cleanup;<br>
}<br>
}<br>
@@ -10530,8 +10526,7 @@ qemuDomainMemoryStatsInternal(virQEMUDriver *driver,<br>
}<br>
<br>
if (virProcessGetStatInfo(NULL, NULL, &rss, vm->pid, 0) < 0) {<br>
- virReportError(VIR_ERR_OPERATION_FAILED, "%s",<br>
- _("cannot get RSS for domain"));<br>
+ virResetLastError();<br>
} else {<br>
stats[ret].tag = VIR_DOMAIN_MEMORY_STAT_RSS;<br>
stats[ret].val = rss;<br>
diff --git a/src/util/virprocess.c b/src/util/virprocess.c<br>
index b559a4257e..cbb31441cc 100644<br>
--- a/src/util/virprocess.c<br>
+++ b/src/util/virprocess.c<br>
@@ -1779,12 +1779,20 @@ virProcessGetStatInfo(unsigned long long *cpuTime,<br>
long rss = 0;<br>
int cpu = 0;<br>
<br>
- if (!proc_stat ||<br>
- virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_UTIME], NULL, 10, &usertime) < 0 ||<br>
+ if (!proc_stat) {<br>
+ VIR_WARN("Unable to get proc stats from the kernel");<br>
+ return 0;<br>
+ }<br>
+<br>
+ if (virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_UTIME], NULL, 10, &usertime) < 0 ||<br>
virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_STIME], NULL, 10, &systime) < 0 ||<br>
virStrToLong_l(proc_stat[VIR_PROCESS_STAT_RSS], NULL, 10, &rss) < 0 ||<br>
virStrToLong_i(proc_stat[VIR_PROCESS_STAT_PROCESSOR], NULL, 10, &cpu) < 0) {<br>
- VIR_WARN("cannot parse process status data");<br>
+ virReportError(VIR_ERR_INTERNAL_ERROR,<br>
+ _("cannot parse process status data for pid '%d/%d'"),<br>
+ (int) pid, (int) tid);<br>
+<br>
+ return -1;<br>
}<br>
<br>
/* We got jiffies<br>
@@ -1881,7 +1889,8 @@ virProcessGetStatInfo(unsigned long long *cpuTime G_GNUC_UNUSED,<br>
pid_t pid G_GNUC_UNUSED,<br>
pid_t tid G_GNUC_UNUSED)<br>
{<br>
- errno = ENOSYS;<br>
+ virReportSystemError(ENOSYS, "%s",<br>
+ _("Process statistics data is not supported on this platform"));<br>
return -1;<br>
}<br>
<br>
-- <br>
2.25.1<br>
<br>
</blockquote></div></div>