Skip to contentSkip to conversation

io_uring: add IORING_OP_UTIMENSAT

RFC PATCH New Méven Car 1 participant 3 messages Nov 14

Subsystems (2)
lore
Share & tools
lore

Méven Car

author
#0 lore raw

v3 cover io_uring: add IORING_OP_UTIMENSAT

From: Méven Car <[email protected]>

A file manager or cp -p that copies many files sets the times of every copy after its last write. KDE's KIO does not use io_uring yet, but could in the future. In a KIO prototype that copies batches of small files through io_uring, open, create, read and write run in the ring, but the metadata of each copy is set outside the ring, with futimens() and, when needed, fchmod() and fchown(). On NFS and SMB each of these calls is a round trip to the server.

In that prototype, setting the metadata from a pool of 16 threads instead of one file at a time cut the copy of 200 files of 4 KiB by 22% on NFS and 45% on SMB. The test copied from ext4 to an NFS 4.2 and an SMB mount of the same machine, over loopback with a netem delay of 2 ms each way. An opcode would give the same parallelism from the ring, and would let a copy be one linked chain per file: WRITE, UTIMENSAT, CLOSE.

Patch 1 splits filename_utimensat() out of do_utimes_path(), so that io_uring can pass a name imported at submission time, as it does for mkdirat and the other path ops.

Patch 2 adds IORING_OP_UTIMENSAT with the semantics of utimensat(2). Like the other path ops it runs from io-wq.

IORING_OP_FCHMOD was proposed in 2024 [1] and not merged. The same questions apply to fchmod and fchown, which a copy also needs, and a single setattr opcode could set the mode, owner and times in one ->setattr() call. I started with the times because a copy always sets them.

Testing: a userspace test of 30 cases (paths, AT_EMPTY_PATH on O_PATH fds, NULL path, UTIME_OMIT, permission and read-only errors, links, copy at submission, punt to io-wq on tmpfs and ramfs) passes in a qemu guest on for-7.4/io_uring. A liburing helper, test and man page will follow if the interface is acceptable.

[1] https://lore.kernel.org/io-uring/[email protected]/

Changes in v3:
- Drop patch 3, the inline attempt with FS_SETATTR_TIMES_NOWAIT and mnt_want_write_trylock(). It added generic VFS API for one filesystem, still ran the blocking parts of notify_change(), and looked the path up twice on every other filesystem. (Christian Brauner)
- Patch 1: add Jan Kara's Reviewed-by.

Changes in v2:
- A NULL path now sets the times through the fd itself, like do_utimes_fd(), instead of a lookup of an empty name. As with utimensat(2), it takes no flags (-EINVAL), an O_PATH fd gives -EBADF, and an open file that was unlinked needs no revalidation. (Sashiko)
- Patch 2 message: drop the wrong claim that AT_EMPTY_PATH on an O_PATH fd differs from the syscall.

v2: https://lore.kernel.org/io-uring/[email protected]/
v1: https://lore.kernel.org/io-uring/[email protected]/

Méven Car (2):
fs: add filename_utimensat()
io_uring: add support for utimensat

 fs/internal.h                 |  2 +
 fs/utimes.c                   | 12 +++--
 include/uapi/linux/io_uring.h |  2 +
 io_uring/fs.c                 | 97 +++++++++++++++++++++++++++++++++++
 io_uring/fs.h                 |  4 ++
 io_uring/opdef.c              |  8 +++
 6 files changed, 122 insertions(+), 3 deletions(-)

base-commit: ecb6817b769fd7d71af2c9f446188649020b2e53

Signature · 1 line
2.56.1
author
#1 lore raw

RFC PATCH v3 1/2 fs: add filename_utimensat()

From: Méven Car <[email protected]>

Copy utilities that preserve timestamps, like cp -p or a file manager, set the times of every copy after its last write. To do that through io_uring, the request needs the utimensat() lookup on a name that was imported at submission time.

io_uring takes the path of a request when it is submitted and looks it up later, from a worker thread. The path ops it already has call the filename_*() helpers of fs/namei.c with a struct filename. utimensat(2) had no such helper: do_utimes_path() took the user pointer and imported the name itself.

Split the lookup and the vfs_utimes() call out of do_utimes_path() into filename_utimensat(), declared in fs/internal.h next to the other filename_*() helpers. do_utimes_path() now only imports the name.

---
 fs/internal.h |  2 ++
 fs/utimes.c   | 12 +++++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)
fs/internal.h +2 -0
index c658c8a5ebd5..985b2bc5895e 100644
@@ -63,6 +63,8 @@ int filename_mknodat(int dfd, struct filename *name, umode_t mode, unsigned int
 int filename_symlinkat(struct filename *from, int newdfd, struct filename *to);
 int filename_linkat(int olddfd, struct filename *old, int newdfd,
 			struct filename *new, int flags);
+int filename_utimensat(int dfd, struct filename *name,
+		       struct timespec64 *times, int flags);
 int vfs_tmpfile(struct mnt_idmap *idmap,
 		const struct path *parentpath,
 		struct file *file, umode_t mode);
fs/utimes.c +9 -3
index e22664e4115f..8072f05ac8dc 100644
@@ -79,8 +79,8 @@ int vfs_utimes(const struct path *path, struct timespec64 *times)
 }
 EXPORT_SYMBOL_GPL(vfs_utimes);
 
