mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
io_uring: convert io_create_mock_file() to FD_PREPARE()
Link: https://patch.msgid.link/20251123-work-fd-prepare-v4-45-b6efa1706cfd@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
@@ -211,10 +211,9 @@ static int io_create_mock_file(struct io_uring_cmd *cmd, unsigned int issue_flag
|
|||||||
const struct file_operations *fops = &io_mock_fops;
|
const struct file_operations *fops = &io_mock_fops;
|
||||||
const struct io_uring_sqe *sqe = cmd->sqe;
|
const struct io_uring_sqe *sqe = cmd->sqe;
|
||||||
struct io_uring_mock_create mc, __user *uarg;
|
struct io_uring_mock_create mc, __user *uarg;
|
||||||
struct io_mock_file *mf = NULL;
|
struct file *file;
|
||||||
struct file *file = NULL;
|
struct io_mock_file *mf __free(kfree) = NULL;
|
||||||
size_t uarg_size;
|
size_t uarg_size;
|
||||||
int fd = -1, ret;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It's a testing only driver that allows exercising edge cases
|
* It's a testing only driver that allows exercising edge cases
|
||||||
@@ -246,10 +245,6 @@ static int io_create_mock_file(struct io_uring_cmd *cmd, unsigned int issue_flag
|
|||||||
if (!mf)
|
if (!mf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ret = fd = get_unused_fd_flags(O_RDWR | O_CLOEXEC);
|
|
||||||
if (fd < 0)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
init_waitqueue_head(&mf->poll_wq);
|
init_waitqueue_head(&mf->poll_wq);
|
||||||
mf->size = mc.file_size;
|
mf->size = mc.file_size;
|
||||||
mf->rw_delay_ns = mc.rw_delay_ns;
|
mf->rw_delay_ns = mc.rw_delay_ns;
|
||||||
@@ -258,33 +253,25 @@ static int io_create_mock_file(struct io_uring_cmd *cmd, unsigned int issue_flag
|
|||||||
mf->pollable = true;
|
mf->pollable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
file = anon_inode_create_getfile("[io_uring_mock]", fops,
|
FD_PREPARE(fdf, O_RDWR | O_CLOEXEC,
|
||||||
mf, O_RDWR | O_CLOEXEC, NULL);
|
anon_inode_create_getfile("[io_uring_mock]", fops, mf,
|
||||||
if (IS_ERR(file)) {
|
O_RDWR | O_CLOEXEC, NULL));
|
||||||
ret = PTR_ERR(file);
|
if (fdf.err)
|
||||||
goto fail;
|
return fdf.err;
|
||||||
}
|
|
||||||
|
|
||||||
file->f_mode |= FMODE_READ | FMODE_CAN_READ |
|
retain_and_null_ptr(mf);
|
||||||
FMODE_WRITE | FMODE_CAN_WRITE |
|
file = fd_prepare_file(fdf);
|
||||||
FMODE_LSEEK;
|
file->f_mode |= FMODE_READ | FMODE_CAN_READ | FMODE_WRITE |
|
||||||
|
FMODE_CAN_WRITE | FMODE_LSEEK;
|
||||||
if (mc.flags & IORING_MOCK_CREATE_F_SUPPORT_NOWAIT)
|
if (mc.flags & IORING_MOCK_CREATE_F_SUPPORT_NOWAIT)
|
||||||
file->f_mode |= FMODE_NOWAIT;
|
file->f_mode |= FMODE_NOWAIT;
|
||||||
|
|
||||||
mc.out_fd = fd;
|
mc.out_fd = fd_prepare_fd(fdf);
|
||||||
if (copy_to_user(uarg, &mc, uarg_size)) {
|
if (copy_to_user(uarg, &mc, uarg_size))
|
||||||
fput(file);
|
return -EFAULT;
|
||||||
ret = -EFAULT;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
fd_install(fd, file);
|
fd_publish(fdf);
|
||||||
return 0;
|
return 0;
|
||||||
fail:
|
|
||||||
if (fd >= 0)
|
|
||||||
put_unused_fd(fd);
|
|
||||||
kfree(mf);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int io_probe_mock(struct io_uring_cmd *cmd)
|
static int io_probe_mock(struct io_uring_cmd *cmd)
|
||||||
|
|||||||
Reference in New Issue
Block a user