mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 21:21:41 +00:00
io_uring: move rsrc related data, core, and commands
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
3b77495a97
commit
7357298448
@ -7,5 +7,5 @@ obj-$(CONFIG_IO_URING) += io_uring.o xattr.o nop.o fs.o splice.o \
|
||||
openclose.o uring_cmd.o epoll.o \
|
||||
statx.o net.o msg_ring.o timeout.o \
|
||||
sqpoll.o fdinfo.o tctx.o poll.o \
|
||||
cancel.o kbuf.o
|
||||
cancel.o kbuf.o rsrc.o
|
||||
obj-$(CONFIG_IO_WQ) += io-wq.o
|
||||
|
1414
io_uring/io_uring.c
1414
io_uring/io_uring.c
File diff suppressed because it is too large
Load Diff
@ -92,6 +92,7 @@ static inline bool io_run_task_work(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
int io_run_task_work_sig(void);
|
||||
void io_req_complete_failed(struct io_kiocb *req, s32 res);
|
||||
void __io_req_complete(struct io_kiocb *req, unsigned issue_flags);
|
||||
void io_req_complete_post(struct io_kiocb *req);
|
||||
@ -110,11 +111,6 @@ int io_fixed_fd_install(struct io_kiocb *req, unsigned int issue_flags,
|
||||
int io_install_fixed_file(struct io_kiocb *req, struct file *file,
|
||||
unsigned int issue_flags, u32 slot_index);
|
||||
|
||||
int io_rsrc_node_switch_start(struct io_ring_ctx *ctx);
|
||||
int io_queue_rsrc_removal(struct io_rsrc_data *data, unsigned idx,
|
||||
struct io_rsrc_node *node, void *rsrc);
|
||||
void io_rsrc_node_switch(struct io_ring_ctx *ctx,
|
||||
struct io_rsrc_data *data_to_kill);
|
||||
bool io_is_uring_fops(struct file *file);
|
||||
bool io_alloc_async_data(struct io_kiocb *req);
|
||||
void io_req_task_work_add(struct io_kiocb *req);
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "io_uring_types.h"
|
||||
#include "io_uring.h"
|
||||
#include "rsrc.h"
|
||||
#include "openclose.h"
|
||||
|
||||
struct io_open {
|
||||
|
1320
io_uring/rsrc.c
Normal file
1320
io_uring/rsrc.c
Normal file
File diff suppressed because it is too large
Load Diff
155
io_uring/rsrc.h
Normal file
155
io_uring/rsrc.h
Normal file
@ -0,0 +1,155 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#ifndef IOU_RSRC_H
|
||||
#define IOU_RSRC_H
|
||||
|
||||
#include <net/af_unix.h>
|
||||
|
||||
#define IO_RSRC_TAG_TABLE_SHIFT (PAGE_SHIFT - 3)
|
||||
#define IO_RSRC_TAG_TABLE_MAX (1U << IO_RSRC_TAG_TABLE_SHIFT)
|
||||
#define IO_RSRC_TAG_TABLE_MASK (IO_RSRC_TAG_TABLE_MAX - 1)
|
||||
|
||||
enum {
|
||||
IORING_RSRC_FILE = 0,
|
||||
IORING_RSRC_BUFFER = 1,
|
||||
};
|
||||
|
||||
struct io_rsrc_put {
|
||||
struct list_head list;
|
||||
u64 tag;
|
||||
union {
|
||||
void *rsrc;
|
||||
struct file *file;
|
||||
struct io_mapped_ubuf *buf;
|
||||
};
|
||||
};
|
||||
|
||||
typedef void (rsrc_put_fn)(struct io_ring_ctx *ctx, struct io_rsrc_put *prsrc);
|
||||
|
||||
struct io_rsrc_data {
|
||||
struct io_ring_ctx *ctx;
|
||||
|
||||
u64 **tags;
|
||||
unsigned int nr;
|
||||
rsrc_put_fn *do_put;
|
||||
atomic_t refs;
|
||||
struct completion done;
|
||||
bool quiesce;
|
||||
};
|
||||
|
||||
struct io_rsrc_node {
|
||||
struct percpu_ref refs;
|
||||
struct list_head node;
|
||||
struct list_head rsrc_list;
|
||||
struct io_rsrc_data *rsrc_data;
|
||||
struct llist_node llist;
|
||||
bool done;
|
||||
};
|
||||
|
||||
void io_rsrc_put_work(struct work_struct *work);
|
||||
void io_rsrc_refs_refill(struct io_ring_ctx *ctx);
|
||||
void io_wait_rsrc_data(struct io_rsrc_data *data);
|
||||
void io_rsrc_node_destroy(struct io_rsrc_node *ref_node);
|
||||
void io_rsrc_refs_drop(struct io_ring_ctx *ctx);
|
||||
int io_rsrc_node_switch_start(struct io_ring_ctx *ctx);
|
||||
int io_queue_rsrc_removal(struct io_rsrc_data *data, unsigned idx,
|
||||
struct io_rsrc_node *node, void *rsrc);
|
||||
void io_rsrc_node_switch(struct io_ring_ctx *ctx,
|
||||
struct io_rsrc_data *data_to_kill);
|
||||
|
||||
|
||||
void __io_sqe_buffers_unregister(struct io_ring_ctx *ctx);
|
||||
int io_sqe_buffers_unregister(struct io_ring_ctx *ctx);
|
||||
int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
|
||||
unsigned int nr_args, u64 __user *tags);
|
||||
void __io_sqe_files_unregister(struct io_ring_ctx *ctx);
|
||||
int io_sqe_files_unregister(struct io_ring_ctx *ctx);
|
||||
int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
|
||||
unsigned nr_args, u64 __user *tags);
|
||||
|
||||
int __io_scm_file_account(struct io_ring_ctx *ctx, struct file *file);
|
||||
|
||||
#if defined(CONFIG_UNIX)
|
||||
static inline bool io_file_need_scm(struct file *filp)
|
||||
{
|
||||
#if defined(IO_URING_SCM_ALL)
|
||||
return true;
|
||||
#else
|
||||
return !!unix_get_socket(filp);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
static inline bool io_file_need_scm(struct file *filp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline int io_scm_file_account(struct io_ring_ctx *ctx,
|
||||
struct file *file)
|
||||
{
|
||||
if (likely(!io_file_need_scm(file)))
|
||||
return 0;
|
||||
return __io_scm_file_account(ctx, file);
|
||||
}
|
||||
|
||||
int io_register_files_update(struct io_ring_ctx *ctx, void __user *arg,
|
||||
unsigned nr_args);
|
||||
int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
|
||||
unsigned size, unsigned type);
|
||||
int io_register_rsrc(struct io_ring_ctx *ctx, void __user *arg,
|
||||
unsigned int size, unsigned int type);
|
||||
|
||||
static inline void io_rsrc_put_node(struct io_rsrc_node *node, int nr)
|
||||
{
|
||||
percpu_ref_put_many(&node->refs, nr);
|
||||
}
|
||||
|
||||
static inline void io_req_put_rsrc(struct io_kiocb *req)
|
||||
{
|
||||
if (req->rsrc_node)
|
||||
io_rsrc_put_node(req->rsrc_node, 1);
|
||||
}
|
||||
|
||||
static inline void io_req_put_rsrc_locked(struct io_kiocb *req,
|
||||
struct io_ring_ctx *ctx)
|
||||
__must_hold(&ctx->uring_lock)
|
||||
{
|
||||
struct io_rsrc_node *node = req->rsrc_node;
|
||||
|
||||
if (node) {
|
||||
if (node == ctx->rsrc_node)
|
||||
ctx->rsrc_cached_refs++;
|
||||
else
|
||||
io_rsrc_put_node(node, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void io_req_set_rsrc_node(struct io_kiocb *req,
|
||||
struct io_ring_ctx *ctx,
|
||||
unsigned int issue_flags)
|
||||
{
|
||||
if (!req->rsrc_node) {
|
||||
req->rsrc_node = ctx->rsrc_node;
|
||||
|
||||
if (!(issue_flags & IO_URING_F_UNLOCKED)) {
|
||||
lockdep_assert_held(&ctx->uring_lock);
|
||||
ctx->rsrc_cached_refs--;
|
||||
if (unlikely(ctx->rsrc_cached_refs < 0))
|
||||
io_rsrc_refs_refill(ctx);
|
||||
} else {
|
||||
percpu_ref_get(&req->rsrc_node->refs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline u64 *io_get_tag_slot(struct io_rsrc_data *data, unsigned int idx)
|
||||
{
|
||||
unsigned int off = idx & IO_RSRC_TAG_TABLE_MASK;
|
||||
unsigned int table_idx = idx >> IO_RSRC_TAG_TABLE_SHIFT;
|
||||
|
||||
return &data->tags[table_idx][off];
|
||||
}
|
||||
|
||||
int io_files_update(struct io_kiocb *req, unsigned int issue_flags);
|
||||
int io_files_update_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user