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

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


  • To: Costin Lupu <costin.lupu@xxxxxxxxx>, "minios-devel@xxxxxxxxxxxxx" <minios-devel@xxxxxxxxxxxxx>
  • From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Date: Wed, 4 Sep 2019 16:17:20 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=stud.acs.upb.ro; dmarc=pass action=none header.from=stud.acs.upb.ro; dkim=pass header.d=stud.acs.upb.ro; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8mNBgRUqvtsjbA9qV9eG67t9dWRwn8eAVZJMHRAxMWU=; b=nAZSgILh5vOSF4pQ0VNDIt7TUD+vRx+ypkQ0fG/sZHpp+5E0wpze/kIfDu81fYlXum+fBzlVdCxCO7EjNAM+lzAPaswckYkEjSxEvySW54nuLFF4mCm22p4rXDEqztVp5TewkqEmZqOiP7UZqTrYysw44cM7iW6xYwpioyO3kSIKNSCQHM6baT+QzmdlHBbGJUVaCEBKDWsKhgHkS/iK2b7zd3tqfRheJeL5GUlU22y+qtMnNaalKRlInFeT4UcvV6RPeyV3Nn/v3AP6FH+2gkEc0imNgVF0BOQyXZJDeCgFQjseMB7PXOo4xeP4EQbn8NGvlpySuwQiT+XkndLaEg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CzCoM6P6V1hxW6cJyWCWBvV9JSJ9WbeWaeEC22eTdDDDNujSvKdUNDsK4vOpkBZWSpvSSSsFDA8dXuoFs07DIw59iq3ig5rHrDVSB6Lf3BqfrOwSnpLLreuLef8o7RtI8ug2/u/KnRXpkxgRdzEeup/+KfOume79QIfgstOyfo89wPDuy6CKz/2ihctPa8Lr08tYzlXIR0ebi9+RvNkGiJjtTgISpSJndvFjmzjdgMukPpeqjfHQKvsAqhWMyw55p2vJulyQVeyAtfUSQFdXHxLAAsvFF+WHGMmRwDsERZ+JGK2u3nA72YOSAWSLuxKmABq9QGe/0ceSjgYYVPHbDw==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=vlad_andrei.badoiu@xxxxxxxxxxxxxxx;
  • Delivery-date: Wed, 04 Sep 2019 16:17:27 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: AQHVYzb2Zt8JZilBSkW31LGUCkk5jKcbsgMA
  • Thread-topic: [UNIKRAFT PATCH v2] lib/vfscore: Enable fcntl() function

Hi Costin,

This patch looks good. I have tested it with the tests from OSv[1]. Thanks!

Vlad

[1] https://github.com/cloudius-systems/osv/blob/master/tests/tst-fcntl.cc

Reviewed-by: Vlad-Andrei Badoiu<vlad_andrei.badoiu@xxxxxxxxxxxxxxx>

On 04.09.2019 18:39, Costin Lupu wrote:
> 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);
_______________________________________________
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®.