Skip to content

Commit e1186a9

Browse files
authored
Merge pull request #207 from keszybz/keep-at-shutdown
Let the swap unit remain survive shutdown
2 parents 597d429 + 222d359 commit e1186a9

File tree

10 files changed

+53
-1
lines changed

10 files changed

+53
-1
lines changed

src/generator.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,16 @@ fn handle_zram_swap(output_directory: &Path, device: &Device) -> Result<()> {
217217

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

220+
let shutdown_conflicts = if device.writeback_dev.is_some() {
221+
// We need to shut down the zram device to disconnect the writeback device.
222+
// Once https://github.com/systemd/systemd/issues/35303 is resolved, we
223+
// may revisit this and rely on the systemd to pull down the device stack
224+
// if appropriate.
225+
"Conflicts=shutdown.target\n"
226+
} else {
227+
""
228+
};
229+
220230
/* dev-zramX.swap */
221231
write_contents(
222232
output_directory,
@@ -226,9 +236,13 @@ fn handle_zram_swap(output_directory: &Path, device: &Device) -> Result<()> {
226236
[Unit]
227237
Description=Compressed Swap on /dev/{zram_device}
228238
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
239+
240+
DefaultDependencies=no
241+
229242
Requires=systemd-zram-setup@{zram_device}.service
230243
After=systemd-zram-setup@{zram_device}.service
231-
244+
Before=swap.target
245+
{shutdown_conflicts}
232246
[Swap]
233247
What=/dev/{zram_device}
234248
Priority={swap_priority}
@@ -237,6 +251,7 @@ Options={options}
237251
zram_device = device.name,
238252
swap_priority = device.swap_priority,
239253
options = device.options.replace('%', "%%"),
254+
shutdown_conflicts = shutdown_conflicts,
240255
),
241256
)?;
242257

tests/01-basic/run.expected/units/dev-zram0.swap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
[Unit]
44
Description=Compressed Swap on /dev/zram0
55
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
6+
7+
DefaultDependencies=no
8+
69
710
11+
Before=swap.target
812

913
[Swap]
1014
What=/dev/zram0

tests/02-zstd/run.expected/units/dev-zram0.swap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
[Unit]
44
Description=Compressed Swap on /dev/zram0
55
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
6+
7+
DefaultDependencies=no
8+
69
710
11+
Before=swap.target
812

913
[Swap]
1014
What=/dev/zram0

tests/04-dropins/run.expected/units/dev-zram0.swap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
[Unit]
44
Description=Compressed Swap on /dev/zram0
55
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
6+
7+
DefaultDependencies=no
8+
69
710
11+
Before=swap.target
812

913
[Swap]
1014
What=/dev/zram0

tests/04-dropins/run.expected/units/dev-zram2.swap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
[Unit]
44
Description=Compressed Swap on /dev/zram2
55
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
6+
7+
DefaultDependencies=no
8+
69
710
11+
Before=swap.target
812

913
[Swap]
1014
What=/dev/zram2

tests/06-kernel-enabled/run.expected/units/dev-zram0.swap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
[Unit]
44
Description=Compressed Swap on /dev/zram0
55
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
6+
7+
DefaultDependencies=no
8+
69
710
11+
Before=swap.target
812

913
[Swap]
1014
What=/dev/zram0

tests/09-zram-size/run.expected/units/dev-zram0.swap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
[Unit]
44
Description=Compressed Swap on /dev/zram0
55
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
6+
7+
DefaultDependencies=no
8+
69
710
11+
Before=swap.target
812

913
[Swap]
1014
What=/dev/zram0

tests/10-example/run.expected/units/dev-zram0.swap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
[Unit]
44
Description=Compressed Swap on /dev/zram0
55
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
6+
7+
DefaultDependencies=no
8+
69
710
11+
Before=swap.target
12+
Conflicts=shutdown.target
813

914
[Swap]
1015
What=/dev/zram0

tests/11-obsolete/run.expected/units/dev-zram0.swap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
[Unit]
44
Description=Compressed Swap on /dev/zram0
55
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
6+
7+
DefaultDependencies=no
8+
69
710
11+
Before=swap.target
812

913
[Swap]
1014
What=/dev/zram0

tests/11-obsolete/run.expected/units/dev-zram1.swap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
[Unit]
44
Description=Compressed Swap on /dev/zram1
55
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
6+
7+
DefaultDependencies=no
8+
69
710
11+
Before=swap.target
812

913
[Swap]
1014
What=/dev/zram1

0 commit comments

Comments
 (0)