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

[UNIKRAFT PATCH 1/3] lib/vfscore: Reduce pread() and pwrite() to their -v() counterparts.



This commit reorganizes the pread() and pwrite() method such that they rely on 
preadv() and pwritev(), respectively.  This is due the overlap in 
functionality, where pread() and pwrite() simply create a struct iovec method 
which is to be passed in their relevant sys_ method.

Signed-off-by: Alexander Jung <alexander.jung@xxxxxxxxx>
---
 lib/vfscore/main.c | 37 ++++++++++---------------------------
 1 file changed, 10 insertions(+), 27 deletions(-)

diff --git a/lib/vfscore/main.c b/lib/vfscore/main.c
index 846e2ef..3dcbd51 100644
--- a/lib/vfscore/main.c
+++ b/lib/vfscore/main.c
@@ -307,7 +307,6 @@ static inline int has_error(int error, int bytes)
                        (error != EWOULDBLOCK && error != EINTR));
 }
 
-
 ssize_t pread(int fd, void *buf, size_t count, off_t offset)
 {
        trace_vfs_pread(fd, buf, count, offset);
@@ -315,25 +314,17 @@ ssize_t pread(int fd, void *buf, size_t count, off_t 
offset)
                        .iov_base       = buf,
                        .iov_len        = count,
        };
-       struct vfscore_file *fp;
-       size_t bytes;
        int error;
 
-       error = fget(fd, &fp);
-       if (error)
+       error = preadv(fd, &iov, 1, offset);
+       if (error < 0)
                goto out_errno;
 
-       error = sys_read(fp, &iov, 1, offset, &bytes);
-       fdrop(fp);
-
-       if (has_error(error, bytes))
-               goto out_errno;
-       trace_vfs_pread_ret(bytes);
-       return bytes;
+       trace_vfs_pread_ret(error);
+       return error;
 
-       out_errno:
+out_errno:
        trace_vfs_pread_err(error);
-       errno = error;
        return -1;
 }
 
@@ -356,25 +347,17 @@ ssize_t pwrite(int fd, const void *buf, size_t count, 
off_t offset)
                        .iov_base       = (void *)buf,
                        .iov_len        = count,
        };
-       struct vfscore_file *fp;
-       size_t bytes;
        int error;
 
-       error = fget(fd, &fp);
-       if (error)
+       error = pwritev(fd, &iov, 1, offset);
+       if (error < 0)
                goto out_errno;
 
-       error = sys_write(fp, &iov, 1, offset, &bytes);
-       fdrop(fp);
-
-       if (has_error(error, bytes))
-               goto out_errno;
-       trace_vfs_pwrite_ret(bytes);
-       return bytes;
+       trace_vfs_pwrite_ret(error);
+       return error;
 
-       out_errno:
+out_errno:
        trace_vfs_pwrite_err(error);
-       errno = error;
        return -1;
 }
 
-- 
2.11.0




 


Rackspace

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