io_uring/fs.c

Source file repositories/reference/linux-study-clean/io_uring/fs.c

File Facts

System
Linux kernel
Corpus path
io_uring/fs.c
Extension
.c
Size
7506 bytes
Lines
306
Domain
Kernel Services
Bucket
io_uring
Inferred role
Kernel Services: implementation source
Status
source implementation candidate

Why This File Exists

Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.

Dependency Surface

Detected Declarations

Annotated Snippet

struct io_rename {
	struct file			*file;
	int				old_dfd;
	int				new_dfd;
	struct delayed_filename		oldpath;
	struct delayed_filename		newpath;
	int				flags;
};

struct io_unlink {
	struct file			*file;
	int				dfd;
	int				flags;
	struct delayed_filename		filename;
};

struct io_mkdir {
	struct file			*file;
	int				dfd;
	umode_t				mode;
	struct delayed_filename		filename;
};

struct io_link {
	struct file			*file;
	int				old_dfd;
	int				new_dfd;
	struct delayed_filename		oldpath;
	struct delayed_filename		newpath;
	int				flags;
};

int io_renameat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{
	struct io_rename *ren = io_kiocb_to_cmd(req, struct io_rename);
	const char __user *oldf, *newf;
	int err;

	if (sqe->buf_index || sqe->splice_fd_in)
		return -EINVAL;
	if (unlikely(req->flags & REQ_F_FIXED_FILE))
		return -EBADF;

	ren->old_dfd = READ_ONCE(sqe->fd);
	oldf = u64_to_user_ptr(READ_ONCE(sqe->addr));
	newf = u64_to_user_ptr(READ_ONCE(sqe->addr2));
	ren->new_dfd = READ_ONCE(sqe->len);
	ren->flags = READ_ONCE(sqe->rename_flags);

	err = delayed_getname(&ren->oldpath, oldf);
	if (unlikely(err))
		return err;

	err = delayed_getname(&ren->newpath, newf);
	if (unlikely(err)) {
		dismiss_delayed_filename(&ren->oldpath);
		return err;
	}

	req->flags |= REQ_F_NEED_CLEANUP;
	req->flags |= REQ_F_FORCE_ASYNC;
	return 0;
}

int io_renameat(struct io_kiocb *req, unsigned int issue_flags)
{
	struct io_rename *ren = io_kiocb_to_cmd(req, struct io_rename);
	CLASS(filename_complete_delayed, old)(&ren->oldpath);
	CLASS(filename_complete_delayed, new)(&ren->newpath);
	int ret;

	WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);

	ret = filename_renameat2(ren->old_dfd, old,
				 ren->new_dfd, new, ren->flags);

	req->flags &= ~REQ_F_NEED_CLEANUP;
	io_req_set_res(req, ret, 0);
	return IOU_COMPLETE;
}

void io_renameat_cleanup(struct io_kiocb *req)
{
	struct io_rename *ren = io_kiocb_to_cmd(req, struct io_rename);

	dismiss_delayed_filename(&ren->oldpath);
	dismiss_delayed_filename(&ren->newpath);
}

int io_unlinkat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)

Annotation

Implementation Notes