vhost_user_fs: Implement support for FUSE_LSEEK

Implement missing support for FUSE_LSEEK, which basically implies
calling to libc::lseek on the file handle. As this operation alters
the file offset, we take a write lock on the File's RwLock.

Signed-off-by: Sergio Lopez <slp@redhat.com>
This commit is contained in:
Sergio Lopez
2020-03-18 13:26:18 +01:00
committed by Rob Bradford
parent 5aa9abca5e
commit c821e96e2a
3 changed files with 58 additions and 10 deletions

View File

@@ -1616,4 +1616,32 @@ impl FileSystem for PassthroughFs {
Err(io::Error::last_os_error())
}
}
fn lseek(
&self,
_ctx: Context,
inode: Inode,
handle: Handle,
offset: u64,
whence: u32,
) -> io::Result<u64> {
let data = self
.handles
.read()
.unwrap()
.get(&handle)
.filter(|hd| hd.inode == inode)
.map(Arc::clone)
.ok_or_else(ebadf)?;
let fd = data.file.write().unwrap().as_raw_fd();
// Safe because this doesn't modify any memory and we check the return value.
let res = unsafe { libc::lseek(fd, offset as libc::off64_t, whence as libc::c_int) };
if res < 0 {
Err(io::Error::last_os_error())
} else {
Ok(res as u64)
}
}
}