Skip to content

Commit

Permalink
NFS: Remove unnecessary inode locking in nfs_llseek_dir()
Browse files Browse the repository at this point in the history
Remove the contentious inode lock, and instead provide thread safety
using the file->f_lock spinlock.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
  • Loading branch information
Trond Myklebust authored and amschuma-ntap committed Nov 12, 2020
1 parent 6c2190b commit 83f2c45
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions fs/nfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,6 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx)

static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence)
{
struct inode *inode = file_inode(filp);
struct nfs_open_dir_context *dir_ctx = filp->private_data;

dfprintk(FILE, "NFS: llseek dir(%pD2, %lld, %d)\n",
Expand All @@ -967,15 +966,15 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence)
case SEEK_SET:
if (offset < 0)
return -EINVAL;
inode_lock(inode);
spin_lock(&filp->f_lock);
break;
case SEEK_CUR:
if (offset == 0)
return filp->f_pos;
inode_lock(inode);
spin_lock(&filp->f_lock);
offset += filp->f_pos;
if (offset < 0) {
inode_unlock(inode);
spin_unlock(&filp->f_lock);
return -EINVAL;
}
}
Expand All @@ -987,7 +986,7 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence)
dir_ctx->dir_cookie = 0;
dir_ctx->duped = 0;
}
inode_unlock(inode);
spin_unlock(&filp->f_lock);
return offset;
}

Expand Down

0 comments on commit 83f2c45

Please sign in to comment.