Skip to contentSkip to conversation

qemu-vmsr-helper: fix socket loop breakage

PATCH New Paolo Bonzini 1 participant 3 messages Jul 30, 2024

lore
Share & tools
lore
#0 lore raw

cover qemu-vmsr-helper: fix socket loop breakage

Coverity reported a breakage that snuck in between v5 and v6 of the series, when the socket loop of qemu-vmsr-helper was changed to allow sending multiple requests on the same socket. Unfortunately, the condition of the while loop is botched and the loop will never be entered. Clean it up, and also improve the error reporting to be more like qemu-pr-helper's.

Paolo

Paolo Bonzini (2):
qemu-vmsr-helper: fix socket loop breakage
qemu-vmsr-helper: implement --verbose/-v

 tools/i386/qemu-vmsr-helper.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/2 qemu-vmsr-helper: fix socket loop breakage

Between v5 and v6 of the series, the socket loop of qemu-vmsr-helper was changed to allow sending multiple requests on the same socket. Unfortunately, the condition of the while loop is botched and the loop will never be entered. Clean it up, and also unify the handling of error reporting.

---
 tools/i386/qemu-vmsr-helper.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/i386/qemu-vmsr-helper.c +7 -5
index ebf562c3ff8..bac3ea70393 100644
@@ -227,19 +227,17 @@ static void coroutine_fn vh_co_entry(void *opaque)
                                 &peer_pid,
                                 &local_err);
     if (r < 0) {
-        error_report_err(local_err);
         goto out;
     }
 
-    while (r < 0) {
+    for (;;) {
         /*
          * Read the requested MSR
          * Only RAPL MSR in rapl-msr-index.h is allowed
          */
         r = qio_channel_read_all(QIO_CHANNEL(client->ioc),
                                 (char *) &request, sizeof(request), &local_err);
-        if (r < 0) {
-            error_report_err(local_err);
+        if (r <= 0) {
             break;
         }
 
@@ -261,11 +259,15 @@ static void coroutine_fn vh_co_entry(void *opaque)
                                   sizeof(vmsr),
                                   &local_err);
         if (r < 0) {
-            error_report_err(local_err);
             break;
         }
     }
+
 out:
+    if (local_err) {
+        error_report_err(local_err);
+    }
+
     object_unref(OBJECT(client->ioc));
     g_free(client);
 }
Signature · 1 line
2.45.2
#2 lore raw

PATCH 2/2 qemu-vmsr-helper: implement --verbose/-v

In reply to Paolo Bonzini

Similar to qemu-pr-helper, do not print errors from the socket handling loop unless a --verbose or -v option is provided explicitly on the command line.

---
 tools/i386/qemu-vmsr-helper.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
tools/i386/qemu-vmsr-helper.c +9 -1
index bac3ea70393..1644ac72da0 100644
@@ -54,6 +54,7 @@ static enum { RUNNING, TERMINATE, TERMINATING } state;
 static QIOChannelSocket *server_ioc;
 static int server_watch;
 static int num_active_sockets = 1;
+static bool verbose;
 
 #ifdef CONFIG_LIBCAP_NG
 static int uid = -1;
@@ -265,7 +266,11 @@ static void coroutine_fn vh_co_entry(void *opaque)
 
 out:
     if (local_err) {
-        error_report_err(local_err);
+        if (!verbose) {
+            error_free(local_err);
+        } else {
+            error_report_err(local_err);
+        }
     }
 
     object_unref(OBJECT(client->ioc));
@@ -431,6 +436,9 @@ int main(int argc, char **argv)
         case 'd':
             daemonize = true;
             break;
+        case 'v':
+            verbose = true;
+            break;
         case 'T':
             trace_opt_parse(optarg);
             break;
Signature · 1 line
2.45.2