44 lines · c
1// SPDX-License-Identifier: GPL-2.02#include <linux/kernel.h>3#include <linux/errno.h>4#include <linux/fs.h>5#include <linux/file.h>6#include <linux/io_uring.h>7 8#include <uapi/linux/io_uring.h>9 10#include "io_uring.h"11#include "nop.h"12 13struct io_nop {14 /* NOTE: kiocb has the file as the first member, so don't do it here */15 struct file *file;16 int result;17};18 19int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)20{21 unsigned int flags;22 struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);23 24 flags = READ_ONCE(sqe->nop_flags);25 if (flags & ~IORING_NOP_INJECT_RESULT)26 return -EINVAL;27 28 if (flags & IORING_NOP_INJECT_RESULT)29 nop->result = READ_ONCE(sqe->len);30 else31 nop->result = 0;32 return 0;33}34 35int io_nop(struct io_kiocb *req, unsigned int issue_flags)36{37 struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);38 39 if (nop->result < 0)40 req_set_fail(req);41 io_req_set_res(req, nop->result, 0);42 return IOU_OK;43}44