fix: 把内核恢复成 GitHub 原版
This commit is contained in:
@@ -1,108 +1,108 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/file.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/namei.h>
|
||||
#include <linux/io_uring.h>
|
||||
|
||||
#include <uapi/linux/fadvise.h>
|
||||
#include <uapi/linux/io_uring.h>
|
||||
|
||||
#include "io_uring.h"
|
||||
#include "advise.h"
|
||||
|
||||
struct io_fadvise {
|
||||
struct file *file;
|
||||
u64 offset;
|
||||
u64 len;
|
||||
u32 advice;
|
||||
};
|
||||
|
||||
struct io_madvise {
|
||||
struct file *file;
|
||||
u64 addr;
|
||||
u64 len;
|
||||
u32 advice;
|
||||
};
|
||||
|
||||
int io_madvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
#if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU)
|
||||
struct io_madvise *ma = io_kiocb_to_cmd(req, struct io_madvise);
|
||||
|
||||
if (sqe->buf_index || sqe->splice_fd_in)
|
||||
return -EINVAL;
|
||||
|
||||
ma->addr = READ_ONCE(sqe->addr);
|
||||
ma->len = READ_ONCE(sqe->off);
|
||||
if (!ma->len)
|
||||
ma->len = READ_ONCE(sqe->len);
|
||||
ma->advice = READ_ONCE(sqe->fadvise_advice);
|
||||
req->flags |= REQ_F_FORCE_ASYNC;
|
||||
return 0;
|
||||
#else
|
||||
return -EOPNOTSUPP;
|
||||
#endif
|
||||
}
|
||||
|
||||
int io_madvise(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
#if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU)
|
||||
struct io_madvise *ma = io_kiocb_to_cmd(req, struct io_madvise);
|
||||
int ret;
|
||||
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
|
||||
|
||||
ret = do_madvise(current->mm, ma->addr, ma->len, ma->advice);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
#else
|
||||
return -EOPNOTSUPP;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool io_fadvise_force_async(struct io_fadvise *fa)
|
||||
{
|
||||
switch (fa->advice) {
|
||||
case POSIX_FADV_NORMAL:
|
||||
case POSIX_FADV_RANDOM:
|
||||
case POSIX_FADV_SEQUENTIAL:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
struct io_fadvise *fa = io_kiocb_to_cmd(req, struct io_fadvise);
|
||||
|
||||
if (sqe->buf_index || sqe->splice_fd_in)
|
||||
return -EINVAL;
|
||||
|
||||
fa->offset = READ_ONCE(sqe->off);
|
||||
fa->len = READ_ONCE(sqe->addr);
|
||||
if (!fa->len)
|
||||
fa->len = READ_ONCE(sqe->len);
|
||||
fa->advice = READ_ONCE(sqe->fadvise_advice);
|
||||
if (io_fadvise_force_async(fa))
|
||||
req->flags |= REQ_F_FORCE_ASYNC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int io_fadvise(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
struct io_fadvise *fa = io_kiocb_to_cmd(req, struct io_fadvise);
|
||||
int ret;
|
||||
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK && io_fadvise_force_async(fa));
|
||||
|
||||
ret = vfs_fadvise(req->file, fa->offset, fa->len, fa->advice);
|
||||
if (ret < 0)
|
||||
req_set_fail(req);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
}
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/file.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/namei.h>
|
||||
#include <linux/io_uring.h>
|
||||
|
||||
#include <uapi/linux/fadvise.h>
|
||||
#include <uapi/linux/io_uring.h>
|
||||
|
||||
#include "io_uring.h"
|
||||
#include "advise.h"
|
||||
|
||||
struct io_fadvise {
|
||||
struct file *file;
|
||||
u64 offset;
|
||||
u64 len;
|
||||
u32 advice;
|
||||
};
|
||||
|
||||
struct io_madvise {
|
||||
struct file *file;
|
||||
u64 addr;
|
||||
u64 len;
|
||||
u32 advice;
|
||||
};
|
||||
|
||||
int io_madvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
#if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU)
|
||||
struct io_madvise *ma = io_kiocb_to_cmd(req, struct io_madvise);
|
||||
|
||||
if (sqe->buf_index || sqe->splice_fd_in)
|
||||
return -EINVAL;
|
||||
|
||||
ma->addr = READ_ONCE(sqe->addr);
|
||||
ma->len = READ_ONCE(sqe->off);
|
||||
if (!ma->len)
|
||||
ma->len = READ_ONCE(sqe->len);
|
||||
ma->advice = READ_ONCE(sqe->fadvise_advice);
|
||||
req->flags |= REQ_F_FORCE_ASYNC;
|
||||
return 0;
|
||||
#else
|
||||
return -EOPNOTSUPP;
|
||||
#endif
|
||||
}
|
||||
|
||||
int io_madvise(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
#if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU)
|
||||
struct io_madvise *ma = io_kiocb_to_cmd(req, struct io_madvise);
|
||||
int ret;
|
||||
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
|
||||
|
||||
ret = do_madvise(current->mm, ma->addr, ma->len, ma->advice);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
#else
|
||||
return -EOPNOTSUPP;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool io_fadvise_force_async(struct io_fadvise *fa)
|
||||
{
|
||||
switch (fa->advice) {
|
||||
case POSIX_FADV_NORMAL:
|
||||
case POSIX_FADV_RANDOM:
|
||||
case POSIX_FADV_SEQUENTIAL:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
struct io_fadvise *fa = io_kiocb_to_cmd(req, struct io_fadvise);
|
||||
|
||||
if (sqe->buf_index || sqe->splice_fd_in)
|
||||
return -EINVAL;
|
||||
|
||||
fa->offset = READ_ONCE(sqe->off);
|
||||
fa->len = READ_ONCE(sqe->addr);
|
||||
if (!fa->len)
|
||||
fa->len = READ_ONCE(sqe->len);
|
||||
fa->advice = READ_ONCE(sqe->fadvise_advice);
|
||||
if (io_fadvise_force_async(fa))
|
||||
req->flags |= REQ_F_FORCE_ASYNC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int io_fadvise(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
struct io_fadvise *fa = io_kiocb_to_cmd(req, struct io_fadvise);
|
||||
int ret;
|
||||
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK && io_fadvise_force_async(fa));
|
||||
|
||||
ret = vfs_fadvise(req->file, fa->offset, fa->len, fa->advice);
|
||||
if (ret < 0)
|
||||
req_set_fail(req);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
}
|
||||
|
||||
@@ -1,119 +1,119 @@
|
||||
#ifndef INTERNAL_IO_SLIST_H
|
||||
#define INTERNAL_IO_SLIST_H
|
||||
|
||||
#include <linux/io_uring_types.h>
|
||||
|
||||
#define __wq_list_for_each(pos, head) \
|
||||
for (pos = (head)->first; pos; pos = (pos)->next)
|
||||
|
||||
#define wq_list_for_each(pos, prv, head) \
|
||||
for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
|
||||
|
||||
#define wq_list_for_each_resume(pos, prv) \
|
||||
for (; pos; prv = pos, pos = (pos)->next)
|
||||
|
||||
#define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
|
||||
|
||||
#define INIT_WQ_LIST(list) do { \
|
||||
(list)->first = NULL; \
|
||||
} while (0)
|
||||
|
||||
static inline void wq_list_add_after(struct io_wq_work_node *node,
|
||||
struct io_wq_work_node *pos,
|
||||
struct io_wq_work_list *list)
|
||||
{
|
||||
struct io_wq_work_node *next = pos->next;
|
||||
|
||||
pos->next = node;
|
||||
node->next = next;
|
||||
if (!next)
|
||||
list->last = node;
|
||||
}
|
||||
|
||||
static inline void wq_list_add_tail(struct io_wq_work_node *node,
|
||||
struct io_wq_work_list *list)
|
||||
{
|
||||
node->next = NULL;
|
||||
if (!list->first) {
|
||||
list->last = node;
|
||||
WRITE_ONCE(list->first, node);
|
||||
} else {
|
||||
list->last->next = node;
|
||||
list->last = node;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void wq_list_add_head(struct io_wq_work_node *node,
|
||||
struct io_wq_work_list *list)
|
||||
{
|
||||
node->next = list->first;
|
||||
if (!node->next)
|
||||
list->last = node;
|
||||
WRITE_ONCE(list->first, node);
|
||||
}
|
||||
|
||||
static inline void wq_list_cut(struct io_wq_work_list *list,
|
||||
struct io_wq_work_node *last,
|
||||
struct io_wq_work_node *prev)
|
||||
{
|
||||
/* first in the list, if prev==NULL */
|
||||
if (!prev)
|
||||
WRITE_ONCE(list->first, last->next);
|
||||
else
|
||||
prev->next = last->next;
|
||||
|
||||
if (last == list->last)
|
||||
list->last = prev;
|
||||
last->next = NULL;
|
||||
}
|
||||
|
||||
static inline void __wq_list_splice(struct io_wq_work_list *list,
|
||||
struct io_wq_work_node *to)
|
||||
{
|
||||
list->last->next = to->next;
|
||||
to->next = list->first;
|
||||
INIT_WQ_LIST(list);
|
||||
}
|
||||
|
||||
static inline bool wq_list_splice(struct io_wq_work_list *list,
|
||||
struct io_wq_work_node *to)
|
||||
{
|
||||
if (!wq_list_empty(list)) {
|
||||
__wq_list_splice(list, to);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void wq_stack_add_head(struct io_wq_work_node *node,
|
||||
struct io_wq_work_node *stack)
|
||||
{
|
||||
node->next = stack->next;
|
||||
stack->next = node;
|
||||
}
|
||||
|
||||
static inline void wq_list_del(struct io_wq_work_list *list,
|
||||
struct io_wq_work_node *node,
|
||||
struct io_wq_work_node *prev)
|
||||
{
|
||||
wq_list_cut(list, node, prev);
|
||||
}
|
||||
|
||||
static inline
|
||||
struct io_wq_work_node *wq_stack_extract(struct io_wq_work_node *stack)
|
||||
{
|
||||
struct io_wq_work_node *node = stack->next;
|
||||
|
||||
stack->next = node->next;
|
||||
return node;
|
||||
}
|
||||
|
||||
static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)
|
||||
{
|
||||
if (!work->list.next)
|
||||
return NULL;
|
||||
|
||||
return container_of(work->list.next, struct io_wq_work, list);
|
||||
}
|
||||
|
||||
#endif // INTERNAL_IO_SLIST_H
|
||||
#ifndef INTERNAL_IO_SLIST_H
|
||||
#define INTERNAL_IO_SLIST_H
|
||||
|
||||
#include <linux/io_uring_types.h>
|
||||
|
||||
#define __wq_list_for_each(pos, head) \
|
||||
for (pos = (head)->first; pos; pos = (pos)->next)
|
||||
|
||||
#define wq_list_for_each(pos, prv, head) \
|
||||
for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
|
||||
|
||||
#define wq_list_for_each_resume(pos, prv) \
|
||||
for (; pos; prv = pos, pos = (pos)->next)
|
||||
|
||||
#define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
|
||||
|
||||
#define INIT_WQ_LIST(list) do { \
|
||||
(list)->first = NULL; \
|
||||
} while (0)
|
||||
|
||||
static inline void wq_list_add_after(struct io_wq_work_node *node,
|
||||
struct io_wq_work_node *pos,
|
||||
struct io_wq_work_list *list)
|
||||
{
|
||||
struct io_wq_work_node *next = pos->next;
|
||||
|
||||
pos->next = node;
|
||||
node->next = next;
|
||||
if (!next)
|
||||
list->last = node;
|
||||
}
|
||||
|
||||
static inline void wq_list_add_tail(struct io_wq_work_node *node,
|
||||
struct io_wq_work_list *list)
|
||||
{
|
||||
node->next = NULL;
|
||||
if (!list->first) {
|
||||
list->last = node;
|
||||
WRITE_ONCE(list->first, node);
|
||||
} else {
|
||||
list->last->next = node;
|
||||
list->last = node;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void wq_list_add_head(struct io_wq_work_node *node,
|
||||
struct io_wq_work_list *list)
|
||||
{
|
||||
node->next = list->first;
|
||||
if (!node->next)
|
||||
list->last = node;
|
||||
WRITE_ONCE(list->first, node);
|
||||
}
|
||||
|
||||
static inline void wq_list_cut(struct io_wq_work_list *list,
|
||||
struct io_wq_work_node *last,
|
||||
struct io_wq_work_node *prev)
|
||||
{
|
||||
/* first in the list, if prev==NULL */
|
||||
if (!prev)
|
||||
WRITE_ONCE(list->first, last->next);
|
||||
else
|
||||
prev->next = last->next;
|
||||
|
||||
if (last == list->last)
|
||||
list->last = prev;
|
||||
last->next = NULL;
|
||||
}
|
||||
|
||||
static inline void __wq_list_splice(struct io_wq_work_list *list,
|
||||
struct io_wq_work_node *to)
|
||||
{
|
||||
list->last->next = to->next;
|
||||
to->next = list->first;
|
||||
INIT_WQ_LIST(list);
|
||||
}
|
||||
|
||||
static inline bool wq_list_splice(struct io_wq_work_list *list,
|
||||
struct io_wq_work_node *to)
|
||||
{
|
||||
if (!wq_list_empty(list)) {
|
||||
__wq_list_splice(list, to);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void wq_stack_add_head(struct io_wq_work_node *node,
|
||||
struct io_wq_work_node *stack)
|
||||
{
|
||||
node->next = stack->next;
|
||||
stack->next = node;
|
||||
}
|
||||
|
||||
static inline void wq_list_del(struct io_wq_work_list *list,
|
||||
struct io_wq_work_node *node,
|
||||
struct io_wq_work_node *prev)
|
||||
{
|
||||
wq_list_cut(list, node, prev);
|
||||
}
|
||||
|
||||
static inline
|
||||
struct io_wq_work_node *wq_stack_extract(struct io_wq_work_node *stack)
|
||||
{
|
||||
struct io_wq_work_node *node = stack->next;
|
||||
|
||||
stack->next = node->next;
|
||||
return node;
|
||||
}
|
||||
|
||||
static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)
|
||||
{
|
||||
if (!work->list.next)
|
||||
return NULL;
|
||||
|
||||
return container_of(work->list.next, struct io_wq_work, list);
|
||||
}
|
||||
|
||||
#endif // INTERNAL_IO_SLIST_H
|
||||
|
||||
@@ -1,121 +1,121 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/file.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/namei.h>
|
||||
#include <linux/io_uring.h>
|
||||
#include <linux/splice.h>
|
||||
|
||||
#include <uapi/linux/io_uring.h>
|
||||
|
||||
#include "io_uring.h"
|
||||
#include "splice.h"
|
||||
|
||||
struct io_splice {
|
||||
struct file *file_out;
|
||||
loff_t off_out;
|
||||
loff_t off_in;
|
||||
u64 len;
|
||||
int splice_fd_in;
|
||||
unsigned int flags;
|
||||
};
|
||||
|
||||
static int __io_splice_prep(struct io_kiocb *req,
|
||||
const struct io_uring_sqe *sqe)
|
||||
{
|
||||
struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
|
||||
unsigned int valid_flags = SPLICE_F_FD_IN_FIXED | SPLICE_F_ALL;
|
||||
|
||||
sp->len = READ_ONCE(sqe->len);
|
||||
sp->flags = READ_ONCE(sqe->splice_flags);
|
||||
if (unlikely(sp->flags & ~valid_flags))
|
||||
return -EINVAL;
|
||||
sp->splice_fd_in = READ_ONCE(sqe->splice_fd_in);
|
||||
req->flags |= REQ_F_FORCE_ASYNC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int io_tee_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
if (READ_ONCE(sqe->splice_off_in) || READ_ONCE(sqe->off))
|
||||
return -EINVAL;
|
||||
return __io_splice_prep(req, sqe);
|
||||
}
|
||||
|
||||
int io_tee(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
|
||||
struct file *out = sp->file_out;
|
||||
unsigned int flags = sp->flags & ~SPLICE_F_FD_IN_FIXED;
|
||||
struct file *in;
|
||||
ssize_t ret = 0;
|
||||
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
|
||||
|
||||
if (sp->flags & SPLICE_F_FD_IN_FIXED)
|
||||
in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags);
|
||||
else
|
||||
in = io_file_get_normal(req, sp->splice_fd_in);
|
||||
if (!in) {
|
||||
ret = -EBADF;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (sp->len)
|
||||
ret = do_tee(in, out, sp->len, flags);
|
||||
|
||||
if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
|
||||
fput(in);
|
||||
done:
|
||||
if (ret != sp->len)
|
||||
req_set_fail(req);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
}
|
||||
|
||||
int io_splice_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
|
||||
|
||||
sp->off_in = READ_ONCE(sqe->splice_off_in);
|
||||
sp->off_out = READ_ONCE(sqe->off);
|
||||
return __io_splice_prep(req, sqe);
|
||||
}
|
||||
|
||||
int io_splice(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
|
||||
struct file *out = sp->file_out;
|
||||
unsigned int flags = sp->flags & ~SPLICE_F_FD_IN_FIXED;
|
||||
loff_t *poff_in, *poff_out;
|
||||
struct file *in;
|
||||
ssize_t ret = 0;
|
||||
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
|
||||
|
||||
if (sp->flags & SPLICE_F_FD_IN_FIXED)
|
||||
in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags);
|
||||
else
|
||||
in = io_file_get_normal(req, sp->splice_fd_in);
|
||||
if (!in) {
|
||||
ret = -EBADF;
|
||||
goto done;
|
||||
}
|
||||
|
||||
poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
|
||||
poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
|
||||
|
||||
if (sp->len)
|
||||
ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
|
||||
|
||||
if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
|
||||
fput(in);
|
||||
done:
|
||||
if (ret != sp->len)
|
||||
req_set_fail(req);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
}
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/file.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/namei.h>
|
||||
#include <linux/io_uring.h>
|
||||
#include <linux/splice.h>
|
||||
|
||||
#include <uapi/linux/io_uring.h>
|
||||
|
||||
#include "io_uring.h"
|
||||
#include "splice.h"
|
||||
|
||||
struct io_splice {
|
||||
struct file *file_out;
|
||||
loff_t off_out;
|
||||
loff_t off_in;
|
||||
u64 len;
|
||||
int splice_fd_in;
|
||||
unsigned int flags;
|
||||
};
|
||||
|
||||
static int __io_splice_prep(struct io_kiocb *req,
|
||||
const struct io_uring_sqe *sqe)
|
||||
{
|
||||
struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
|
||||
unsigned int valid_flags = SPLICE_F_FD_IN_FIXED | SPLICE_F_ALL;
|
||||
|
||||
sp->len = READ_ONCE(sqe->len);
|
||||
sp->flags = READ_ONCE(sqe->splice_flags);
|
||||
if (unlikely(sp->flags & ~valid_flags))
|
||||
return -EINVAL;
|
||||
sp->splice_fd_in = READ_ONCE(sqe->splice_fd_in);
|
||||
req->flags |= REQ_F_FORCE_ASYNC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int io_tee_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
if (READ_ONCE(sqe->splice_off_in) || READ_ONCE(sqe->off))
|
||||
return -EINVAL;
|
||||
return __io_splice_prep(req, sqe);
|
||||
}
|
||||
|
||||
int io_tee(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
|
||||
struct file *out = sp->file_out;
|
||||
unsigned int flags = sp->flags & ~SPLICE_F_FD_IN_FIXED;
|
||||
struct file *in;
|
||||
ssize_t ret = 0;
|
||||
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
|
||||
|
||||
if (sp->flags & SPLICE_F_FD_IN_FIXED)
|
||||
in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags);
|
||||
else
|
||||
in = io_file_get_normal(req, sp->splice_fd_in);
|
||||
if (!in) {
|
||||
ret = -EBADF;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (sp->len)
|
||||
ret = do_tee(in, out, sp->len, flags);
|
||||
|
||||
if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
|
||||
fput(in);
|
||||
done:
|
||||
if (ret != sp->len)
|
||||
req_set_fail(req);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
}
|
||||
|
||||
int io_splice_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
|
||||
|
||||
sp->off_in = READ_ONCE(sqe->splice_off_in);
|
||||
sp->off_out = READ_ONCE(sqe->off);
|
||||
return __io_splice_prep(req, sqe);
|
||||
}
|
||||
|
||||
int io_splice(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
|
||||
struct file *out = sp->file_out;
|
||||
unsigned int flags = sp->flags & ~SPLICE_F_FD_IN_FIXED;
|
||||
loff_t *poff_in, *poff_out;
|
||||
struct file *in;
|
||||
ssize_t ret = 0;
|
||||
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
|
||||
|
||||
if (sp->flags & SPLICE_F_FD_IN_FIXED)
|
||||
in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags);
|
||||
else
|
||||
in = io_file_get_normal(req, sp->splice_fd_in);
|
||||
if (!in) {
|
||||
ret = -EBADF;
|
||||
goto done;
|
||||
}
|
||||
|
||||
poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
|
||||
poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
|
||||
|
||||
if (sp->len)
|
||||
ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
|
||||
|
||||
if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
|
||||
fput(in);
|
||||
done:
|
||||
if (ret != sp->len)
|
||||
req_set_fail(req);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
}
|
||||
|
||||
@@ -1,112 +1,112 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/file.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/namei.h>
|
||||
#include <linux/io_uring.h>
|
||||
#include <linux/fsnotify.h>
|
||||
|
||||
#include <uapi/linux/io_uring.h>
|
||||
|
||||
#include "io_uring.h"
|
||||
#include "sync.h"
|
||||
|
||||
struct io_sync {
|
||||
struct file *file;
|
||||
loff_t len;
|
||||
loff_t off;
|
||||
int flags;
|
||||
int mode;
|
||||
};
|
||||
|
||||
int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
|
||||
|
||||
if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in))
|
||||
return -EINVAL;
|
||||
|
||||
sync->off = READ_ONCE(sqe->off);
|
||||
sync->len = READ_ONCE(sqe->len);
|
||||
sync->flags = READ_ONCE(sqe->sync_range_flags);
|
||||
req->flags |= REQ_F_FORCE_ASYNC;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
|
||||
int ret;
|
||||
|
||||
/* sync_file_range always requires a blocking context */
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
|
||||
|
||||
ret = sync_file_range(req->file, sync->off, sync->len, sync->flags);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
}
|
||||
|
||||
int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
|
||||
|
||||
if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in))
|
||||
return -EINVAL;
|
||||
|
||||
sync->flags = READ_ONCE(sqe->fsync_flags);
|
||||
if (unlikely(sync->flags & ~IORING_FSYNC_DATASYNC))
|
||||
return -EINVAL;
|
||||
|
||||
sync->off = READ_ONCE(sqe->off);
|
||||
sync->len = READ_ONCE(sqe->len);
|
||||
req->flags |= REQ_F_FORCE_ASYNC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int io_fsync(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
|
||||
loff_t end = sync->off + sync->len;
|
||||
int ret;
|
||||
|
||||
/* fsync always requires a blocking context */
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
|
||||
|
||||
ret = vfs_fsync_range(req->file, sync->off, end > 0 ? end : LLONG_MAX,
|
||||
sync->flags & IORING_FSYNC_DATASYNC);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
}
|
||||
|
||||
int io_fallocate_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
|
||||
|
||||
if (sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
|
||||
return -EINVAL;
|
||||
|
||||
sync->off = READ_ONCE(sqe->off);
|
||||
sync->len = READ_ONCE(sqe->addr);
|
||||
sync->mode = READ_ONCE(sqe->len);
|
||||
req->flags |= REQ_F_FORCE_ASYNC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int io_fallocate(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
|
||||
int ret;
|
||||
|
||||
/* fallocate always requiring blocking context */
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
|
||||
|
||||
ret = vfs_fallocate(req->file, sync->mode, sync->off, sync->len);
|
||||
if (ret >= 0)
|
||||
fsnotify_modify(req->file);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
}
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/file.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/namei.h>
|
||||
#include <linux/io_uring.h>
|
||||
#include <linux/fsnotify.h>
|
||||
|
||||
#include <uapi/linux/io_uring.h>
|
||||
|
||||
#include "io_uring.h"
|
||||
#include "sync.h"
|
||||
|
||||
struct io_sync {
|
||||
struct file *file;
|
||||
loff_t len;
|
||||
loff_t off;
|
||||
int flags;
|
||||
int mode;
|
||||
};
|
||||
|
||||
int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
|
||||
|
||||
if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in))
|
||||
return -EINVAL;
|
||||
|
||||
sync->off = READ_ONCE(sqe->off);
|
||||
sync->len = READ_ONCE(sqe->len);
|
||||
sync->flags = READ_ONCE(sqe->sync_range_flags);
|
||||
req->flags |= REQ_F_FORCE_ASYNC;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
|
||||
int ret;
|
||||
|
||||
/* sync_file_range always requires a blocking context */
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
|
||||
|
||||
ret = sync_file_range(req->file, sync->off, sync->len, sync->flags);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
}
|
||||
|
||||
int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
|
||||
|
||||
if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in))
|
||||
return -EINVAL;
|
||||
|
||||
sync->flags = READ_ONCE(sqe->fsync_flags);
|
||||
if (unlikely(sync->flags & ~IORING_FSYNC_DATASYNC))
|
||||
return -EINVAL;
|
||||
|
||||
sync->off = READ_ONCE(sqe->off);
|
||||
sync->len = READ_ONCE(sqe->len);
|
||||
req->flags |= REQ_F_FORCE_ASYNC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int io_fsync(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
|
||||
loff_t end = sync->off + sync->len;
|
||||
int ret;
|
||||
|
||||
/* fsync always requires a blocking context */
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
|
||||
|
||||
ret = vfs_fsync_range(req->file, sync->off, end > 0 ? end : LLONG_MAX,
|
||||
sync->flags & IORING_FSYNC_DATASYNC);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
}
|
||||
|
||||
int io_fallocate_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||
{
|
||||
struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
|
||||
|
||||
if (sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
|
||||
return -EINVAL;
|
||||
|
||||
sync->off = READ_ONCE(sqe->off);
|
||||
sync->len = READ_ONCE(sqe->addr);
|
||||
sync->mode = READ_ONCE(sqe->len);
|
||||
req->flags |= REQ_F_FORCE_ASYNC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int io_fallocate(struct io_kiocb *req, unsigned int issue_flags)
|
||||
{
|
||||
struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
|
||||
int ret;
|
||||
|
||||
/* fallocate always requiring blocking context */
|
||||
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
|
||||
|
||||
ret = vfs_fallocate(req->file, sync->mode, sync->off, sync->len);
|
||||
if (ret >= 0)
|
||||
fsnotify_modify(req->file);
|
||||
io_req_set_res(req, ret, 0);
|
||||
return IOU_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user