[PATCH v3 1/5] fs,io_uring: add infrastructure for uring-cmd

Jens Axboe axboe at kernel.dk
Tue May 3 14:03:42 PDT 2022


On 5/3/22 12:48 PM, Pankaj Raghav wrote:
> From: Jens Axboe <axboe at kernel.dk>
> 
> file_operations->uring_cmd is a file private handler, similar to ioctls
> but hopefully a lot more sane and useful.
> 
> IORING_OP_URING_CMD is a file private kind of request. io_uring doesn't
> know what is in this command type, it's for the provider of ->uring_cmd()
> to deal with. This operation can be issued only on the ring that is
> setup with both IORING_SETUP_SQE128 and IORING_SETUP_CQE32 flags.

A few minor comments below.

> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index c7e3f7e74d92..b774e6eac538 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> +static int io_uring_cmd_prep(struct io_kiocb *req,
> +			     const struct io_uring_sqe *sqe)
> +{
> +	struct io_uring_cmd *ioucmd = &req->uring_cmd;
> +
> +	if (req->ctx->flags & IORING_SETUP_IOPOLL)
> +		return -EOPNOTSUPP;
> +	/* do not support uring-cmd without big SQE/CQE */
> +	if (!(req->ctx->flags & IORING_SETUP_SQE128))
> +		return -EOPNOTSUPP;
> +	if (!(req->ctx->flags & IORING_SETUP_CQE32))
> +		return -EOPNOTSUPP;
> +	ioucmd->cmd = (void *) &sqe->cmd;
> +	ioucmd->cmd_op = READ_ONCE(sqe->cmd_op);
> +	ioucmd->flags = 0;
> +	return 0;
> +}

I'd define

	struct io_ring_ctx *ctx = req->ctx;

here. And you should read 'rw_flags' and return -EINVAL if it's set, so
we can be backwards compatible if flags are added later. Probably read
eg sqe->ioprio as well as that isn't directly applicable (it'd just be
set in the command directly) and -EINVAL if that is set. Ala:

static int io_uring_cmd_prep(struct io_kiocb *req,
			     const struct io_uring_sqe *sqe)
{
	struct io_uring_cmd *ioucmd = &req->uring_cmd;
	struct io_ring_ctx *ctx = req->ctx;

	if (ctx->flags & IORING_SETUP_IOPOLL)
		return -EOPNOTSUPP;
	/* do not support uring-cmd without big SQE/CQE */
	if (!(ctx->flags & IORING_SETUP_SQE128))
		return -EOPNOTSUPP;
	if (!(ctx->flags & IORING_SETUP_CQE32))
		return -EOPNOTSUPP;
	if (sqe->ioprio || sqe->rw_flags
		return -EINVAL;

	ioucmd->cmd = (void *) &sqe->cmd;
	ioucmd->cmd_op = READ_ONCE(sqe->cmd_op);
	ioucmd->flags = 0;
	return 0;
}

> +static int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
> +{
> +	struct file *file = req->file;
> +	struct io_uring_cmd *ioucmd = &req->uring_cmd;
> +
> +	if (!req->file->f_op->uring_cmd)
> +		return -EOPNOTSUPP;
> +	ioucmd->flags |= issue_flags;
> +	file->f_op->uring_cmd(ioucmd);
> +	return 0;
> +}

We should pass in issue_flags here, it's a property of the call path,
not the command itself:

static int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
{
	struct file *file = req->file;
	struct io_uring_cmd *ioucmd = &req->uring_cmd;

	if (!req->file->f_op->uring_cmd)
		return -EOPNOTSUPP;
	file->f_op->uring_cmd(ioucmd, issue_flags);
	return 0;
}

and then get rid of ioucmd->flags, that can get re-added as the copy of
sqe->rw_flags when we need that.

Agree with Christoph on the things he brought up. If possible, please
just respin this patch with the suggested changes and we can queue it
up.

-- 
Jens Axboe




More information about the Linux-nvme mailing list