vmm: open backing file read-only when not shared
When restoring from snapshot with shared=false, write access to the backing file is not required. Opening it read-only allows restore to succeed on read-only media and overlay lower layers while preserving MAP_PRIVATE semantics. Signed-off-by: Rowen-Ye <rowenye1@gmail.com>
This commit is contained in:
parent
258f826027
commit
2c2f5d2431
1 changed files with 7 additions and 3 deletions
|
|
@ -1356,13 +1356,17 @@ impl MemoryManager {
|
|||
Ok(FileOffset::new(f, 0))
|
||||
}
|
||||
|
||||
fn open_backing_file(backing_file: &PathBuf, file_offset: u64) -> Result<FileOffset, Error> {
|
||||
fn open_backing_file(
|
||||
backing_file: &PathBuf,
|
||||
file_offset: u64,
|
||||
shared: bool,
|
||||
) -> Result<FileOffset, Error> {
|
||||
if backing_file.is_dir() {
|
||||
Err(Error::DirectoryAsBackingFileForMemory)
|
||||
} else {
|
||||
let f = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.write(shared)
|
||||
.open(backing_file)
|
||||
.map_err(Error::SharedFileCreate)?;
|
||||
|
||||
|
|
@ -1397,7 +1401,7 @@ impl MemoryManager {
|
|||
} else {
|
||||
mmap_flags |= libc::MAP_PRIVATE;
|
||||
}
|
||||
Some(Self::open_backing_file(backing_file, file_offset)?)
|
||||
Some(Self::open_backing_file(backing_file, file_offset, shared)?)
|
||||
} else if shared || hugepages {
|
||||
// For hugepages we must also MAP_SHARED otherwise we will trigger #4805
|
||||
// because the MAP_PRIVATE will trigger CoW against the backing file with
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue