* [RFC PATCH v3 1/2] fs: add filename_utimensat()
2026-11-14 10:46 [RFC PATCH v3 0/2] io_uring: add IORING_OP_UTIMENSAT Méven Car
@ 2026-11-14 10:46 ` Méven Car
2026-11-14 10:46 ` [RFC PATCH v3 2/2] io_uring: add support for utimensat Méven Car
2026-11-20 10:33 ` [RFC PATCH v3 0/2] io_uring: add IORING_OP_UTIMENSAT Christian Brauner
2 siblings, 0 replies; 5+ messages in thread
From: Méven Car @ 2026-11-14 10:46 UTC (permalink / raw)
To: Jens Axboe
Cc: io-uring, linux-fsdevel, Alexander Viro, Christian Brauner,
Jan Kara, Méven Car
From: Méven Car <meven@kde.org>
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.
Signed-off-by: Méven Car <meven@kde.org>
Reviewed-by: Jan Kara <jack@suse.cz>
---
fs/internal.h | 2 ++
fs/utimes.c | 12 +++++++++---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/fs/internal.h b/fs/internal.h
index c658c8a5ebd5..985b2bc5895e 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -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);
diff --git a/fs/utimes.c b/fs/utimes.c
index e22664e4115f..8072f05ac8dc 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -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)
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [RFC PATCH v3 2/2] io_uring: add support for utimensat
2026-11-14 10:46 [RFC PATCH v3 0/2] io_uring: add IORING_OP_UTIMENSAT Méven Car
2026-11-14 10:46 ` [RFC PATCH v3 1/2] fs: add filename_utimensat() Méven Car
@ 2026-11-14 10:46 ` Méven Car
2026-11-20 10:33 ` [RFC PATCH v3 0/2] io_uring: add IORING_OP_UTIMENSAT Christian Brauner
2 siblings, 0 replies; 5+ messages in thread
From: Méven Car @ 2026-11-14 10:46 UTC (permalink / raw)
To: Jens Axboe
Cc: io-uring, linux-fsdevel, Alexander Viro, Christian Brauner,
Jan Kara, Méven Car
From: Méven Car <meven@kde.org>
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.
Signed-off-by: Méven Car <meven@kde.org>
---
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(+)
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index b42b66b424a7..6a98c9282e0b 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -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,
diff --git a/io_uring/fs.c b/io_uring/fs.c
index 26ea841a22e7..71164bddd958 100644
--- a/io_uring/fs.c
+++ b/io_uring/fs.c
@@ -304,3 +304,100 @@ void io_link_cleanup(struct io_kiocb *req)
dismiss_delayed_filename(&sl->oldpath);
dismiss_delayed_filename(&sl->newpath);
}
+
+/* Internal flags, above the AT_ flags of the SQE */
+#define IO_UTIMENSAT_NOOP BIT(30) /* both times UTIME_OMIT */
+#define IO_UTIMENSAT_NO_PATH BIT(31) /* NULL path: the dfd itself */
+
+struct io_utimensat {
+ struct file *file;
+ int dfd;
+ unsigned int flags;
+ struct delayed_filename filename;
+ /* NULL sets both times to the current time */
+ struct timespec64 *times;
+ struct timespec64 ts[2];
+};
+
+int io_utimensat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+{
+ struct io_utimensat *ut = io_kiocb_to_cmd(req, struct io_utimensat);
+ struct __kernel_timespec __user *uts;
+ const char __user *fname;
+ int err;
+
+ if (sqe->len || sqe->buf_index || sqe->splice_fd_in || sqe->addr3 ||
+ sqe->__pad2[0])
+ return -EINVAL;
+ if (unlikely(req->flags & REQ_F_FIXED_FILE))
+ return -EBADF;
+
+ ut->dfd = READ_ONCE(sqe->fd);
+ ut->flags = READ_ONCE(sqe->utimes_flags);
+ if (ut->flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH))
+ return -EINVAL;
+
+ uts = u64_to_user_ptr(READ_ONCE(sqe->addr2));
+ ut->times = NULL;
+ if (uts) {
+ if (get_timespec64(&ut->ts[0], &uts[0]) ||
+ get_timespec64(&ut->ts[1], &uts[1]))
+ return -EFAULT;
+ ut->times = ut->ts;
+ if (ut->ts[0].tv_nsec == UTIME_OMIT &&
+ ut->ts[1].tv_nsec == UTIME_OMIT) {
+ ut->flags |= IO_UTIMENSAT_NOOP;
+ return 0;
+ }
+ }
+
+ fname = u64_to_user_ptr(READ_ONCE(sqe->addr));
+ if (!fname) {
+ if (ut->dfd == AT_FDCWD)
+ return -EFAULT;
+ if (ut->flags)
+ return -EINVAL;
+ ut->flags |= IO_UTIMENSAT_NO_PATH;
+ goto out;
+ }
+ err = delayed_getname_uflags(&ut->filename, fname, ut->flags);
+ if (unlikely(err))
+ return err;
+ req->flags |= REQ_F_NEED_CLEANUP;
+out:
+ req->flags |= REQ_F_FORCE_ASYNC;
+ return 0;
+}
+
+int io_utimensat(struct io_kiocb *req, unsigned int issue_flags)
+{
+ struct io_utimensat *ut = io_kiocb_to_cmd(req, struct io_utimensat);
+ int ret = 0;
+
+ WARN_ON_ONCE((issue_flags & IO_URING_F_NONBLOCK) &&
+ !(ut->flags & IO_UTIMENSAT_NOOP));
+
+ if (ut->flags & IO_UTIMENSAT_NO_PATH) {
+ CLASS(fd, f)(ut->dfd);
+
+ ret = -EBADF;
+ if (!fd_empty(f))
+ ret = vfs_utimes(&fd_file(f)->f_path, ut->times);
+ } else if (!(ut->flags & IO_UTIMENSAT_NOOP)) {
+ CLASS(filename_complete_delayed, name)(&ut->filename);
+ ret = filename_utimensat(ut->dfd, name, ut->times, ut->flags);
+ }
+
+ req->flags &= ~REQ_F_NEED_CLEANUP;
+ if (ret < 0)
+ req_set_fail(req);
+ io_req_set_res(req, ret, 0);
+ return IOU_COMPLETE;
+}
+
+void io_utimensat_cleanup(struct io_kiocb *req)
+{
+ struct io_utimensat *ut = io_kiocb_to_cmd(req, struct io_utimensat);
+
+ dismiss_delayed_filename(&ut->filename);
+}
diff --git a/io_uring/fs.h b/io_uring/fs.h
index 0bb5efe3d6bb..2812dc3b4b2f 100644
--- a/io_uring/fs.h
+++ b/io_uring/fs.h
@@ -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);
diff --git a/io_uring/opdef.c b/io_uring/opdef.c
index cf3aa2242cd7..383a9b9d1df4 100644
--- a/io_uring/opdef.c
+++ b/io_uring/opdef.c
@@ -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)
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [RFC PATCH v3 0/2] io_uring: add IORING_OP_UTIMENSAT
2026-11-14 10:46 [RFC PATCH v3 0/2] io_uring: add IORING_OP_UTIMENSAT Méven Car
2026-11-14 10:46 ` [RFC PATCH v3 1/2] fs: add filename_utimensat() Méven Car
2026-11-14 10:46 ` [RFC PATCH v3 2/2] io_uring: add support for utimensat Méven Car
@ 2026-11-20 10:33 ` Christian Brauner
2026-11-20 16:34 ` Jens Axboe
2 siblings, 1 reply; 5+ messages in thread
From: Christian Brauner @ 2026-11-20 10:33 UTC (permalink / raw)
To: Méven Car, Jens Axboe
Cc: io-uring, linux-fsdevel, Alexander Viro, Jan Kara, Méven Car
On Sat, Nov 14, 2026 at 11:46:19AM +0100, Méven Car wrote:
> 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.
To me it seems strange to grow an io_uring opcode per attribute. What
makes the most sense to me is a common interface to set multiple
attributes in one shot that is shared between io_uring and the regular
system call path. IOW, an extensible struct based system call that takes
the mode, owner and times and does a single ->setattr() and an io_uring
opcode that uses the same struct. Then a copy sets everything at once
and userspace that doesn't use io_uring gets the same thing and it would
reduce the number of system calls for userspace and less work for
io_uring as well.
The other thing that this would allow is for filesystems to implement
multi-attribute changes in one transaction.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH v3 0/2] io_uring: add IORING_OP_UTIMENSAT
2026-11-20 10:33 ` [RFC PATCH v3 0/2] io_uring: add IORING_OP_UTIMENSAT Christian Brauner
@ 2026-11-20 16:34 ` Jens Axboe
0 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2026-11-20 16:34 UTC (permalink / raw)
To: Christian Brauner, Méven Car
Cc: io-uring, linux-fsdevel, Alexander Viro, Jan Kara, Méven Car
On 11/20/26 3:33 AM, Christian Brauner wrote:
> On Sat, Nov 14, 2026 at 11:46:19AM +0100, M?ven Car wrote:
>> 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.
>
> To me it seems strange to grow an io_uring opcode per attribute. What
> makes the most sense to me is a common interface to set multiple
> attributes in one shot that is shared between io_uring and the regular
> system call path. IOW, an extensible struct based system call that takes
> the mode, owner and times and does a single ->setattr() and an io_uring
> opcode that uses the same struct. Then a copy sets everything at once
> and userspace that doesn't use io_uring gets the same thing and it would
> reduce the number of system calls for userspace and less work for
> io_uring as well.
>
> The other thing that this would allow is for filesystems to implement
> multi-attribute changes in one transaction.
Arrays of things is usually unhandy for io_uring, eg if the idea is to
have an array of structs to deal with. It's a lot more expensive for
persisting the data, as you know need to copy a bunch of it, rather than
just have the single item which will fit in the per-sqe data for
io_uring and not require any allocations. An example are things like
sendmmsg - that kind of construct just doesn't make sense for io_uring,
as you could've just done N SQEs instead.
It also becomes problematic with the non-blocking aspect to deal with
multiples at the time, dealing with "yep first N worked, N+1 would've
blocked" which then turns into do you blocking retry the latter bits, or
do you just return N done and let the app deal with it.
With that said, I need to actually set some time aside to look at this
patchset and render an informed opinion :-)
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread