Skip to content

Commit ac46bd3

Browse files
committed
pNFS: Ensure we layoutcommit before revalidating attributes
If we need to update the cached attributes, then we'd better make sure that we also layoutcommit first. Otherwise, the server may have stale attributes. Prior to this patch, the revalidation code tried to "fix" this problem by simply disabling attributes that would be affected by the layoutcommit. That approach breaks nfs_writeback_check_extend(), leading to a file size corruption. Signed-off-by: Trond Myklebust <[email protected]>
1 parent 2e18d4d commit ac46bd3

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

fs/nfs/inode.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,13 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
974974
if (NFS_STALE(inode))
975975
goto out;
976976

977+
/* pNFS: Attributes aren't updated until we layoutcommit */
978+
if (S_ISREG(inode->i_mode)) {
979+
status = pnfs_sync_inode(inode, false);
980+
if (status)
981+
goto out;
982+
}
983+
977984
status = -ENOMEM;
978985
fattr = nfs_alloc_fattr();
979986
if (fattr == NULL)
@@ -1493,28 +1500,12 @@ static int nfs_inode_attrs_need_update(const struct inode *inode, const struct n
14931500
((long)nfsi->attr_gencount - (long)nfs_read_attr_generation_counter() > 0);
14941501
}
14951502

1496-
/*
1497-
* Don't trust the change_attribute, mtime, ctime or size if
1498-
* a pnfs LAYOUTCOMMIT is outstanding
1499-
*/
1500-
static void nfs_inode_attrs_handle_layoutcommit(struct inode *inode,
1501-
struct nfs_fattr *fattr)
1502-
{
1503-
if (pnfs_layoutcommit_outstanding(inode))
1504-
fattr->valid &= ~(NFS_ATTR_FATTR_CHANGE |
1505-
NFS_ATTR_FATTR_MTIME |
1506-
NFS_ATTR_FATTR_CTIME |
1507-
NFS_ATTR_FATTR_SIZE);
1508-
}
1509-
15101503
static int nfs_refresh_inode_locked(struct inode *inode, struct nfs_fattr *fattr)
15111504
{
15121505
int ret;
15131506

15141507
trace_nfs_refresh_inode_enter(inode);
15151508

1516-
nfs_inode_attrs_handle_layoutcommit(inode, fattr);
1517-
15181509
if (nfs_inode_attrs_need_update(inode, fattr))
15191510
ret = nfs_update_inode(inode, fattr);
15201511
else

0 commit comments

Comments
 (0)