diff --git a/src/config.rs b/src/config.rs index 16f63e9d..c625e4a9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,9 +22,10 @@ pub struct Device { pub disksize: u64, pub swap_priority: i32, - pub mount_point: Option, // when set, a mount unit will be created - pub fs_type: Option, // useful mostly for mounts, None is the same - // as "swap" when mount_point is not set + pub mount_point: Option, // when set, a mount unit will be created + pub fs_type: Option, // useful mostly for mounts, None is the same + // as "swap" when mount_point is not set + pub mount_options: Option, // when set, mount options will be applied } impl Device { @@ -39,6 +40,7 @@ impl Device { swap_priority: 100, mount_point: None, fs_type: None, + mount_options: None, } } @@ -295,6 +297,10 @@ fn parse_line(dev: &mut Device, key: &str, value: &str) -> Result<()> { dev.fs_type = Some(value.to_string()); } + "mount-options" => { + dev.mount_options = Some(value.to_string()); + } + _ => { warn!("Unknown key {}, ignoring.", key); } diff --git a/src/generator.rs b/src/generator.rs index d042db0d..442d218f 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -285,9 +285,11 @@ After=systemd-zram-setup@{zram_device}.service [Mount] What=/dev/{zram_device} Where={mount_point:?} +Options={mount_options:?} ", zram_device = device.name, mount_point = device.mount_point.as_ref().unwrap(), + mount_options = device.mount_options.as_ref().unwrap_or(&String::new()), ), )?; diff --git a/tests/07-mount-point/run.expected/units/var-compressed.mount b/tests/07-mount-point/run.expected/units/var-compressed.mount index 02b82206..8efcecb5 100644 --- a/tests/07-mount-point/run.expected/units/var-compressed.mount +++ b/tests/07-mount-point/run.expected/units/var-compressed.mount @@ -9,3 +9,4 @@ After=systemd-zram-setup@zram11.service [Mount] What=/dev/zram11 Where="/var/compressed" +Options="" diff --git a/tests/09-mount-options/etc/systemd/zram-generator.conf b/tests/09-mount-options/etc/systemd/zram-generator.conf new file mode 100644 index 00000000..01e9d7bb --- /dev/null +++ b/tests/09-mount-options/etc/systemd/zram-generator.conf @@ -0,0 +1,4 @@ +[zram11] +mount-point = /var/compressed +fs-type = ext4 +mount-options = discard diff --git a/tests/09-mount-options/proc/meminfo b/tests/09-mount-options/proc/meminfo new file mode 100644 index 00000000..6a918b3c --- /dev/null +++ b/tests/09-mount-options/proc/meminfo @@ -0,0 +1,3 @@ +MemTotal: 801322 kB +MemFree: 611992 kB +MemAvailable: 139764 kB diff --git a/tests/09-mount-options/run.expected/units/local-fs.target.wants/var-compressed.mount b/tests/09-mount-options/run.expected/units/local-fs.target.wants/var-compressed.mount new file mode 120000 index 00000000..545c1f6b --- /dev/null +++ b/tests/09-mount-options/run.expected/units/local-fs.target.wants/var-compressed.mount @@ -0,0 +1 @@ +../var-compressed.mount \ No newline at end of file diff --git a/tests/09-mount-options/run.expected/units/systemd-zram-setup@zram11.service.d/bindsto-mount.conf b/tests/09-mount-options/run.expected/units/systemd-zram-setup@zram11.service.d/bindsto-mount.conf new file mode 100644 index 00000000..af059c7f --- /dev/null +++ b/tests/09-mount-options/run.expected/units/systemd-zram-setup@zram11.service.d/bindsto-mount.conf @@ -0,0 +1,4 @@ +# Automatically generated by "zram-generator" + +[Unit] +BindsTo=var-compressed.mount diff --git a/tests/09-mount-options/run.expected/units/var-compressed.mount b/tests/09-mount-options/run.expected/units/var-compressed.mount new file mode 100644 index 00000000..af045d2c --- /dev/null +++ b/tests/09-mount-options/run.expected/units/var-compressed.mount @@ -0,0 +1,12 @@ +# Automatically generated by "/home/zbyszek/src/zram-generator/target/debug/zram-generator" + +[Unit] +Description=Compressed Storage on /dev/zram11 +Documentation=man:zram-generator(8) man:zram-generator.conf(5) +Requires=systemd-zram-setup@zram11.service +After=systemd-zram-setup@zram11.service + +[Mount] +What=/dev/zram11 +Where="/var/compressed" +Options="discard" diff --git a/tests/test_cases.rs b/tests/test_cases.rs index 49d39c1e..21a440c8 100644 --- a/tests/test_cases.rs +++ b/tests/test_cases.rs @@ -183,3 +183,8 @@ fn test_07_mount_point() { fn test_08_plain_device() { test_generation("08-plain-device").unwrap(); } + +#[test] +fn test_09_mount_options() { + test_generation("09-mount-options").unwrap(); +}