Commit 57c55cd7 authored by Ronnie Sahlberg's avatar Ronnie Sahlberg Committed by Steve French

cifs: invalidate cache when we truncate a file

RHBZ: 1566345

When truncating a file we always do this synchronously to the server.
Thus we need to make sure that the cached inode metadata is
marked as stale so that on next getattr we will refresh the metadata.
In this particular bug we want to ensure that both ctime and mtime
are updated and become visible to the application after a truncate.
Signed-off-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
Reported-by: default avatarXiaoli Feng <xifeng@redhat.com>
parent e0386e44
...@@ -746,7 +746,8 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, ...@@ -746,7 +746,8 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
cifs_dbg(FYI, "Getting info on %s\n", full_path); cifs_dbg(FYI, "Getting info on %s\n", full_path);
if ((data == NULL) && (*inode != NULL)) { if ((data == NULL) && (*inode != NULL)) {
if (CIFS_CACHE_READ(CIFS_I(*inode))) { if (CIFS_CACHE_READ(CIFS_I(*inode)) &&
CIFS_I(*inode)->time != 0) {
cifs_dbg(FYI, "No need to revalidate cached inode sizes\n"); cifs_dbg(FYI, "No need to revalidate cached inode sizes\n");
goto cgii_exit; goto cgii_exit;
} }
...@@ -1857,15 +1858,15 @@ cifs_inode_needs_reval(struct inode *inode) ...@@ -1857,15 +1858,15 @@ cifs_inode_needs_reval(struct inode *inode)
struct cifsInodeInfo *cifs_i = CIFS_I(inode); struct cifsInodeInfo *cifs_i = CIFS_I(inode);
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
if (cifs_i->time == 0)
return true;
if (CIFS_CACHE_READ(cifs_i)) if (CIFS_CACHE_READ(cifs_i))
return false; return false;
if (!lookupCacheEnabled) if (!lookupCacheEnabled)
return true; return true;
if (cifs_i->time == 0)
return true;
if (!cifs_sb->actimeo) if (!cifs_sb->actimeo)
return true; return true;
...@@ -2104,10 +2105,14 @@ static int cifs_truncate_page(struct address_space *mapping, loff_t from) ...@@ -2104,10 +2105,14 @@ static int cifs_truncate_page(struct address_space *mapping, loff_t from)
static void cifs_setsize(struct inode *inode, loff_t offset) static void cifs_setsize(struct inode *inode, loff_t offset)
{ {
struct cifsInodeInfo *cifs_i = CIFS_I(inode);
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
i_size_write(inode, offset); i_size_write(inode, offset);
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
/* Cached inode must be refreshed on truncate */
cifs_i->time = 0;
truncate_pagecache(inode, offset); truncate_pagecache(inode, offset);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment