Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at f2aeea57504cbbc58da3c59b939fc16150087648 88 lines 2.6 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2#ifndef IOU_FILE_TABLE_H 3#define IOU_FILE_TABLE_H 4 5#include <linux/file.h> 6#include <linux/io_uring_types.h> 7 8/* 9 * FFS_SCM is only available on 64-bit archs, for 32-bit we just define it as 0 10 * and define IO_URING_SCM_ALL. For this case, we use SCM for all files as we 11 * can't safely always dereference the file when the task has exited and ring 12 * cleanup is done. If a file is tracked and part of SCM, then unix gc on 13 * process exit may reap it before __io_sqe_files_unregister() is run. 14 */ 15#define FFS_NOWAIT 0x1UL 16#define FFS_ISREG 0x2UL 17#if defined(CONFIG_64BIT) 18#define FFS_SCM 0x4UL 19#else 20#define IO_URING_SCM_ALL 21#define FFS_SCM 0x0UL 22#endif 23#define FFS_MASK ~(FFS_NOWAIT|FFS_ISREG|FFS_SCM) 24 25bool io_alloc_file_tables(struct io_file_table *table, unsigned nr_files); 26void io_free_file_tables(struct io_file_table *table); 27 28int io_fixed_fd_install(struct io_kiocb *req, unsigned int issue_flags, 29 struct file *file, unsigned int file_slot); 30int __io_fixed_fd_install(struct io_ring_ctx *ctx, struct file *file, 31 unsigned int file_slot); 32int io_fixed_fd_remove(struct io_ring_ctx *ctx, unsigned int offset); 33 34int io_register_file_alloc_range(struct io_ring_ctx *ctx, 35 struct io_uring_file_index_range __user *arg); 36 37unsigned int io_file_get_flags(struct file *file); 38 39static inline void io_file_bitmap_clear(struct io_file_table *table, int bit) 40{ 41 __clear_bit(bit, table->bitmap); 42 table->alloc_hint = bit; 43} 44 45static inline void io_file_bitmap_set(struct io_file_table *table, int bit) 46{ 47 WARN_ON_ONCE(test_bit(bit, table->bitmap)); 48 __set_bit(bit, table->bitmap); 49 table->alloc_hint = bit + 1; 50} 51 52static inline struct io_fixed_file * 53io_fixed_file_slot(struct io_file_table *table, unsigned i) 54{ 55 return &table->files[i]; 56} 57 58static inline struct file *io_file_from_index(struct io_file_table *table, 59 int index) 60{ 61 struct io_fixed_file *slot = io_fixed_file_slot(table, index); 62 63 return (struct file *) (slot->file_ptr & FFS_MASK); 64} 65 66static inline void io_fixed_file_set(struct io_fixed_file *file_slot, 67 struct file *file) 68{ 69 unsigned long file_ptr = (unsigned long) file; 70 71 file_ptr |= io_file_get_flags(file); 72 file_slot->file_ptr = file_ptr; 73} 74 75static inline void io_reset_alloc_hint(struct io_ring_ctx *ctx) 76{ 77 ctx->file_table.alloc_hint = ctx->file_alloc_start; 78} 79 80static inline void io_file_table_set_alloc_range(struct io_ring_ctx *ctx, 81 unsigned off, unsigned len) 82{ 83 ctx->file_alloc_start = off; 84 ctx->file_alloc_end = off + len; 85 io_reset_alloc_hint(ctx); 86} 87 88#endif