[RFC 4/5] hostfs: flush times when closing FDs
Johannes Berg
johannes at sipsolutions.net
Thu Nov 19 05:24:41 PST 2026
From: Benjamin Berg <benjamin.berg at intel.com>
In time-travel mode we have a different time from the host. As the host
updates the timestamps when the file is written, we also need to update
them after the write has happened. Do so when we destroy the inode as
that is the point in time where we'll forget our own timestamps and need
them to on disk in case the file is reopened.
Not for upstream as-is. If not in time-travel mode, we should just use
S_NOCMTIME while in time-travel mode we probably want to do something
like this.
Signed-off-by: Benjamin Berg <benjamin.berg at intel.com>
Signed-off-by: Johannes Berg <johannes.berg at intel.com>
---
fs/hostfs/hostfs_kern.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index 224683fd74cb..09640dd6f373 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -239,6 +239,36 @@ static void hostfs_evict_inode(struct inode *inode)
truncate_inode_pages_final(&inode->i_data);
clear_inode(inode);
if (HOSTFS_I(inode)->fd != -1) {
+ /*
+ * If writes happened, then the host will have updated the
+ * timestamps. This is a good time to ensure timestamps are
+ * correct as no further changes will be done by us and our
+ * internal cache is disappearing.
+ */
+ if (HOSTFS_I(inode)->mode & FMODE_WRITE) {
+ struct hostfs_iattr attrs = {
+ .ia_valid = HOSTFS_ATTR_ATIME_SET |
+ HOSTFS_ATTR_MTIME_SET |
+ HOSTFS_ATTR_ATIME |
+ HOSTFS_ATTR_MTIME |
+ HOSTFS_ATTR_CTIME,
+ .ia_atime = (struct hostfs_timespec) {
+ inode->i_atime_sec,
+ inode->i_atime_nsec
+ },
+ .ia_mtime = (struct hostfs_timespec) {
+ inode->i_mtime_sec,
+ inode->i_mtime_nsec
+ },
+ .ia_ctime = (struct hostfs_timespec) {
+ inode->i_ctime_sec,
+ inode->i_ctime_nsec
+ },
+ };
+
+ set_attr(NULL, &attrs, HOSTFS_I(inode)->fd);
+ }
+
close_file(&HOSTFS_I(inode)->fd);
HOSTFS_I(inode)->fd = -1;
HOSTFS_I(inode)->dev = 0;
--
2.56.1
More information about the linux-um
mailing list