Skip to content

Commit bb65191

Browse files
vireshkjiangliu
authored andcommitted
mmap_xen: Don't drop the FileOffset while in use
The drop implementation of `struct MmapXenGrant` issues an Ioctl call, which uses the file descriptor. Currently the FileOffset is getting dropped before that, and results in "Bad File Descriptor" error from the Ioctl. This commit fixes it by keeping a copy of the same in `struct MmapXenGrant`. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent 22416e0 commit bb65191

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/mmap_xen.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -787,32 +787,32 @@ fn ioctl_gntdev_unmap_grant_ref() -> c_ulong {
787787
}
788788

789789
// Xen grant memory specific implementation.
790-
#[derive(Clone, Debug, PartialEq)]
790+
#[derive(Clone, Debug)]
791791
struct MmapXenGrant {
792792
guest_base: GuestAddress,
793793
unix_mmap: Option<MmapUnix>,
794+
file_offset: FileOffset,
794795
flags: i32,
795-
fd: i32,
796796
size: usize,
797797
index: u64,
798798
domid: u32,
799799
}
800800

801801
impl AsRawFd for MmapXenGrant {
802802
fn as_raw_fd(&self) -> i32 {
803-
self.fd
803+
self.file_offset.file().as_raw_fd()
804804
}
805805
}
806806

807807
impl MmapXenGrant {
808808
fn new(range: &MmapRange, mmap_flags: MmapXenFlags) -> Result<Self> {
809-
let (fd, _) = validate_file(&range.file_offset)?;
809+
validate_file(&range.file_offset)?;
810810

811811
let mut grant = Self {
812812
guest_base: range.addr,
813813
unix_mmap: None,
814+
file_offset: range.file_offset.as_ref().unwrap().clone(),
814815
flags: range.flags.ok_or(Error::UnexpectedError)?,
815-
fd,
816816
size: 0,
817817
index: 0,
818818
domid: range.mmap_data,
@@ -838,7 +838,7 @@ impl MmapXenGrant {
838838
fn mmap_range(&self, addr: GuestAddress, size: usize, prot: i32) -> Result<(MmapUnix, u64)> {
839839
let (count, size) = pages(size);
840840
let index = self.mmap_ioctl(addr, count)?;
841-
let unix_mmap = MmapUnix::new(size, prot, self.flags, self.fd, index)?;
841+
let unix_mmap = MmapUnix::new(size, prot, self.flags, self.as_raw_fd(), index)?;
842842

843843
Ok((unix_mmap, index))
844844
}

0 commit comments

Comments
 (0)