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

[Minios-devel] [UNIKRAFT PATCH v2] lib/vfscore: Enable fcntl() function


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Wed, 4 Sep 2019 18:39:32 +0300
  • Cc: vlad_andrei.badoiu@xxxxxxxxxxxxxxx
  • Delivery-date: Wed, 04 Sep 2019 15:39:42 +0000
  • Ironport-phdr: 9a23:zCovzxwyBRP74SnXCy+O+j09IxM/srCxBDY+r6Qd2+kQIJqq85mqBkHD//Il1AaPAdyBrasb1qGG7OjJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fcbglVmjaxe65+IRe2oAnetcQbg5ZpJ7osxBfOvnZGYfldy3lyJVKUkRb858Ow84Bm/i9Npf8v9NNOXLvjcaggQrNWEDopM2Yu5M32rhbDVheA5mEdUmoNjBVFBRXO4QzgUZfwtiv6sfd92DWfMMbrQ704RSiu4qF2QxLulSwJNSM28HvPh8JwkqxVvRyvqR94zYPPfI2ZKOBzcr/HcN8GWWZMWNtaWSxbAoO7aosCF/QMPeFDr4nhplsOqwa1Cw+xBOP31z9Dm3j70rE90+Q6DQHG3QogE8gKsHTJtNX1KbwfXvyuzKXS1TXDcuhZ1S3n6IjPax0sp+yHU7FoccfJ1EUiGB7Jgk+TpIHlJT+ZyPoBvmqB4+duTe6jlmEqpxxrrjWsxsogkJfFi4wbx1ze6Cl0z5g5KNulQ0Bhe9GkCoFftySCOotzRcMtXn9ntT4hyr0DpZ67ZC8KyIk7xxLHa/yIbYyI4hX7WeaPJDd3nnNleLalixmu6kis0PX8VtSv31pQtCpFlcHAtnEL1xPN9siKUuZx80i81TqV1A3e6vtILV4qmafZMZIszKY8lp8JvkTCGi/2ll/2jKiTdkg85ueo7P/nYqnnpp+aLYN0jhz+MrwzmsGkHes4KRICX3CG+eunzrHj50r5TK1QjvIqiqnZrIzaJcMDq668Ag9V1Icj6xGkDzu/zdsXg2cHI0xBeB+ci4jpOkrOIOzjDfuljFWjjjFry+rBPr37DZXHNmLDn6v5fbZh905czxI+zc5b551OF74OOOj8Wknsu9zCEBA5Mha4zP39B9pg0YMeWH+PD7SCMKPOrF+H+/gjLPOQa48Oojr9NuAl6OX0gX8jnl9ONZWuiJ4WbnG/BbFqLluUZVLog8wdCiEaswx4S/bl23OYVjsGTHGpQ6M6rhUmEJ/uWYzEXZyshvqFwT+mNpZNIHhbABaWFiG7JM2/R/4QZXfKcYdamTseWO35Rg==
  • Ironport-sdr: wVUzVkDZHgUpeOSR/XY0vJQFX/yNaXDQhafQQedv//4AXfBkA0qvGqpiY5Z8hOwNCqIptqpoZw q/Wk8TGCItLw==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

This patch enables and adapt the existing fcntl() implementation which was
previously imported from OSv. Beside that, it also handles F_DUPFD_CLOEXEC
case, which is heavily used by Python 3 interpreter.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 lib/vfscore/exportsyms.uk          |  1 +
 lib/vfscore/include/vfscore/file.h |  4 +++
 lib/vfscore/main.c                 | 41 +++++++++++++++++++-----------
 lib/vfscore/syscalls.c             |  2 ++
 4 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/lib/vfscore/exportsyms.uk b/lib/vfscore/exportsyms.uk
index 822e6ecc..e3d6723a 100644
--- a/lib/vfscore/exportsyms.uk
+++ b/lib/vfscore/exportsyms.uk
@@ -78,3 +78,4 @@ uk_syscall_writev
 dentry_alloc
 drele
 vrele
+fcntl
diff --git a/lib/vfscore/include/vfscore/file.h 
b/lib/vfscore/include/vfscore/file.h
index 51f0791a..354a414e 100644
--- a/lib/vfscore/include/vfscore/file.h
+++ b/lib/vfscore/include/vfscore/file.h
@@ -59,8 +59,12 @@ struct vfscore_file {
        void            *f_data;        /* file descriptor specific data */
        int             f_vfs_flags;    /* internal implementation flags */
        struct dentry   *f_dentry;
+       struct uk_mutex f_lock;
 };
 
+#define FD_LOCK(fp)       uk_mutex_lock(&(fp->f_lock))
+#define FD_UNLOCK(fp)     uk_mutex_unlock(&(fp->f_lock))
+
 int vfscore_alloc_fd(void);
 void vfscore_put_fd(int fd);
 int vfscore_install_fd(int fd, struct vfscore_file *file);
