Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix booted deploy detection with transient /etc #3163

Closed
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
4 changes: 2 additions & 2 deletions src/libostree/ostree-sysroot-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ struct OstreeSysroot
/* The device/inode for / and /etc, used to detect booted deployment */
dev_t root_device;
ino_t root_inode;
dev_t etc_device;
ino_t etc_inode;
dev_t deploydir_device;
ino_t deploydir_inode;

gboolean is_physical; /* TRUE if we're pointed at physical storage root and not a deployment */
GPtrArray *deployments;
Expand Down
20 changes: 5 additions & 15 deletions src/libostree/ostree-sysroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,26 +808,16 @@ parse_deployment (OstreeSysroot *self, const char *boot_link, OstreeDeployment *
if (looking_for_booted_deployment)
{
struct stat stbuf;
struct stat etc_stbuf = {};
if (!glnx_fstat (deployment_dfd, &stbuf, error))
return FALSE;

/* We look for either the root or the etc subdir of the
* deployment. We need to do this, because when using composefs,
* the root is not a bind mount of the deploy dir, but the etc
* dir is.
*/

if (!glnx_fstatat_allow_noent (deployment_dfd, "etc", &etc_stbuf, 0, error))
return FALSE;

/* A bit ugly, we're assigning to a sysroot-owned variable from deep in
* this parsing code. But eh, if something fails the sysroot state can't
* be relied on anyways.
*/
is_booted_deployment
= (stbuf.st_dev == self->root_device && stbuf.st_ino == self->root_inode)
|| (etc_stbuf.st_dev == self->etc_device && etc_stbuf.st_ino == self->etc_inode);
|| (stbuf.st_dev == self->deploydir_device && stbuf.st_ino == self->deploydir_inode);
}

g_autoptr (OstreeDeployment) ret_deployment
Expand Down Expand Up @@ -1029,13 +1019,13 @@ ostree_sysroot_initialize (OstreeSysroot *self, GError **error)
}

{
struct stat etc_stbuf;
if (!glnx_fstatat_allow_noent (AT_FDCWD, "/etc", &etc_stbuf, 0, error))
struct stat deploydir_stbuf;
if (!glnx_fstatat_allow_noent (AT_FDCWD, OTCORE_RUN_DEPLOYDIR, &deploydir_stbuf, 0, error))
return FALSE;
if (errno != ENOENT)
{
self->etc_device = etc_stbuf.st_dev;
self->etc_inode = etc_stbuf.st_ino;
self->deploydir_device = deploydir_stbuf.st_dev;
self->deploydir_inode = deploydir_stbuf.st_ino;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libotcore/otcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ GKeyFile *otcore_load_config (int rootfs, const char *filename, GError **error);
// we make it with mode 0 (which requires CAP_DAC_OVERRIDE to pass through).
#define OTCORE_RUN_OSTREE_PRIVATE "/run/ostree/.private"

#define OTCORE_RUN_DEPLOYDIR OTCORE_RUN_OSTREE "/deploy"

// The directory holding extra/backing data for a deployment, such as overlayfs workdirs
#define OSTREE_DEPLOYMENT_BACKING_DIR "backing"
// The directory holding the root overlayfs
Expand Down
10 changes: 10 additions & 0 deletions src/switchroot/ostree-prepare-root.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ main (int argc, char *argv[])
err (EXIT_FAILURE, "Failed to create %s", OTCORE_RUN_OSTREE);
if (mkdirat (AT_FDCWD, OTCORE_RUN_OSTREE_PRIVATE, 0) < 0)
err (EXIT_FAILURE, "Failed to create %s", OTCORE_RUN_OSTREE_PRIVATE);
if (mkdirat (AT_FDCWD, OTCORE_RUN_DEPLOYDIR, 0) < 0)
err (EXIT_FAILURE, "Failed to create %s", OTCORE_RUN_DEPLOYDIR);

/* Bind mount deploy dir (readonly) so we can later find the active deployment */
if (mount (deploy_path, OTCORE_RUN_DEPLOYDIR, NULL, MS_BIND | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to bind-mount deploy dir %s", deploy_path);
if (mount (OTCORE_RUN_DEPLOYDIR, OTCORE_RUN_DEPLOYDIR, NULL,
MS_BIND | MS_REMOUNT | MS_RDONLY | MS_SILENT, NULL)
< 0)
err (EXIT_FAILURE, "failed to bind mount (class:readonly) deploy dir");

/* Fall back to querying the repository configuration in the target disk.
* This is an operating system builder choice. More info:
Expand Down
Loading