Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/libostree/ostree-impl-system-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ fstab_generator (const char *ostree_target, const bool is_aboot, const char *nor
* inherit normal shared propagation. See mount_namespaces(7), Linux
* Documentation/filesystems/sharedsubtree.txt and
* https://github.com/ostreedev/ostree/issues/2086. This also happens in
* ostree-prepare-root.c for the INITRAMFS_MOUNT_VAR case.
* ostree-prepare-root.c for the '#ifndef HAVE_SYSTEMD_AND_LIBMOUNT' case.
*/
if (!g_output_stream_printf (outstream, &bytes_written, cancellable, error,
"##\n# Automatically generated by ostree-system-generator\n##\n\n"
Expand Down Expand Up @@ -284,11 +284,6 @@ gboolean
_ostree_impl_system_generator (const char *normal_dir, const char *early_dir, const char *late_dir,
GError **error)
{
/* We conflict with the magic ostree-mount-deployment-var file for ostree-prepare-root.
* If this file is present, we have nothing to do! */
if (unlinkat (AT_FDCWD, INITRAMFS_MOUNT_VAR, 0) == 0)
return TRUE;

#ifdef OSTREE_PREPARE_ROOT_STATIC
// Create /run/ostree-booted now, because other things rely on it.
// If the system compiled with a static prepareroot, then our generator
Expand Down
1 change: 0 additions & 1 deletion src/switchroot/ostree-mount-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <sys/statvfs.h>
#include <unistd.h>

#define INITRAMFS_MOUNT_VAR "/run/ostree/initramfs-mount-var"
#define _OSTREE_SYSROOT_READONLY_STAMP "/run/ostree-sysroot-ro.stamp"
#define _OSTREE_COMPOSEFS_ROOT_STAMP "/run/ostree-composefs-root.stamp"

Expand Down
45 changes: 17 additions & 28 deletions src/switchroot/ostree-prepare-root.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,36 +356,25 @@ main (int argc, char *argv[])
err (EXIT_FAILURE, "failed to make writable /var bind-mount at %s", srcpath);
}

/* When running under systemd, /var will be handled by a 'var.mount' unit outside
* of initramfs.
* Systemd auto-detection can be overridden by a marker file under /run. */
#ifdef HAVE_SYSTEMD_AND_LIBMOUNT
bool mount_var = false;
#else
bool mount_var = true;
#endif
if (lstat (INITRAMFS_MOUNT_VAR, &stbuf) == 0)
mount_var = true;
#ifndef HAVE_SYSTEMD_AND_LIBMOUNT
/* When running under systemd, /var will be handled by a 'var.mount' unit outside of initramfs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The first line of this comment is a bit confusing as it describes the systemd case, but this code block is executed when HAVE_SYSTEMD_AND_LIBMOUNT is not defined. To improve clarity, consider rephrasing this line to describe the case this code block handles.

  /* When not using systemd to mount /var, we do it here from the initramfs.

* Bind-mount `/var` in the deployment to the "stateroot", which is
* the shared persistent directory for a set of deployments. More info:
* https://ostreedev.github.io/ostree/deployment/#stateroot-aka-osname-group-of-deployments-that-share-var
*/
if (mount ("../../var", TMP_SYSROOT "/var", NULL, MS_BIND | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to bind mount ../../var to var");

/* If required, bind-mount `/var` in the deployment to the "stateroot", which is
* the shared persistent directory for a set of deployments. More info:
* https://ostreedev.github.io/ostree/deployment/#stateroot-aka-osname-group-of-deployments-that-share-var
/* To avoid having submounts of /var propagate into $stateroot/var, the
* mount is made with slave+shared propagation. See the comment in
* ostree-impl-system-generator.c when /var isn't mounted in the
* initramfs for further explanation.
*/
if (mount_var)
{
if (mount ("../../var", TMP_SYSROOT "/var", NULL, MS_BIND | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to bind mount ../../var to var");

/* To avoid having submounts of /var propagate into $stateroot/var, the
* mount is made with slave+shared propagation. See the comment in
* ostree-impl-system-generator.c when /var isn't mounted in the
* initramfs for further explanation.
*/
if (mount (NULL, TMP_SYSROOT "/var", NULL, MS_SLAVE | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to change /var to slave mount");
if (mount (NULL, TMP_SYSROOT "/var", NULL, MS_SHARED | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to change /var to slave+shared mount");
}
if (mount (NULL, TMP_SYSROOT "/var", NULL, MS_SLAVE | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to change /var to slave mount");
if (mount (NULL, TMP_SYSROOT "/var", NULL, MS_SHARED | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to change /var to slave+shared mount");
#endif

/* This can be used by other things to signal ostree is in use */
{
Expand Down
Loading