]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch: support poll with -1 in chSocketRecv
authorPurna Pavan Chandra <paekkaladevi@linux.microsoft.com>
Mon, 5 Aug 2024 14:40:56 +0000 (14:40 +0000)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 9 Aug 2024 13:03:07 +0000 (15:03 +0200)
chSocketRecv fn can be used by operations such as restore, which cannot
have a specific poll timeout. The runtime of these operations at server
side (vmm) cannot be determined or capped as it depends on the guest
configuration. Hence, add a new parameter 'use_timeout' which when set
will pass -1 as timeout to poll, otherwise the default PKT_TIMEOUT_MS is
used.

Signed-off-by: Purna Pavan Chandra <paekkaladevi@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/ch/ch_process.c

index 5a9801d8f3c0d0a60f4a18e969941f7b41549e83..a0a1770139b37e3cd41f2196b4b42f8a6e9a792f 100644 (file)
@@ -535,11 +535,12 @@ chMonitorSocketConnect(virCHMonitor *mon)
 #define PKT_TIMEOUT_MS 500 /* ms */
 
 static char *
-chSocketRecv(int sock)
+chSocketRecv(int sock, bool use_timeout)
 {
     struct pollfd pfds[1];
     char *buf = NULL;
     size_t buf_len = 1024;
+    int timeout = PKT_TIMEOUT_MS;
     int ret;
 
     buf = g_new0(char, buf_len);
@@ -547,8 +548,11 @@ chSocketRecv(int sock)
     pfds[0].fd = sock;
     pfds[0].events = POLLIN;
 
+    if (!use_timeout)
+        timeout = -1;
+
     do {
-        ret = poll(pfds, G_N_ELEMENTS(pfds), PKT_TIMEOUT_MS);
+        ret = poll(pfds, G_N_ELEMENTS(pfds), timeout);
     } while (ret < 0 && errno == EINTR);
 
     if (ret <= 0) {
@@ -575,12 +579,12 @@ chSocketRecv(int sock)
 #undef PKT_TIMEOUT_MS
 
 static int
-chSocketProcessHttpResponse(int sock)
+chSocketProcessHttpResponse(int sock, bool use_poll_timeout)
 {
     g_autofree char *response = NULL;
     int http_res;
 
-    response = chSocketRecv(sock);
+    response = chSocketRecv(sock, use_poll_timeout);
     if (response == NULL) {
         return -1;
     }
@@ -706,7 +710,7 @@ chProcessAddNetworkDevices(virCHDriver *driver,
             return -1;
         }
 
-        if (chSocketProcessHttpResponse(mon_sockfd) < 0)
+        if (chSocketProcessHttpResponse(mon_sockfd, true) < 0)
             return -1;
     }