Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let the swap unit remain survive shutdown #207

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ fn handle_zram_swap(output_directory: &Path, device: &Device) -> Result<()> {

handle_zram_bindings(output_directory, device, "dev-%i.swap")?;

let shutdown_conflicts = if device.writeback_dev.is_some() {
// We need to shut down the zram device to disconnect the writeback device.
// Once https://github.com/systemd/systemd/issues/35303 is resolved, we
// may revisit this and rely on the systemd to pull down the device stack
// if appropriate.
"Conflicts=shutdown.target\n"
} else {
""
};

/* dev-zramX.swap */
write_contents(
output_directory,
Expand All @@ -226,9 +236,13 @@ fn handle_zram_swap(output_directory: &Path, device: &Device) -> Result<()> {
[Unit]
Description=Compressed Swap on /dev/{zram_device}
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

Requires=systemd-zram-setup@{zram_device}.service
After=systemd-zram-setup@{zram_device}.service

Before=swap.target
{shutdown_conflicts}
[Swap]
What=/dev/{zram_device}
Priority={swap_priority}
Expand All @@ -237,6 +251,7 @@ Options={options}
zram_device = device.name,
swap_priority = device.swap_priority,
options = device.options.replace('%', "%%"),
shutdown_conflicts = shutdown_conflicts,
),
)?;

Expand Down
4 changes: 4 additions & 0 deletions tests/01-basic/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/02-zstd/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/04-dropins/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/04-dropins/run.expected/units/dev-zram2.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram2
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram2
Expand Down
4 changes: 4 additions & 0 deletions tests/06-kernel-enabled/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/09-zram-size/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
5 changes: 5 additions & 0 deletions tests/10-example/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target
Conflicts=shutdown.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/11-obsolete/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/11-obsolete/run.expected/units/dev-zram1.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram1
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram1
Expand Down