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

Commit 240393d

Browse files
committed
Add backwards compatbility down to kernel 4.4 (fixes #199)
4.5 added * copy_file_range (torvalds/linux@2973293) * clone_file_range (torvalds/linux@04b38d6) * dedupe_file_range (torvalds/linux@54dbc15) 4.7 added iterate_shared (torvalds/linux@6192269), a variant of iterate that takes a non-exclusive lock. It sounds like it'd be safe to provide an implementation of iterate_shared as iterate. 4.9 removed aio_fsync (torvalds/linux@723c038), which was never actually used, so we can set it to None in older kernels and not think about it. 4.13 added wait_for_random_bytes (torvalds/linux@e297a78). For now, conditionalize the entire random module on it. All test cases other than random pass on Ubuntu 16.04's kernel. Update the README to say we expect 4.4 onwards to work, possibly with newer Clang for really new kernels (refs #219).
1 parent 86a8004 commit 240393d

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

README.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ concurrently (such as by implementing locking).
3838
## System requirements
3939

4040
We're currently only running CI on Linux 4.15 (Ubuntu Xenial) on amd64,
41-
although we try to keep support for newer (and perhaps older) kernels
42-
working. Other architectures should work but are untested - see
43-
[#112](https://github.com/fishinabarrel/linux-kernel-module-rust/issues/112)
44-
for expected status.
41+
although we intend to support kernels from 4.4 through the latest
42+
release. Please report a bug (or better yet, send in a patch!) if your
43+
kernel doesn't work.
44+
45+
Other architectures aren't implemented yet, but should work as long as
46+
there's Rust and LLVM support - see [#112]
47+
(https://github.com/fishinabarrel/linux-kernel-module-rust/issues/112)
48+
for expected status. They'll need src/c_types.rs ported, too.
4549

4650
You'll need to have [Rust](https://www.rust-lang.org) - in particular
4751
Rust nightly, as we use [some unstable
@@ -55,6 +59,9 @@ you're running kernel 5.0 or newer, [you'll need Clang
5559
You may need to set the `CLANG` environment variable appropriately,
5660
e.g., `CLANG=clang-9`.
5761

62+
Very recent kernels may require newer versions of Clang - try Clang 11
63+
if older versions don't work for you.
64+
5865
## Building hello-world
5966

6067
1. Install clang, kernel headers, and the `rust-src` and `rustfmt` components

build.rs

+12
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ fn handle_kernel_version_cfg(bindings_path: &PathBuf) {
7373
}
7474
}
7575
let version = version.expect("Couldn't find kernel version");
76+
if version >= kernel_version_code(4, 5, 0) {
77+
println!("cargo:rustc-cfg=kernel_4_5_0_or_greater")
78+
}
79+
if version >= kernel_version_code(4, 7, 0) {
80+
println!("cargo:rustc-cfg=kernel_4_7_0_or_greater")
81+
}
82+
if version >= kernel_version_code(4, 9, 0) {
83+
println!("cargo:rustc-cfg=kernel_4_9_0_or_greater")
84+
}
85+
if version >= kernel_version_code(4, 13, 0) {
86+
println!("cargo:rustc-cfg=kernel_4_13_0_or_greater")
87+
}
7688
if version >= kernel_version_code(4, 15, 0) {
7789
println!("cargo:rustc-cfg=kernel_4_15_0_or_greater")
7890
}

src/file_operations.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,15 @@ impl FileOperationsVtable {
144144
open: Some(open_callback::<T>),
145145
release: Some(release_callback::<T>),
146146

147+
#[cfg(not(kernel_4_9_0_or_greater))]
148+
aio_fsync: None,
147149
check_flags: None,
148-
#[cfg(not(kernel_4_20_0_or_greater))]
150+
#[cfg(all(kernel_4_5_0_or_greater, not(kernel_4_20_0_or_greater)))]
149151
clone_file_range: None,
150152
compat_ioctl: None,
153+
#[cfg(all(kernel_4_5_0_or_greater, not(kernel_4_20_0_or_greater)))]
151154
copy_file_range: None,
152-
#[cfg(not(kernel_4_20_0_or_greater))]
155+
#[cfg(all(kernel_4_5_0_or_greater, not(kernel_4_20_0_or_greater)))]
153156
dedupe_file_range: None,
154157
fallocate: None,
155158
#[cfg(kernel_4_19_0_or_greater)]
@@ -160,6 +163,7 @@ impl FileOperationsVtable {
160163
fsync: None,
161164
get_unmapped_area: None,
162165
iterate: None,
166+
#[cfg(kernel_4_7_0_or_greater)]
163167
iterate_shared: None,
164168
#[cfg(kernel_5_1_0_or_greater)]
165169
iopoll: None,

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mod error;
1313
pub mod file_operations;
1414
pub mod filesystem;
1515
pub mod printk;
16+
#[cfg(kernel_4_13_0_or_greater)]
1617
pub mod random;
1718
pub mod sysctl;
1819
mod types;

0 commit comments

Comments
 (0)