Skip to content

Commit ffdec8d

Browse files
committed
cifs: do not ignore the SYNC flags in getattr
Check the AT_STATX_FORCE_SYNC flag and force an attribute revalidation if requested by the caller, and if the caller specificies AT_STATX_DONT_SYNC only revalidate cached attributes if required. In addition do not flush writes in getattr (which can be expensive) if size or timestamps not requested by the caller. Reviewed-by: Aurelien Aptel <[email protected]> Reviewed-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 16fbf79 commit ffdec8d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

fs/cifs/inode.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,18 +2148,30 @@ int cifs_getattr(const struct path *path, struct kstat *stat,
21482148
* We need to be sure that all dirty pages are written and the server
21492149
* has actual ctime, mtime and file length.
21502150
*/
2151-
if (!CIFS_CACHE_READ(CIFS_I(inode)) && inode->i_mapping &&
2152-
inode->i_mapping->nrpages != 0) {
2151+
if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE)) &&
2152+
!CIFS_CACHE_READ(CIFS_I(inode)) &&
2153+
inode->i_mapping && inode->i_mapping->nrpages != 0) {
21532154
rc = filemap_fdatawait(inode->i_mapping);
21542155
if (rc) {
21552156
mapping_set_error(inode->i_mapping, rc);
21562157
return rc;
21572158
}
21582159
}
21592160

2160-
rc = cifs_revalidate_dentry_attr(dentry);
2161-
if (rc)
2162-
return rc;
2161+
if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_FORCE_SYNC)
2162+
CIFS_I(inode)->time = 0; /* force revalidate */
2163+
2164+
/*
2165+
* If the caller doesn't require syncing, only sync if
2166+
* necessary (e.g. due to earlier truncate or setattr
2167+
* invalidating the cached metadata)
2168+
*/
2169+
if (((flags & AT_STATX_SYNC_TYPE) != AT_STATX_DONT_SYNC) ||
2170+
(CIFS_I(inode)->time == 0)) {
2171+
rc = cifs_revalidate_dentry_attr(dentry);
2172+
if (rc)
2173+
return rc;
2174+
}
21632175

21642176
generic_fillattr(inode, stat);
21652177
stat->blksize = cifs_sb->bsize;

0 commit comments

Comments
 (0)