fuse: llseek optimize SEEK_CUR and SEEK_SET
Use generic_file_llseek() instead of open coding the seek function. i_mutex protection is only necessary for SEEK_END (and SEEK_HOLE, SEEK_DATA), so move SEEK_CUR and SEEK_SET out from under i_mutex. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
This commit is contained in:
parent
73104b6e37
commit
c07c3d1934
@ -1555,48 +1555,16 @@ static loff_t fuse_file_llseek(struct file *file, loff_t offset, int origin)
|
|||||||
loff_t retval;
|
loff_t retval;
|
||||||
struct inode *inode = file->f_path.dentry->d_inode;
|
struct inode *inode = file->f_path.dentry->d_inode;
|
||||||
|
|
||||||
mutex_lock(&inode->i_mutex);
|
/* No i_mutex protection necessary for SEEK_CUR and SEEK_SET */
|
||||||
if (origin != SEEK_CUR && origin != SEEK_SET) {
|
if (origin == SEEK_CUR || origin == SEEK_SET)
|
||||||
retval = fuse_update_attributes(inode, NULL, file, NULL);
|
return generic_file_llseek(file, offset, origin);
|
||||||
if (retval)
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (origin) {
|
mutex_lock(&inode->i_mutex);
|
||||||
case SEEK_END:
|
retval = fuse_update_attributes(inode, NULL, file, NULL);
|
||||||
offset += i_size_read(inode);
|
if (!retval)
|
||||||
break;
|
retval = generic_file_llseek(file, offset, origin);
|
||||||
case SEEK_CUR:
|
|
||||||
if (offset == 0) {
|
|
||||||
retval = file->f_pos;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
offset += file->f_pos;
|
|
||||||
break;
|
|
||||||
case SEEK_DATA:
|
|
||||||
if (offset >= i_size_read(inode)) {
|
|
||||||
retval = -ENXIO;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SEEK_HOLE:
|
|
||||||
if (offset >= i_size_read(inode)) {
|
|
||||||
retval = -ENXIO;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
offset = i_size_read(inode);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
retval = -EINVAL;
|
|
||||||
if (offset >= 0 && offset <= inode->i_sb->s_maxbytes) {
|
|
||||||
if (offset != file->f_pos) {
|
|
||||||
file->f_pos = offset;
|
|
||||||
file->f_version = 0;
|
|
||||||
}
|
|
||||||
retval = offset;
|
|
||||||
}
|
|
||||||
exit:
|
|
||||||
mutex_unlock(&inode->i_mutex);
|
mutex_unlock(&inode->i_mutex);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user