Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/mock: add trivial poll handler

Add a flag that enables polling on the mock file. For now it's trivially
says that there is always data available, it'll be extended in the
future.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/f16de043ec4876d65fae294fc99ade57415fba0c.1750599274.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Pavel Begunkov and committed by
Jens Axboe
e448d578 0c98a443

+37 -2
+2
include/uapi/linux/io_uring/mock_file.h
··· 8 8 IORING_MOCK_FEAT_RW_ZERO, 9 9 IORING_MOCK_FEAT_RW_NOWAIT, 10 10 IORING_MOCK_FEAT_RW_ASYNC, 11 + IORING_MOCK_FEAT_POLL, 11 12 12 13 IORING_MOCK_FEAT_END, 13 14 }; ··· 20 19 21 20 enum { 22 21 IORING_MOCK_CREATE_F_SUPPORT_NOWAIT = 1, 22 + IORING_MOCK_CREATE_F_POLL = 2, 23 23 }; 24 24 25 25 struct io_uring_mock_create {
+35 -2
io_uring/mock_file.c
··· 6 6 #include <linux/anon_inodes.h> 7 7 #include <linux/ktime.h> 8 8 #include <linux/hrtimer.h> 9 + #include <linux/poll.h> 9 10 10 11 #include <linux/io_uring/cmd.h> 11 12 #include <linux/io_uring_types.h> ··· 21 20 struct io_mock_file { 22 21 size_t size; 23 22 u64 rw_delay_ns; 23 + bool pollable; 24 + struct wait_queue_head poll_wq; 24 25 }; 25 26 26 27 #define IO_VALID_COPY_CMD_FLAGS IORING_MOCK_COPY_FROM ··· 164 161 return fixed_size_llseek(file, offset, whence, mf->size); 165 162 } 166 163 164 + static __poll_t io_mock_poll(struct file *file, struct poll_table_struct *pt) 165 + { 166 + struct io_mock_file *mf = file->private_data; 167 + __poll_t mask = 0; 168 + 169 + poll_wait(file, &mf->poll_wq, pt); 170 + 171 + mask |= EPOLLOUT | EPOLLWRNORM; 172 + mask |= EPOLLIN | EPOLLRDNORM; 173 + return mask; 174 + } 175 + 167 176 static int io_mock_release(struct inode *inode, struct file *file) 168 177 { 169 178 struct io_mock_file *mf = file->private_data; ··· 193 178 .llseek = io_mock_llseek, 194 179 }; 195 180 196 - #define IO_VALID_CREATE_FLAGS (IORING_MOCK_CREATE_F_SUPPORT_NOWAIT) 181 + static const struct file_operations io_mock_poll_fops = { 182 + .owner = THIS_MODULE, 183 + .release = io_mock_release, 184 + .uring_cmd = io_mock_cmd, 185 + .read_iter = io_mock_read_iter, 186 + .write_iter = io_mock_write_iter, 187 + .llseek = io_mock_llseek, 188 + .poll = io_mock_poll, 189 + }; 190 + 191 + #define IO_VALID_CREATE_FLAGS (IORING_MOCK_CREATE_F_SUPPORT_NOWAIT | \ 192 + IORING_MOCK_CREATE_F_POLL) 197 193 198 194 static int io_create_mock_file(struct io_uring_cmd *cmd, unsigned int issue_flags) 199 195 { 196 + const struct file_operations *fops = &io_mock_fops; 200 197 const struct io_uring_sqe *sqe = cmd->sqe; 201 198 struct io_uring_mock_create mc, __user *uarg; 202 199 struct io_mock_file *mf = NULL; ··· 250 223 if (fd < 0) 251 224 goto fail; 252 225 226 + init_waitqueue_head(&mf->poll_wq); 253 227 mf->size = mc.file_size; 254 228 mf->rw_delay_ns = mc.rw_delay_ns; 255 - file = anon_inode_create_getfile("[io_uring_mock]", &io_mock_fops, 229 + if (mc.flags & IORING_MOCK_CREATE_F_POLL) { 230 + fops = &io_mock_poll_fops; 231 + mf->pollable = true; 232 + } 233 + 234 + file = anon_inode_create_getfile("[io_uring_mock]", fops, 256 235 mf, O_RDWR | O_CLOEXEC, NULL); 257 236 if (IS_ERR(file)) { 258 237 ret = PTR_ERR(file);