]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ci: add test for new validatefs work
authorLennart Poettering <lennart@poettering.net>
Thu, 13 Mar 2025 15:58:59 +0000 (16:58 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 31 Mar 2025 13:14:53 +0000 (15:14 +0200)
test/units/TEST-81-GENERATORS.fstab-generator.sh
test/units/TEST-87-AUX-UTILS-VM.validatefs.sh [new file with mode: 0755]

index 0c1b27eb1dec1e4176e4acf1bac5a637ba50083d..95eba8a9f639b95f14f18907f2847e245af56201 100755 (executable)
@@ -46,6 +46,7 @@ FSTAB_GENERAL=(
     "/dev/test22    /initrd/mount                       ext2        defaults,x-systemd.rw-only,x-initrd.mount 0 1"
     "/dev/test23    /initrd/mount/nofail                ext3        defaults,nofail,x-initrd.mount 0 1"
     "/dev/test24    /initrd/mount/deps                  ext4        x-initrd.mount,x-systemd.before=early.service,x-systemd.after=late.service 0 1"
+    "/dev/test25    /x-systemd.validatefs               xfs         x-systemd.validatefs 0 0"
 
     # Incomplete, but valid entries
     "/dev/incomplete1 /incomplete1"
@@ -282,6 +283,9 @@ check_fstab_mount_units() {
             elif [[ "$opt" == x-systemd.growfs ]]; then
                 service="$(systemd-escape --template=systemd-growfs@.service --path "$where")"
                 link_endswith "$out_dir/${unit}.wants/$service" "/lib/systemd/system/systemd-growfs@.service"
+            elif [[ "$opt" == x-systemd.validatefs ]]; then
+                service="$(systemd-escape --template=systemd-validatefs@.service --path "$where")"
+                link_endswith "$out_dir/${unit}.wants/$service" "/lib/systemd/system/systemd-validatefs@.service"
             elif [[ "$opt" == bg ]] && [[ "$fstype" =~ ^(nfs|nfs4)$ ]]; then
                 # We "convert" nfs bg mounts to fg, so we can do the job-control
                 # ourselves
diff --git a/test/units/TEST-87-AUX-UTILS-VM.validatefs.sh b/test/units/TEST-87-AUX-UTILS-VM.validatefs.sh
new file mode 100755 (executable)
index 0000000..5b142e1
--- /dev/null
@@ -0,0 +1,116 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eux
+set -o pipefail
+
+if ! command -v systemd-repart >/dev/null; then
+    echo "no systemd-repart"
+    return
+fi
+
+if ! test -x /usr/lib/systemd/systemd-validatefs ; then
+    echo "no systemd-validatefs"
+    return
+fi
+
+export SYSTEMD_LOG_LEVEL=debug
+export PAGER=cat
+
+at_exit() {
+    set +e
+    rm -rf /tmp/validatefs-test/
+    rm -f /var/tmp/validatefs-test.raw
+    systemd-dissect --umount --rmdir /tmp/validatefs-test.mount
+    umount /tmp/validatefs-test.fake
+    rmdir /tmp/validatefs-test.fake
+}
+
+trap at_exit EXIT
+
+mkdir /tmp/validatefs-test
+cat > /tmp/validatefs-test/validatefs-root.conf <<EOF
+[Partition]
+Type=root
+Label=kromm
+Format=ext4
+EOF
+
+cat > /tmp/validatefs-test/validatefs-usr.conf <<EOF
+[Partition]
+Type=usr
+Label=plisch
+Format=ext4
+EOF
+
+cat > /tmp/validatefs-test/validatefs-home.conf <<EOF
+[Partition]
+Type=home
+Label=rupft
+Format=ext4
+EOF
+
+cat > /tmp/validatefs-test/validatefs-esp.conf <<EOF
+[Partition]
+Type=esp
+Label=fumm
+Format=vfat
+EOF
+
+cat > /tmp/validatefs-test/validatefs-generic.conf <<EOF
+[Partition]
+Label=qnurx
+Type=linux-generic
+MountPoint=/somewhere/else
+Format=ext4
+EOF
+
+systemd-repart --dry-run=no --empty=create --size=256M --definitions=/tmp/validatefs-test /var/tmp/validatefs-test.raw
+
+systemd-dissect --mount --mkdir /var/tmp/validatefs-test.raw /tmp/validatefs-test.mount
+
+getfattr --dump /tmp/validatefs-test.mount/
+getfattr --dump /tmp/validatefs-test.mount/ | grep -q user.validatefs.gpt_type_uuid=
+getfattr --dump /tmp/validatefs-test.mount/ | grep -q user.validatefs.gpt_label=\"kromm\"
+getfattr --dump /tmp/validatefs-test.mount/ | grep -q user.validatefs.mount_point=\"/\"
+/usr/lib/systemd/systemd-validatefs --root=/tmp/validatefs-test.mount /tmp/validatefs-test.mount/
+(! /usr/lib/systemd/systemd-validatefs /tmp/validatefs-test.mount/ )
+
+getfattr --dump /tmp/validatefs-test.mount/usr
+getfattr --dump /tmp/validatefs-test.mount/usr | grep -q user.validatefs.gpt_type_uuid=
+getfattr --dump /tmp/validatefs-test.mount/usr | grep -q user.validatefs.gpt_label=\"plisch\"
+getfattr --dump /tmp/validatefs-test.mount/usr | grep -q user.validatefs.mount_point=\"/usr\"
+/usr/lib/systemd/systemd-validatefs --root=/tmp/validatefs-test.mount /tmp/validatefs-test.mount/usr
+(! /usr/lib/systemd/systemd-validatefs /tmp/validatefs-test.mount/usr )
+
+getfattr --dump /tmp/validatefs-test.mount/home
+getfattr --dump /tmp/validatefs-test.mount/home | grep -q user.validatefs.gpt_type_uuid=
+getfattr --dump /tmp/validatefs-test.mount/home | grep -q user.validatefs.gpt_label=\"rupft\"
+getfattr --dump /tmp/validatefs-test.mount/home | grep -q user.validatefs.mount_point=\"/home\"
+/usr/lib/systemd/systemd-validatefs --root=/tmp/validatefs-test.mount /tmp/validatefs-test.mount/home
+(! /usr/lib/systemd/systemd-validatefs /tmp/validatefs-test.mount/home )
+
+getfattr --dump /tmp/validatefs-test.mount/efi
+(! getfattr --dump /tmp/validatefs-test.mount/efi | grep -q user.validatefs.gpt_type_uuid= )
+(! getfattr --dump /tmp/validatefs-test.mount/efi | grep -q user.validatefs.gpt_label= )
+(! getfattr --dump /tmp/validatefs-test.mount/efi | grep -q  user.validatefs.mount_point= )
+/usr/lib/systemd/systemd-validatefs --root=/tmp/validatefs-test.mount /tmp/validatefs-test.mount/efi
+/usr/lib/systemd/systemd-validatefs /tmp/validatefs-test.mount/efi
+
+# the generic one we must mount by hand
+mkdir -p /tmp/validatefs-test.mount/somewhere/else
+mount /dev/disk/by-label/qnurx /tmp/validatefs-test.mount/somewhere/else
+getfattr --dump /tmp/validatefs-test.mount/somewhere/else
+
+/usr/lib/systemd/systemd-validatefs --root=/tmp/validatefs-test.mount /tmp/validatefs-test.mount/somewhere/else
+
+# Set up a fake mount point with incorrect data to validate a failure
+mkdir /tmp/validatefs-test.fake
+mount --bind /tmp/validatefs-test.fake /tmp/validatefs-test.fake
+/usr/lib/systemd/systemd-validatefs /tmp/validatefs-test.fake
+
+if setfattr -n "user.validatefs.mount_point" -v "/foo\000/bar\000/tmp/validatefs-test.fake\000/waldo" /tmp/validatefs-test.fake ; then
+    # xattrs on tmpfs are only available starting with kernel 6.6, hence handle setfattr failures gracefully
+    /usr/lib/systemd/systemd-validatefs /tmp/validatefs-test.fake
+    setfattr -n "user.validatefs.mount_point" -v "/knurz/schnurz\000/foo/bar/mor\000/end" /tmp/validatefs-test.fake
+    (! /usr/lib/systemd/systemd-validatefs /tmp/validatefs-test.fake )
+fi