diff --git a/lib/vfscore/main.c b/lib/vfscore/main.c
index be055b78..8d0e4b2c 100644
--- a/lib/vfscore/main.c
+++ b/lib/vfscore/main.c
@@ -1425,17 +1425,22 @@ int dup2(int oldfd, int newfd)
  */
 #define SETFL (O_APPEND | O_ASYNC | O_DIRECT | O_NOATIME | O_NONBLOCK)
 
-#if 0
 UK_TRACEPOINT(trace_vfs_fcntl, "%d %d 0x%x", int, int, int);
 UK_TRACEPOINT(trace_vfs_fcntl_ret, "\"%s\"", int);
 UK_TRACEPOINT(trace_vfs_fcntl_err, "%d", int);
 
-int fcntl(int fd, int cmd, int arg)
+int fcntl(int fd, int cmd, ...)
 {
+       int arg;
+       va_list ap;
        struct vfscore_file *fp;
        int ret = 0, error;
        int tmp;
 
+       va_start(ap, cmd);
+       arg = va_arg(ap, int);
+       va_end(ap);
+
        trace_vfs_fcntl(fd, cmd, arg);
        error = fget(fd, &fp);
        if (error)
@@ -1450,7 +1455,7 @@ int fcntl(int fd, int cmd, int arg)
        // ignored in OSv anyway, as it doesn't support exec().
        switch (cmd) {
        case F_DUPFD:
-               error = _fdalloc(fp, &ret, arg);
+               error = fdalloc(fp, &ret);
                if (error)
                        goto out_errno;
                break;
@@ -1467,35 +1472,42 @@ int fcntl(int fd, int cmd, int arg)
                // As explained above, the O_CLOEXEC should have been in 
f_flags,
                // and shouldn't be returned. Linux always returns 0100000 ("the
                // flag formerly known as O_LARGEFILE) so let's do it too.
-               ret = (oflags(fp->f_flags) & ~O_CLOEXEC) | 0100000;
+               ret = (vfscore_oflags(fp->f_flags) & ~O_CLOEXEC) | 0100000;
                break;
        case F_SETFL:
                FD_LOCK(fp);
-               fp->f_flags = fflags((oflags(fp->f_flags) & ~SETFL) |
+               fp->f_flags = vfscore_fflags((vfscore_oflags(fp->f_flags) & 
~SETFL) |
                                (arg & SETFL));
                FD_UNLOCK(fp);
 
+#if defined(FIONBIO) && defined(FIOASYNC)
                /* Sync nonblocking/async state with file flags */
                tmp = fp->f_flags & FNONBLOCK;
-               fp->ioctl(FIONBIO, &tmp);
+               vfs_ioctl(fp, FIONBIO, &tmp);
                tmp = fp->f_flags & FASYNC;
-               fp->ioctl(FIOASYNC, &tmp);
-
+               vfs_ioctl(fp, FIOASYNC, &tmp);
+#endif
+               break;
+       case F_DUPFD_CLOEXEC:
+               error = fdalloc(fp, &ret);
+               if (error)
+                       goto out_errno;
+               fp->f_flags |= O_CLOEXEC;
                break;
        case F_SETLK:
-               WARN_ONCE("fcntl(F_SETLK) stubbed\n");
+               uk_pr_warn("fcntl(F_SETLK) stubbed\n");
                break;
        case F_GETLK:
-               WARN_ONCE("fcntl(F_GETLK) stubbed\n");
+               uk_pr_warn("fcntl(F_GETLK) stubbed\n");
                break;
        case F_SETLKW:
-               WARN_ONCE("fcntl(F_SETLKW) stubbed\n");
+               uk_pr_warn("fcntl(F_SETLKW) stubbed\n");
                break;
        case F_SETOWN:
-               WARN_ONCE("fcntl(F_SETOWN) stubbed\n");
+               uk_pr_warn("fcntl(F_SETOWN) stubbed\n");
                break;
        default:
-               kprintf("unsupported fcntl cmd 0x%x\n", cmd);
+               uk_pr_err("unsupported fcntl cmd 0x%x\n", cmd);
                error = EINVAL;
        }
 
@@ -1505,12 +1517,11 @@ int fcntl(int fd, int cmd, int arg)
        trace_vfs_fcntl_ret(ret);
        return ret;
 
-       out_errno:
+out_errno:
        trace_vfs_fcntl_err(error);
        errno = error;
        return -1;
 }
-#endif
 
 UK_TRACEPOINT(trace_vfs_access, "\"%s\" 0%0o", const char*, int);
 UK_TRACEPOINT(trace_vfs_access_ret, "");
diff --git a/lib/vfscore/syscalls.c b/lib/vfscore/syscalls.c
index f9666c4c..54adc2d2 100644
--- a/lib/vfscore/syscalls.c
+++ b/lib/vfscore/syscalls.c
@@ -210,6 +210,8 @@ sys_open(char *path, int flags, mode_t mode, struct 
vfscore_file **fpp)
        fp->f_dentry = dp;
        dp = NULL;
 
+       uk_mutex_init(&fp->f_lock);
+
        error = VOP_OPEN(vp, fp);
        if (error) {
                vn_unlock(vp);
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

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