Skip to content

Commit 222d359

Browse files
committed
Pull down the device during shutdown if writeback device is configured
1 parent 5059ea0 commit 222d359

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/generator.rs

Lines changed: 12 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,
@@ -232,7 +242,7 @@ DefaultDependencies=no
232242
Requires=systemd-zram-setup@{zram_device}.service
233243
After=systemd-zram-setup@{zram_device}.service
234244
Before=swap.target
235-
245+
{shutdown_conflicts}
236246
[Swap]
237247
What=/dev/{zram_device}
238248
Priority={swap_priority}
@@ -241,6 +251,7 @@ Options={options}
241251
zram_device = device.name,
242252
swap_priority = device.swap_priority,
243253
options = device.options.replace('%', "%%"),
254+
shutdown_conflicts = shutdown_conflicts,
244255
),
245256
)?;
246257

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ DefaultDependencies=no
99
1010
1111
Before=swap.target
12+
Conflicts=shutdown.target
1213

1314
[Swap]
1415
What=/dev/zram0

0 commit comments

Comments
 (0)