Skip to content

Commit

Permalink
Merge pull request #207 from keszybz/keep-at-shutdown
Browse files Browse the repository at this point in the history
Let the swap unit remain survive shutdown
  • Loading branch information
keszybz authored Nov 26, 2024
2 parents 597d429 + 222d359 commit e1186a9
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 1 deletion.
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

0 comments on commit e1186a9

Please sign in to comment.