forked from bottlerocket-os/bottlerocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request bottlerocket-os#3460 from foersleo/feature/module_…
…loading models: add new setting to auto-load kernel modules
- Loading branch information
Showing
16 changed files
with
253 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{{#if settings.kernel.modules}} | ||
{{#each settings.kernel.modules}} | ||
{{#if this.allowed}} | ||
{{#if this.autoload}} | ||
{{@key}} | ||
{{/if}} | ||
{{/if}} | ||
{{/each}} | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
sources/api/migration/migrations/v1.16.0/kernel-modules-autoload-configs/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "kernel-modules-autoload-configs" | ||
version = "0.1.0" | ||
authors = ["Leonard Foerster <foersleo@amazon.com>"] | ||
license = "Apache-2.0 OR MIT" | ||
edition = "2021" | ||
publish = false | ||
# Don't rebuild crate just because of changes to README. | ||
exclude = ["README.md"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
migration-helpers = { path = "../../../migration-helpers/", version = "0.1.0" } | ||
serde_json = "1" |
23 changes: 23 additions & 0 deletions
23
sources/api/migration/migrations/v1.16.0/kernel-modules-autoload-configs/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use migration_helpers::common_migrations::AddPrefixesMigration; | ||
use migration_helpers::{migrate, Result}; | ||
use std::process; | ||
|
||
/// We added new settings under `settings.kernel.modules` for configuring | ||
/// /etc/modules-load.d/modules-load.conf. The actual autoload settings are | ||
/// migrated separately in kernel-modules-autoload-settings migration as they | ||
/// require a custom migration implementation. | ||
fn run() -> Result<()> { | ||
migrate(AddPrefixesMigration(vec![ | ||
"configuration-files.modules-load", | ||
])) | ||
} | ||
|
||
// Returning a Result from main makes it print a Debug representation of the error, but with Snafu | ||
// we have nice Display representations of the error, so we wrap "main" (run) and print any error. | ||
// /~https://github.com/shepmaster/snafu/issues/110 | ||
fn main() { | ||
if let Err(e) = run() { | ||
eprintln!("{}", e); | ||
process::exit(1); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
sources/api/migration/migrations/v1.16.0/kernel-modules-autoload-files/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "kernel-modules-autoload-files" | ||
version = "0.1.0" | ||
authors = ["Leonard Foerster <foersleo@amazon.com>"] | ||
license = "Apache-2.0 OR MIT" | ||
edition = "2021" | ||
publish = false | ||
# Don't rebuild crate just because of changes to README. | ||
exclude = ["README.md"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
migration-helpers = { path = "../../../migration-helpers/", version = "0.1.0" } | ||
serde_json = "1" |
23 changes: 23 additions & 0 deletions
23
sources/api/migration/migrations/v1.16.0/kernel-modules-autoload-files/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use migration_helpers::common_migrations::{ListReplacement, ReplaceListsMigration}; | ||
use migration_helpers::{migrate, Result}; | ||
use std::process; | ||
|
||
/// We added a config file to the configuration-files list for services.kernel-modules | ||
/// to facilitate module autoload. This needs to be restored to prior values on downgrade. | ||
fn run() -> Result<()> { | ||
migrate(ReplaceListsMigration(vec![ListReplacement { | ||
setting: "services.kernel-modules.configuration-files", | ||
old_vals: &["modprobe-conf"], | ||
new_vals: &["modprobe-conf", "modules-load"], | ||
}])) | ||
} | ||
|
||
// Returning a Result from main makes it print a Debug representation of the error, but with Snafu | ||
// we have nice Display representations of the error, so we wrap "main" (run) and print any error. | ||
// /~https://github.com/shepmaster/snafu/issues/110 | ||
fn main() { | ||
if let Err(e) = run() { | ||
eprintln!("{}", e); | ||
process::exit(1); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
sources/api/migration/migrations/v1.16.0/kernel-modules-autoload-restart/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "kernel-modules-autoload-restart" | ||
version = "0.1.0" | ||
authors = ["Leonard Foerster <foersleo@amazon.com>"] | ||
license = "Apache-2.0 OR MIT" | ||
edition = "2021" | ||
publish = false | ||
# Don't rebuild crate just because of changes to README. | ||
exclude = ["README.md"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
migration-helpers = { path = "../../../migration-helpers/", version = "0.1.0" } | ||
serde_json = "1" |
23 changes: 23 additions & 0 deletions
23
sources/api/migration/migrations/v1.16.0/kernel-modules-autoload-restart/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use migration_helpers::common_migrations::{ListReplacement, ReplaceListsMigration}; | ||
use migration_helpers::{migrate, Result}; | ||
use std::process; | ||
|
||
/// We added a new `autoload` setting to `settings.kernel.modules`, which needs | ||
/// re restart of `systemd-modules-load.services`. | ||
fn run() -> Result<()> { | ||
migrate(ReplaceListsMigration(vec![ListReplacement { | ||
setting: "services.kernel-modules.restart-commands", | ||
old_vals: &[], | ||
new_vals: &["/usr/bin/systemctl try-restart systemd-modules-load"], | ||
}])) | ||
} | ||
|
||
// Returning a Result from main makes it print a Debug representation of the error, but with Snafu | ||
// we have nice Display representations of the error, so we wrap "main" (run) and print any error. | ||
// /~https://github.com/shepmaster/snafu/issues/110 | ||
fn main() { | ||
if let Err(e) = run() { | ||
eprintln!("{}", e); | ||
process::exit(1); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
sources/api/migration/migrations/v1.16.0/kernel-modules-autoload-settings/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "kernel-modules-autoload-settings" | ||
version = "0.1.0" | ||
authors = ["Leonard Foerster <foersleo@amazon.com>"] | ||
license = "Apache-2.0 OR MIT" | ||
edition = "2021" | ||
publish = false | ||
# Don't rebuild crate just because of changes to README. | ||
exclude = ["README.md"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
migration-helpers = { path = "../../../migration-helpers/", version = "0.1.0" } |
53 changes: 53 additions & 0 deletions
53
sources/api/migration/migrations/v1.16.0/kernel-modules-autoload-settings/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use migration_helpers::{migrate, Migration, MigrationData, Result}; | ||
use std::process; | ||
|
||
const KMOD_AUTOLOAD_PREFIX: &str = "settings.kernel.modules"; | ||
const KMOD_AUTOLOAD_SETTING: &str = "autoload"; | ||
|
||
/// We added a new autoload setting to the kernel.mudules set of tables. These tables | ||
/// come with a variable name containing the module name. We can hence not just use | ||
/// an `AddSettingsMigration` as these require the full name. We rather need a hybrid | ||
/// of `AddSettingsMigration` and `AddPrefixesMigration` in order to select the correct | ||
/// parts of these variably named tables to remove on downgrade. Similar to the common | ||
/// forms of `Add*Migrations` we do not need to do anything on upgrade. | ||
pub struct AddKmodAutoload; | ||
|
||
impl Migration for AddKmodAutoload { | ||
/// On upgrade there is nothing to do (see above). | ||
fn forward(&mut self, input: MigrationData) -> Result<MigrationData> { | ||
Ok(input) | ||
} | ||
|
||
/// On downgrade, we need to find the `autoload` setting in all tables with | ||
/// prefix `settings.kernel.modules` and remove them. | ||
fn backward(&mut self, mut input: MigrationData) -> Result<MigrationData> { | ||
let settings = input | ||
.data | ||
.keys() | ||
.filter(|k| k.starts_with(KMOD_AUTOLOAD_PREFIX)) | ||
.filter(|k| k.ends_with(KMOD_AUTOLOAD_SETTING)) | ||
.cloned() | ||
.collect::<Vec<_>>(); | ||
for setting in settings { | ||
if let Some(data) = input.data.remove(&setting) { | ||
println!("Removed {}, which was set to '{}'", setting, data); | ||
} | ||
} | ||
Ok(input) | ||
} | ||
} | ||
|
||
/// We added `settigns.kernel.modules.<name>.auotload`. | ||
fn run() -> Result<()> { | ||
migrate(AddKmodAutoload) | ||
} | ||
|
||
// Returning a Result from main makes it print a Debug representation of the error, but with Snafu | ||
// we have nice Display representations of the error, so we wrap "main" (run) and print any error. | ||
// /~https://github.com/shepmaster/snafu/issues/110 | ||
fn main() { | ||
if let Err(e) = run() { | ||
eprintln!("{}", e); | ||
process::exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters