]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-fd: Move heap-alloc ofiles out of fdtab
authorAndrei Tatar <andrei@unikraft.io>
Tue, 18 Mar 2025 16:55:34 +0000 (17:55 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Thu, 27 Mar 2025 17:23:26 +0000 (17:23 +0000)
This change moves the responsibility for allocating, managing the
lifetime of, and freeing heap-allocated open file descriptions out of
individual fdtab instances and into the main posix-fd API.
This allows libraries to create kernel-wide dynamic open file
descriptions independent of an fdtab.

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

lib/posix-fd/Config.uk
lib/posix-fd/include/uk/posix-fd.h
lib/posix-fdio/fd-shim.c
lib/posix-fdtab/Config.uk
lib/posix-fdtab/fdtab.c
lib/posix-fdtab/include/uk/posix-fdtab.h
lib/posix-poll/epoll.c
lib/posix-socket/socket.c
lib/posix-timerfd/timerfd.c

index 5f513f495c0372b55fdcc9d079ebb402b888d81c..89809e76691c72064b1f0b3b05324c606b3846e3 100644 (file)
@@ -1,5 +1,13 @@
-config LIBPOSIX_FD
+menuconfig LIBPOSIX_FD
        bool "posix-fd: Open file descriptions"
        select LIBUKFILE
        select LIBUKLOCK
        select LIBUKLOCK_MUTEX
+
+if LIBPOSIX_FD
+
+config LIBPOSIX_FD_HEAPOFD
+       bool "Heap-allocated open file descriptions"
+       select LIBUKALLOC
+
+endif
index a2ead23051375358704039b1d5e1da0ff2a2ed2e..7380e979d9a82fb342f083e53f89c93e78e34f4e 100644 (file)
 #include <uk/essentials.h>
 #include <uk/file.h>
 #include <uk/mutex.h>
+
+#if CONFIG_LIBPOSIX_FD_HEAPOFD
+#include <uk/alloc.h>
 #include <uk/refcount.h>
+#endif /* CONFIG_LIBPOSIX_FD_HEAPOFD */
 
 /* Open file description */
 struct uk_ofile {
        const struct uk_file *file;
-       unsigned int mode;
-       __atomic refcnt;
        size_t pos; /* Current file read/write offset position */
        struct uk_mutex lock; /* Lock for modifying open file state */
+       unsigned int mode;
+#if CONFIG_LIBPOSIX_FD_HEAPOFD
+       __atomic refcnt;
+#endif /* CONFIG_LIBPOSIX_FD_HEAPOFD */
        char name[]; /* Name of open file description; driver dependent */
        /* Filesystem-backed files should be named after the path they were
         * opened with. Pseudo-files should be named something descriptive.
@@ -44,44 +50,16 @@ static inline
 void uk_ofile_init(struct uk_ofile *of,
                   const struct uk_file *f, unsigned int mode)
 {
+#if CONFIG_LIBPOSIX_FD_HEAPOFD
        uk_refcount_init(&of->refcnt, 1);
+#endif /* CONFIG_LIBPOSIX_FD_HEAPOFD */
        uk_mutex_init(&of->lock);
        of->file = f;
-       of->mode = mode;
+       /* O_CLOEXEC is uniquely not a file description flag; ignore */
+       of->mode = mode & ~O_CLOEXEC;
        of->pos = 0;
 }
 
-/**
- * Acquire a reference on open file description `of`.
- *
- * @param of Open file description
- */
-static inline
-void uk_ofile_acquire(struct uk_ofile *of)
-{
-       uk_refcount_acquire(&of->refcnt);
-}
-
-/**
- * Release a reference held on open file description `of`.
- *
- * Do not call directly unless you are prepared to handle cleanup after the last
- * reference is dropped. Instead use the release function provided by the lib
- * where you got the open file reference from.
- *
- * @param of Open file description
- *
- * @return
- *  == 0: There are remaining references held
- *  != 0: The last reference has just been released
- */
-static inline
-int uk_ofile_release(struct uk_ofile *of)
-{
-       return uk_refcount_release(&of->refcnt);
-}
-
-
 /* Mode bits from fcntl.h that open files are interested in */
 #define UKFD_MODE_MASK \
        (O_WRONLY|O_RDWR|O_NONBLOCK|O_APPEND|O_DIRECT|O_SYNC|O_DSYNC)
@@ -115,4 +93,72 @@ const char *uk_ofile_name(const struct uk_ofile *of, const char *fallback)
 #define UKFD_POLLIN (EPOLLIN|EPOLLRDNORM|EPOLLRDBAND)
 #define UKFD_POLLOUT (EPOLLOUT|EPOLLWRNORM|EPOLLWRBAND)
 
+/* Heap-allocated open file descriptions */
+
+#if CONFIG_LIBPOSIX_FD_HEAPOFD
+
+/**
+ * Allocate heap memory for an open file description with name of length `len`
+ * and initialize its fields.
+ *
+ * The caller is responsible for populating the .name field.
+ *
+ * @return
+ *   != NULL: Success
+ *   == NULL: Failed to allocate memory
+ */
+static inline
+struct uk_ofile *uk_ofile_new(const struct uk_file *f, unsigned int mode,
+                             size_t len)
+{
+       struct uk_ofile *ret = uk_malloc(uk_alloc_get_default(),
+                                        UKFD_OFILE_SIZE(len));
+
+       if (unlikely(!ret))
+               return NULL;
+
+       if (len)
+               mode |= UKFD_O_NAMED;
+       uk_file_acquire(f);
+       uk_ofile_init(ret, f, mode);
+       return ret;
+}
+
+/**
+ * Free a heap-allocated open file description `of`.
+ */
+static inline
+void uk_ofile_free(struct uk_ofile *of)
+{
+       return uk_free(uk_alloc_get_default(), of);
+}
+
+/**
+ * Acquire a reference on open file description `of`.
+ *
+ * @param of Open file description
+ */
+static inline
+void uk_ofile_acquire(struct uk_ofile *of)
+{
+       uk_refcount_acquire(&of->refcnt);
+}
+
+/**
+ * Release a reference held on open file description `of`, freeing resources
+ * if needed.
+ */
+static inline
+void uk_ofile_release(struct uk_ofile *of)
+{
+       const int last_ref = uk_refcount_release(&of->refcnt);
+
+       if (unlikely(last_ref)) {
+               uk_file_release(of->file);
+               uk_ofile_free(of);
+       }
+}
+
+#endif /* CONFIG_LIBPOSIX_FD_HEAPOFD */
+
 #endif /* __UK_POSIX_FD_H__ */
index 687dfcb031925277ab6abf6608302dbdddcb328e..181fcec681a926a008e7d05eb9ba6006b16c64f9 100644 (file)
@@ -28,7 +28,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, preadv2, int, fd, const struct iovec *, iov,
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_preadv2(sf.ofile, iov, iovcnt, offset, flags);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -53,7 +53,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, preadv, int, fd, const struct iovec *, iov,
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_preadv(sf.ofile, iov, iovcnt, offset);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -85,7 +85,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, pread64, int, fd,
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_pread(sf.ofile, buf, count, offset);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -111,7 +111,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, readv, int, fd,
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_readv(sf.ofile, iov, iovcnt);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -133,7 +133,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, read, int, fd,
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_read(sf.ofile, buf, count);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -155,7 +155,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, pwritev2, int, fd, const struct iovec*, iov,
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_pwritev2(sf.ofile, iov, iovcnt, offset, flags);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -180,7 +180,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, pwritev, int, fd, const struct iovec*, iov,
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_pwritev(sf.ofile, iov, iovcnt, offset);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -207,7 +207,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, pwrite64, int, fd,
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_pwrite(sf.ofile, buf, count, offset);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -233,7 +233,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, writev, int, fd, const struct iovec *, iov,
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_writev(sf.ofile, iov, iovcnt);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -254,7 +254,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, write, int, fd, const void *, buf, size_t, count)
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_write(sf.ofile, buf, count);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -275,7 +275,7 @@ UK_SYSCALL_R_DEFINE(off_t, lseek, int, fd, off_t, offset, int, whence)
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_lseek(sf.ofile, offset, whence);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -307,7 +307,7 @@ UK_SYSCALL_R_DEFINE(int, fstat, int, fd, struct stat *, statbuf)
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_fstat(sf.ofile, statbuf);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -330,7 +330,7 @@ UK_SYSCALL_R_DEFINE(int, fchmod, int, fd, mode_t, mode)
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_fchmod(sf.ofile, mode);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -353,7 +353,7 @@ UK_SYSCALL_R_DEFINE(int, fchown, int, fd, uid_t, owner, gid_t, group)
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_fchown(sf.ofile, owner, group);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -378,7 +378,7 @@ UK_SYSCALL_R_DEFINE(int, fsync, int, fd)
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_fsync(sf.ofile);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -401,7 +401,7 @@ UK_SYSCALL_R_DEFINE(int, fdatasync, int, fd)
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_fdatasync(sf.ofile);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -425,7 +425,7 @@ UK_SYSCALL_R_DEFINE(int, ftruncate, int, fd, off_t, len)
        switch (uk_fdtab_shim_get(fd, &sf)) {
        case UK_SHIM_OFILE:
                r = uk_sys_ftruncate(sf.ofile, len);
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -448,7 +448,7 @@ UK_SYSCALL_R_DEFINE(int, fallocate, int, fd, int, mode, off_t, off, off_t, len)
        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);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -472,7 +472,7 @@ UK_SYSCALL_R_DEFINE(int, fadvise64,
        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);
+               uk_ofile_release(sf.ofile);
                break;
 #if CONFIG_LIBVFSCORE
        case UK_SHIM_LEGACY:
@@ -514,7 +514,7 @@ UK_LLSYSCALL_R_DEFINE(int, fcntl, int, fd,
                switch (uk_fdtab_shim_get(fd, &sf)) {
                case UK_SHIM_OFILE:
                        r = uk_sys_fcntl(sf.ofile, cmd, arg);
-                       uk_fdtab_ret(sf.ofile);
+                       uk_ofile_release(sf.ofile);
                        break;
 #if CONFIG_LIBVFSCORE
                case UK_SHIM_LEGACY:
@@ -587,7 +587,7 @@ UK_LLSYSCALL_R_DEFINE(int, ioctl, int, fd, unsigned int, request, void *, arg)
                switch (uk_fdtab_shim_get(fd, &sf)) {
                case UK_SHIM_OFILE:
                        r = uk_sys_ioctl(sf.ofile, request, arg);
-                       uk_fdtab_ret(sf.ofile);
+                       uk_ofile_release(sf.ofile);
                        break;
 #if CONFIG_LIBVFSCORE
                case UK_SHIM_LEGACY:
index 12116f7ddec5473a47796f0c2190f57f4d4b6fa7..49a806f7ae80e5072dea9da64a3b4c5218930eac 100644 (file)
@@ -3,6 +3,7 @@ menuconfig LIBPOSIX_FDTAB
        select LIBUKATOMIC
        select LIBUKFILE
        select LIBPOSIX_FD
+       select LIBPOSIX_FD_HEAPOFD
 
 if LIBPOSIX_FDTAB
        config LIBPOSIX_FDTAB_MAXFDS
index 6a59b96fc2fd8c9aac88cd10098f883b0dfde0c6..2e607546bd97bab065939dd445c08cb98e064708 100644 (file)
@@ -128,41 +128,6 @@ static inline struct fdval fdtab_decode(void *p)
        };
 }
 
-/* struct uk_ofile allocation & refcounting */
-static inline struct uk_ofile *ofile_new(struct uk_fdtab *tab,
-                                        const struct uk_file *f,
-                                        unsigned int mode,
-                                        size_t len)
-{
-       struct uk_ofile *of;
-
-       of = uk_malloc(tab->alloc, UKFD_OFILE_SIZE(len));
-       if (of) {
-               if (len)
-                       mode |= UKFD_O_NAMED;
-               uk_ofile_init(of, f, mode);
-       }
-       return of;
-}
-static inline void ofile_del(struct uk_fdtab *tab, struct uk_ofile *of)
-{
-       uk_free(tab->alloc, of);
-}
-
-static inline void ofile_acq(struct uk_ofile *of)
-{
-       uk_ofile_acquire(of);
-}
-static inline void ofile_rel(struct uk_fdtab *tab, struct uk_ofile *of)
-{
-       if (uk_ofile_release(of)) {
-               uk_file_release(of->file);
-               ofile_del(tab, of);
-       }
-}
-
-#if CONFIG_LIBPOSIX_FDTAB_LEGACY_SHIM
-
 static inline void file_acq(void *p, int flags __maybe_unused)
 {
 #if CONFIG_LIBVFSCORE
@@ -170,40 +135,21 @@ static inline void file_acq(void *p, int flags __maybe_unused)
                fhold((struct vfscore_file *)p);
        else
 #endif /* CONFIG_LIBVFSCORE */
-               ofile_acq((struct uk_ofile *)p);
+               uk_ofile_acquire((struct uk_ofile *)p);
 }
 
-static inline
-void file_rel(struct uk_fdtab *tab, void *p, int flags __maybe_unused)
+static inline void file_rel(void *p, int flags __maybe_unused)
 {
 #if CONFIG_LIBVFSCORE
        if (flags & UK_FDTAB_VFSCORE)
                fdrop((struct vfscore_file *)p);
        else
 #endif /* CONFIG_LIBVFSCORE */
-               ofile_rel(tab, (struct uk_ofile *)p);
+               uk_ofile_release((struct uk_ofile *)p);
 }
 
-#else /* !CONFIG_LIBPOSIX_FDTAB_LEGACY_SHIM */
-
-#define file_acq(p, f) ofile_acq((struct uk_ofile *)(p))
-#define file_rel(t, p, f) ofile_rel((t), (struct uk_ofile *)(p))
-
-#endif /* !CONFIG_LIBPOSIX_FDTAB_LEGACY_SHIM */
-
 /* Ops */
 
-struct uk_ofile *uk_fdtab_new_desc(const struct uk_file *f, unsigned int mode,
-                                  size_t len)
-{
-       struct uk_ofile *of;
-
-       of = ofile_new(active_fdtab, f, mode & ~O_CLOEXEC, len);
-       if (of)
-               uk_file_acquire(f);
-       return of;
-}
-
 int uk_fdtab_open_desc(struct uk_ofile *of, unsigned int mode)
 {
        int fd;
@@ -226,7 +172,7 @@ int uk_fdtab_open_named(const struct uk_file *f, unsigned int mode,
        if (!name)
                len = 0;
 
-       of = uk_fdtab_new_desc(f, mode, len);
+       of = uk_ofile_new(f, mode, len);
        if (unlikely(!of))
                return -ENOMEM;
        if (len) {
@@ -237,7 +183,7 @@ int uk_fdtab_open_named(const struct uk_file *f, unsigned int mode,
        /* Place the file in fdtab */
        fd = uk_fdtab_open_desc(of, mode);
        if (unlikely(fd < 0))
-               ofile_rel(active_fdtab, of);
+               uk_ofile_release(of);
        return fd;
 }
 
@@ -351,7 +297,7 @@ int uk_fdtab_shim_get(int fd, union uk_shim_file *out)
                {
                        struct uk_ofile *of = (struct uk_ofile *)v.p;
 
-                       ofile_acq(of);
+                       uk_ofile_acquire(of);
                        uk_fmap_critical_put(fmap, fd, p);
                        out->ofile = of;
                        return UK_SHIM_OFILE;
@@ -386,19 +332,13 @@ struct uk_ofile *uk_fdtab_get(int fd)
 #if CONFIG_LIBPOSIX_FDTAB_LEGACY_SHIM
        /* Report legacy files as not present if called through new API */
        if (v.p && v.flags & UK_FDTAB_VFSCORE) {
-               file_rel(active_fdtab, v.p, v.flags);
+               file_rel(v.p, v.flags);
                return NULL;
        }
 #endif /* CONFIG_LIBPOSIX_FDTAB_LEGACY_SHIM */
        return (struct uk_ofile *)v.p;
 }
 
-void uk_fdtab_ret(struct uk_ofile *of)
-{
-       UK_ASSERT(of);
-       ofile_rel(active_fdtab, of);
-}
-
 static void fdtab_cleanup(struct uk_fdtab *tab, int all)
 {
        struct uk_fmap *fmap = &tab->fmap;
@@ -414,7 +354,7 @@ static void fdtab_cleanup(struct uk_fdtab *tab, int all)
 
                                pp = uk_fmap_take(fmap, i);
                                UK_ASSERT(p == pp);
-                               file_rel(tab, v.p, v.flags);
+                               file_rel(v.p, v.flags);
                        }
                }
        }
@@ -574,7 +514,7 @@ int uk_sys_close(int fd)
        if (!p)
                return -EBADF;
        v = fdtab_decode(p);
-       file_rel(active_fdtab, v.p, v.flags);
+       file_rel(v.p, v.flags);
        return 0;
 }
 
@@ -606,7 +546,7 @@ int uk_sys_dup3(int oldfd, int newfd, int flags)
        if (prevp) {
                struct fdval prevv = fdtab_decode(prevp);
 
-               file_rel(active_fdtab, prevv.p, prevv.flags);
+               file_rel(prevv.p, prevv.flags);
        }
        return newfd;
 }
