2022-05-25 01:56:42 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/io_uring.h>
|
|
|
|
|
|
|
|
#include <uapi/linux/io_uring.h>
|
|
|
|
|
|
|
|
#include "io_uring.h"
|
|
|
|
#include "nop.h"
|
|
|
|
|
2024-05-10 11:50:28 +08:00
|
|
|
struct io_nop {
|
|
|
|
/* NOTE: kiocb has the file as the first member, so don't do it here */
|
|
|
|
struct file *file;
|
|
|
|
int result;
|
|
|
|
};
|
|
|
|
|
2022-05-25 01:56:42 +08:00
|
|
|
int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
|
|
|
{
|
2024-05-10 11:50:28 +08:00
|
|
|
unsigned int flags;
|
|
|
|
struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
|
|
|
|
|
|
|
|
flags = READ_ONCE(sqe->nop_flags);
|
|
|
|
if (flags & ~IORING_NOP_INJECT_RESULT)
|
2024-05-10 11:50:27 +08:00
|
|
|
return -EINVAL;
|
2024-05-10 11:50:28 +08:00
|
|
|
|
|
|
|
if (flags & IORING_NOP_INJECT_RESULT)
|
|
|
|
nop->result = READ_ONCE(sqe->len);
|
|
|
|
else
|
|
|
|
nop->result = 0;
|
2022-05-25 01:56:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int io_nop(struct io_kiocb *req, unsigned int issue_flags)
|
|
|
|
{
|
2024-05-10 11:50:28 +08:00
|
|
|
struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
|
|
|
|
|
|
|
|
if (nop->result < 0)
|
|
|
|
req_set_fail(req);
|
|
|
|
io_req_set_res(req, nop->result, 0);
|
2022-05-25 01:56:42 +08:00
|
|
|
return IOU_OK;
|
|
|
|
}
|