From 23941ea9cab9773ae771e5521d4dc0dd47064874 Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Sat, 2 Nov 2024 12:08:52 -0700 Subject: [PATCH] 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. --- src/history/file.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/history/file.rs b/src/history/file.rs index c9b5234e1..1e44f0c5f 100644 --- a/src/history/file.rs +++ b/src/history/file.rs @@ -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 {