未验证 提交 2aa1056f 编写于 作者: Z zmq810150896 提交者: GitHub

Add fops for dfs_v2 and rt_set_errno (#7910)

上级 325c3d2a
......@@ -164,7 +164,7 @@ static int epoll_poll(struct dfs_file *file, struct rt_pollreq *req)
fdlist = fdlist->next;
mask = epoll_get_event(fdlist, &fdlist->req);
if (mask & fdlist->epev.events)
if (mask & fdlist->revents)
{
events |= mask | POLLIN | EPOLLRDNORM;
break;
......@@ -221,7 +221,7 @@ static int epoll_rdlist_add(struct rt_fd_list *fdl, rt_uint32_t revents)
if (rdlist != RT_NULL)
{
rdlist->rdl_event = fdl;
rdlist->rdl_event->epev.events = fdl->epev.events & revents;
rdlist->rdl_event->epev.events = fdl->revents & revents;
rdlist->next = ep->rdlist->next;
rdlist->exclusive = 0;
ep->rdlist->next = rdlist;
......@@ -250,7 +250,7 @@ static int epoll_wqueue_callback(struct rt_wqueue_node *wait, void *key)
fdlist = rt_container_of(wait, struct rt_fd_list, wqn);
if (fdlist->epev.events)
if (fdlist->revents)
{
epoll_rdlist_add(fdlist, (rt_ubase_t)key);
}
......@@ -279,10 +279,10 @@ static void epoll_ctl_install(struct rt_fd_list *fdlist, struct rt_eventpoll *ep
{
rt_uint32_t mask = 0;
fdlist->req._key = fdlist->epev.events;
fdlist->req._key = fdlist->revents;
mask = epoll_get_event(fdlist, &fdlist->req);
if (mask & fdlist->epev.events)
if (mask & fdlist->revents)
{
epoll_rdlist_add(fdlist, mask);
}
......@@ -317,6 +317,10 @@ static int epoll_epf_init(int fd)
rt_mutex_init(&ep->lock, EPOLL_MUTEX_NAME, RT_IPC_FLAG_FIFO);
#ifdef RT_USING_DFS_V2
df->fops = &epoll_fops;
#endif
df->vnode = (struct dfs_vnode *)rt_malloc(sizeof(struct dfs_vnode));
if (df->vnode)
{
......@@ -353,13 +357,13 @@ static int epoll_epf_init(int fd)
static int epoll_do_create(int size)
{
rt_err_t ret = 0;
rt_err_t ret = -1;
int status;
int fd;
if (size < 0)
{
ret = -EINVAL;
rt_set_errno(EINVAL);
}
else
{
......@@ -371,12 +375,12 @@ static int epoll_do_create(int size)
if (status < 0)
{
fd_release(fd);
ret = status;
rt_set_errno(-status);
}
}
else
{
ret = fd;
rt_set_errno(-fd);
}
}
......@@ -518,23 +522,31 @@ static int epoll_do_ctl(int epfd, int op, int fd, struct epoll_event *event)
{
struct dfs_file *epdf;
struct rt_eventpoll *ep;
rt_err_t ret = -EINVAL;
rt_err_t ret = 0;
if (op & ~EFD_SHARED_EPOLL_TYPE)
return -EINVAL;
{
rt_set_errno(EINVAL);
return -1;
}
if ((epfd == fd) || (epfd < 0) || (fd < 0) || (event->data.fd != fd))
return -EINVAL;
{
rt_set_errno(EINVAL);
return -1;
}
if (!(event->events & EPOLLEXCLUSIVE_BITS))
return -EINVAL;
{
rt_set_errno(EINVAL);
return -1;
}
epdf = fd_get(epfd);
if (epdf->vnode->data)
{
ep = epdf->vnode->data;
ret = 0;
rt_mutex_take(&ep->lock, RT_WAITING_FOREVER);
......@@ -550,12 +562,18 @@ static int epoll_do_ctl(int epfd, int op, int fd, struct epoll_event *event)
ret = epoll_ctl_mod(epdf, event);
break;
default:
ret = -EINVAL;
rt_set_errno(EINVAL);
break;
}
}
rt_mutex_release(&ep->lock);
if (ret < 0)
{
rt_set_errno(-ret);
ret = -1;
}
rt_mutex_release(&ep->lock);
}
return ret;
}
......@@ -613,13 +631,13 @@ static int epoll_get_event(struct rt_fd_list *fl, rt_pollreq_t *req)
{
if (df->vnode->fops->poll)
{
req->_key = fl->epev.events | POLLERR | POLLHUP;
req->_key = fl->revents | POLLERR | POLLHUP;
mask = df->vnode->fops->poll(df, req);
if (mask < 0)
return mask;
}
mask &= fl->epev.events | EPOLLOUT | POLLERR;
mask &= fl->revents | EPOLLOUT | POLLERR;
}
}
......@@ -659,7 +677,8 @@ static int epoll_do(struct rt_eventpoll *ep, struct epoll_event *events, int max
if (rdlist->rdl_event->revents & EPOLLET)
{
rt_wqueue_remove(&rdlist->rdl_event->wqn);
epoll_get_event(rdlist->rdl_event, &rdlist->rdl_event->req);
mask = epoll_get_event(rdlist->rdl_event, &rdlist->rdl_event->req);
rdlist->rdl_event->epev.events = mask & rdlist->rdl_event->revents;
isfree = 1;
}
else
......@@ -729,7 +748,7 @@ static int epoll_do_wait(int epfd, struct epoll_event *events, int maxevents, in
struct rt_eventpoll *ep;
struct dfs_file *df;
lwp_sigset_t old_sig, new_sig;
rt_err_t ret = -EINVAL;
rt_err_t ret = 0;
if (ss)
{
......@@ -755,6 +774,12 @@ static int epoll_do_wait(int epfd, struct epoll_event *events, int maxevents, in
lwp_thread_signal_mask(rt_thread_self(), LWP_SIG_MASK_CMD_SET_MASK, &old_sig, RT_NULL);
}
if (ret < 0)
{
rt_set_errno(-ret);
ret = -1;
}
return ret;
}
......
......@@ -40,13 +40,13 @@ struct eventfd_ctx
#ifndef RT_USING_DFS_V2
static int eventfd_close(struct dfs_file *file);
static int eventfd_poll(struct dfs_file *file, struct rt_pollreq *req);
static int eventfd_read(struct dfs_file *file, void *buf, size_t count);
static int eventfd_write(struct dfs_file *file, const void *buf, size_t count);
static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count);
static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t count);
#else
static int eventfd_close(struct dfs_file *file);
static int eventfd_poll(struct dfs_file *file, struct rt_pollreq *req);
static int eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *pos);
static int eventfd_write(struct dfs_file *file, const void *buf, size_t count, off_t *pos);
static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *pos);
static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t count, off_t *pos);
#endif
static const struct dfs_file_ops eventfd_fops =
......@@ -76,7 +76,6 @@ static int eventfd_poll(struct dfs_file *file, struct rt_pollreq *req)
count = ctx->count;
rt_poll_add(&ctx->reader_queue, req);
rt_poll_add(&ctx->writer_queue, req);
if (count > 0)
events |= POLLIN;
......@@ -91,9 +90,9 @@ static int eventfd_poll(struct dfs_file *file, struct rt_pollreq *req)
}
#ifndef RT_USING_DFS_V2
static int eventfd_read(struct dfs_file *file, void *buf, size_t count)
static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count)
#else
static int eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *pos)
static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *pos)
#endif
{
struct eventfd_ctx *ctx = (struct eventfd_ctx *)file->vnode->data;
......@@ -107,7 +106,7 @@ static int eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *p
rt_mutex_take(&ctx->lock, RT_WAITING_FOREVER);
if (ctx->count == 0)
if (ctx->count <= 0)
{
if (file->flags & O_NONBLOCK)
{
......@@ -135,7 +134,6 @@ static int eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *p
}
ctx->count -= counter_num;
(*buffer) = counter_num;
rt_mutex_release(&ctx->lock);
......@@ -144,9 +142,9 @@ static int eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *p
}
#ifndef RT_USING_DFS_V2
static int eventfd_write(struct dfs_file *file, const void *buf, size_t count)
static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t count)
#else
static int eventfd_write(struct dfs_file *file, const void *buf, size_t count, off_t *pos)
static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t count, off_t *pos)
#endif
{
struct eventfd_ctx *ctx = (struct eventfd_ctx *)file->vnode->data;
......@@ -182,7 +180,6 @@ static int eventfd_write(struct dfs_file *file, const void *buf, size_t count, o
/* Release the mutex to avoid a deadlock */
rt_mutex_release(&ctx->lock);
rt_wqueue_wait(&ctx->writer_queue, 0, RT_WAITING_FOREVER);
rt_wqueue_wakeup(&ctx->reader_queue, (void *)POLLIN);
rt_mutex_take(&ctx->lock, RT_WAITING_FOREVER);
}
}
......@@ -232,6 +229,11 @@ static int rt_eventfd_create(struct dfs_file *df, unsigned int count, int flags)
rt_free(ctx);
ret = -ENOMEM;
}
#ifdef RT_USING_DFS_V2
df->fops = &eventfd_fops;
#endif
}
return ret;
......@@ -245,7 +247,10 @@ static int do_eventfd(unsigned int count, int flags)
rt_ssize_t ret = 0;
if (flags & ~EFD_FLAGS_SET)
return -RT_EINVAL;
{
rt_set_errno(EINVAL);
return -1;
}
fd = fd_new();
if (fd >= 0)
......@@ -257,12 +262,14 @@ static int do_eventfd(unsigned int count, int flags)
if (status < 0)
{
fd_release(fd);
ret = status;
rt_set_errno(-status);
ret = -1;
}
}
else
{
ret = fd;
rt_set_errno(-fd);
ret = -1;
}
return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册