nop.c 961 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: GPL-2.0
  2. #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. #include <uapi/linux/io_uring.h>
  8. #include "io_uring.h"
  9. #include "nop.h"
  10. struct io_nop {
  11. /* NOTE: kiocb has the file as the first member, so don't do it here */
  12. struct file *file;
  13. int result;
  14. };
  15. int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
  16. {
  17. unsigned int flags;
  18. struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
  19. flags = READ_ONCE(sqe->nop_flags);
  20. if (flags & ~IORING_NOP_INJECT_RESULT)
  21. return -EINVAL;
  22. if (flags & IORING_NOP_INJECT_RESULT)
  23. nop->result = READ_ONCE(sqe->len);
  24. else
  25. nop->result = 0;
  26. return 0;
  27. }
  28. int io_nop(struct io_kiocb *req, unsigned int issue_flags)
  29. {
  30. struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
  31. if (nop->result < 0)
  32. req_set_fail(req);
  33. io_req_set_res(req, nop->result, 0);
  34. return IOU_OK;
  35. }