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

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


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Wed, 4 Sep 2019 17:50:32 +0300
  • Cc: vlad_andrei.badoiu@xxxxxxxxxxxxxxx
  • Delivery-date: Wed, 04 Sep 2019 14:50:43 +0000
  • Ironport-phdr: 9a23:uDOUsRIHXD5nlrMKvNmcpTZWNBhigK39O0sv0rFitYgeKfrxwZ3uMQTl6Ol3ixeRBMOHsqgC0rWL+P+wEUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCejbb9oMRm7rwXcusYUjIZhN6081gbHrnxUdupM2GhmP0iTnxHy5sex+J5s7SFdsO8/+sBDTKv3Yb02QaRXAzo6PW814tbrtQTYQguU+nQcSGQWnQFWDAXD8Rr3Q43+sir+tup6xSmaIcj7Rq06VDi+86tmTgLjhSEaPDA77W7XkNR9gqJFrhy8qRJxwInabZqJOPZiZK7RYckXSXZdUstXSidPApm8b4wKD+cZI+tYqJL9p0cPrRu4GAKiAv7vyidVhnTr2qA1z+MhERra3AwhGdICqnDUrMjtNKcPSu260LLIwS/bb/NLwjjx8pLIchc4rPyKQLl+ctLRxFEyGw7Kk1mcs4/oMjOP2ugTrWSW7fBsWOy3h2I6pAx9vyKjy8Qsh4XTmI4YxF7J+T9kzIs6O9G1TlNwb8S+H5tKrS6aMpN7QsYlQ251pik30qYGuZunfCgSz5Qn2gLfZ+SHc4eW5hLjU/6cISl9hH1/ebK/gwy+/lS7yuHmTsm0zU1FojBfktnLrnwN1hrT5dabSvZl40us1iuD2xrQ5+xEO0w4i7TXJpw7zrM+jpYTtF7MHi7ymEX4lq+WcUAk9/C05OTgebXmup6cN4luhgH6L6QugtG/DP8kPQgVRWSb4fm826b58U3jR7VGluc2nbXBsJDGOcQboba0AwpU0oYl6ha/CCym3M0FknYZMlJKZhaHgpPtO1HPO/D4Eey/j06jkTh1wfDKJLrhAo/CLnLbirfuYa5961JAyAo01d1f+ZZUBascL/3rQEDxssHXDgUnPAy12eroE89y2Z4ZWWKOH6+UK7jSsUOV5u0yOeWDfpMauC3nJ/g4//7hlmU1mUUaffrh4ZxCbXG+H/N9ZkmUf3foqtMACnsR+BozSqrtklLRfyRUYiOZWLkg5zdzLJ++EM+XTYe2nL2HmiOmBoB+bXsAEk2GV23vIdbXE8wQYT6fd5cy2gcPUqKsHtcs
  • Ironport-sdr: DRsc1pe2jiT8RgtH0L+vxsDhtBv9ZhMOI/xpz+6uCfAkF+bjiHDXLRjA4YK1xiSV9wC++Ng0lE DMgHFK0tiq8g==
  • 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 05434dfe..c698201d 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);
 int 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 4498811d..925ce762 100644
--- a/lib/vfscore/main.c
+++ b/lib/vfscore/main.c
@@ -1427,17 +1427,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)
@@ -1452,7 +1457,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;
@@ -1469,35 +1474,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;
        }
 
@@ -1507,12 +1519,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®.