Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit f6db971

Browse files
authored
Only use file_operations::setfl on AUFS-patched kernels (closes #167) (#182)
Debian and Ubuntu, which we're using for all our CI and local dev, have a patched kernel which adds a setfl method to struct file_operations, so our builds don't work on unpatched (e.g., upstream) kernels. The patchset also does an EXPORT_SYMBOL_GPL(setfl), so we can key on that to determine whether we need to fill in the setfl method or not. Current patches are at https://salsa.debian.org/kernel-team/linux/tree/debian/5.2.9-2/debian/patches/features/all/aufs5
1 parent c510585 commit f6db971

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

build.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,28 @@ fn handle_kernel_version_cfg(bindings_path: &PathBuf) {
8585
}
8686
}
8787

88+
fn handle_kernel_symbols_cfg(symvers_path: &PathBuf) {
89+
let f = BufReader::new(fs::File::open(symvers_path).unwrap());
90+
for line in f.lines() {
91+
let line = line.unwrap();
92+
if let Some(symbol) = line.split_ascii_whitespace().nth(1) {
93+
if symbol == "setfl" {
94+
println!("cargo:rustc-cfg=kernel_aufs_setfl");
95+
break;
96+
}
97+
}
98+
}
99+
}
100+
88101
fn main() {
89102
println!("cargo:rerun-if-env-changed=KDIR");
103+
let kdir = env::var("KDIR").unwrap_or(format!(
104+
"/lib/modules/{}/build",
105+
std::str::from_utf8(&(Command::new("uname").arg("-r").output().unwrap().stdout))
106+
.unwrap()
107+
.trim()
108+
));
109+
90110
println!("cargo:rerun-if-env-changed=CLANG");
91111
println!("cargo:rerun-if-changed=kernel-cflags-finder/Makefile");
92112
let output = Command::new("make")
@@ -136,6 +156,7 @@ fn main() {
136156
.expect("Couldn't write bindings!");
137157

138158
handle_kernel_version_cfg(&out_path.join("bindings.rs"));
159+
handle_kernel_symbols_cfg(&PathBuf::from(&kdir).join("Module.symvers"));
139160

140161
let mut builder = cc::Build::new();
141162
println!("cargo:rerun-if-env-changed=CLANG");

src/chrdev.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ impl FileOperationsVtable {
225225
#[cfg(kernel_4_20_0_or_greater)]
226226
remap_file_range: None,
227227
sendpage: None,
228+
#[cfg(kernel_aufs_setfl)]
228229
setfl: None,
229230
setlease: None,
230231
show_fdinfo: None,

0 commit comments

Comments
 (0)