Skip to content

Commit

Permalink
WIP: Add concept of "staged" deployment
Browse files Browse the repository at this point in the history
Add API to write a deployment state to `/run/ostree/staged-deployment`,
along with a systemd service which runs at shutdown time.

Just compile tested, still WIP.

For: coreos/rpm-ostree#40
  • Loading branch information
cgwalters committed Mar 18, 2018
1 parent 5b3f79d commit df530e4
Show file tree
Hide file tree
Showing 16 changed files with 558 additions and 112 deletions.
3 changes: 2 additions & 1 deletion Makefile-boot.am
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ endif

if BUILDOPT_SYSTEMD
systemdsystemunit_DATA = src/boot/ostree-prepare-root.service \
src/boot/ostree-remount.service
src/boot/ostree-remount.service src/boot/ostree-deploy-staged.service
systemdtmpfilesdir = $(prefix)/lib/tmpfiles.d
dist_systemdtmpfiles_DATA = src/boot/ostree-tmpfiles.conf

Expand All @@ -65,6 +65,7 @@ EXTRA_DIST += src/boot/dracut/module-setup.sh \
src/boot/mkinitcpio/ostree \
src/boot/ostree-prepare-root.service \
src/boot/ostree-remount.service \
src/boot/ostree-deploy-staged.service \
src/boot/grub2/grub2-15_ostree \
src/boot/grub2/ostree-grub-generator \
$(NULL)
39 changes: 39 additions & 0 deletions src/boot/ostree-deploy-staged.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (C) 2018 Red Hat, Inc.
#
# 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, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

[Unit]
Description=OSTree Deploy Staged
DefaultDependencies=no
ConditionPathExists=/run/ostree-booted
ConditionPathExists=/run/ostree/staged-deployment

# TODO: Make any failures here very user visible
# OnFailure=emergency.service

# Go between these two to ensure that any service
# which might write a file to /etc should be done
# at this point
After=shutdown.target
Before=final.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/ostree/ostree-deploy-staged

[Install]
WantedBy=final.target
3 changes: 3 additions & 0 deletions src/libostree/libostree-devel.sym
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ LIBOSTREE_2018.3 {
ostree_deployment_origin_remove_transient_state;
ostree_sysroot_deployment_set_pinned;
ostree_deployment_is_pinned;
ostree_sysroot_stage_tree;
ostree_sysroot_get_staged_deployment;
ostree_deployment_is_staged;
} LIBOSTREE_2018.2;

/* Stub section for the stable release *after* this development one; don't
Expand Down
5 changes: 3 additions & 2 deletions src/libostree/ostree-cmdprivate.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "ostree-core-private.h"
#include "ostree-repo-pull-private.h"
#include "ostree-repo-static-delta-private.h"
#include "ostree-sysroot.h"
#include "ostree-sysroot-private.h"
#include "ostree-bootloader-grub2.h"

#include "otutil.h"
Expand All @@ -52,7 +52,8 @@ ostree_cmd__private__ (void)
_ostree_repo_static_delta_dump,
_ostree_repo_static_delta_query_exists,
_ostree_repo_static_delta_delete,
_ostree_repo_verify_bindings
_ostree_repo_verify_bindings,
_ostree_sysroot_deploy_staged,
};

return &table;
Expand Down
1 change: 1 addition & 0 deletions src/libostree/ostree-cmdprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef struct {
gboolean (* ostree_static_delta_query_exists) (OstreeRepo *repo, const char *delta_id, gboolean *out_exists, GCancellable *cancellable, GError **error);
gboolean (* ostree_static_delta_delete) (OstreeRepo *repo, const char *delta_id, GCancellable *cancellable, GError **error);
gboolean (* ostree_repo_verify_bindings) (const char *collection_id, const char *ref_name, GVariant *commit, GError **error);
gboolean (* ostree_deploy_staged) (OstreeSysroot *sysroot, GError **error);
} OstreeCmdPrivateVTable;

/* Note this not really "public", we just export the symbol, but not the header */
Expand Down
2 changes: 2 additions & 0 deletions src/libostree/ostree-deployment-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ G_BEGIN_DECLS
* @bootconfig: Bootloader configuration
* @origin: How to construct an upgraded version of this tree
* @unlocked: The unlocked state
* @staged: TRUE iff this deployment is staged
*/
struct _OstreeDeployment
{
Expand All @@ -50,6 +51,7 @@ struct _OstreeDeployment
OstreeBootconfigParser *bootconfig;
GKeyFile *origin;
OstreeDeploymentUnlockedState unlocked;
gboolean staged;
};

void _ostree_deployment_set_bootcsum (OstreeDeployment *self, const char *bootcsum);
Expand Down
13 changes: 13 additions & 0 deletions src/libostree/ostree-deployment.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,16 @@ ostree_deployment_is_pinned (OstreeDeployment *self)
return FALSE;
return g_key_file_get_boolean (self->origin, OSTREE_ORIGIN_TRANSIENT_GROUP, "pinned", NULL);
}

/**
* ostree_deployment_is_staged:
* @self: Deployment
*
* Returns: `TRUE` if deployment should be "finalized" at shutdown time
* Since: 2018.3
*/
gboolean
ostree_deployment_is_staged (OstreeDeployment *self)
{
return self->staged;
}
3 changes: 2 additions & 1 deletion src/libostree/ostree-deployment.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ OstreeBootconfigParser *ostree_deployment_get_bootconfig (OstreeDeployment *self
_OSTREE_PUBLIC
GKeyFile *ostree_deployment_get_origin (OstreeDeployment *self);


_OSTREE_PUBLIC
gboolean ostree_deployment_is_staged (OstreeDeployment *self);
_OSTREE_PUBLIC
gboolean ostree_deployment_is_pinned (OstreeDeployment *self);

Expand Down
7 changes: 7 additions & 0 deletions src/libostree/ostree-sysroot-cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ cleanup_old_deployments (OstreeSysroot *self,
g_hash_table_replace (active_boot_checksums, bootcsum, bootcsum);
}

/* And also the staged deployment, if any */
if (self->staged_deployment)
{
char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, self->staged_deployment);
g_hash_table_replace (active_deployment_dirs, deployment_path, deployment_path);
}

/* Find all deployment directories, both active and inactive */
g_autoptr(GPtrArray) all_deployment_dirs = NULL;
if (!list_all_deployment_directories (self, &all_deployment_dirs,
Expand Down
Loading

0 comments on commit df530e4

Please sign in to comment.