Re: [WIP PATCH] io_uring: Support opening a file into the fixed-file table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 15, 2020 at 10:54:21PM +0300, Pavel Begunkov wrote:
> On 15/07/2020 00:08, Josh Triplett wrote:
> > +static int io_openat2_fixed_file(struct io_kiocb *req, bool force_nonblock)
> > +{
> 
> How about having it in io_openat2()? There are almost identical, that would be
> just a couple of if's.

It's a little more complex than that. It would require making three
pieces of io_openat2 conditional, and the control flow would be
intertwined with whether the file descriptor (from get_unused_fd_flags)
has been initialized. It's absolutely *doable*, but the resulting
complexity didn't seem worth it.

> > +	struct io_open *open = &req->open;
> > +	struct open_flags op;
> > +	struct file *file;
> > +	int ret;
> > +
> > +	if (force_nonblock) {
> > +		/* only need file table for an actual valid fd */
> > +		if (open->dfd == -1 || open->dfd == AT_FDCWD)
> > +			req->flags |= REQ_F_NO_FILE_TABLE;
> > +		return -EAGAIN;
> > +	}
> > +
> > +	ret = build_open_flags(&open->how, &op);
> > +	if (ret)
> > +		goto err;
> > +
> > +	file = do_filp_open(open->dfd, open->filename, &op);
> > +	if (IS_ERR(file)) {
> > +		ret = PTR_ERR(file);
> > +	} else {
> > +		fsnotify_open(file);
> > +		ret = io_sqe_files_add_new(req->ctx, open->open_fixed_idx, file);
> > +		if (ret)
> > +			fput(file);
> > +	}
> > +err:
> > +	putname(open->filename);
> > +	req->flags &= ~REQ_F_NEED_CLEANUP;
> > +	if (ret < 0)
> > +		req_set_fail_links(req);
> > +	io_cqring_add_event(req, ret);
> > +	io_put_req(req);
> 
> These 2 lines are better to be replace with (since 5.9):
> 
> io_req_complete(req, ret);

This was directly copied from the same code in io_openat2.

> > +	return 0;
> > +}
> > +
> >  static int io_openat2(struct io_kiocb *req, bool force_nonblock)
> >  {
> >  	struct open_flags op;
> > @@ -5048,6 +5094,7 @@ static int io_req_defer_prep(struct io_kiocb *req,
> >  		ret = io_madvise_prep(req, sqe);
> >  		break;
> >  	case IORING_OP_OPENAT2:
> > +	case IORING_OP_OPENAT2_FIXED_FILE:
> >  		ret = io_openat2_prep(req, sqe);
> >  		break;
> >  	case IORING_OP_EPOLL_CTL:
> > @@ -5135,6 +5182,7 @@ static void io_cleanup_req(struct io_kiocb *req)
> >  		break;
> >  	case IORING_OP_OPENAT:
> >  	case IORING_OP_OPENAT2:
> > +	case IORING_OP_OPENAT2_FIXED_FILE:
> 
> These OPENAT cases weren't doing anything, so were killed,
> as should be this line.

Makes sense.

> >  		break;
> >  	case IORING_OP_SPLICE:
> >  	case IORING_OP_TEE:
> > @@ -5329,12 +5377,17 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
> >  		ret = io_madvise(req, force_nonblock);
> >  		break;
> >  	case IORING_OP_OPENAT2:
> > +	case IORING_OP_OPENAT2_FIXED_FILE:
> >  		if (sqe) {
> >  			ret = io_openat2_prep(req, sqe);
> >  			if (ret)
> >  				break;
> >  		}
> > -		ret = io_openat2(req, force_nonblock);
> > +		if (req->opcode == IORING_OP_OPENAT2) {
> > +			ret = io_openat2(req, force_nonblock);
> > +		} else {
> > +			ret = io_openat2_fixed_file(req, force_nonblock);
> > +		}
> 
> We don't need all these brackets for one liners

Habit; most codebases I work on *always* include the braces.

> > --- a/include/uapi/linux/io_uring.h
> > +++ b/include/uapi/linux/io_uring.h
> > @@ -54,7 +54,10 @@ struct io_uring_sqe {
> >  			} __attribute__((packed));
> >  			/* personality to use, if used */
> >  			__u16	personality;
> > -			__s32	splice_fd_in;
> > +			union {
> > +				__s32	splice_fd_in;
> > +				__s32	open_fixed_idx;
> > +			};
> >  		};
> >  		__u64	__pad2[3];
> >  	};
> > @@ -130,6 +133,7 @@ enum {
> >  	IORING_OP_PROVIDE_BUFFERS,
> >  	IORING_OP_REMOVE_BUFFERS,
> >  	IORING_OP_TEE,
> > +	IORING_OP_OPENAT2_FIXED_FILE,
> 
> I think, it's better to reuse IORING_OP_OPENAT2.
> E.g. fixed version if "open_fixed_idx != 0" or something similar.

As far as I can tell, nothing in today's handling of IORING_OP_OPENAT2
will give an EINVAL for splice_fd_in!=0. It might be possible to arrange
for it to be the same op via a new flag or something else that the
current IORING_OP_OPENAT2 wil reject (and if it's a flag or similar, all
other operations that don't involve opening a file would also need to
reject it).



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux