From f829a93b62bd117db30123a405f3087ff811b574 Mon Sep 17 00:00:00 2001 From: Gurchetan Singh Date: Tue, 1 Oct 2019 09:52:49 -0700 Subject: [PATCH] guest_memory: remove optional memfd Builders should all have memfd support now. BUG=chromium:942183 TEST=compile and run, CQ will also test Cq-Depend: chromium:1901871, chromium:1907541 Change-Id: I0cd4ec43a51e9995def2e105d68e12a703168365 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1834701 Commit-Queue: Gurchetan Singh Tested-by: kokoro Tested-by: Gurchetan Singh Reviewed-by: Zach Reizner Reviewed-by: Daniel Verkamp Auto-Submit: Gurchetan Singh --- sys_util/src/guest_memory.rs | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/sys_util/src/guest_memory.rs b/sys_util/src/guest_memory.rs index 162960ff3f..a745248757 100644 --- a/sys_util/src/guest_memory.rs +++ b/sys_util/src/guest_memory.rs @@ -95,15 +95,12 @@ fn region_end(region: &MemoryRegion) -> GuestAddress { #[derive(Clone)] pub struct GuestMemory { regions: Arc>, - memfd: Option>, + memfd: Arc, } impl AsRawFd for GuestMemory { fn as_raw_fd(&self) -> RawFd { - match &self.memfd { - Some(memfd) => memfd.as_raw_fd(), - None => panic!("GuestMemory is not backed by a memfd"), - } + self.memfd.as_raw_fd() } } @@ -142,19 +139,7 @@ impl GuestMemory { pub fn new(ranges: &[(GuestAddress, u64)]) -> Result { // Create memfd - // TODO(prilik) remove optional memfd once parallel CQ lands (crbug.com/942183). - // Many classic CQ builders run old kernels without memfd support, resulting in test - // failures. It's less effort to introduce this temporary optional path than to - // manually mark all affected tests as ignore. - let memfd = match GuestMemory::create_memfd(ranges) { - Err(Error::MemoryCreationFailed { .. }) => { - warn!("GuestMemory is not backed by a memfd"); - None - } - Err(e) => return Err(e), - Ok(memfd) => Some(memfd), - }; - + let memfd = GuestMemory::create_memfd(ranges)?; // Create memory regions let mut regions = Vec::::new(); let mut offset = 0; @@ -170,12 +155,8 @@ impl GuestMemory { } } - let mapping = match &memfd { - Some(memfd) => MemoryMapping::from_fd_offset(memfd, range.1 as usize, offset), - None => MemoryMapping::new(range.1 as usize), - } - .map_err(Error::MemoryMappingFailed)?; - + let mapping = MemoryMapping::from_fd_offset(&memfd, range.1 as usize, offset) + .map_err(Error::MemoryMappingFailed)?; regions.push(MemoryRegion { mapping, guest_base: range.0, @@ -187,10 +168,7 @@ impl GuestMemory { Ok(GuestMemory { regions: Arc::new(regions), - memfd: match memfd { - Some(memfd) => Some(Arc::new(memfd)), - None => None, - }, + memfd: Arc::new(memfd), }) }