Commit b2b1ff3d authored by Trond Myklebust's avatar Trond Myklebust

NFS: Allow optimisation of lseek(fd, SEEK_CUR, 0) on directories

There should be no need to grab the inode lock if we're only reading
the file offset.
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
parent 411ae722
...@@ -904,23 +904,29 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence) ...@@ -904,23 +904,29 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence)
dfprintk(FILE, "NFS: llseek dir(%pD2, %lld, %d)\n", dfprintk(FILE, "NFS: llseek dir(%pD2, %lld, %d)\n",
filp, offset, whence); filp, offset, whence);
inode_lock(inode);
switch (whence) { switch (whence) {
case 1: default:
offset += filp->f_pos; return -EINVAL;
case 0: case SEEK_SET:
if (offset >= 0) if (offset < 0)
break; return -EINVAL;
default: inode_lock(inode);
offset = -EINVAL; break;
goto out; case SEEK_CUR:
if (offset == 0)
return filp->f_pos;
inode_lock(inode);
offset += filp->f_pos;
if (offset < 0) {
inode_unlock(inode);
return -EINVAL;
}
} }
if (offset != filp->f_pos) { if (offset != filp->f_pos) {
filp->f_pos = offset; filp->f_pos = offset;
dir_ctx->dir_cookie = 0; dir_ctx->dir_cookie = 0;
dir_ctx->duped = 0; dir_ctx->duped = 0;
} }
out:
inode_unlock(inode); inode_unlock(inode);
return offset; return 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