]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-fdio: Adopt f*sync syscalls from vfscore
authorAndrei Tatar <andrei@unikraft.io>
Thu, 6 Feb 2025 15:27:58 +0000 (16:27 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Mon, 10 Feb 2025 11:24:18 +0000 (11:24 +0000)
This change moves the implementation of the fsync and fdatasync syscalls
from vfscore to posix-fdio, allowing shim operation on both ukfiles and
legacy vfscore files.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1581

lib/posix-fdio/Makefile.uk
lib/posix-fdio/fd-shim.c
lib/vfscore/Makefile.uk
lib/vfscore/exportsyms.uk
lib/vfscore/include/vfscore/syscalls.h
lib/vfscore/main.c
lib/vfscore/syscalls.c
lib/vfscore/vfs.h

index 3a5665768e8b56cb29ecfa466d737cda4b13f88b..a604ea2ce51c08fd3863793ffb9e6609526dfc5b 100644 (file)
@@ -23,6 +23,9 @@ UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDIO) += lseek-3
 
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDIO) += fstat-2
 
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDIO) += fsync-1
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDIO) += fdatasync-1
+
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDIO) += fcntl-3
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDIO) += ioctl-3
 endif
index 9c6b3221e7fad708a4a9f374ff06740281cd2c65..c9d5748be1d3ad37f2d628a191251c613193c674 100644 (file)
@@ -324,6 +324,53 @@ UK_SYSCALL_R_DEFINE(int, fstat, int, fd, struct stat *, statbuf)
 
 /* Ctl */
 
+UK_SYSCALL_R_DEFINE(int, fsync, int, fd)
+{
+       int r;
+       union uk_shim_file sf;
+
+       switch (uk_fdtab_shim_get(fd, &sf)) {
+       case UK_SHIM_OFILE:
+               r = uk_sys_fsync(sf.ofile);
+               uk_fdtab_ret(sf.ofile);
+               break;
+#if CONFIG_LIBVFSCORE
+       case UK_SHIM_LEGACY:
+               /* vfscore_fsync returns positive error codes */
+               r = -vfscore_fsync(sf.vfile);
+               fdrop(sf.vfile);
+               break;
+#endif /* CONFIG_LIBVFSCORE */
+       default:
+               r = -EBADF;
+       }
+       return r;
+}
+
+UK_SYSCALL_R_DEFINE(int, fdatasync, int, fd)
+{
+       int r;
+       union uk_shim_file sf;
+
+       switch (uk_fdtab_shim_get(fd, &sf)) {
+       case UK_SHIM_OFILE:
+               r = uk_sys_fdatasync(sf.ofile);
+               uk_fdtab_ret(sf.ofile);
+               break;
+#if CONFIG_LIBVFSCORE
+       case UK_SHIM_LEGACY:
+               /* vfscore has no separate fdatasync; use fsync */
+               /* vfscore_fsync returns positive error codes */
+               r = -vfscore_fsync(sf.vfile);
+               fdrop(sf.vfile);
+               break;
+#endif /* CONFIG_LIBVFSCORE */
+       default:
+               r = -EBADF;
+       }
+       return r;
+}
+
 UK_LLSYSCALL_R_DEFINE(int, fcntl, int, fd,
                      unsigned int, cmd, unsigned long, arg)
 {
index 51483f680da5ab75d8cc2dd6e48aa4e3ea5ec606..4fc752d8aba42dcb98a1889500fb49366b63384f 100644 (file)
@@ -41,8 +41,6 @@ UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += mknod-3
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += rmdir-1
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += rename-2
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += renameat-4
-UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += fsync-1
-UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += fdatasync-1
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += umask-1
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += lstat-2
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += flock-2
index 83a77367c273953a24dba78f93b52934c3e67078..be0bb0bc311755a0f69910803b96d723bb386967 100644 (file)
@@ -31,9 +31,6 @@ uk_syscall_r_mkdir
 mkdirat
 uk_syscall_e_mkdirat
 uk_syscall_r_mkdirat
-fsync
-uk_syscall_e_fsync
-uk_syscall_r_fsync
 fstat
 fstat64
 uk_syscall_e_fstat
@@ -144,9 +141,6 @@ preadv64
 ioctl
 uk_syscall_e_ioctl
 uk_syscall_r_ioctl
-fdatasync
-uk_syscall_e_fdatasync
-uk_syscall_r_fdatasync
 fdopendir
 dirfd
 rewinddir
@@ -274,6 +268,7 @@ vfscore_pwrite64
 vfscore_writev
 vfscore_write
 vfscore_lseek
+vfscore_fsync
 vfscore_fstat
 vfscore_fcntl
 vfscore_ioctl
index 2bef135beef4d776717a47f5024d49a573744820..e9d775d90a0b230cfd00e0f64543dd85d7e31636 100644 (file)
@@ -30,6 +30,8 @@ int vfscore_lseek(struct vfscore_file *fp, off_t off, int type, off_t *origin);
 
 int vfscore_fstat(struct vfscore_file *fp, struct stat *st);
 
+int vfscore_fsync(struct vfscore_file *fp);
+
 int vfscore_fcntl(struct vfscore_file *fp, unsigned int cmd, unsigned long arg);
 int vfscore_ioctl(struct vfscore_file *fp, unsigned long request, void *buf);
 
index 1de597dadc17f1f89eeaf495d84697770d7c13ac..9a68ad897fb00cff755265de5fabd1184a8e788c 100644 (file)
@@ -628,39 +628,6 @@ ssize_t vfscore_write(struct vfscore_file *fp, const void *buf, size_t count)
        return bytes;
 }
 
-UK_TRACEPOINT(trace_vfs_fsync, "%d", int);
-UK_TRACEPOINT(trace_vfs_fsync_ret, "");
-UK_TRACEPOINT(trace_vfs_fsync_err, "%d", int);
-
-UK_SYSCALL_R_DEFINE(int, fsync, int, fd)
-{
-       struct vfscore_file *fp;
-       int error;
-
-       trace_vfs_fsync(fd);
-       error = fget(fd, &fp);
-       if (error)
-               goto out_error;
-
-       error = sys_fsync(fp);
-       fdrop(fp);
-
-       if (error)
-               goto out_error;
-       trace_vfs_fsync_ret();
-       return 0;
-
-       out_error:
-       trace_vfs_fsync_err(error);
-       return -error;
-}
-
-UK_SYSCALL_R_DEFINE(int, fdatasync, int, fd)
-{
-       // TODO: See if we can do less than fsync().
-       return fsync(fd);
-}
-
 static int __fxstatat_helper(int ver __unused, int dirfd, const char *pathname,
                struct stat *st, int flags);
 
index 40d379838edb865b4013dcadc8f6819b3c1cbc9a..16e1784ed77fbc82bc11c520b899fb4ab48b8c13 100644 (file)
@@ -431,7 +431,7 @@ exit:
 }
 
 int
-sys_fsync(struct vfscore_file *fp)
+vfscore_fsync(struct vfscore_file *fp)
 {
        struct vnode *vp;
        int error;
index c51057aba8914fbfd071d081b62990a017f71098..2dcfdff0e4529aa7d7f984527da72f129e77a975 100644 (file)
@@ -164,19 +164,6 @@ int sys_read(struct vfscore_file *fp, const struct iovec *iov, size_t niov,
 int sys_write(struct vfscore_file *fp, const struct iovec *iov, size_t niov,
                off_t offset, size_t *count);
 
-
-/**
- * Synchronizes the in-core data referred by vfscore_file to the backing
- * store device.
- *
- * @param fp
- *     Pointer to the vfscore_file structure
- * @return
- *     - (0):  Completed successfully
- *     - (<0): Negative value with error code
- */
-int sys_fsync(struct vfscore_file *fp);
-
 /**
  * Gets the next directory entry in the directory stream.
  *