@@ -642,7 +582,7 @@ int uk_sys_dup_min(int oldfd, int min, int flags)
        newent = fdtab_encode(dup.p, dup.flags);
        fd = uk_fmap_put(&active_fdtab->fmap, newent, min);
        if (fd >= UK_FDTAB_SIZE) {
-               file_rel(active_fdtab, dup.p, dup.flags);
+               file_rel(dup.p, dup.flags);
                return -ENFILE;
        }
        return fd;
index 3cc064e906330984bbec498c579083df43fa6304..44b317a4bff44c4c7c679a5aa0e28a10478b359d 100644 (file)
@@ -49,37 +49,12 @@ int uk_fdtab_open(const struct uk_file *f, unsigned int mode);
 int uk_fdtab_open_named(const struct uk_file *f, unsigned int mode,
                        const char *name, size_t len);
 
-/**
- * Create a new open file description for file `f` with `mode` and optional
- * name, without associating it with a file descriptor.
- *
- * The caller is responsible for filling in the .name field of returned open
- * file descriptions before use.
- * The returned open file description must be released with `uk_fdtab_ret` when
- * caller is finished with it.
- * Open file descriptions created in this way may be used as-is, or later
- * associated with an fd with `uk_fdtab_open_desc`.
- *
- * @param f
- *   File to open
- * @param mode
- *   Mode flags to apply on the new open file description
- * @param len
- *   If > 0, allocate space for a file name of length `len` (excluding NUL)
- * @return
- *   The new open file description, or NULL if no memory is available
- */
-struct uk_ofile *uk_fdtab_new_desc(const struct uk_file *f, unsigned int mode,
-                                  size_t len);
-
 /**
  * Associate a file descriptor to an existing open file description.
  *
  * This call consumes the `of` reference. The caller MUST NOT use or release
  * `of` after this call returns successfully.
  * In case of error, the reference is left untouched.
- * The open file description must have been opened by this fdtab, through either
- * `uk_fdtab_new_desc` or `uk_fdtab_open*`.
  *
  * @param of
  *   Open file description to associate fd with
@@ -103,14 +78,6 @@ int uk_fdtab_open_desc(struct uk_ofile *of, unsigned int mode);
  */
 struct uk_ofile *uk_fdtab_get(int fd);
 
