fs/vfs: Add file descriptor based timers support

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko
2021-12-17 02:20:26 +02:00
committed by Xiang Xiao
parent 187d9e58c9
commit d445282566
15 changed files with 1005 additions and 63 deletions
+1 -29
View File
@@ -85,35 +85,7 @@ config SENDFILE_BUFSIZE
---help---
Size of the I/O buffer to allocate in sendfile(). Default: 512b
config EVENT_FD
bool "EventFD"
default n
---help---
Create a file descriptor for event notification
if EVENT_FD
config EVENT_FD_VFS_PATH
string "Path to eventfd storage"
default "/var/event"
---help---
The path to where eventfd will exist in the VFS namespace.
config EVENT_FD_POLL
bool "EventFD poll support"
default y
---help---
Poll support for file descriptor based events
config EVENT_FD_NPOLLWAITERS
int "Number of eventFD poll waiters"
default 2
depends on EVENT_FD_POLL
---help---
Maximum number of threads that can be waiting on poll()
endif # EVENT_FD
source "fs/vfs/Kconfig"
source "fs/aio/Kconfig"
source "fs/semaphore/Kconfig"
source "fs/mqueue/Kconfig"
+1
View File
@@ -61,6 +61,7 @@ include rpmsgfs/Make.defs
endif
CFLAGS += ${shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)fs}
CFLAGS += ${shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)sched}
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
+2 -3
View File
@@ -70,7 +70,7 @@ int closedir(FAR DIR *dirp)
if (!idir)
{
ret = EBADF;
ret = -EBADF;
goto errout;
}
@@ -107,7 +107,6 @@ int closedir(FAR DIR *dirp)
ret = inode->u.i_mops->closedir(inode, idir);
if (ret < 0)
{
ret = -ret;
goto errout_with_inode;
}
}
@@ -142,6 +141,6 @@ errout_with_inode:
#endif
errout:
set_errno(ret);
set_errno(-ret);
return ERROR;
}
+6 -7
View File
@@ -71,7 +71,7 @@ static inline int open_mountpoint(FAR struct inode *inode,
if (!inode->u.i_mops || !inode->u.i_mops->opendir)
{
return ENOSYS;
return -ENOSYS;
}
/* Take reference to the mountpoint inode. Note that we do not use
@@ -98,7 +98,7 @@ static inline int open_mountpoint(FAR struct inode *inode,
/* Negate the error value so that it can be used to set errno */
return -ret;
return ret;
}
return OK;
@@ -227,7 +227,6 @@ FAR DIR *opendir(FAR const char *path)
ret = inode_semtake();
if (ret < 0)
{
ret = -ret;
goto errout;
}
@@ -249,7 +248,7 @@ FAR DIR *opendir(FAR const char *path)
{
/* Inode for 'path' does not exist. */
ret = ENOTDIR;
ret = -ENOTDIR;
goto errout_with_semaphore;
}
@@ -262,7 +261,7 @@ FAR DIR *opendir(FAR const char *path)
{
/* Insufficient memory to complete the operation. */
ret = ENOMEM;
ret = -ENOMEM;
goto errout_with_semaphore;
}
@@ -315,7 +314,7 @@ FAR DIR *opendir(FAR const char *path)
}
else
{
ret = ENOTDIR;
ret = -ENOTDIR;
goto errout_with_direntry;
}
}
@@ -334,6 +333,6 @@ errout_with_semaphore:
inode_semgive();
errout:
set_errno(ret);
set_errno(-ret);
return NULL;
}
+3 -7
View File
@@ -181,7 +181,7 @@ FAR struct dirent *readdir(DIR *dirp)
if (!idir)
{
ret = EBADF;
ret = -EBADF;
goto errout;
}
@@ -215,7 +215,7 @@ FAR struct dirent *readdir(DIR *dirp)
if (!inode->u.i_mops || !inode->u.i_mops->readdir)
{
ret = EACCES;
ret = -EACCES;
goto errout;
}
@@ -239,10 +239,6 @@ FAR struct dirent *readdir(DIR *dirp)
{
ret = OK;
}
else
{
ret = -ret;
}
goto errout;
}
@@ -253,6 +249,6 @@ FAR struct dirent *readdir(DIR *dirp)
return &idir->fd_dir;
errout:
set_errno(ret);
set_errno(-ret);
return NULL;
}
+62
View File
@@ -0,0 +1,62 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config EVENT_FD
bool "EventFD"
default n
---help---
Create a file descriptor for event notification
if EVENT_FD
config EVENT_FD_VFS_PATH
string "Path to eventfd storage"
default "/var/event"
---help---
The path to where eventfd will exist in the VFS namespace.
config EVENT_FD_POLL
bool "EventFD poll support"
default y
---help---
Poll support for file descriptor based events
config EVENT_FD_NPOLLWAITERS
int "Number of eventFD poll waiters"
default 2
depends on EVENT_FD_POLL
---help---
Maximum number of threads that can be waiting on poll()
endif # EVENT_FD
config TIMER_FD
bool "TimerFD"
default n
---help---
Create a file descriptor for timer notification
if TIMER_FD
config TIMER_FD_VFS_PATH
string "Path to timerfd storage"
default "/var/timer"
---help---
The path to where timerfd will exist in the VFS namespace.
config TIMER_FD_POLL
bool "TimerFD poll support"
default y
---help---
Poll support for file descriptor based timers
config TIMER_FD_NPOLLWAITERS
int "Number of timerFD poll waiters"
default 2
depends on TIMER_FD_POLL
---help---
Maximum number of threads that can be waiting on poll()
endif # TIMER_FD
+6
View File
@@ -48,6 +48,12 @@ ifeq ($(CONFIG_EVENT_FD),y)
CSRCS += fs_eventfd.c
endif
# Support for timerfd
ifeq ($(CONFIG_TIMER_FD),y)
CSRCS += fs_timerfd.c
endif
# Include vfs build support
DEPPATH += --dep-path vfs
+9 -10
View File
@@ -226,7 +226,7 @@ static int eventfd_do_close(FAR struct file *filep)
FAR struct inode *inode = filep->f_inode;
FAR struct eventfd_priv_s *priv = inode->i_private;
/* devpath: EVENT_FD_VFS_PATH + /efd (4) + %d (10) + null char (1) */
/* devpath: EVENT_FD_VFS_PATH + /efd (4) + %u (10) + null char (1) */
char devpath[sizeof(CONFIG_EVENT_FD_VFS_PATH) + 4 + 10 + 1];
@@ -256,7 +256,7 @@ static int eventfd_do_close(FAR struct file *filep)
/* Re-create the path to the driver. */
finfo("destroy\n");
sprintf(devpath, CONFIG_EVENT_FD_VFS_PATH "/efd%d", priv->minor);
sprintf(devpath, CONFIG_EVENT_FD_VFS_PATH "/efd%u", priv->minor);
/* Will be unregistered later after close is done */
@@ -501,7 +501,7 @@ static int eventfd_do_poll(FAR struct file *filep, FAR struct pollfd *fds,
*slot = NULL;
fds->priv = NULL;
goto errout;
goto out;
}
/* This is a request to set up the poll. Find an available
@@ -526,7 +526,7 @@ static int eventfd_do_poll(FAR struct file *filep, FAR struct pollfd *fds,
{
fds->priv = NULL;
ret = -EBUSY;
goto errout;
goto out;
}
/* Notify the POLLOUT event if the pipe is not full, but only if
@@ -551,7 +551,7 @@ static int eventfd_do_poll(FAR struct file *filep, FAR struct pollfd *fds,
eventfd_pollnotify(dev, eventset);
}
errout:
out:
nxsem_post(&dev->exclsem);
return ret;
}
@@ -567,7 +567,7 @@ int eventfd(unsigned int count, int flags)
int new_fd;
FAR struct eventfd_priv_s *new_dev;
/* devpath: EVENT_FD_VFS_PATH + /efd (4) + size_t (10) + null char (1) */
/* devpath: EVENT_FD_VFS_PATH + /efd (4) + %u (10) + null char (1) */
char devpath[sizeof(CONFIG_EVENT_FD_VFS_PATH) + 4 + 10 + 1];
@@ -578,7 +578,7 @@ int eventfd(unsigned int count, int flags)
{
/* Failed to allocate new device */
ret = ENOMEM;
ret = -ENOMEM;
goto exit_set_errno;
}
@@ -599,7 +599,6 @@ int eventfd(unsigned int count, int flags)
if (ret < 0)
{
ferr("Failed to register new device %s: %d\n", devpath, ret);
ret = -ret;
goto exit_release_minor;
}
@@ -614,7 +613,7 @@ int eventfd(unsigned int count, int flags)
if (new_fd < 0)
{
ret = -new_fd;
ret = new_fd;
goto exit_unregister_driver;
}
@@ -626,6 +625,6 @@ exit_release_minor:
eventfd_release_minor(new_dev->minor);
eventfd_destroy(new_dev);
exit_set_errno:
set_errno(ret);
set_errno(-ret);
return ERROR;
}
+3 -5
View File
@@ -80,13 +80,13 @@ int statfs(FAR const char *path, FAR struct statfs *buf)
if (path == NULL || buf == NULL)
{
ret = EFAULT;
ret = -EFAULT;
goto errout;
}
if (*path == '\0')
{
ret = ENOENT;
ret = -ENOENT;
goto errout;
}
@@ -101,7 +101,6 @@ int statfs(FAR const char *path, FAR struct statfs *buf)
* mountpoint that includes in this path.
*/
ret = -ret;
goto errout_with_search;
}
@@ -140,7 +139,6 @@ int statfs(FAR const char *path, FAR struct statfs *buf)
if (ret < 0)
{
ret = -ret;
goto errout_with_inode;
}
@@ -159,6 +157,6 @@ errout_with_search:
RELEASE_SEARCH(&desc);
errout:
set_errno(ret);
set_errno(-ret);
return ERROR;
}
+822
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -90,7 +90,7 @@ extern "C"
* Name: wd_start
*
* Description:
* This function adds a watchdog timer to the actuve timer queue. The
* This function adds a watchdog timer to the active timer queue. The
* specified watchdog function at 'wdentry' will be called from the
* interrupt level after the specified number of ticks has elapsed.
* Watchdog timers may be started from the interrupt level.
+5
View File
@@ -218,6 +218,11 @@ SYSCALL_LOOKUP(pwrite, 4)
#ifdef CONFIG_EVENT_FD
SYSCALL_LOOKUP(eventfd, 2)
#endif
#ifdef CONFIG_TIMER_FD
SYSCALL_LOOKUP(timerfd_create, 2)
SYSCALL_LOOKUP(timerfd_settime, 4)
SYSCALL_LOOKUP(timerfd_gettime, 2)
#endif
#ifdef CONFIG_SERIAL_TERMIOS
SYSCALL_LOOKUP(tcdrain, 1)
#endif
+80
View File
@@ -0,0 +1,80 @@
/****************************************************************************
* include/sys/timerfd.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_SYS_TIMERFD_H
#define __INCLUDE_SYS_TIMERFD_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
#include <fcntl.h>
#include <time.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define TFD_NONBLOCK O_NONBLOCK
#define TFD_CLOEXEC O_CLOEXEC
#define TFD_TIMER_ABSTIME TIMER_ABSTIME
/****************************************************************************
* Public Type Declarations
****************************************************************************/
/* Type for timer counter */
/* Type for event counter */
#ifdef __INT64_DEFINED
typedef uint64_t timerfd_t;
#else
typedef uint32_t timerfd_t;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
int timerfd_create(int clockid, int flags);
int timerfd_settime(int fd, int flags,
FAR const struct itimerspec *new_value,
FAR struct itimerspec *old_value);
int timerfd_gettime(int fd, FAR struct itimerspec *curr_value);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __INCLUDE_SYS_TIMERFD_H */
+1 -1
View File
@@ -173,7 +173,7 @@ ssize_t getdelim(FAR char **lineptr, size_t *n, int delimiter,
newbuffer = (FAR char *)lib_realloc(*lineptr, bufsize);
if (newbuffer == NULL)
{
ret = -ENOMEM;
ret = ENOMEM;
goto errout;
}
+3
View File
@@ -184,6 +184,9 @@
"timer_getoverrun","time.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","int","timer_t"
"timer_gettime","time.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","int","timer_t","FAR struct itimerspec *"
"timer_settime","time.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","int","timer_t","int","FAR const struct itimerspec *","FAR struct itimerspec *"
"timerfd_create","sys/timerfd.h","defined(CONFIG_TIMER_FD)","int","int","int"
"timerfd_gettime","sys/timerfd.h","defined(CONFIG_TIMER_FD)","int","int","FAR struct itimerspec *"
"timerfd_settime","sys/timerfd.h","defined(CONFIG_TIMER_FD)","int","int","int","FAR const struct itimerspec *","FAR const struct itimerspec *"
"umount2","sys/mount.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *","unsigned int"
"unlink","unistd.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *"
"unsetenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *"
1 _exit unistd.h noreturn int
184 timer_getoverrun time.h !defined(CONFIG_DISABLE_POSIX_TIMERS) int timer_t
185 timer_gettime time.h !defined(CONFIG_DISABLE_POSIX_TIMERS) int timer_t
186 timer_settime time.h !defined(CONFIG_DISABLE_POSIX_TIMERS) int timer_t
187 timerfd_create sys/timerfd.h defined(CONFIG_TIMER_FD) int int
188 timerfd_gettime sys/timerfd.h defined(CONFIG_TIMER_FD) int int
189 timerfd_settime sys/timerfd.h defined(CONFIG_TIMER_FD) int int
190 umount2 sys/mount.h !defined(CONFIG_DISABLE_MOUNTPOINT) int FAR const char *
191 unlink unistd.h !defined(CONFIG_DISABLE_MOUNTPOINT) int FAR const char *
192 unsetenv stdlib.h !defined(CONFIG_DISABLE_ENVIRON) int FAR const char *