[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v20210601 04/38] tools: add readv_exact to libxenctrl


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Olaf Hering <olaf@xxxxxxxxx>
  • Date: Tue, 1 Jun 2021 18:10:44 +0200
  • Arc-authentication-results: i=1; strato.com; dkim=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563887; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=5m93ctia/WnTzxirdrXBAXbAAhmoz3AnrSBGz7krrzI=; b=hvRDmt8H5FRof7n8T1KREYMwr4EyVRPtnWlsjqHTb/OoQ16P6xmPM9ZnRLnH2d+p7o r9ddcdQUyFSU8Baptt58b+ojz0976r30YMAzDEnUN9I5HIrjnQs2foYO+bpTSWB/kIIT Vc09t2YPC5uRl7zPnBFVp4cSkFq20jDGAAvLT6SjvykWKYLB+tlpeGrzJ/VG1jfxguDe lbNdHU3vJYme5kU8Etm/GNgEpw0KgUNIRPpgwt7zqrXaXThz173ZxZU3JGnAtgazvD4b kqcb/a3P5km9vBa76oDN8tIdori3xicH63GzUqeELh52ycHVBat4pQsFj0/jpU727CDD D91A==
  • Arc-seal: i=1; a=rsa-sha256; t=1622563887; cv=none; d=strato.com; s=strato-dkim-0002; b=YjmQDA4/eh3J54LS6IB/jTUMgrucmiljDftMd5EfbbEYqO7565Xc5Z0QceBEhFaguu FA6KyT2U+N//foL6O6GZjxkepQgFvqy94h9RaRNOJKE8hllGOVRcYiJ/1gZgpMJN0j1u VgQUUjwce13nf6EZgmqJK6KcwnfvUHAlH4H4Y3N5qz3wi4OPo51IWmYR46EzUCv9D2Zb J0Xno6qVUBuAcLkG9cqy2w3qDxUkP0/xo3r/9Fb2fiJtxMOXY9X/csSR6c/3dX+sLqfe PzU6L13ebt4VXJrWg9q+EJ23yU8zHk3mMkzf3xoUiUSZLy2VHBDKN0lxxe2MNicJqjgF C9ig==
  • Authentication-results: strato.com; dkim=none
  • Cc: Olaf Hering <olaf@xxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 01 Jun 2021 16:11:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Read a batch of iovec's.

In the common case of short reads, finish individual iov's with read_exact.

Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
---
 tools/libs/ctrl/xc_private.c | 55 +++++++++++++++++++++++++++++++++++-
 tools/libs/ctrl/xc_private.h |  1 +
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/tools/libs/ctrl/xc_private.c b/tools/libs/ctrl/xc_private.c
index d94f846686..ea420b9ba8 100644
--- a/tools/libs/ctrl/xc_private.c
+++ b/tools/libs/ctrl/xc_private.c
@@ -659,8 +659,23 @@ int write_exact(int fd, const void *data, size_t size)
 
 #if defined(__MINIOS__)
 /*
- * MiniOS's libc doesn't know about writev(). Implement it as multiple 
write()s.
+ * MiniOS's libc doesn't know about readv/writev().
+ * Implement it as multiple read/write()s.
  */
+int readv_exact(int fd, const struct iovec *iov, int iovcnt)
+{
+    int rc, i;
+
+    for ( i = 0; i < iovcnt; ++i )
+    {
+        rc = read_exact(fd, iov[i].iov_base, iov[i].iov_len);
+        if ( rc )
+            return rc;
+    }
+
+    return 0;
+}
+
 int writev_exact(int fd, const struct iovec *iov, int iovcnt)
 {
     int rc, i;
@@ -675,6 +690,44 @@ int writev_exact(int fd, const struct iovec *iov, int 
iovcnt)
     return 0;
 }
 #else
+int readv_exact(int fd, const struct iovec *iov, int iovcnt)
+{
+    int rc = 0, idx = 0;
+    ssize_t len;
+
+    while ( idx < iovcnt )
+    {
+        len = readv(fd, &iov[idx], min(iovcnt - idx, IOV_MAX));
+        if ( len == -1 && errno == EINTR )
+            continue;
+        if ( len <= 0 )
+        {
+            rc = -1;
+            goto out;
+        }
+        while ( len > 0 && idx < iovcnt )
+        {
+            if ( len >= iov[idx].iov_len )
+            {
+                len -= iov[idx].iov_len;
+            }
+            else
+            {
+                void *p = iov[idx].iov_base + len;
+                size_t l = iov[idx].iov_len - len;
+
+                rc = read_exact(fd, p, l);
+                if ( rc )
+                    goto out;
+                len = 0;
+            }
+            idx++;
+        }
+    }
+out:
+    return rc;
+}
+
 int writev_exact(int fd, const struct iovec *iov, int iovcnt)
 {
     struct iovec *local_iov = NULL;
diff --git a/tools/libs/ctrl/xc_private.h b/tools/libs/ctrl/xc_private.h
index f0b5f83ac8..5d2c7274fb 100644
--- a/tools/libs/ctrl/xc_private.h
+++ b/tools/libs/ctrl/xc_private.h
@@ -441,6 +441,7 @@ int xc_flush_mmu_updates(xc_interface *xch, struct xc_mmu 
*mmu);
 
 /* Return 0 on success; -1 on error setting errno. */
 int read_exact(int fd, void *data, size_t size); /* EOF => -1, errno=0 */
+int readv_exact(int fd, const struct iovec *iov, int iovcnt);
 int write_exact(int fd, const void *data, size_t size);
 int writev_exact(int fd, const struct iovec *iov, int iovcnt);
 



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.