-/**
- * Returns a reference to an open file when done using it.
- *
- * @param of
- *   Reference to the open file description to be returned
- */
-void uk_fdtab_ret(struct uk_ofile *of);
-
 /**
  * Sets flags on file descriptor. Currently only supports O_CLOEXEC.
  *
index 71fbf96162682d1b3d534c4972dcd505ed5d860b..ae1da36f7137346b63652433c9de1e6e25ccf07d 100644 (file)
@@ -551,7 +551,7 @@ int uk_sys_epoll_ctl(const struct uk_file *epf, int op, int fd,
                fdrop(sf.vfile);
        else
 #endif /* CONFIG_LIBVFSCORE */
-               uk_fdtab_ret(sf.ofile);
+               uk_ofile_release(sf.ofile);
 
        return ret;
 }
@@ -676,7 +676,7 @@ UK_SYSCALL_R_DEFINE(int, epoll_ctl, int, epfd, int, op, int, fd,
        if (unlikely(!of))
                return -EBADF;
        r = uk_sys_epoll_ctl(of->file, op, fd, event);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
        return r;
 }
 
@@ -691,7 +691,7 @@ UK_SYSCALL_R_DEFINE(int, epoll_pwait2, int, epfd, struct epoll_event *, events,
                return -EBADF;
        r = uk_sys_epoll_pwait2(of->file, events, maxevents,
                                timeout, sigmask, sigsetsize);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
        return r;
 }
 
@@ -710,7 +710,7 @@ UK_LLSYSCALL_R_DEFINE(int, epoll_pwait, int, epfd, struct epoll_event *, events,
                return -EBADF;
        r = uk_sys_epoll_pwait(of->file, events, maxevents,
                               timeout, sigmask, sigsetsize);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
        return r;
 }
 
@@ -724,6 +724,6 @@ UK_SYSCALL_R_DEFINE(int, epoll_wait, int, epfd, struct epoll_event *, events,
                return -EBADF;
        r = uk_sys_epoll_pwait(of->file, events, maxevents,
                               timeout, NULL, 0);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
        return r;
 }
index 5ba8be91193fe89336395ecc24a4a3dde97ee011..b07149bc27ff216c88fa441e23d75dcf952e73e8 100644 (file)
@@ -93,7 +93,7 @@ static struct uk_ofile *socketfd_get(int fd)
        if (unlikely(!of))
                return ERR2PTR(-EBADF);
        if (unlikely(of->file->vol != POSIX_SOCKET_VOLID)) {
-               uk_fdtab_ret(of);
+               uk_ofile_release(of);
                return ERR2PTR(-ENOTSOCK);
        }
        return of;
@@ -420,7 +420,7 @@ int do_accept4(int sock, struct sockaddr *addr, socklen_t *addr_len,
        mode = of->mode;
        ret = uk_sys_accept(of->file, _SHOULD_BLOCK(mode),
                            addr, addr_len, flags);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret >= 0)
