1use std::sync::atomic;
11use std::sync::atomic::AtomicI64;
12use std::sync::atomic::AtomicU32;
13
14pub static SYMLINK_ATOMIC_WRITE: atomic::AtomicBool = atomic::AtomicBool::new(cfg!(test));
20
21static ENFORCE_FSYNC: atomic::AtomicBool = atomic::AtomicBool::new(false);
23
24pub static CHMOD_DIR: AtomicI64 = AtomicI64::new(0o2775);
27
28pub static CHMOD_FILE: AtomicI64 = AtomicI64::new(0o664);
31
32pub static INDEX_CHECKSUM_MAX_CHAIN_LEN: AtomicU32 = AtomicU32::new(10);
34
35pub fn set_global_fsync(flag: bool) {
38 ENFORCE_FSYNC.store(flag, atomic::Ordering::Release);
39}
40
41pub fn get_global_fsync() -> bool {
43 ENFORCE_FSYNC.load(atomic::Ordering::Acquire)
44}
45
46pub fn set_page_out_threshold(threshold: i64) {
64 let old_threshold = crate::page_out::THRESHOLD.swap(threshold, atomic::Ordering::AcqRel);
65 let delta = threshold - old_threshold;
66 crate::page_out::adjust_available(delta);
67}
68
69#[cfg(feature = "configurable")]
71pub fn configure(config: &dyn configmodel::Config) -> configmodel::Result<()> {
72 use configmodel::convert::ByteCount;
73 use configmodel::ConfigExt;
74
75 if cfg!(unix) {
76 let chmod_file = config.get_or("permissions", "chmod-file", || -1)?;
77 if chmod_file >= 0 {
78 CHMOD_FILE.store(chmod_file, atomic::Ordering::Release);
79 }
80
81 let chmod_dir = config.get_or("permissions", "chmod-dir", || -1)?;
82 if chmod_dir >= 0 {
83 CHMOD_DIR.store(chmod_dir, atomic::Ordering::Release);
84 }
85
86 let use_symlink_atomic_write: bool =
87 config.get_or_default("format", "use-symlink-atomic-write")?;
88 SYMLINK_ATOMIC_WRITE.store(use_symlink_atomic_write, atomic::Ordering::Release);
89
90 #[cfg(all(unix, feature = "sigbus-handler"))]
91 {
92 let use_sigbus_handler: bool =
93 config.get_or_default("unsafe", "indexedlog-zerofill-mmap-sigbus")?;
94 if use_sigbus_handler {
95 crate::sigbus::register_sigbus_handler();
96 }
97 }
98 }
99
100 if let Some(max_chain_len) =
101 config.get_opt::<u32>("storage", "indexedlog-max-index-checksum-chain-len")?
102 {
103 INDEX_CHECKSUM_MAX_CHAIN_LEN.store(max_chain_len, atomic::Ordering::Release);
104 }
105
106 if let Some(threshold) =
107 config.get_opt::<ByteCount>("storage", "indexedlog-page-out-threshold")?
108 {
109 set_page_out_threshold(threshold.value() as _);
110 }
111
112 let fsync: bool = config.get_or_default("storage", "indexedlog-fsync")?;
113 set_global_fsync(fsync);
114
115 Ok(())
116}