return -ENFILE;
}
-bool io_alloc_file_tables(struct io_file_table *table, unsigned nr_files)
+bool io_alloc_file_tables(struct io_ring_ctx *ctx, struct io_file_table *table,
+ unsigned nr_files)
{
if (io_rsrc_data_alloc(&table->data, nr_files))
return false;
table->bitmap = bitmap_zalloc(nr_files, GFP_KERNEL_ACCOUNT);
if (table->bitmap)
return true;
- io_rsrc_data_free(&table->data);
+ io_rsrc_data_free(ctx, &table->data);
return false;
}
-void io_free_file_tables(struct io_file_table *table)
+void io_free_file_tables(struct io_ring_ctx *ctx, struct io_file_table *table)
{
- io_rsrc_data_free(&table->data);
+ io_rsrc_data_free(ctx, &table->data);
bitmap_free(table->bitmap);
table->bitmap = NULL;
}
if (!node)
return -ENOMEM;
- if (!io_reset_rsrc_node(&ctx->file_table.data, slot_index))
+ if (!io_reset_rsrc_node(ctx, &ctx->file_table.data, slot_index))
io_file_bitmap_set(&ctx->file_table, slot_index);
ctx->file_table.data.nodes[slot_index] = node;
node = io_rsrc_node_lookup(&ctx->file_table.data, offset);
if (!node)
return -EBADF;
- io_reset_rsrc_node(&ctx->file_table.data, offset);
+ io_reset_rsrc_node(ctx, &ctx->file_table.data, offset);
io_file_bitmap_clear(&ctx->file_table, offset);
return 0;
}
#include <linux/io_uring_types.h>
#include "rsrc.h"
-bool io_alloc_file_tables(struct io_file_table *table, unsigned nr_files);
-void io_free_file_tables(struct io_file_table *table);
+bool io_alloc_file_tables(struct io_ring_ctx *ctx, struct io_file_table *table, unsigned nr_files);
+void io_free_file_tables(struct io_ring_ctx *ctx, struct io_file_table *table);
int io_fixed_fd_install(struct io_kiocb *req, unsigned int issue_flags,
struct file *file, unsigned int file_slot);
return node;
}
-__cold void io_rsrc_data_free(struct io_rsrc_data *data)
+__cold void io_rsrc_data_free(struct io_ring_ctx *ctx, struct io_rsrc_data *data)
{
if (!data->nr)
return;
while (data->nr--) {
if (data->nodes[data->nr])
- io_put_rsrc_node(data->nodes[data->nr]);
+ io_put_rsrc_node(ctx, data->nodes[data->nr]);
}
kvfree(data->nodes);
data->nodes = NULL;
continue;
i = up->offset + done;
- if (io_reset_rsrc_node(&ctx->file_table.data, i))
+ if (io_reset_rsrc_node(ctx, &ctx->file_table.data, i))
io_file_bitmap_clear(&ctx->file_table, i);
if (fd != -1) {
node->tag = tag;
}
i = array_index_nospec(up->offset + done, ctx->buf_table.nr);
- io_reset_rsrc_node(&ctx->buf_table, i);
+ io_reset_rsrc_node(ctx, &ctx->buf_table, i);
ctx->buf_table.nodes[i] = node;
if (ctx->compat)
user_data += sizeof(struct compat_iovec);
return IOU_OK;
}
-void io_free_rsrc_node(struct io_rsrc_node *node)
+void io_free_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
{
- struct io_ring_ctx *ctx = io_rsrc_node_ctx(node);
-
lockdep_assert_held(&ctx->uring_lock);
if (node->tag)
if (!ctx->file_table.data.nr)
return -ENXIO;
- io_free_file_tables(&ctx->file_table);
+ io_free_file_tables(ctx, &ctx->file_table);
io_file_table_set_alloc_range(ctx, 0, 0);
return 0;
}
return -EMFILE;
if (nr_args > rlimit(RLIMIT_NOFILE))
return -EMFILE;
- if (!io_alloc_file_tables(&ctx->file_table, nr_args))
+ if (!io_alloc_file_tables(ctx, &ctx->file_table, nr_args))
return -ENOMEM;
for (i = 0; i < nr_args; i++) {
{
if (!ctx->buf_table.nr)
return -ENXIO;
- io_rsrc_data_free(&ctx->buf_table);
+ io_rsrc_data_free(ctx, &ctx->buf_table);
return 0;
}
if (ret) {
kvfree(imu);
if (node)
- io_put_rsrc_node(node);
+ io_put_rsrc_node(ctx, node);
node = ERR_PTR(ret);
}
kvfree(pages);
* old and new nodes at this point.
*/
if (arg->flags & IORING_REGISTER_DST_REPLACE)
- io_rsrc_data_free(&ctx->buf_table);
+ io_rsrc_data_free(ctx, &ctx->buf_table);
/*
* ctx->buf_table should be empty now - either the contents are being
kfree(data.nodes[i]);
}
out_unlock:
- io_rsrc_data_free(&data);
+ io_rsrc_data_free(ctx, &data);
mutex_unlock(&src_ctx->uring_lock);
mutex_lock(&ctx->uring_lock);
return ret;
};
struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx, int type);
-void io_free_rsrc_node(struct io_rsrc_node *node);
-void io_rsrc_data_free(struct io_rsrc_data *data);
+void io_free_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node);
+void io_rsrc_data_free(struct io_ring_ctx *ctx, struct io_rsrc_data *data);
int io_rsrc_data_alloc(struct io_rsrc_data *data, unsigned nr);
int io_import_fixed(int ddir, struct iov_iter *iter,
return NULL;
}
-static inline void io_put_rsrc_node(struct io_rsrc_node *node)
+static inline void io_put_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
{
if (node && !--node->refs)
- io_free_rsrc_node(node);
+ io_free_rsrc_node(ctx, node);
}
-static inline bool io_reset_rsrc_node(struct io_rsrc_data *data, int index)
+static inline bool io_reset_rsrc_node(struct io_ring_ctx *ctx,
+ struct io_rsrc_data *data, int index)
{
struct io_rsrc_node *node = data->nodes[index];
if (!node)
return false;
- io_put_rsrc_node(node);
+ io_put_rsrc_node(ctx, node);
data->nodes[index] = NULL;
return true;
}
static inline void io_req_put_rsrc_nodes(struct io_kiocb *req)
{
if (req->file_node) {
- io_put_rsrc_node(req->file_node);
+ io_put_rsrc_node(req->ctx, req->file_node);
req->file_node = NULL;
}
if (req->flags & REQ_F_BUF_NODE) {
- io_put_rsrc_node(req->buf_node);
+ io_put_rsrc_node(req->ctx, req->buf_node);
req->buf_node = NULL;
}
}
-static inline struct io_ring_ctx *io_rsrc_node_ctx(struct io_rsrc_node *node)
-{
- return (struct io_ring_ctx *) (node->ctx_ptr & ~IORING_RSRC_TYPE_MASK);
-}
-
static inline int io_rsrc_node_type(struct io_rsrc_node *node)
{
return node->ctx_ptr & IORING_RSRC_TYPE_MASK;
{
struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
- io_put_rsrc_node(sp->rsrc_node);
+ io_put_rsrc_node(req->ctx, sp->rsrc_node);
}
static struct file *io_splice_get_file(struct io_kiocb *req,