Skip to content

tmpfiles: do not require STATX_ATIME - #41232

Merged
keszybz merged 3 commits into
systemd:mainfrom
intelfx:work/tmpfiles-do-not-mandate-atime
Apr 8, 2026
Merged

keszybz merged 3 commits into
systemd:mainfrom
intelfx:work/tmpfiles-do-not-mandate-atime

Conversation

@intelfx

@intelfx intelfx commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Timestamps are not guaranteed to be set by statx(), and their presence
should not be asserted as a proxy to judge the kernel version. In
particular, STATX_ATIME is omitted from the return when querying a
file on a noatime superblock, causing spurious errors from tmpfiles:

# SYSTEMD_LOG_LEVEL=debug systemd-tmpfiles --clean
<...>
Running clean action for entry X /var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-*/tmp
statx() does not support 'STATX_ATIME' mask (running on an old kernel?)
statx(/var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-prometheus-smartctl-exporter.service-GKguQK/tmp) failed: Protocol driver not attached
statx() does not support 'STATX_ATIME' mask (running on an old kernel?)
statx(/var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-systemd-logind.service-k8j52T/tmp) failed: Protocol driver not attached
statx() does not support 'STATX_ATIME' mask (running on an old kernel?)
statx(/var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-irqbalance.service-7RJkev/tmp) failed: Protocol driver not attached
statx() does not support 'STATX_ATIME' mask (running on an old kernel?)
statx(/var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-chronyd.service-8hkO5G/tmp) failed: Protocol driver not attached
statx() does not support 'STATX_ATIME' mask (running on an old kernel?)
statx(/var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-dbus-broker.service-6P6LVl/tmp) failed: Protocol driver not attached
statx() does not support 'STATX_ATIME' mask (running on an old kernel?)
statx(/var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-nginx.service-B5HX8B/tmp) failed: Protocol driver not attached
Running clean action for entry x /var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-*
Running clean action for entry q /var/tmp
statx() does not support 'STATX_ATIME' mask (running on an old kernel?)
statx(/var/tmp) failed: Protocol driver not attached
<...>

Additionally, refactor dir_cleanup() slightly for self-consistency to make
it evident that the NSEC_INFINITY transformation is correct.

Fixes #41227.

@github-actions github-actions Bot added tmpfiles please-review PR is ready for (re-)review by a maintainer labels Mar 20, 2026

@keszybz keszybz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Comment thread src/tmpfiles/tmpfiles.c Resolved
Comment thread src/tmpfiles/tmpfiles.c Resolved
@keszybz keszybz added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed please-review PR is ready for (re-)review by a maintainer labels Mar 20, 2026
@github-actions

github-actions Bot commented Mar 22, 2026 •

Copy link
Copy Markdown

Claude review of PR #41232 (122de8d)

Overall this is a well-reasoned bugfix. All three commits are correct in their core logic and the PR is a strict improvement over the status quo (before: xstatx() fails with EUNATCH on noatime filesystems, preventing cleanup entirely; after: cleanup works correctly). The correctness analysis in the commit messages is thorough.

Suggestions

  • futimens fails when only one timestamp is NSEC_INFINITY — src/tmpfiles/tmpfiles.c:864 — On a noatime filesystem, self_atime_nsec will be NSEC_INFINITY while self_mtime_nsec is valid. The finish block guard passes (OR condition), but timespec_store_nsec(NSEC_INFINITY) produces {-1, -1} which causes futimens() to fail with EINVAL, preventing mtime restoration too. Consider using TIMESPEC_OMIT for unavailable timestamps.

Workflow run

Comment thread src/tmpfiles/tmpfiles.c Resolved
@daandemeyer daandemeyer added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed labels Mar 22, 2026
@poettering poettering added this to the v261 milestone Mar 25, 2026
intelfx added 3 commits April 6, 2026 22:53
Correctness analysis
====================

The *time_nsec variables are used for a total of 2 or 3 times:

- twice in needs_cleanup() (lines 788, 839)
- once in a recursive dir_cleanup() (line 764) as self_*time_nsec

In needs_cleanup(), all passed timestamps are guarded against
NSEC_INFINITY (this does not fix any real bugs as a 0 value is also
older than any cutoff point and thus would not cause any deletions).

Recursively in dir_cleanup(), the self_* variables are used to reset
the toplevel directory utimes, where they are superficially compared
against NSEC_INFINITY as a guard, but subsequently mishandled in the
case when only one of the times is NSEC_INFINITY: in this case, it will
be a) logged as a bogus value and b) passed through directly to
timespec_store_nsec(), which does special-case it, but in a way that
is invalid for futimens(). This is further fixed up by explicitly
mapping NSEC_INFINITY to TIMESPEC_OMIT.

This constitutes a bugfix in theory, as a ~STATX_ATIME return from
statx() would have previously caused the corresponding utime to be
reset to 0 epoch) rather than being omitted from being set. However,
in a directory with ~STATX_ATIME, attempts to set atime would likely
be ignored as well.

Mostly this is a self-consistency fix that establishes that
dir_cleanup() should be called with NSEC_INFINITY in place of
absent timestamps.
Timestamps are not guaranteed to be set by `statx()`, and their presence
should not be asserted as a proxy to judge the kernel version. In
particular, `STATX_ATIME` is omitted from the return when querying a
file on a `noatime` superblock, causing spurious errors from tmpfiles.

Correctness analysis
====================

The timestamps produced by the `statx()` call in `opendir_and_stat()`
are only ever used once, in `clean_item_instance()` (lines 3148-3149)
as inputs to `dir_cleanup()`. Convert absent timestamps into
`NSEC_INFINITY` as per the previous commit.

Fixes systemd#41227.
@intelfx
intelfx force-pushed the work/tmpfiles-do-not-mandate-atime branch from 6b1727d to 122de8d Compare April 6, 2026 21:00
@github-actions github-actions Bot added util-lib please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Apr 6, 2026
@poettering poettering added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed please-review PR is ready for (re-)review by a maintainer labels Apr 7, 2026

@keszybz keszybz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too.

@keszybz
keszybz merged commit df45055 into systemd:main Apr 8, 2026
57 of 58 checks passed
@github-actions github-actions Bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Apr 8, 2026
@PaulGrandperrin

Copy link
Copy Markdown

Hi, could this be backported to the 260 branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

tmpfiles: bogus error condition when STATX_ATIME is not set

5 participants