[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH] lib/vfscore: Enable fcntl() function
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
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |