Support overlayfs whiteouts on checkout

Introduces an intermediate format for overlayfs storage, where
.wh-ostree. prefixed files will be converted into char 0:0
whiteout devices used by overlayfs to mark deletions across layers.

The CI scripts now uses a volume for the scratch directories
previously in /var/tmp otherwise we cannot create whiteout
devices into an overlayfs mounted filesystem.

Related-Issue: #2712
This commit is contained in:
Miguel Angel Ajo committed 2022-09-28 12:26:31 +02:00
1 parent c6c3c5ae9f
commit e234b630f8
13 files changed
+292 -9

No files matched your search

+6 -1
View File
@@ -71,6 +71,11 @@ mkdir -p test-overlays
date > test-overlays/overlaid-file
$OSTREE commit ${COMMIT_ARGS} -b test-base --base test2 --owner-uid 42 --owner-gid 42 test-overlays/
$OSTREE ls -R test-base > ls.txt
assert_streq "$(wc -l < ls.txt)" 14
if can_create_whiteout_devices; then
assert_streq "$(wc -l < ls.txt)" 17
else
assert_streq "$(wc -l < ls.txt)" 14
fi
assert_streq "$(grep '42.*42' ls.txt | wc -l)" 2
echo "ok commit overlay base"
+28 -1
View File
@@ -19,7 +19,7 @@
set -euo pipefail
echo "1..$((88 + ${extra_basic_tests:-0}))"
echo "1..$((90 + ${extra_basic_tests:-0}))"
CHECKOUT_U_ARG=""
CHECKOUT_H_ARGS="-H"
@@ -1203,3 +1203,30 @@ if test "$(id -u)" != "0"; then
else
echo "ok # SKIP not run when root"
fi
if ! skip_one_without_whiteouts_devices; then
cd ${test_tmpdir}
rm checkout-test2 -rf
$OSTREE checkout test2 checkout-test2
assert_not_has_file checkout-test2/whiteouts/whiteout
assert_not_has_file checkout-test2/whiteouts/whiteout2
assert_has_file checkout-test2/whiteouts/.ostree-wh.whiteout
assert_has_file checkout-test2/whiteouts/.ostree-wh.whiteout2
echo "ok checkout: no whiteout passthrough by default"
fi
if ! skip_one_without_whiteouts_devices; then
cd ${test_tmpdir}
rm checkout-test2 -rf
$OSTREE checkout --process-passthrough-whiteouts test2 checkout-test2
assert_not_has_file checkout-test2/whiteouts/.ostree-wh.whiteout
assert_not_has_file checkout-test2/whiteouts/.ostree-wh.whiteout2
assert_is_whiteout_device checkout-test2/whiteouts/whiteout
assert_is_whiteout_device checkout-test2/whiteouts/whiteout2
echo "ok checkout: whiteout with overlayfs passthrough processing"
fi
@@ -163,6 +163,13 @@ assert_file_has_mode () {
fi
}
assert_is_whiteout_device () {
device_details="$(stat -c '%F %t:%T' $1)"
if [ "$device_details" != "character special file 0:0" ]; then
fatal "File '$1' is not a whiteout character device 0:0"
fi
}
assert_symlink_has_content () {
if ! test -L "$1"; then
fatal "File '$1' is not a symbolic link"
+51 -1
View File
@@ -148,6 +148,20 @@ if ! have_selinux_relabel; then
fi
echo done
# whiteout char 0:0 devices can be created as regular users, but
# cannot be created inside containers mounted via overlayfs
can_create_whiteout_devices() {
mknod -m 000 ${test_tmpdir}/.test-whiteout c 0 0 || return 1
rm -f ${test_tmpdir}/.test-whiteout
return 0
}
echo -n checking for overlayfs whiteouts...
if ! can_create_whiteout_devices; then
export OSTREE_NO_WHITEOUTS=1
fi
echo done
if test -n "${OT_TESTS_DEBUG:-}"; then
set -x
fi
@@ -245,6 +259,15 @@ setup_test_repository () {
ln -s nonexistent baz/alink
mkdir baz/another/
echo x > baz/another/y
# if we are running inside a container we cannot test
# the overlayfs whiteout marker passthrough
if ! test -n "${OSTREE_NO_WHITEOUTS:-}"; then
mkdir whiteouts
touch whiteouts/.ostree-wh.whiteout
touch whiteouts/.ostree-wh.whiteout2
chmod 755 whiteouts/.ostree-wh.whiteout2
fi
umask "${oldumask}"
cd ${test_tmpdir}/files
@@ -406,7 +429,7 @@ setup_os_repository () {
mkdir osdata
cd osdata
kver=3.6.0
mkdir -p usr/bin ${bootdir} usr/lib/modules/${kver} usr/share usr/etc
mkdir -p usr/bin ${bootdir} usr/lib/modules/${kver} usr/share usr/etc usr/container/layers/abcd
kernel_path=${bootdir}/vmlinuz
initramfs_path=${bootdir}/initramfs.img
# the HMAC file is only in /usr/lib/modules
@@ -449,6 +472,17 @@ EOF
mkdir -p usr/etc/testdirectory
echo "a default daemon file" > usr/etc/testdirectory/test
# if we are running inside a container we cannot test
# the overlayfs whiteout marker passthrough
if ! test -n "${OSTREE_NO_WHITEOUTS:-}"; then
# overlayfs whiteout passhthrough marker files
touch usr/container/layers/abcd/.ostree-wh.whiteout
chmod 400 usr/container/layers/abcd/.ostree-wh.whiteout
touch usr/container/layers/abcd/.ostree-wh.whiteout2
chmod 777 usr/container/layers/abcd/.ostree-wh.whiteout2
fi
${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo commit ${bootable_flag} --add-metadata-string version=1.0.9 -b testos/buildmain/x86_64-runtime -s "Build"
# Ensure these commits have distinct second timestamps
@@ -588,6 +622,22 @@ skip_without_user_xattrs () {
fi
}
# Usage: if ! skip_one_without_whiteouts_devices; then ... more tests ...; fi
skip_one_without_whiteouts_devices() {
if ! can_create_whiteout_devices; then
echo "ok # SKIP - this test requires whiteout device support (test outside containers)"
return 0
else
return 1
fi
}
skip_without_whiteouts_devices () {
if ! can_create_whiteout_devices; then
skip "this test requires whiteout device support (test outside containers)"
fi
}
_have_systemd_and_libmount=''
have_systemd_and_libmount() {
if test "${_have_systemd_and_libmount}" = ''; then
+42
View File
@@ -0,0 +1,42 @@
#!/bin/bash
#
# Copyright (C) 2022 Red Hat, Inc.
#
# SPDX-License-Identifier: LGPL-2.0+
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <https://www.gnu.org/licenses/>.
set -euox pipefail
. $(dirname $0)/libtest.sh
skip_without_whiteouts_devices
# Exports OSTREE_SYSROOT so --sysroot not needed.
setup_os_repository "archive" "syslinux"
${CMD_PREFIX} ostree --repo=sysroot/ostree/repo pull-local --remote=testos testos-repo testos/buildmain/x86_64-runtime
echo "1..3"
${CMD_PREFIX} ostree admin deploy --os=testos --karg=root=LABEL=foo --karg=testkarg=1 testos:testos/buildmain/x86_64-runtime
origdeployment=$(${CMD_PREFIX} ostree admin --sysroot=sysroot --print-current-dir)
assert_is_whiteout_device "${origdeployment}"/usr/container/layers/abcd/whiteout
echo "ok whiteout deployment"
assert_not_has_file "${origdeployment}"/usr/container/layers/abcd/.ostree-wh.whiteout
echo "ok .ostree-wh.whiteout not created"
assert_file_has_mode "${origdeployment}"/usr/container/layers/abcd/whiteout 400
assert_file_has_mode "${origdeployment}"/usr/container/layers/abcd/whiteout2 777
echo "ok whiteout permissions are preserved"