Skip to content

Commit 647aa76

Browse files
committed
Revert "fs: add infrastructure for multigrain timestamps"
This reverts commit ffb6cf1. Users reported regressions due to enabling multi-grained timestamps unconditionally. As no clear consensus on a solution has come up and the discussion has gone back to the drawing board revert the infrastructure changes for. If it isn't code that's here to stay, make it go away. Message-ID: <20230920-keine-eile-c9755b5825db@brauner> Acked-by: Jan Kara <jack@suse.cz> Acked-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent efd34f0 commit 647aa76

File tree

3 files changed

+7
-162
lines changed

3 files changed

+7
-162
lines changed

fs/inode.c

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,52 +2102,10 @@ int file_remove_privs(struct file *file)
21022102
}
21032103
EXPORT_SYMBOL(file_remove_privs);
21042104

2105-
/**
2106-
* current_mgtime - Return FS time (possibly fine-grained)
2107-
* @inode: inode.
2108-
*
2109-
* Return the current time truncated to the time granularity supported by
2110-
* the fs, as suitable for a ctime/mtime change. If the ctime is flagged
2111-
* as having been QUERIED, get a fine-grained timestamp.
2112-
*/
2113-
struct timespec64 current_mgtime(struct inode *inode)
2114-
{
2115-
struct timespec64 now, ctime;
2116-
atomic_long_t *pnsec = (atomic_long_t *)&inode->__i_ctime.tv_nsec;
2117-
long nsec = atomic_long_read(pnsec);
2118-
2119-
if (nsec & I_CTIME_QUERIED) {
2120-
ktime_get_real_ts64(&now);
2121-
return timestamp_truncate(now, inode);
2122-
}
2123-
2124-
ktime_get_coarse_real_ts64(&now);
2125-
now = timestamp_truncate(now, inode);
2126-
2127-
/*
2128-
* If we've recently fetched a fine-grained timestamp
2129-
* then the coarse-grained one may still be earlier than the
2130-
* existing ctime. Just keep the existing value if so.
2131-
*/
2132-
ctime = inode_get_ctime(inode);
2133-
if (timespec64_compare(&ctime, &now) > 0)
2134-
now = ctime;
2135-
2136-
return now;
2137-
}
2138-
EXPORT_SYMBOL(current_mgtime);
2139-
2140-
static struct timespec64 current_ctime(struct inode *inode)
2141-
{
2142-
if (is_mgtime(inode))
2143-
return current_mgtime(inode);
2144-
return current_time(inode);
2145-
}
2146-
21472105
static int inode_needs_update_time(struct inode *inode)
21482106
{
21492107
int sync_it = 0;
2150-
struct timespec64 now = current_ctime(inode);
2108+
struct timespec64 now = current_time(inode);
21512109
struct timespec64 ctime;
21522110

21532111
/* First try to exhaust all avenues to not sync */
@@ -2578,43 +2536,9 @@ EXPORT_SYMBOL(current_time);
25782536
*/
25792537
struct timespec64 inode_set_ctime_current(struct inode *inode)
25802538
{
2581-
struct timespec64 now;
2582-
struct timespec64 ctime;
2583-
2584-
ctime.tv_nsec = READ_ONCE(inode->__i_ctime.tv_nsec);
2585-
if (!(ctime.tv_nsec & I_CTIME_QUERIED)) {
2586-
now = current_time(inode);
2539+
struct timespec64 now = current_time(inode);
25872540

2588-
/* Just copy it into place if it's not multigrain */
2589-
if (!is_mgtime(inode)) {
2590-
inode_set_ctime_to_ts(inode, now);
2591-
return now;
2592-
}
2593-
2594-
/*
2595-
* If we've recently updated with a fine-grained timestamp,
2596-
* then the coarse-grained one may still be earlier than the
2597-
* existing ctime. Just keep the existing value if so.
2598-
*/
2599-
ctime.tv_sec = inode->__i_ctime.tv_sec;
2600-
if (timespec64_compare(&ctime, &now) > 0)
2601-
return ctime;
2602-
2603-
/*
2604-
* Ctime updates are usually protected by the inode_lock, but
2605-
* we can still race with someone setting the QUERIED flag.
2606-
* Try to swap the new nsec value into place. If it's changed
2607-
* in the interim, then just go with a fine-grained timestamp.
2608-
*/
2609-
if (cmpxchg(&inode->__i_ctime.tv_nsec, ctime.tv_nsec,
2610-
now.tv_nsec) != ctime.tv_nsec)
2611-
goto fine_grained;
2612-
inode->__i_ctime.tv_sec = now.tv_sec;
2613-
return now;
2614-
}
2615-
fine_grained:
2616-
ktime_get_real_ts64(&now);
2617-
inode_set_ctime_to_ts(inode, timestamp_truncate(now, inode));
2541+
inode_set_ctime(inode, now.tv_sec, now.tv_nsec);
26182542
return now;
26192543
}
26202544
EXPORT_SYMBOL(inode_set_ctime_current);

fs/stat.c

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,6 @@
2626
#include "internal.h"
2727
#include "mount.h"
2828

29-
/**
30-
* fill_mg_cmtime - Fill in the mtime and ctime and flag ctime as QUERIED
31-
* @stat: where to store the resulting values
32-
* @request_mask: STATX_* values requested
33-
* @inode: inode from which to grab the c/mtime
34-
*
35-
* Given @inode, grab the ctime and mtime out if it and store the result
36-
* in @stat. When fetching the value, flag it as queried so the next write
37-
* will use a fine-grained timestamp.
38-
*/
39-
void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode)
40-
{
41-
atomic_long_t *pnsec = (atomic_long_t *)&inode->__i_ctime.tv_nsec;
42-
43-
/* If neither time was requested, then don't report them */
44-
if (!(request_mask & (STATX_CTIME|STATX_MTIME))) {
45-
stat->result_mask &= ~(STATX_CTIME|STATX_MTIME);
46-
return;
47-
}
48-
49-
stat->mtime = inode->i_mtime;
50-
stat->ctime.tv_sec = inode->__i_ctime.tv_sec;
51-
/*
52-
* Atomically set the QUERIED flag and fetch the new value with
53-
* the flag masked off.
54-
*/
55-
stat->ctime.tv_nsec = atomic_long_fetch_or(I_CTIME_QUERIED, pnsec) &
56-
~I_CTIME_QUERIED;
57-
}
58-
EXPORT_SYMBOL(fill_mg_cmtime);
59-
6029
/**
6130
* generic_fillattr - Fill in the basic attributes from the inode struct
6231
* @idmap: idmap of the mount the inode was found from
@@ -89,14 +58,8 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask,
8958
stat->rdev = inode->i_rdev;
9059
stat->size = i_size_read(inode);
9160
stat->atime = inode->i_atime;
92-
93-
if (is_mgtime(inode)) {
94-
fill_mg_cmtime(stat, request_mask, inode);
95-
} else {
96-
stat->mtime = inode->i_mtime;
97-
stat->ctime = inode_get_ctime(inode);
98-
}
99-
61+
stat->mtime = inode->i_mtime;
62+
stat->ctime = inode_get_ctime(inode);
10063
stat->blksize = i_blocksize(inode);
10164
stat->blocks = inode->i_blocks;
10265

include/linux/fs.h

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,47 +1508,18 @@ static inline bool fsuidgid_has_mapping(struct super_block *sb,
15081508
kgid_has_mapping(fs_userns, kgid);
15091509
}
15101510

1511-
struct timespec64 current_mgtime(struct inode *inode);
15121511
struct timespec64 current_time(struct inode *inode);
15131512
struct timespec64 inode_set_ctime_current(struct inode *inode);
15141513

1515-
/*
1516-
* Multigrain timestamps
1517-
*
1518-
* Conditionally use fine-grained ctime and mtime timestamps when there
1519-
* are users actively observing them via getattr. The primary use-case
1520-
* for this is NFS clients that use the ctime to distinguish between
1521-
* different states of the file, and that are often fooled by multiple
1522-
* operations that occur in the same coarse-grained timer tick.
1523-
*
1524-
* The kernel always keeps normalized struct timespec64 values in the ctime,
1525-
* which means that only the first 30 bits of the value are used. Use the
1526-
* 31st bit of the ctime's tv_nsec field as a flag to indicate that the value
1527-
* has been queried since it was last updated.
1528-
*/
1529-
#define I_CTIME_QUERIED (1L<<30)
1530-
15311514
/**
15321515
* inode_get_ctime - fetch the current ctime from the inode
15331516
* @inode: inode from which to fetch ctime
15341517
*
1535-
* Grab the current ctime tv_nsec field from the inode, mask off the
1536-
* I_CTIME_QUERIED flag and return it. This is mostly intended for use by
1537-
* internal consumers of the ctime that aren't concerned with ensuring a
1538-
* fine-grained update on the next change (e.g. when preparing to store
1539-
* the value in the backing store for later retrieval).
1540-
*
1541-
* This is safe to call regardless of whether the underlying filesystem
1542-
* is using multigrain timestamps.
1518+
* Grab the current ctime from the inode and return it.
15431519
*/
15441520
static inline struct timespec64 inode_get_ctime(const struct inode *inode)
15451521
{
1546-
struct timespec64 ctime;
1547-
1548-
ctime.tv_sec = inode->__i_ctime.tv_sec;
1549-
ctime.tv_nsec = inode->__i_ctime.tv_nsec & ~I_CTIME_QUERIED;
1550-
1551-
return ctime;
1522+
return inode->__i_ctime;
15521523
}
15531524

