]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
report error when virProcessGetStatInfo() is unable to parse data
authorAni Sinha <ani@anisinha.ca>
Tue, 11 Jan 2022 10:20:43 +0000 (15:50 +0530)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 12 Jan 2022 13:18:38 +0000 (14:18 +0100)
Currently virProcessGetStatInfo() always returns success and only logs error
when it is unable to parse the data. Make this function actually report the
error and return a negative value in this error scenario.

Fix the callers so that they do not override the error generated.
Also fix non-linux implementation of this function so as to report error.

Signed-off-by: Ani Sinha <ani@anisinha.ca>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/ch/ch_driver.c
src/qemu/qemu_driver.c
src/util/virprocess.c

index 53e0872207cba12d9932a3f5aaa9d6ea1270ef58..3cbc66848989de870e83d4b02408adffbfea094e 100644 (file)
@@ -1073,8 +1073,6 @@ chDomainHelperGetVcpus(virDomainObj *vm,
             if (virProcessGetStatInfo(&vcpuinfo->cpuTime,
                                       &vcpuinfo->cpu, NULL,
                                       vm->pid, vcpupid) < 0) {
-                virReportSystemError(errno, "%s",
-                                      _("cannot get vCPU placement & pCPU time"));
                 return -1;
             }
         }
index d3d76c003f00ae4c82a585d4271dcb1db30b16b9..65ac5ef367fc3a0a5f6cfbdfee685f2de43ea936 100644 (file)
@@ -1359,8 +1359,6 @@ qemuDomainHelperGetVcpus(virDomainObj *vm,
             if (virProcessGetStatInfo(&vcpuinfo->cpuTime,
                                       &vcpuinfo->cpu, NULL,
                                       vm->pid, vcpupid) < 0) {
-                virReportSystemError(errno, "%s",
-                                     _("cannot get vCPU placement & pCPU time"));
                 return -1;
             }
         }
@@ -2521,8 +2519,6 @@ qemuDomainGetInfo(virDomainPtr dom,
     if (virDomainObjIsActive(vm)) {
         if (virProcessGetStatInfo(&(info->cpuTime), NULL, NULL,
                                   vm->pid, 0) < 0) {
-            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-                           _("cannot read cputime for domain"));
             goto cleanup;
         }
     }
@@ -10530,8 +10526,7 @@ qemuDomainMemoryStatsInternal(virQEMUDriver *driver,
     }
 
     if (virProcessGetStatInfo(NULL, NULL, &rss, vm->pid, 0) < 0) {
-        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-                       _("cannot get RSS for domain"));
+        virResetLastError();
     } else {
         stats[ret].tag = VIR_DOMAIN_MEMORY_STAT_RSS;
         stats[ret].val = rss;
index b559a4257ec6621eced5b3b75edd64a1b9da418a..85d8c8e747cb622754a339cb46ebc3bf2ee79def 100644 (file)
@@ -1784,7 +1784,10 @@ virProcessGetStatInfo(unsigned long long *cpuTime,
         virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_STIME], NULL, 10, &systime) < 0 ||
         virStrToLong_l(proc_stat[VIR_PROCESS_STAT_RSS], NULL, 10, &rss) < 0 ||
         virStrToLong_i(proc_stat[VIR_PROCESS_STAT_PROCESSOR], NULL, 10, &cpu) < 0) {
-        VIR_WARN("cannot parse process status data");
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("cannot parse process status data for pid '%d/%d'"),
+                       (int) pid, (int) tid);
+        return -1;
     }
 
     /* We got jiffies
@@ -1881,7 +1884,8 @@ virProcessGetStatInfo(unsigned long long *cpuTime G_GNUC_UNUSED,
                       pid_t pid G_GNUC_UNUSED,
                       pid_t tid G_GNUC_UNUSED)
 {
-    errno = ENOSYS;
+    virReportSystemError(ENOSYS, "%s",
+                         _("Process statistics data is not supported on this platform"));
     return -1;
 }