]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-fdio: Adopt file space mgmt syscalls
authorAndrei Tatar <andrei@unikraft.io>
Thu, 6 Feb 2025 15:33:03 +0000 (16:33 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Mon, 10 Feb 2025 11:24:18 +0000 (11:24 +0000)
This change moves the implementation of the ftruncate and fallocate
syscalls from vfscore to posix-fdio, allowing shim operation on both
ukfiles and legacy vfscore files alike.
In addition, the related fadvise64 syscall is implemented, stubbed out
as success for 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 a604ea2ce51c08fd3863793ffb9e6609526dfc5b..ec299602d93b6cac1bdbc3aa08a5fe5078b3c693 100644 (file)
@@ -26,6 +26,10 @@ 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) += ftruncate-2
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDIO) += fallocate-4
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDIO) += fadvise64-4
+
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDIO) += fcntl-3
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDIO) += ioctl-3
 endif
index c9d5748be1d3ad37f2d628a191251c613193c674..1bb008d34fba5ab2689cde5d51aa57e8195afcef 100644 (file)
@@ -371,6 +371,76 @@ UK_SYSCALL_R_DEFINE(int, fdatasync, int, fd)
        return r;
 }
 
+UK_SYSCALL_R_DEFINE(int, ftruncate, int, fd, off_t, len)
+{
+       int r;
+       union uk_shim_file sf;
+
+       switch (uk_fdtab_shim_get(fd, &sf)) {
+       case UK_SHIM_OFILE:
+               r = uk_sys_ftruncate(sf.ofile, len);
+               uk_fdtab_ret(sf.ofile);
+               break;
+#if CONFIG_LIBVFSCORE
+       case UK_SHIM_LEGACY:
+               /* vfscore_fallocate returns positive error codes */
+               r = -vfscore_ftruncate(sf.vfile, len);
+               fdrop(sf.vfile);
+               break;
+#endif /* CONFIG_LIBVFSCORE */
+       default:
+               r = -EBADF;
+       }
+       return r;
+}
+
+UK_SYSCALL_R_DEFINE(int, fallocate, int, fd, int, mode, off_t, off, off_t, len)
+{
+       int r;
+       union uk_shim_file sf;
+
+       switch (uk_fdtab_shim_get(fd, &sf)) {
+       case UK_SHIM_OFILE:
+               r = uk_sys_fallocate(sf.ofile, mode, off, len);
+               uk_fdtab_ret(sf.ofile);
+               break;
+#if CONFIG_LIBVFSCORE
+       case UK_SHIM_LEGACY:
+               /* vfscore_fallocate returns positive error codes */
+               r = -vfscore_fallocate(sf.vfile, mode, off, len);
+               fdrop(sf.vfile);
+               break;
+#endif /* CONFIG_LIBVFSCORE */
+       default:
+               r = -EBADF;
+       }
+       return r;
+}
+
+UK_SYSCALL_R_DEFINE(int, fadvise64,
+                   int, fd, off_t, off, off_t, len, int, advice)
+{
+       int r;
+       union uk_shim_file sf;
+
+       switch (uk_fdtab_shim_get(fd, &sf)) {
+       case UK_SHIM_OFILE:
+               r = uk_sys_fadvise(sf.ofile, off, len, advice);
+               uk_fdtab_ret(sf.ofile);
+               break;
+#if CONFIG_LIBVFSCORE
+       case UK_SHIM_LEGACY:
+               /* vfscore does not support fadvise; stub out */
+               fdrop(sf.vfile);
+               r = 0;
+               break;
+#endif /* CONFIG_LIBVFSCORE */
+       default:
+               r = -EBADF;
+       }
+       return r;
+}
+
 UK_LLSYSCALL_R_DEFINE(int, fcntl, int, fd,
                      unsigned int, cmd, unsigned long, arg)
 {
index 4fc752d8aba42dcb98a1889500fb49366b63384f..0165d7ed3825114a34ac5c5ec67a4c8b0f93ae78 100644 (file)
@@ -26,11 +26,9 @@ LIBVFSCORE_EINITRD_CDEPS += $(CONFIG_LIBVFSCORE_AUTOMOUNT_EINITRD_PATH)
 
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += readlink-3
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += link-2
-UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += ftruncate-2
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += truncate-2
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += access-2
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += faccessat-4
-UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += fallocate-4
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += chdir-1
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += fchdir-1
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += chmod-2
index be0bb0bc311755a0f69910803b96d723bb386967..2b045078bc7e1c96aa31ab109847a95375d1c5dc 100644 (file)
@@ -41,10 +41,6 @@ uk_syscall_r_flock
 fhold
 fdrop
 fget
-ftruncate
-ftruncate64
-uk_syscall_e_ftruncate
-uk_syscall_r_ftruncate
 stat
 stat64
 uk_syscall_e_stat
@@ -168,10 +164,6 @@ uk_syscall_r_faccessat
 readlink
 uk_syscall_e_readlink
 uk_syscall_r_readlink
-fallocate
-fallocate64
-uk_syscall_e_fallocate
-uk_syscall_r_fallocate
 lseek
 lseek64
 uk_syscall_e_lseek
@@ -269,6 +261,8 @@ vfscore_writev
 vfscore_write
 vfscore_lseek
 vfscore_fsync
+vfscore_ftruncate
+vfscore_fallocate
 vfscore_fstat
 vfscore_fcntl
 vfscore_ioctl
index e9d775d90a0b230cfd00e0f64543dd85d7e31636..3b7766b53a874a1ead50e48e4e57042c6368b8de 100644 (file)
@@ -32,6 +32,9 @@ int vfscore_fstat(struct vfscore_file *fp, struct stat *st);
 
 int vfscore_fsync(struct vfscore_file *fp);
 
+int vfscore_ftruncate(struct vfscore_file *fp, off_t length);
+int vfscore_fallocate(struct vfscore_file *fp, int mode, off_t off, off_t len);
+
 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 9a68ad897fb00cff755265de5fabd1184a8e788c..4e72dbab6f99b3319ad4c26c52614d6cb3b58d1b 100644 (file)
@@ -2146,39 +2146,6 @@ UK_SYSCALL_R_DEFINE(int, truncate, const char*, pathname, off_t, length)
 
 LFS64(truncate);
 
-UK_TRACEPOINT(trace_vfs_ftruncate, "%d %#x", int, off_t);
-UK_TRACEPOINT(trace_vfs_ftruncate_ret, "");
-UK_TRACEPOINT(trace_vfs_ftruncate_err, "%d", int);
-
-UK_SYSCALL_R_DEFINE(int, ftruncate, int, fd, off_t, length)
-{
-       trace_vfs_ftruncate(fd, length);
-       struct vfscore_file *fp;
-       int error;
-
-       error = fget(fd, &fp);
-       if (error)
-               goto out_error;
-
-       error = sys_ftruncate(fp, length);
-       fdrop(fp);
-
-       if (error)
-               goto out_error;
-       trace_vfs_ftruncate_ret();
-       return 0;
-
-       out_error:
-       trace_vfs_ftruncate_err(error);
-       return -error;
-}
-
-#ifdef ftruncate64
-#undef ftruncate64
-#endif
-
-LFS64(ftruncate);
-
 UK_SYSCALL_DEFINE(ssize_t, readlink, const char *, pathname, char *, buf, size_t, bufsize)
 {
        struct task *t = main_task;
@@ -2209,39 +2176,6 @@ UK_SYSCALL_DEFINE(ssize_t, readlink, const char *, pathname, char *, buf, size_t
        return -1;
 }
 
-UK_TRACEPOINT(trace_vfs_fallocate, "%d %d %#x %#x", int, int, loff_t, loff_t);
-UK_TRACEPOINT(trace_vfs_fallocate_ret, "");
-UK_TRACEPOINT(trace_vfs_fallocate_err, "%d", int);
-
-UK_SYSCALL_R_DEFINE(int, fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
-{
-       struct vfscore_file *fp;
-       int error;
-
-       trace_vfs_fallocate(fd, mode, offset, len);
-       error = fget(fd, &fp);
-       if (error)
-               goto out_error;
-
-       error = sys_fallocate(fp, mode, offset, len);
-       fdrop(fp);
-
-       if (error)
-               goto out_error;
-       trace_vfs_fallocate_ret();
-       return 0;
-
-       out_error:
-       trace_vfs_fallocate_err(error);
-       return -error;
-}
-
-#ifdef fallocate64
-#undef fallocate64
-#endif
-
-LFS64(fallocate);
-
 UK_TRACEPOINT(trace_vfs_utimes, "\"%s\"", const char*);
 UK_TRACEPOINT(trace_vfs_utimes_ret, "");
 UK_TRACEPOINT(trace_vfs_utimes_err, "%d", int);
index 16e1784ed77fbc82bc11c520b899fb4ab48b8c13..e72df7f1dc0cc80ed5815a9c60c7db95e22d2930 100644 (file)
@@ -1186,7 +1186,7 @@ sys_truncate(char *path, off_t length)
 }
 
 int
-sys_ftruncate(struct vfscore_file *fp, off_t length)
+vfscore_ftruncate(struct vfscore_file *fp, off_t length)
 {
        struct vnode *vp;
        int error;
@@ -1508,7 +1508,7 @@ sys_futimens(int fd, const struct timespec times[2])
 }
 
 int
-sys_fallocate(struct vfscore_file *fp, int mode, off_t offset, off_t len)
+vfscore_fallocate(struct vfscore_file *fp, int mode, off_t offset, off_t len)
 {
        int error;
        struct vnode *vp;
index 2dcfdff0e4529aa7d7f984527da72f129e77a975..b726b20bb43bca3e2396b41c24e52670afeedff6 100644 (file)
@@ -415,20 +415,6 @@ int sys_fstatfs(struct vfscore_file *fp, struct statfs *buf);
  */
 int sys_truncate(char *path, off_t length);
 
-/**
- * Similar to the sys_truncate() function, but it takes a vfscore_file
- * instead of path.
- *
- * @param fp
- *     Pointer to the vfscore_file
- * @param length
- *     The new size (in bytes) of the file to which fp is referring to
- * @return
- *     - (0):  Completed successfully
- *     - (<0): Negative value with error code
- */
-int sys_ftruncate(struct vfscore_file *fp, off_t length);
-
 /**
  * Store at most bufsize bytes from the content to which the symlink
  * at path is pointing in the char array buf. The number of bytes written
@@ -508,32 +494,6 @@ int sys_utimensat(int dirfd, const char *pathname,
  */
 int sys_futimens(int fd, const struct timespec times[2]);
 
-/**
- * Manipulates the file space for the file referred by fd, starting
- * at offset and continuing for len bytes.
- *
- * @param fp
- *     Pointer to a vfscore_file structure
- * @param mode
- *     Specifies how to manipulates the space. The mode can have the
- *     the following values:
- *             * 0 - allocates len bytes starting from offset.
- *             * FALLOC_FL_KEEP_SIZE - the file size will not change even
- *                     if offset + len is greater than the file size.
- *             * FALLOC_FL_PUNCH_HOLE - deallocates len bytes starting at
- *                     offset and creates a hole in the file. This flag should
- *                     always come together with FALLOC_FL_KEEP_SIZE, otherwise
- *                     the sys_futimens call will fail.
- * @param offset
- *     Starting byte from which this operation will apply
- * @param len
- *     Number of bytes for which this operation will apply
- * @return
- *     - (0):  Completed successfully
- *     - (<0): Negative value with error code
- */
-int sys_fallocate(struct vfscore_file *fp, int mode, loff_t offset, loff_t len);
-
 /**
  * This function is not used at this point.
  */