Skip to contentSkip to conversation

libvhost-user: Send messages with no data

PATCH In review Dr. David Alan Gilbert (git) 3 participants 3 messages May 4, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libvhost-user: Send messages with no data

From: "Dr. David Alan Gilbert" <[email protected]>

The response to a VHOST_USER_POSTCOPY_ADVISE contains a fd but doesn't
actually contain any data. FIx vu_message_write so that it doesn't
do a 0-byte write() call, since this was ending up with rc=0 that was confusing the error handling code.

---
 contrib/libvhost-user/libvhost-user.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
contrib/libvhost-user/libvhost-user.c +9 -7
index beeed0c43f..54e643d871 100644
@@ -323,13 +323,15 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg *vmsg)
         rc = sendmsg(conn_fd, &msg, 0);
     } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
 
-    do {
-        if (vmsg->data) {
-            rc = write(conn_fd, vmsg->data, vmsg->size);
-        } else {
-            rc = write(conn_fd, p + VHOST_USER_HDR_SIZE, vmsg->size);
-        }
-    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+    if (vmsg->size) {
+        do {
+            if (vmsg->data) {
+                rc = write(conn_fd, vmsg->data, vmsg->size);
+            } else {
+                rc = write(conn_fd, p + VHOST_USER_HDR_SIZE, vmsg->size);
+            }
+        } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+    }
 
     if (rc <= 0) {
         vu_panic(dev, "Error while writing: %s", strerror(errno));
Signature · 1 line
2.17.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

The response to a VHOST_USER_POSTCOPY_ADVISE contains a fd but doesn't
actually contain any data. FIx vu_message_write so that it doesn't
do a 0-byte write() call, since this was ending up with rc=0 that was confusing the error handling code.

Quoted 35 lines
---
 contrib/libvhost-user/libvhost-user.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
contrib/libvhost-user/libvhost-user.c +9 -8
index beeed0c43f..54e643d871 100644
@@ -323,13 +323,15 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg *vmsg)
         rc = sendmsg(conn_fd, &msg, 0);
     } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
 
-    do {
-        if (vmsg->data) {
-            rc = write(conn_fd, vmsg->data, vmsg->size);
-        } else {
-            rc = write(conn_fd, p + VHOST_USER_HDR_SIZE, vmsg->size);
-        }
-    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+    if (vmsg->size) {
+        do {
+            if (vmsg->data) {
+                rc = write(conn_fd, vmsg->data, vmsg->size);
+            } else {
+                rc = write(conn_fd, p + VHOST_USER_HDR_SIZE, vmsg->size);
+            }
+        } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+    }
 
     if (rc <= 0) {
         vu_panic(dev, "Error while writing: %s", strerror(errno));
--

2.17.0

Signature · 1 line
Marc-André Lureau
#2 lore raw
In reply to Dr. David Alan Gilbert (git)
Quoted 3 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

The response to a VHOST_USER_POSTCOPY_ADVISE contains a fd but doesn't

s/a fd/an fd/ ? Depends on whether you pronounce it "eff-dee" or "file-descriptor".

Quoted 1 line

actually contain any data. FIx vu_message_write so that it doesn't

s/FIx/Fix/

Quoted 8 lines

do a 0-byte write() call, since this was ending up with rc=0 that was confusing the error handling code.

---
  contrib/libvhost-user/libvhost-user.c | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org