From 59377dbef288bff2e9df1254f9cbccd3c7d726a5 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 4 Nov 2022 09:44:34 +0100 Subject: [PATCH 1/3] test: re-enable skipped systemd-firstboot --locale-messages= test Since the original issue should be resolved by #25253. --- test/units/testsuite-74.firstboot.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/units/testsuite-74.firstboot.sh b/test/units/testsuite-74.firstboot.sh index 02f9f5cd7a..f17b35e672 100755 --- a/test/units/testsuite-74.firstboot.sh +++ b/test/units/testsuite-74.firstboot.sh @@ -33,10 +33,9 @@ touch "$ROOT/bin/fooshell" "$ROOT/bin/barshell" systemd-firstboot --root="$ROOT" --locale=foo grep -q "LANG=foo" "$ROOT/etc/locale.conf" rm -fv "$ROOT/etc/locale.conf" -# FIXME: https://github.com/systemd/systemd/issues/25249 -#systemd-firstboot --root="$ROOT" --locale-messages=foo -#grep -q "LC_MESSAGES=foo" "$ROOT/etc/locale.conf" -#rm -fv "$ROOT/etc/locale.conf" +systemd-firstboot --root="$ROOT" --locale-messages=foo +grep -q "LC_MESSAGES=foo" "$ROOT/etc/locale.conf" +rm -fv "$ROOT/etc/locale.conf" systemd-firstboot --root="$ROOT" --locale=foo --locale-messages=bar grep -q "LANG=foo" "$ROOT/etc/locale.conf" grep -q "LC_MESSAGES=bar" "$ROOT/etc/locale.conf" From 7d4f00c88c65532bf66d20b3ec498b5bfaa621d2 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sun, 6 Nov 2022 22:49:47 +0100 Subject: [PATCH 2/3] mountpoint-util: tmpfs supports uid=/gid= mount options As tmpfs(5) says, both uid= and gid= are supported since kernel 2.5.7 and the mount utility seems to agree: ``` # stat -c "%U:%G" mnt root:root # mount -o uid=testuser,gid=testuser -t tmpfs tmpfs mnt # stat -c "%U:%G" mnt testuser:testuser ``` However, systemd-mount currently complains: ``` # systemd-mount --owner testuser -t tmpfs tmpfs mnt File system type tmpfs is not known to support uid=/gid=, refusing. ``` --- src/basic/mountpoint-util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/basic/mountpoint-util.c b/src/basic/mountpoint-util.c index dc682688a7..8292869e7c 100644 --- a/src/basic/mountpoint-util.c +++ b/src/basic/mountpoint-util.c @@ -480,6 +480,7 @@ bool fstype_can_uid_gid(const char *fstype) { "iso9660", "msdos", "ntfs", + "tmpfs", "vfat"); } From 6da7d0c76671d4efe5e812cd5945925acd0617dd Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sun, 6 Nov 2022 22:40:40 +0100 Subject: [PATCH 3/3] test: add coverage for systemd-mount --- test/units/testsuite-74.mount.sh | 116 +++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100755 test/units/testsuite-74.mount.sh diff --git a/test/units/testsuite-74.mount.sh b/test/units/testsuite-74.mount.sh new file mode 100755 index 0000000000..95d17c78ba --- /dev/null +++ b/test/units/testsuite-74.mount.sh @@ -0,0 +1,116 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eux +set -o pipefail + +# We're going to play around with block/loop devices, so bail out early +# if we're running in nspawn +if systemd-detect-virt --container >/dev/null; then + echo "Container detected, skipping the test" + exit 0 +fi + +at_exit() { + set +e + + [[ -n "${LOOP:-}" ]] && losetup -d "$LOOP" + [[ -n "${WORK_DIR:-}" ]] && rm -fr "$WORK_DIR" +} + +trap at_exit EXIT + +WORK_DIR="$(mktemp -d)" + +systemd-mount --list +systemd-mount --list --full +systemd-mount --list --no-legend +systemd-mount --list --no-pager +systemd-mount --list --quiet + +# Set up a simple block device for further tests +dd if=/dev/zero of="$WORK_DIR/simple.img" bs=1M count=16 +LOOP="$(losetup --show --find "$WORK_DIR/simple.img")" +mkfs.ext4 -L sd-mount-test "$LOOP" +mkdir "$WORK_DIR/mnt" +mount "$LOOP" "$WORK_DIR/mnt" +touch "$WORK_DIR/mnt/foo.bar" +umount "$LOOP" +(! mountpoint "$WORK_DIR/mnt") + +# Mount with both source and destination set +systemd-mount "$LOOP" "$WORK_DIR/mnt" +systemctl status "$WORK_DIR/mnt" +systemd-mount --list --full +test -e "$WORK_DIR/mnt/foo.bar" +systemd-umount "$WORK_DIR/mnt" +# Same thing, but with explicitly specified filesystem and disabled filesystem check +systemd-mount --type=ext4 --fsck=no --collect "$LOOP" "$WORK_DIR/mnt" +systemctl status "$(systemd-escape --path "$WORK_DIR/mnt").mount" +test -e "$WORK_DIR/mnt/foo.bar" +systemd-mount --umount "$LOOP" +# Discover additional metadata (unit description should now contain filesystem label) +systemd-mount --no-ask-password --discover "$LOOP" "$WORK_DIR/mnt" +test -e "$WORK_DIR/mnt/foo.bar" +systemctl show -P Description "$WORK_DIR/mnt" | grep -q sd-mount-test +systemd-umount "$WORK_DIR/mnt" +# Set a property +systemd-mount --property="Description=Foo Bar" "$LOOP" "$WORK_DIR/mnt" +test -e "$WORK_DIR/mnt/foo.bar" +systemctl show -P Description "$WORK_DIR/mnt" | grep -q "Foo Bar" +systemd-umount "$WORK_DIR/mnt" +# Set mount options +systemd-mount --options ro,x-foo-bar "$LOOP" "$WORK_DIR/mnt" +test -e "$WORK_DIR/mnt/foo.bar" +systemctl show -P Options "$WORK_DIR/mnt" | grep -Eq "(^ro|,ro)" +systemctl show -P Options "$WORK_DIR/mnt" | grep -q "x-foo-bar" +systemd-umount "$WORK_DIR/mnt" + +# Mount with only source set +systemd-mount "$LOOP" +systemctl status /run/media/system/sd-mount-test +systemd-mount --list --full +test -e /run/media/system/sd-mount-test/foo.bar +systemd-umount LABEL=sd-mount-test + +# Automount +systemd-mount --automount=yes "$LOOP" "$WORK_DIR/mnt" +systemd-mount --list --full +systemctl status "$(systemd-escape --path "$WORK_DIR/mnt").automount" +[[ "$(systemctl show -P ActiveState "$WORK_DIR/mnt")" == inactive ]] +test -e "$WORK_DIR/mnt/foo.bar" +systemctl status "$WORK_DIR/mnt" +systemd-umount "$WORK_DIR/mnt" +# Automount + automount-specific property +systemd-mount --automount=yes --automount-property="Description=Bar Baz" "$LOOP" "$WORK_DIR/mnt" +systemctl show -P Description "$(systemd-escape --path "$WORK_DIR/mnt").automount" | grep -q "Bar Baz" +test -e "$WORK_DIR/mnt/foo.bar" +systemd-umount "$WORK_DIR/mnt" + +# Automount + --bind-device +systemd-mount --automount=yes --bind-device --timeout-idle-sec=1 "$LOOP" "$WORK_DIR/mnt" +systemctl status "$(systemd-escape --path "$WORK_DIR/mnt").automount" +# Trigger the automount +test -e "$WORK_DIR/mnt/foo.bar" +# Wait until it's idle again +sleep 1.5 +# Safety net for slower/overloaded systems +timeout 10s bash -c "while systemctl is-active -q $WORK_DIR/mnt; do sleep .2; done" +systemctl status "$(systemd-escape --path "$WORK_DIR/mnt").automount" +# Disassemble the underlying block device +losetup -d "$LOOP" +unset LOOP +# The automount unit should be gone at this point +(! systemctl status "$(systemd-escape --path "$WORK_DIR/mnt").automount") + +# Mount a disk image +systemd-mount "$WORK_DIR/simple.img" +systemd-mount --list --full +test -e /run/media/system/simple.img/foo.bar +systemd-umount "$WORK_DIR/simple.img" + +# --owner + tmpfs +[[ "$(stat -c "%U:%G" "$WORK_DIR/mnt")" == "root:root" ]] +systemd-mount --owner testuser -t tmpfs tmpfs "$WORK_DIR/mnt" +systemctl status "$WORK_DIR/mnt" +[[ "$(stat -c "%U:%G" "$WORK_DIR/mnt")" == "testuser:testuser" ]] +systemd-umount "$WORK_DIR/mnt"