-static int do_utimes_path(int dfd, const char __user *filename,
-		struct timespec64 *times, int flags)
+int filename_utimensat(int dfd, struct filename *name,
+		       struct timespec64 *times, int flags)
 {
 	struct path path;
 	int lookup_flags = 0, error;
@@ -91,7 +91,6 @@ static int do_utimes_path(int dfd, const char __user *filename,
 	if (!(flags & AT_SYMLINK_NOFOLLOW))
 		lookup_flags |= LOOKUP_FOLLOW;
 
-	CLASS(filename_uflags, name)(filename, flags);
 retry:
 	error = filename_lookup(dfd, name, lookup_flags, &path, NULL);
 	if (error)
@@ -105,6 +104,13 @@ static int do_utimes_path(int dfd, const char __user *filename,
 	return error;
 }
 
+static int do_utimes_path(int dfd, const char __user *filename,
+		struct timespec64 *times, int flags)
+{
+	CLASS(filename_uflags, name)(filename, flags);
+	return filename_utimensat(dfd, name, times, flags);
+}
+
 static int do_utimes_fd(int fd, struct timespec64 *times, int flags)
 {
 	if (flags)
Signature · 1 line
2.56.1
author
#2 lore raw

RFC PATCH v3 2/2 io_uring: add support for utimensat

In reply to Méven Car

From: Méven Car <[email protected]>

A program that copies many files sets the times of every copy after its last write. On NFS and SMB each of those calls is a round trip to the server, and with io_uring it is one of the steps of the copy that still have to leave the ring and run one file at a time.

IORING_OP_UTIMENSAT behaves like utimensat(2). sqe->fd is the directory fd, sqe->addr the path, sqe->addr2 a pointer to two struct __kernel_timespec, and sqe->utimes_flags takes AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH. An addr2 of zero sets both times to the current time, as a NULL times argument does. The times and the path are copied at submission.

As with utimensat(2), a NULL path sets the times of the file that sqe->fd refers to, without a lookup, and takes no flags. Two UTIME_OMIT times complete with 0 without a lookup.

Like the other path ops, the request is issued from io-wq, apart from the no-op, because the lookup and notify_change() can sleep. A fixed file is not accepted as the directory fd. A failed request fails the rest of its link.

---
 include/uapi/linux/io_uring.h |  2 +
 io_uring/fs.c                 | 97 +++++++++++++++++++++++++++++++++++
 io_uring/fs.h                 |  4 ++
 io_uring/opdef.c              |  8 +++
 4 files changed, 111 insertions(+)
include/uapi/linux/io_uring.h +2 -0
index b42b66b424a7..6a98c9282e0b 100644
@@ -76,6 +76,7 @@ struct io_uring_sqe {
 		__u32		install_fd_flags;
 		__u32		nop_flags;
 		__u32		pipe_flags;
+		__u32		utimes_flags;
 	};
 	__u64	user_data;	/* data to be passed back at completion time */
 	/* pack this to avoid bogus arm OABI complaints */
@@ -319,6 +320,7 @@ enum io_uring_op {
 	IORING_OP_PIPE,
 	IORING_OP_NOP128,
 	IORING_OP_URING_CMD128,
+	IORING_OP_UTIMENSAT,
 
 	/* this goes last, obviously */
 	IORING_OP_LAST,
io_uring/fs.c +97 -0

100 lines not on this page · raw message

io_uring/fs.h +4 -0
index 0bb5efe3d6bb..2812dc3b4b2f 100644
@@ -18,3 +18,7 @@ int io_symlinkat(struct io_kiocb *req, unsigned int issue_flags);
 int io_linkat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
 int io_linkat(struct io_kiocb *req, unsigned int issue_flags);
 void io_link_cleanup(struct io_kiocb *req);
+
+int io_utimensat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
+int io_utimensat(struct io_kiocb *req, unsigned int issue_flags);
+void io_utimensat_cleanup(struct io_kiocb *req);
io_uring/opdef.c +8 -0
index cf3aa2242cd7..383a9b9d1df4 100644
@@ -591,6 +591,10 @@ const struct io_issue_def io_issue_defs[] = {
 		.prep			= io_uring_cmd_prep,
 		.issue			= io_uring_cmd,
 	},
+	[IORING_OP_UTIMENSAT] = {
+		.prep			= io_utimensat_prep,
+		.issue			= io_utimensat,
+	},
 };
 
 const struct io_cold_def io_cold_defs[] = {
@@ -849,6 +853,10 @@ const struct io_cold_def io_cold_defs[] = {
 		.sqe_copy		= io_uring_cmd_sqe_copy,
 		.cleanup		= io_uring_cmd_cleanup,
 	},
+	[IORING_OP_UTIMENSAT] = {
+		.name			= "UTIMENSAT",
+		.cleanup		= io_utimensat_cleanup,
+	},
 };
 
 const char *io_uring_get_opcode(u8 opcode)
Signature · 1 line
2.56.1