Add an option to choose whether the file supports FMODE_NOWAIT, that changes the execution path io_uring request takes.
Unified · Split
| @@ -6,6 +6,7 @@ · 5 unmodified lines | |||
| 6 | enum { | 6 | enum { |
| 7 | IORING_MOCK_FEAT_CMD_COPY, | 7 | IORING_MOCK_FEAT_CMD_COPY, |
| 8 | IORING_MOCK_FEAT_RW_ZERO, | 8 | IORING_MOCK_FEAT_RW_ZERO, |
| 9 | IORING_MOCK_FEAT_RW_NOWAIT, | ||
| 9 | 10 | ||
| 10 | IORING_MOCK_FEAT_END, | 11 | IORING_MOCK_FEAT_END, |
| 11 | }; | 12 | }; |
| @@ -15,6 +16,10 @@ struct io_uring_mock_probe { · 3 unmodified lines | |||
| 15 | __u64 __resv[9]; | 16 | __u64 __resv[9]; |
| 16 | }; | 17 | }; |
| 17 | 18 | ||
| 19 | enum { | ||
| 20 | IORING_MOCK_CREATE_F_SUPPORT_NOWAIT = 1, | ||
| 21 | }; | ||
| 22 | |||
| 18 | struct io_uring_mock_create { | 23 | struct io_uring_mock_create { |
| 19 | __u32 out_fd; | 24 | __u32 out_fd; |
| 20 | __u32 flags; | 25 | __u32 flags; |
| @@ -131,6 +131,8 @@ static const struct file_operations io_mock_fops = { · 130 unmodified lines | |||
| 131 | .llseek = io_mock_llseek, | 131 | .llseek = io_mock_llseek, |
| 132 | }; | 132 | }; |
| 133 | 133 | ||
| 134 | #define IO_VALID_CREATE_FLAGS (IORING_MOCK_CREATE_F_SUPPORT_NOWAIT) | ||
| 135 | |||
| 134 | static int io_create_mock_file(struct io_uring_cmd *cmd, unsigned int issue_flags) | 136 | static int io_create_mock_file(struct io_uring_cmd *cmd, unsigned int issue_flags) |
| 135 | { | 137 | { |
| 136 | const struct io_uring_sqe *sqe = cmd->sqe; | 138 | const struct io_uring_sqe *sqe = cmd->sqe; |
| @@ -157,7 +159,9 @@ static int io_create_mock_file(struct io_uring_cmd *cmd, unsigned int issue_flag · 20 unmodified lines | |||
| 157 | memset(&mc, 0, sizeof(mc)); | 159 | memset(&mc, 0, sizeof(mc)); |
| 158 | if (copy_from_user(&mc, uarg, uarg_size)) | 160 | if (copy_from_user(&mc, uarg, uarg_size)) |
| 159 | return -EFAULT; | 161 | return -EFAULT; |
| 160 | if (!mem_is_zero(mc.__resv, sizeof(mc.__resv)) || mc.flags) | 162 | if (!mem_is_zero(mc.__resv, sizeof(mc.__resv))) |
| 163 | return -EINVAL; | ||
| 164 | if (mc.flags & ~IO_VALID_CREATE_FLAGS) | ||
| 161 | return -EINVAL; | 165 | return -EINVAL; |
| 162 | if (mc.file_size > SZ_1G) | 166 | if (mc.file_size > SZ_1G) |
| 163 | return -EINVAL; | 167 | return -EINVAL; |
| @@ -180,6 +184,8 @@ static int io_create_mock_file(struct io_uring_cmd *cmd, unsigned int issue_flag · 16 unmodified lines | |||
| 180 | file->f_mode |= FMODE_READ | FMODE_CAN_READ | | 184 | file->f_mode |= FMODE_READ | FMODE_CAN_READ | |
| 181 | FMODE_WRITE | FMODE_CAN_WRITE | | 185 | FMODE_WRITE | FMODE_CAN_WRITE | |
| 182 | FMODE_LSEEK; | 186 | FMODE_LSEEK; |
| 187 | if (mc.flags & IORING_MOCK_CREATE_F_SUPPORT_NOWAIT) | ||
| 188 | file->f_mode |= FMODE_NOWAIT; | ||
| 183 | 189 | ||
| 184 | mc.out_fd = fd; | 190 | mc.out_fd = fd; |
| 185 | if (copy_to_user(uarg, &mc, uarg_size)) { | 191 | if (copy_to_user(uarg, &mc, uarg_size)) { |