15541525
/**
@@ -2334,7 +2305,6 @@ struct file_system_type {
23342305
#define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */
23352306
#define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */
23362307
#define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */
2337-
#define FS_MGTIME 64 /* FS uses multigrain timestamps */
23382308
#define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
23392309
int (*init_fs_context)(struct fs_context *);
23402310
const struct fs_parameter_spec *parameters;
@@ -2358,17 +2328,6 @@ struct file_system_type {
23582328

23592329
#define MODULE_ALIAS_FS(NAME) MODULE_ALIAS("fs-" NAME)
23602330

2361-
/**
2362-
* is_mgtime: is this inode using multigrain timestamps
2363-
* @inode: inode to test for multigrain timestamps
2364-
*
2365-
* Return true if the inode uses multigrain timestamps, false otherwise.
2366-
*/
2367-
static inline bool is_mgtime(const struct inode *inode)
2368-
{
2369-
return inode->i_sb->s_type->fs_flags & FS_MGTIME;
2370-
}
2371-
23722331
extern struct dentry *mount_bdev(struct file_system_type *fs_type,
23732332
int flags, const char *dev_name, void *data,
23742333
int (*fill_super)(struct super_block *, void *, int));
@@ -3054,7 +3013,6 @@ extern void page_put_link(void *);
30543013
extern int page_symlink(struct inode *inode, const char *symname, int len);
30553014
extern const struct inode_operations page_symlink_inode_operations;
30563015
extern void kfree_link(void *);
3057-
void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode);
30583016
void generic_fillattr(struct mnt_idmap *, u32, struct inode *, struct kstat *);
30593017
void generic_fill_statx_attr(struct inode *inode, struct kstat *stat);
30603018
extern int vfs_getattr_nosec(const struct path *, struct kstat *, u32, unsigned int);

0 commit comments

Comments
 (0)