Skip to content

Commit

Permalink
NFS: Reduce time spent holding the i_mutex during fallocate()
Browse files Browse the repository at this point in the history
At the very least, we should not be taking the i_mutex until after
checking if the server even supports ALLOCATE or DEALLOCATE, allowing
v4.0 or v4.1 to exit without potentially waiting on a lock.

Signed-off-by: Anna Schumaker <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
  • Loading branch information
amschuma-ntap authored and trondmypd committed Apr 23, 2015
1 parent 9a51940 commit f830f7d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 8 additions & 0 deletions fs/nfs/nfs42proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ int nfs42_proc_allocate(struct file *filep, loff_t offset, loff_t len)
if (!nfs_server_capable(inode, NFS_CAP_ALLOCATE))
return -EOPNOTSUPP;

mutex_lock(&inode->i_mutex);

err = nfs42_proc_fallocate(&msg, filep, offset, len);
if (err == -EOPNOTSUPP)
NFS_SERVER(inode)->caps &= ~NFS_CAP_ALLOCATE;

mutex_unlock(&inode->i_mutex);
return err;
}

Expand All @@ -114,11 +118,15 @@ int nfs42_proc_deallocate(struct file *filep, loff_t offset, loff_t len)
return -EOPNOTSUPP;

nfs_wb_all(inode);
mutex_lock(&inode->i_mutex);

err = nfs42_proc_fallocate(&msg, filep, offset, len);
if (err == 0)
truncate_pagecache_range(inode, offset, (offset + len) -1);
if (err == -EOPNOTSUPP)
NFS_SERVER(inode)->caps &= ~NFS_CAP_DEALLOCATE;

mutex_unlock(&inode->i_mutex);
return err;
}

Expand Down
9 changes: 2 additions & 7 deletions fs/nfs/nfs4file.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,9 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_t
if (ret < 0)
return ret;

mutex_lock(&inode->i_mutex);
if (mode & FALLOC_FL_PUNCH_HOLE)
ret = nfs42_proc_deallocate(filep, offset, len);
else
ret = nfs42_proc_allocate(filep, offset, len);
mutex_unlock(&inode->i_mutex);

return ret;
return nfs42_proc_deallocate(filep, offset, len);
return nfs42_proc_allocate(filep, offset, len);
}
#endif /* CONFIG_NFS_V4_2 */

Expand Down

0 comments on commit f830f7d

Please sign in to comment.