Blame SOURCES/0001-Support-overlayfs-whiteouts-on-checkout.patch

a19281
From 0085494e350c72599fc5c0e00422885d80b3c660 Mon Sep 17 00:00:00 2001
a19281
From: Miguel Angel Ajo <majopela@redhat.com>
a19281
Date: Mon, 19 Sep 2022 17:15:24 +0200
a19281
Subject: [PATCH] Support overlayfs whiteouts on checkout
a19281
a19281
Introduces an intermediate format for overlayfs storage, where
a19281
.wh-ostree. prefixed files will be converted into char 0:0
a19281
whiteout devices used by overlayfs to mark deletions across layers.
a19281
a19281
The CI scripts now uses a volume for the scratch directories
a19281
previously in /var/tmp otherwise we cannot create whiteout
a19281
devices into an overlayfs mounted filesystem.
a19281
a19281
Related-Issue: #2712
a19281
(cherry picked from commit e234b630f85b97e48ecf45d5aaba9b1aa64e6b54)
a19281
---
a19281
 .github/workflows/tests.yml                |   8 +-
a19281
 Makefile-tests.am                          |   1 +
a19281
 bash/ostree                                |   1 +
a19281
 man/ostree-checkout.xml                    |  11 ++
a19281
 src/libostree/ostree-repo-checkout.c       | 129 ++++++++++++++++++++-
a19281
 src/libostree/ostree-repo.h                |   5 +-
a19281
 src/libostree/ostree-sysroot-deploy.c      |   2 +-
a19281
 src/ostree/ot-builtin-checkout.c           |   7 +-
a19281
 tests/archive-test.sh                      |   7 +-
a19281
 tests/basic-test.sh                        |  29 ++++-
a19281
 tests/kolainst/data-shared/libtest-core.sh |   7 ++
a19281
 tests/libtest.sh                           |  52 ++++++++-
a19281
 tests/test-admin-deploy-whiteouts.sh       |  42 +++++++
a19281
 13 files changed, 292 insertions(+), 9 deletions(-)
a19281
 create mode 100755 tests/test-admin-deploy-whiteouts.sh
a19281
a19281
--- a/Makefile-tests.am
a19281
+++ b/Makefile-tests.am
a19281
@@ -107,6 +107,7 @@ _installed_or_uninstalled_test_scripts = \
a19281
 	tests/test-admin-deploy-nomerge.sh \
a19281
 	tests/test-admin-deploy-none.sh \
a19281
 	tests/test-admin-deploy-bootid-gc.sh \
a19281
+	tests/test-admin-deploy-whiteouts.sh \
a19281
 	tests/test-osupdate-dtb.sh \
a19281
 	tests/test-admin-instutil-set-kargs.sh \
a19281
 	tests/test-admin-upgrade-not-backwards.sh \
a19281
diff --git a/bash/ostree b/bash/ostree
a19281
index 46363315..6f3b86ea 100644
a19281
--- a/bash/ostree
a19281
+++ b/bash/ostree
a19281
@@ -249,6 +249,7 @@ _ostree_checkout() {
a19281
         --union-identical
a19281
         --user-mode -U
a19281
         --whiteouts
a19281
+        --process-passthrough-whiteouts
a19281
     "
a19281
 
a19281
     local options_with_args="
a19281
diff --git a/man/ostree-checkout.xml b/man/ostree-checkout.xml
a19281
index 4ed53a91..8f7d4f9b 100644
a19281
--- a/man/ostree-checkout.xml
a19281
+++ b/man/ostree-checkout.xml
a19281
@@ -114,6 +114,17 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
a19281
                 </para></listitem>
a19281
             </varlistentry>
a19281
 
a19281
+            <varlistentry>
a19281
+                <term><option>--process-passthrough-whiteouts</option></term>
a19281
+
a19281
+                <listitem><para>
a19281
+                   Enable overlayfs whiteout extraction into 0:0 character devices.
a19281
+                   Overlayfs whiteouts are encoded inside ostree as <literal>.ostree-wh.filename</literal>
a19281
+                   and extracted as 0:0 character devices. This is useful to carry
a19281
+                   container storage embedded into ostree.
a19281
+                </para></listitem>
a19281
+            </varlistentry>
a19281
+
a19281
             <varlistentry>
a19281
                 <term><option>--allow-noent</option></term>
a19281
 
a19281
diff --git a/src/libostree/ostree-repo-checkout.c b/src/libostree/ostree-repo-checkout.c
a19281
index 663292a9..7c7d0cc7 100644
a19281
--- a/src/libostree/ostree-repo-checkout.c
a19281
+++ b/src/libostree/ostree-repo-checkout.c
a19281
@@ -35,6 +35,8 @@
a19281
 #define WHITEOUT_PREFIX ".wh."
a19281
 #define OPAQUE_WHITEOUT_NAME ".wh..wh..opq"
a19281
 
a19281
+#define OVERLAYFS_WHITEOUT_PREFIX ".ostree-wh."
a19281
+
a19281
 /* Per-checkout call state/caching */
a19281
 typedef struct {
a19281
   GString *path_buf; /* buffer for real path if filtering enabled */
a19281
@@ -582,6 +584,117 @@ checkout_file_hardlink (OstreeRepo                          *self,
a19281
   return TRUE;
a19281
 }
a19281
 
a19281
+static gboolean
a19281
+_checkout_overlayfs_whiteout_at_no_overwrite (OstreeRepoCheckoutAtOptions    *options,
a19281
+                                              int                             destination_dfd,
a19281
+                                              const char                     *destination_name,
a19281
+                                              GFileInfo                      *file_info,
a19281
+                                              GVariant                       *xattrs,
a19281
+                                              gboolean                       *found_exant_file,
a19281
+                                              GCancellable                   *cancellable,
a19281
+                                              GError                        **error)
a19281
+{
a19281
+  if (found_exant_file != NULL)
a19281
+    *found_exant_file = FALSE;
a19281
+  guint32 file_mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode");
a19281
+  if (mknodat(destination_dfd, destination_name, (file_mode & ~S_IFMT) | S_IFCHR, (dev_t)0) < 0)
a19281
+    {
a19281
+      if (errno == EEXIST && found_exant_file != NULL)
a19281
+        {
a19281
+          *found_exant_file = TRUE;
a19281
+          return TRUE;
a19281
+        }
a19281
+      return glnx_throw_errno_prefix (error, "Creating whiteout char device");
a19281
+    }
a19281
+  if (options->mode != OSTREE_REPO_CHECKOUT_MODE_USER)
a19281
+    {
a19281
+      if (xattrs != NULL &&
a19281
+          !glnx_dfd_name_set_all_xattrs(destination_dfd, destination_name, xattrs,
a19281
+                                          cancellable, error))
a19281
+          return glnx_throw_errno_prefix (error, "Setting xattrs for whiteout char device");
a19281
+
a19281
+      if (TEMP_FAILURE_RETRY(fchownat(destination_dfd, destination_name,
a19281
+                                      g_file_info_get_attribute_uint32 (file_info, "unix::uid"),
a19281
+                                      g_file_info_get_attribute_uint32 (file_info, "unix::gid"),
a19281
+                                      AT_SYMLINK_NOFOLLOW) < 0))
a19281
+          return glnx_throw_errno_prefix (error, "fchownat");
a19281
+      if (TEMP_FAILURE_RETRY (fchmodat (destination_dfd, destination_name, file_mode & ~S_IFMT, 0)) < 0)
a19281
+          return glnx_throw_errno_prefix (error, "fchmodat %s to 0%o", destination_name, file_mode & ~S_IFMT);
a19281
+    }
a19281
+
a19281
+  return TRUE;
a19281
+}
a19281
+
a19281
+static gboolean
a19281
+_checkout_overlayfs_whiteout_at (OstreeRepo                     *repo,
a19281
+                                 OstreeRepoCheckoutAtOptions    *options,
a19281
+                                 int                             destination_dfd,
a19281
+                                 const char                     *destination_name,
a19281
+                                 GFileInfo                      *file_info,
a19281
+                                 GVariant                       *xattrs,
a19281
+                                 GCancellable                   *cancellable,
a19281
+                                 GError                        **error)
a19281
+{
a19281
+  gboolean found_exant_file = FALSE;
a19281
+  if (!_checkout_overlayfs_whiteout_at_no_overwrite(options, destination_dfd, destination_name,
a19281
+                                                    file_info, xattrs,&found_exant_file,
a19281
+                                                    cancellable, error))
a19281
+    return FALSE;
a19281
+
a19281
+   if (!found_exant_file)
a19281
+    return TRUE;
a19281
+
a19281
+  guint32 uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid");
a19281
+  guint32 gid = g_file_info_get_attribute_uint32 (file_info, "unix::gid");
a19281
+  guint32 file_mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode");
a19281
+
a19281
+  struct stat dest_stbuf;
a19281
+
a19281
+  switch(options->overwrite_mode)
a19281
+    {
a19281
+      case OSTREE_REPO_CHECKOUT_OVERWRITE_NONE:
a19281
+        return FALSE;
a19281
+      case OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES:
a19281
+        if (!ot_ensure_unlinked_at (destination_dfd, destination_name, error))
a19281
+          return FALSE;
a19281
+        return _checkout_overlayfs_whiteout_at_no_overwrite(options, destination_dfd, destination_name,
a19281
+                                                   file_info, xattrs, NULL, cancellable, error);
a19281
+      case OSTREE_REPO_CHECKOUT_OVERWRITE_ADD_FILES:
a19281
+        return TRUE;
a19281
+
a19281
+      case OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL:
a19281
+        if (!glnx_fstatat(destination_dfd, destination_name, &dest_stbuf, AT_SYMLINK_NOFOLLOW,
a19281
+                          error))
a19281
+          return FALSE;
a19281
+        if (!(repo->disable_xattrs || repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY))
a19281
+          {
a19281
+            g_autoptr(GVariant) fs_xattrs;
a19281
+            if (!glnx_dfd_name_get_all_xattrs (destination_dfd, destination_name,
a19281
+                                               &fs_xattrs, cancellable, error))
a19281
+              return FALSE;
a19281
+            if (!g_variant_equal(fs_xattrs, xattrs))
a19281
+              return glnx_throw(error, "existing destination file %s xattrs don't match",
a19281
+                                destination_name);
a19281
+          }
a19281
+        if (options->mode != OSTREE_REPO_CHECKOUT_MODE_USER)
a19281
+          {
a19281
+            if (gid != dest_stbuf.st_gid)
a19281
+              return glnx_throw(error, "existing destination file %s does not match gid %d",
a19281
+                                destination_name, gid);
a19281
+
a19281
+            if (uid != dest_stbuf.st_uid)
a19281
+              return glnx_throw(error, "existing destination file %s does not match uid %d",
a19281
+                                destination_name, gid);
a19281
+
a19281
+            if ((file_mode & ALLPERMS) != (dest_stbuf.st_mode & ALLPERMS))
a19281
+              return glnx_throw(error, "existing destination file %s does not match mode %o",
a19281
+                                destination_name, file_mode);
a19281
+          }
a19281
+        break;
a19281
+    }
a19281
+    return TRUE;
a19281
+}
a19281
+
a19281
 static gboolean
a19281
 checkout_one_file_at (OstreeRepo                        *repo,
a19281
                       OstreeRepoCheckoutAtOptions       *options,
a19281
@@ -603,7 +716,8 @@ checkout_one_file_at (OstreeRepo                        *repo,
a19281
 
a19281
   /* FIXME - avoid the GFileInfo here */
a19281
   g_autoptr(GFileInfo) source_info = NULL;
a19281
-  if (!ostree_repo_load_file (repo, checksum, NULL, &source_info, NULL,
a19281
+  g_autoptr(GVariant) source_xattrs = NULL;
a19281
+  if (!ostree_repo_load_file (repo, checksum, NULL, &source_info, &source_xattrs,
a19281
                               cancellable, error))
a19281
     return FALSE;
a19281
 
a19281
@@ -623,6 +737,7 @@ checkout_one_file_at (OstreeRepo                        *repo,
a19281
   const gboolean is_unreadable = (!is_symlink && (source_mode & S_IRUSR) == 0);
a19281
   const gboolean is_whiteout = (!is_symlink && options->process_whiteouts &&
a19281
                                 g_str_has_prefix (destination_name, WHITEOUT_PREFIX));
a19281
+  const gboolean is_overlayfs_whiteout = (!is_symlink && g_str_has_prefix (destination_name, OVERLAYFS_WHITEOUT_PREFIX));
a19281
   const gboolean is_reg_zerosized = (!is_symlink && g_file_info_get_size (source_info) == 0);
a19281
   const gboolean override_user_unreadable = (options->mode == OSTREE_REPO_CHECKOUT_MODE_USER && is_unreadable);
a19281
 
a19281
@@ -643,6 +758,18 @@ checkout_one_file_at (OstreeRepo                        *repo,
a19281
 
a19281
       need_copy = FALSE;
a19281
     }
a19281
+  else if (is_overlayfs_whiteout && options->process_passthrough_whiteouts)
a19281
+    {
a19281
+      const char *name = destination_name + (sizeof (OVERLAYFS_WHITEOUT_PREFIX) - 1);
a19281
+
a19281
+      if (!name[0])
a19281
+        return glnx_throw (error, "Invalid empty overlayfs whiteout '%s'", name);
a19281
+
a19281
+      g_assert (name[0] != '/'); /* Sanity */
a19281
+
a19281
+      return _checkout_overlayfs_whiteout_at(repo, options, destination_dfd, name,
a19281
+                                             source_info, source_xattrs, cancellable, error);
a19281
+    }
a19281
   else if (is_reg_zerosized || override_user_unreadable)
a19281
     {
a19281
       /* In https://github.com/ostreedev/ostree/commit/673cacd633f9d6b653cdea530657d3e780a41bbd we
a19281
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
a19281
index 98571170..b3d7f986 100644
a19281
--- a/src/libostree/ostree-repo.h
a19281
+++ b/src/libostree/ostree-repo.h
a19281
@@ -989,8 +989,9 @@ typedef struct {
a19281
   gboolean force_copy; /* Since: 2017.6 */
a19281
   gboolean bareuseronly_dirs; /* Since: 2017.7 */
a19281
   gboolean force_copy_zerosized; /* Since: 2018.9 */
a19281
-  gboolean unused_bools[4];
a19281
-  /* 4 byte hole on 64 bit */
a19281
+  gboolean process_passthrough_whiteouts;
a19281
+  gboolean unused_bools[3];
a19281
+  /* 3 byte hole on 64 bit */
a19281
 
a19281
   const char *subpath;
a19281
 
a19281
diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c
a19281
index 404f336f..5c98103b 100644
a19281
--- a/src/libostree/ostree-sysroot-deploy.c
a19281
+++ b/src/libostree/ostree-sysroot-deploy.c
a19281
@@ -641,7 +641,7 @@ checkout_deployment_tree (OstreeSysroot     *sysroot,
a19281
     return FALSE;
a19281
 
a19281
   /* Generate hardlink farm, then opendir it */
a19281
-  OstreeRepoCheckoutAtOptions checkout_opts = { 0, };
a19281
+  OstreeRepoCheckoutAtOptions checkout_opts = { .process_passthrough_whiteouts = TRUE };
a19281
   if (!ostree_repo_checkout_at (repo, &checkout_opts, osdeploy_dfd,
a19281
                                 checkout_target_name, csum,
a19281
                                 cancellable, error))
a19281
diff --git a/src/ostree/ot-builtin-checkout.c b/src/ostree/ot-builtin-checkout.c
a19281
index d69c8b0b..bfa43885 100644
a19281
--- a/src/ostree/ot-builtin-checkout.c
a19281
+++ b/src/ostree/ot-builtin-checkout.c
a19281
@@ -37,6 +37,7 @@ static gboolean opt_union;
a19281
 static gboolean opt_union_add;
a19281
 static gboolean opt_union_identical;
a19281
 static gboolean opt_whiteouts;
a19281
+static gboolean opt_process_passthrough_whiteouts;
a19281
 static gboolean opt_from_stdin;
a19281
 static char *opt_from_file;
a19281
 static gboolean opt_disable_fsync;
a19281
@@ -77,6 +78,7 @@ static GOptionEntry options[] = {
a19281
   { "union-add", 0, 0, G_OPTION_ARG_NONE, &opt_union_add, "Keep existing files/directories, only add new", NULL },
a19281
   { "union-identical", 0, 0, G_OPTION_ARG_NONE, &opt_union_identical, "When layering checkouts, error out if a file would be replaced with a different version, but add new files and directories", NULL },
a19281
   { "whiteouts", 0, 0, G_OPTION_ARG_NONE, &opt_whiteouts, "Process 'whiteout' (Docker style) entries", NULL },
a19281
+  { "process-passthrough-whiteouts", 0, 0, G_OPTION_ARG_NONE, &opt_process_passthrough_whiteouts, "Enable overlayfs whiteout extraction into char 0:0 devices", NULL },
a19281
   { "allow-noent", 0, 0, G_OPTION_ARG_NONE, &opt_allow_noent, "Do nothing if specified path does not exist", NULL },
a19281
   { "from-stdin", 0, 0, G_OPTION_ARG_NONE, &opt_from_stdin, "Process many checkouts from standard input", NULL },
a19281
   { "from-file", 0, 0, G_OPTION_ARG_STRING, &opt_from_file, "Process many checkouts from input file", "FILE" },
a19281
@@ -129,7 +131,8 @@ process_one_checkout (OstreeRepo           *repo,
a19281
   if (opt_disable_cache || opt_whiteouts || opt_require_hardlinks ||
a19281
       opt_union_add || opt_force_copy || opt_force_copy_zerosized ||
a19281
       opt_bareuseronly_dirs || opt_union_identical ||
a19281
-      opt_skiplist_file || opt_selinux_policy || opt_selinux_prefix)
a19281
+      opt_skiplist_file || opt_selinux_policy || opt_selinux_prefix ||
a19281
+      opt_process_passthrough_whiteouts)
a19281
     {
a19281
       OstreeRepoCheckoutAtOptions checkout_options = { 0, };
a19281
 
a19281
@@ -162,6 +165,8 @@ process_one_checkout (OstreeRepo           *repo,
a19281
         }
a19281
       if (opt_whiteouts)
a19281
         checkout_options.process_whiteouts = TRUE;
a19281
+      if (opt_process_passthrough_whiteouts)
a19281
+        checkout_options.process_passthrough_whiteouts = TRUE;
a19281
       if (subpath)
a19281
         checkout_options.subpath = subpath;
a19281
 
a19281
diff --git a/tests/archive-test.sh b/tests/archive-test.sh
a19281
index b6d84979..6b45790e 100644
a19281
--- a/tests/archive-test.sh
a19281
+++ b/tests/archive-test.sh
a19281
@@ -71,6 +71,11 @@ mkdir -p test-overlays
a19281
 date > test-overlays/overlaid-file
a19281
 $OSTREE commit ${COMMIT_ARGS} -b test-base --base test2 --owner-uid 42 --owner-gid 42 test-overlays/
a19281
 $OSTREE ls -R test-base > ls.txt
a19281
-assert_streq "$(wc -l < ls.txt)" 14
a19281
+if can_create_whiteout_devices; then
a19281
+    assert_streq "$(wc -l < ls.txt)" 17
a19281
+else
a19281
+    assert_streq "$(wc -l < ls.txt)" 14
a19281
+fi
a19281
+
a19281
 assert_streq "$(grep '42.*42' ls.txt | wc -l)" 2
a19281
 echo "ok commit overlay base"
a19281
diff --git a/tests/basic-test.sh b/tests/basic-test.sh
a19281
index 04506c3d..0878e6f6 100644
a19281
--- a/tests/basic-test.sh
a19281
+++ b/tests/basic-test.sh
a19281
@@ -19,7 +19,7 @@
a19281
 
a19281
 set -euo pipefail
a19281
 
a19281
-echo "1..$((87 + ${extra_basic_tests:-0}))"
a19281
+echo "1..$((89 + ${extra_basic_tests:-0}))"
a19281
 
a19281
 CHECKOUT_U_ARG=""
a19281
 CHECKOUT_H_ARGS="-H"
a19281
@@ -1187,3 +1187,30 @@ if test "$(id -u)" != "0"; then
a19281
 else
a19281
     echo "ok # SKIP not run when root"
a19281
 fi
a19281
+
a19281
+if ! skip_one_without_whiteouts_devices; then
a19281
+    cd ${test_tmpdir}
a19281
+    rm checkout-test2 -rf
a19281
+    $OSTREE checkout test2 checkout-test2
a19281
+
a19281
+    assert_not_has_file checkout-test2/whiteouts/whiteout
a19281
+    assert_not_has_file checkout-test2/whiteouts/whiteout2
a19281
+    assert_has_file checkout-test2/whiteouts/.ostree-wh.whiteout
a19281
+    assert_has_file checkout-test2/whiteouts/.ostree-wh.whiteout2
a19281
+
a19281
+    echo "ok checkout: no whiteout passthrough by default"
a19281
+fi
a19281
+
a19281
+if ! skip_one_without_whiteouts_devices; then
a19281
+    cd ${test_tmpdir}
a19281
+    rm checkout-test2 -rf
a19281
+    $OSTREE checkout --process-passthrough-whiteouts test2 checkout-test2
a19281
+
a19281
+    assert_not_has_file checkout-test2/whiteouts/.ostree-wh.whiteout
a19281
+    assert_not_has_file checkout-test2/whiteouts/.ostree-wh.whiteout2
a19281
+
a19281
+    assert_is_whiteout_device checkout-test2/whiteouts/whiteout
a19281
+    assert_is_whiteout_device checkout-test2/whiteouts/whiteout2
a19281
+
a19281
+    echo "ok checkout: whiteout with overlayfs passthrough processing"
a19281
+fi
a19281
diff --git a/tests/libtest.sh b/tests/libtest.sh
a19281
index 686f08dc..5830f210 100755
a19281
--- a/tests/libtest.sh
a19281
+++ b/tests/libtest.sh
a19281
@@ -148,6 +148,20 @@ if ! have_selinux_relabel; then
a19281
 fi
a19281
 echo done
a19281
 
a19281
+# whiteout char 0:0 devices can be created as regular users, but
a19281
+# cannot be created inside containers mounted via overlayfs
a19281
+can_create_whiteout_devices() {
a19281
+    mknod -m 000 ${test_tmpdir}/.test-whiteout c 0 0 || return 1
a19281
+    rm -f ${test_tmpdir}/.test-whiteout
a19281
+    return 0
a19281
+}
a19281
+
a19281
+echo -n checking for overlayfs whiteouts...
a19281
+if ! can_create_whiteout_devices; then
a19281
+    export OSTREE_NO_WHITEOUTS=1
a19281
+fi
a19281
+echo done
a19281
+
a19281
 if test -n "${OT_TESTS_DEBUG:-}"; then
a19281
     set -x
a19281
 fi
a19281
@@ -245,6 +259,15 @@ setup_test_repository () {
a19281
     ln -s nonexistent baz/alink
a19281
     mkdir baz/another/
a19281
     echo x > baz/another/y
a19281
+
a19281
+    # if we are running inside a container we cannot test
a19281
+    # the overlayfs whiteout marker passthrough
a19281
+    if ! test -n "${OSTREE_NO_WHITEOUTS:-}"; then
a19281
+        mkdir whiteouts
a19281
+        touch whiteouts/.ostree-wh.whiteout
a19281
+        touch whiteouts/.ostree-wh.whiteout2
a19281
+        chmod 755 whiteouts/.ostree-wh.whiteout2
a19281
+    fi
a19281
     umask "${oldumask}"
a19281
 
a19281
     cd ${test_tmpdir}/files
a19281
@@ -406,7 +429,7 @@ setup_os_repository () {
a19281
     mkdir osdata
a19281
     cd osdata
a19281
     kver=3.6.0
a19281
-    mkdir -p usr/bin ${bootdir} usr/lib/modules/${kver} usr/share usr/etc
a19281
+    mkdir -p usr/bin ${bootdir} usr/lib/modules/${kver} usr/share usr/etc usr/container/layers/abcd
a19281
     kernel_path=${bootdir}/vmlinuz
a19281
     initramfs_path=${bootdir}/initramfs.img
a19281
     # the HMAC file is only in /usr/lib/modules
a19281
@@ -449,6 +472,17 @@ EOF
a19281
     mkdir -p usr/etc/testdirectory
a19281
     echo "a default daemon file" > usr/etc/testdirectory/test
a19281
 
a19281
+    # if we are running inside a container we cannot test
a19281
+    # the overlayfs whiteout marker passthrough
a19281
+    if ! test -n "${OSTREE_NO_WHITEOUTS:-}"; then
a19281
+        # overlayfs whiteout passhthrough marker files
a19281
+        touch usr/container/layers/abcd/.ostree-wh.whiteout
a19281
+        chmod 400 usr/container/layers/abcd/.ostree-wh.whiteout
a19281
+
a19281
+        touch usr/container/layers/abcd/.ostree-wh.whiteout2
a19281
+        chmod 777 usr/container/layers/abcd/.ostree-wh.whiteout2
a19281
+    fi
a19281
+
a19281
     ${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"
a19281
 
a19281
     # Ensure these commits have distinct second timestamps
a19281
@@ -588,6 +622,22 @@ skip_without_user_xattrs () {
a19281
     fi
a19281
 }
a19281
 
a19281
+# Usage: if ! skip_one_without_whiteouts_devices; then ... more tests ...; fi
a19281
+skip_one_without_whiteouts_devices() {
a19281
+    if ! can_create_whiteout_devices; then
a19281
+        echo "ok # SKIP - this test requires whiteout device support (test outside containers)"
a19281
+        return 0
a19281
+    else
a19281
+        return 1
a19281
+    fi
a19281
+}
a19281
+
a19281
+skip_without_whiteouts_devices () {
a19281
+    if ! can_create_whiteout_devices; then
a19281
+        skip "this test requires whiteout device support (test outside containers)"
a19281
+    fi
a19281
+}
a19281
+
a19281
 _have_systemd_and_libmount=''
a19281
 have_systemd_and_libmount() {
a19281
     if test "${_have_systemd_and_libmount}" = ''; then
a19281
diff --git a/tests/test-admin-deploy-whiteouts.sh b/tests/test-admin-deploy-whiteouts.sh
a19281
new file mode 100755
a19281
index 00000000..66421949
a19281
--- /dev/null
a19281
+++ b/tests/test-admin-deploy-whiteouts.sh
a19281
@@ -0,0 +1,42 @@
a19281
+#!/bin/bash
a19281
+#
a19281
+# Copyright (C) 2022 Red Hat, Inc.
a19281
+#
a19281
+# SPDX-License-Identifier: LGPL-2.0+
a19281
+#
a19281
+# This library is free software; you can redistribute it and/or
a19281
+# modify it under the terms of the GNU Lesser General Public
a19281
+# License as published by the Free Software Foundation; either
a19281
+# version 2 of the License, or (at your option) any later version.
a19281
+#
a19281
+# This library is distributed in the hope that it will be useful,
a19281
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
a19281
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a19281
+# Lesser General Public License for more details.
a19281
+#
a19281
+# You should have received a copy of the GNU Lesser General Public
a19281
+# License along with this library. If not, see <https://www.gnu.org/licenses/>.
a19281
+
a19281
+set -euox pipefail
a19281
+
a19281
+. $(dirname $0)/libtest.sh
a19281
+
a19281
+skip_without_whiteouts_devices
a19281
+
a19281
+# Exports OSTREE_SYSROOT so --sysroot not needed.
a19281
+setup_os_repository "archive" "syslinux"
a19281
+${CMD_PREFIX} ostree --repo=sysroot/ostree/repo pull-local --remote=testos testos-repo testos/buildmain/x86_64-runtime
a19281
+
a19281
+echo "1..3"
a19281
+${CMD_PREFIX} ostree admin deploy --os=testos --karg=root=LABEL=foo --karg=testkarg=1 testos:testos/buildmain/x86_64-runtime
a19281
+origdeployment=$(${CMD_PREFIX} ostree admin --sysroot=sysroot --print-current-dir)
a19281
+
a19281
+assert_is_whiteout_device "${origdeployment}"/usr/container/layers/abcd/whiteout
a19281
+echo "ok whiteout deployment"
a19281
+
a19281
+assert_not_has_file  "${origdeployment}"/usr/container/layers/abcd/.ostree-wh.whiteout
a19281
+echo "ok .ostree-wh.whiteout not created"
a19281
+
a19281
+assert_file_has_mode "${origdeployment}"/usr/container/layers/abcd/whiteout 400
a19281
+assert_file_has_mode "${origdeployment}"/usr/container/layers/abcd/whiteout2 777
a19281
+echo "ok whiteout permissions are preserved"
a19281
-- 
a19281
2.37.3
a19281