Don't try locking the history file if mmap returns ENODEV

If we try to memory map the history file, and we get back ENODEV meaning that
the underlying device does not support memory mapping, then treat that as a hint
that the filesystem is remote and disable history locking.
This commit is contained in:
Peter Ammon 2024-11-02 12:08:52 -07:00
parent 344b072e82
commit 23941ea9ca
No known key found for this signature in database

View file

@ -130,7 +130,15 @@ impl HistoryFileContents {
let region = if should_mmap() {
match MmapRegion::map_file(file.as_raw_fd(), len) {
Ok(region) => region,
Err(err) if err.raw_os_error() == Some(ENODEV) => map_anon(file, len)?,
Err(err) if err.raw_os_error() == Some(ENODEV) => {
// Our mmap failed with ENODEV, which means the underlying
// filesystem does not support mapping. Treat this as a hint
// that the filesystem is remote, and so disable locks for
// the history file.
super::ABANDONED_LOCKING.store(true);
// Create an anonymous mapping and read() the file into it.
map_anon(file, len)?
}
Err(_err) => return None,
}
} else {