]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
sockets.c: Change error handling to match vfs expectations
authorMihai Pogonaru <pogonarumihai@gmail.com>
Sat, 29 Jun 2019 13:54:59 +0000 (16:54 +0300)
committerFelipe Huici <felipe.huici@neclab.eu>
Sat, 29 Jun 2019 14:43:11 +0000 (16:43 +0200)
vfs expects file system functions (vnops) to return 0 on success
(and update the uio structure) or a positive error number
in case of an error.

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

index 1a3ddfdbf004894a221af97a69ed4ca913d4e0bf..38639f8a7f4993c2d22406839f182356d50f1890 100644 (file)
--- a/sockets.c
+++ b/sockets.c
@@ -237,9 +237,18 @@ static int sock_net_close(struct vnode *s_vnode,
        /*
         * Free socket file
         * The rest of the resources will be freed by vfs
+        *
+        * TODO: vfs ignores close errors right now, so free our file
         */
        uk_free(uk_alloc_get_default(), file);
 
+       /*
+        * lwip sets errno and returns -1 in case of error, but
+        * vfs expects us to return a positive errno
+        */
+       if (ret < 0)
+               return errno;
+
        return ret;
 }
 
@@ -255,9 +264,12 @@ static int 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);
-       /* lwip sets errno and returns -1 in case of error */
+       /*
+        * lwip sets errno and returns -1 in case of error, but
+        * vfs expects us to return a positive errno
+        */
        if (ret < 0)
-               return ret;
+               return errno;
 
        buf->uio_resid -= ret;
        return 0;
@@ -276,9 +288,12 @@ static int 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);
-       /* lwip sets errno and returns -1 in case of error */
+       /*
+        * lwip sets errno and returns -1 in case of error, but
+        * vfs expects us to return a positive errno
+        */
        if (ret < 0)
-               return ret;
+               return errno;
 
        buf->uio_resid -= ret;
        return 0;