]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
Update the number of remaining unprocessed bytes correctly
authorMihai Pogonaru <pogonarumihai@gmail.com>
Sat, 29 Jun 2019 13:54:57 +0000 (16:54 +0300)
committerFelipe Huici <felipe.huici@neclab.eu>
Sat, 29 Jun 2019 14:43:11 +0000 (16:43 +0200)
Update uio structure in sock_net_write/read. VFSCORE expects the
update of the resid member of uio such that it reflects the
number of bytes that remain unprocessed.

Set the UK_VFSCORE_NOPOS flag on the socket vfscore_file. This
flag informs VFSCORE to do not update the offset of our socket
file since it doesn't make sense for sockets.

Signed-off-by: Mihai Pogonaru <pogonarumihai@gmail.com>
Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
sockets.c

index cbe3030812cf3d3526a23a6c1363bab73f4f1a49..304009919727433f34a45d5ae457017a18ff969b 100644 (file)
--- a/sockets.c
+++ b/sockets.c
@@ -139,6 +139,7 @@ static int sock_fd_alloc(struct vnops *v_op, int sock_fd)
        vfs_file->f_count = 1;
        vfs_file->f_data = file;
        vfs_file->f_dentry = s_dentry;
+       vfs_file->f_vfs_flags = UK_VFSCORE_NOPOS;
 
        s_dentry->d_refcnt = 1;
        s_dentry->d_vnode = s_vnode;
@@ -225,7 +226,7 @@ static int sock_net_close(struct vnode *s_vnode,
        return ret;
 }
 
-static ssize_t sock_net_write(struct vnode *s_vnode,
+static int sock_net_write(struct vnode *s_vnode,
                              struct uio *buf, int ioflag __unused)
 {
        int ret = 0;
@@ -237,10 +238,15 @@ static ssize_t sock_net_write(struct vnode *s_vnode,
                                    file->vfscore_file->fd,
                                    file->sock_fd));
        ret = lwip_writev(file->sock_fd, buf->uio_iov, buf->uio_iovcnt);
-       return ret;
+       /* lwip sets errno and returns -1 in case of error */
+       if (ret < 0)
+               return ret;
+
+       buf->uio_resid -= ret;
+       return 0;
 }
 
-static ssize_t sock_net_read(struct vnode *s_vnode,
+static int sock_net_read(struct vnode *s_vnode,
                             struct vfscore_file *vfscore_file __unused,
                             struct uio *buf, int ioflag __unused)
 {
@@ -253,7 +259,12 @@ static ssize_t sock_net_read(struct vnode *s_vnode,
                                    file->vfscore_file->fd,
                                    file->sock_fd));
        ret = lwip_readv(file->sock_fd, buf->uio_iov, buf->uio_iovcnt);
-       return ret;
+       /* lwip sets errno and returns -1 in case of error */
+       if (ret < 0)
+               return ret;
+
+       buf->uio_resid -= ret;
+       return 0;
 }
 
 #define sock_net_inactive  ((vnop_inactive_t) vfscore_vop_nullop)