@@ -468,7 +468,7 @@ UK_SYSCALL_R_DEFINE(int, bind, int, sock, const struct sockaddr *, addr,
        uk_file_wlock(of->file);
        ret = posix_socket_bind(of->file, addr, addr_len);
        uk_file_wunlock(of->file);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret) {
@@ -511,7 +511,7 @@ UK_SYSCALL_R_DEFINE(int, shutdown, int, sock, int, how)
        uk_file_wlock(of->file);
        ret = posix_socket_shutdown(of->file, how);
        uk_file_wunlock(of->file);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret)
@@ -544,7 +544,7 @@ UK_SYSCALL_R_DEFINE(int, getpeername, int, sock,
        uk_file_rlock(of->file);
        ret = posix_socket_getpeername(of->file, addr, addr_len);
        uk_file_runlock(of->file);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret)
@@ -577,7 +577,7 @@ UK_SYSCALL_R_DEFINE(int, getsockname, int, sock,
        uk_file_rlock(of->file);
        ret = posix_socket_getsockname(of->file, addr, addr_len);
        uk_file_runlock(of->file);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret)
@@ -609,7 +609,7 @@ UK_SYSCALL_R_DEFINE(int, getsockopt, int, sock, int, level, int, optname,
        uk_file_rlock(of->file);
        ret = posix_socket_getsockopt(of->file, level, optname, optval, optlen);
        uk_file_runlock(of->file);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret)
@@ -644,7 +644,7 @@ UK_SYSCALL_R_DEFINE(int, setsockopt, int, sock, int, level, int, optname,
        uk_file_rlock(of->file);
        ret = posix_socket_setsockopt(of->file, level, optname, optval, optlen);
        uk_file_runlock(of->file);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret)
@@ -691,7 +691,7 @@ UK_SYSCALL_R_DEFINE(int, connect, int, sock, const struct sockaddr *, addr,
                                        &ret, &_opsz);
                uk_file_runlock(of->file);
        }
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret && ret != -EINPROGRESS) {
@@ -727,7 +727,7 @@ UK_SYSCALL_R_DEFINE(int, listen, int, sock, int, backlog)
        uk_file_wlock(of->file);
        ret = posix_socket_listen(of->file, backlog);
        uk_file_wunlock(of->file);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret) {
@@ -776,7 +776,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, recvfrom, int, sock, void *, buf, size_t, len,
                        break;
                (void)uk_file_poll(of->file, UKFD_POLLIN);
        }
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret < 0 && ret != -EAGAIN)
@@ -825,7 +825,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, recvmsg, int, sock, struct msghdr *, msg,
                        break;
                (void)uk_file_poll(of->file, UKFD_POLLIN);
        }
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret < 0 && ret != -EAGAIN)
@@ -867,7 +867,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, sendmsg, int, sock, const struct msghdr *, msg,
                        break;
                (void)uk_file_poll(of->file, UKFD_POLLOUT);
        }
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret < 0 && ret != -EAGAIN)
@@ -912,7 +912,7 @@ UK_SYSCALL_R_DEFINE(ssize_t, sendto, int, sock, const void *, buf, size_t, len,
                        break;
                (void)uk_file_poll(of->file, UKFD_POLLOUT);
        }
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
 
 out:
        if (ret < 0 && ret != -EAGAIN)
index b9b2fb6610002b7013c6525ed07324ca350772ee..e6108fd70e9c96a4847516cf4d3f8821272e2e72 100644 (file)
@@ -410,7 +410,7 @@ UK_SYSCALL_R_DEFINE(int, timerfd_settime, int, fd, int, flags,
        if (unlikely(!of))
                return -EBADF;
        r = uk_sys_timerfd_settime(of->file, flags, new_value, old_value);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
        return r;
 }
 
@@ -427,7 +427,7 @@ UK_SYSCALL_R_DEFINE(int, timerfd_gettime, int, fd,
        if (unlikely(!of))
                return -EBADF;
        r = uk_sys_timerfd_gettime(of->file, curr_value);
-       uk_fdtab_ret(of);
+       uk_ofile_release(of);
        return r;
 }
 #endif /* CONFIG_LIBPOSIX_FDTAB */