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

daemon: make use of the new deployment flags #942

Closed
wants to merge 1 commit into from
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
130 changes: 33 additions & 97 deletions src/daemon/rpmostree-sysroot-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,80 +313,6 @@ rpmostree_syscore_bump_mtime (OstreeSysroot *sysroot,
return TRUE;
}

/* A version of ostree_sysroot_simple_write_deployment() but with
* a few changes:
*
* - There's just @pushing_rollback, which if true makes the deployment not-default
* as well as retaining the pending deployment
* - osname logic is based on new deployment
* - Fix insertion of deployment to be after booted (patch pending for ostree upstream)
*/
GPtrArray *
rpmostree_syscore_add_deployment (OstreeSysroot *sysroot,
OstreeDeployment *new_deployment,
OstreeDeployment *merge_deployment,
gboolean pushing_rollback,
GError **error)
{
OstreeDeployment *booted_deployment = NULL;
g_autoptr(GPtrArray) deployments = NULL;
g_autoptr(GPtrArray) new_deployments = g_ptr_array_new_with_free_func (g_object_unref);
const char *osname = ostree_deployment_get_osname (new_deployment);
/* Whether or not we added @new_deployment to the list yet */
gboolean added_new = FALSE;
/* Keep track of whether we're looking at a deployment before or after the booted */
gboolean before_booted = TRUE;
gboolean booted_is_live = FALSE;

deployments = ostree_sysroot_get_deployments (sysroot);
booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);

if (!pushing_rollback)
{
g_ptr_array_add (new_deployments, g_object_ref (new_deployment));
added_new = TRUE;
}

for (guint i = 0; i < deployments->len; i++)
{
OstreeDeployment *deployment = deployments->pdata[i];
const gboolean osname_matches = (strcmp (ostree_deployment_get_osname (deployment), osname) == 0);
const gboolean is_booted = ostree_deployment_equal (deployment, booted_deployment);
const gboolean is_merge_or_booted = is_booted ||
ostree_deployment_equal (deployment, merge_deployment);
const gboolean is_last = (i == (deployments->len - 1));

if (is_booted)
{
before_booted = FALSE;
if (!rpmostree_syscore_deployment_is_live (sysroot, deployment, -1,
&booted_is_live, error))
return NULL;
}

/* Retain deployment if:
* - The deployment is for another osname
* - We're pushing a rollback and this is a pending deployment
* - It's the merge or booted deployment
* - The booted deployment is live, this is a rollback
*/
if (!osname_matches
|| (pushing_rollback && before_booted)
|| is_merge_or_booted
|| (!before_booted && booted_is_live))
g_ptr_array_add (new_deployments, g_object_ref (deployment));

/* Insert new rollback right after the booted */
if (!added_new && (!before_booted || is_last))
{
g_ptr_array_add (new_deployments, g_object_ref (new_deployment));
added_new = TRUE;
}
}

return g_steal_pointer (&new_deployments);
}

/* Also a variant of ostree_sysroot_simple_write_deployment(), but here we are
* just trying to remove a pending and/or rollback.
*/
Expand Down Expand Up @@ -440,30 +366,43 @@ rpmostree_syscore_filter_deployments (OstreeSysroot *sysroot,
return g_steal_pointer (&new_deployments);
}

/* Commit @new_deployments and perform a cleanup */
/* A wrapper around ostree_sysroot_simple_write_deployment() that makes it easy to push
* livefs rollbacks as well as retain them afterwards */
gboolean
rpmostree_syscore_write_deployments (OstreeSysroot *sysroot,
OstreeRepo *repo,
GPtrArray *new_deployments,
GCancellable *cancellable,
GError **error)
rpmostree_syscore_write_deployment (OstreeSysroot *sysroot,
OstreeDeployment *new_deployment,
OstreeDeployment *merge_deployment,
gboolean pushing_rollback,
GCancellable *cancellable,
GError **error)
{
glnx_unref_object OstreeRepo *owned_repo = NULL;
OstreeRepo *repo = ostree_sysroot_repo (sysroot);

/* we do our own cleanup afterwards */
OstreeSysrootSimpleWriteDeploymentFlags flags =
OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN;

/* Allow the caller to pass NULL as a convenience; in the future we really
* should have a strong ref to a repo in the sysroot and make retrieving it
* not failable.
*/
if (repo == NULL)
if (pushing_rollback)
flags |= (OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT |
OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN_PENDING);
else
{
if (!ostree_sysroot_get_repo (sysroot, &owned_repo, cancellable, error))
return FALSE;
repo = owned_repo;
/* make sure rollbacks of live deployments aren't pruned */
OstreeDeployment *booted = ostree_sysroot_get_booted_deployment (sysroot);
if (booted)
{
gboolean is_live;
if (!rpmostree_syscore_deployment_is_live (sysroot, booted,
&is_live, error))
return FALSE;
if (is_live)
flags |= OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN_ROLLBACK;
}
}

OstreeSysrootWriteDeploymentsOpts write_opts = { .do_postclean = FALSE };
if (!ostree_sysroot_write_deployments_with_options (sysroot, new_deployments,
&write_opts, cancellable, error))
const char *osname = ostree_deployment_get_osname (new_deployment);
if (!ostree_sysroot_simple_write_deployment (sysroot, osname, new_deployment,
merge_deployment, flags, cancellable, error))
return FALSE;

if (!rpmostree_syscore_cleanup (sysroot, repo, cancellable, error))
Expand All @@ -478,7 +417,6 @@ rpmostree_syscore_write_deployments (OstreeSysroot *sysroot,
gboolean
rpmostree_syscore_deployment_get_live (OstreeSysroot *sysroot,
OstreeDeployment *deployment,
int deployment_dfd,
char **out_inprogress_checksum,
char **out_livereplaced_checksum,
GError **error)
Expand All @@ -494,16 +432,14 @@ rpmostree_syscore_deployment_get_live (OstreeSysroot *sysroot,
gboolean
rpmostree_syscore_deployment_is_live (OstreeSysroot *sysroot,
OstreeDeployment *deployment,
int deployment_dfd,
gboolean *out_is_live,
GError **error)
{
g_autofree char *inprogress_checksum = NULL;
g_autofree char *livereplaced_checksum = NULL;

if (!rpmostree_syscore_deployment_get_live (sysroot, deployment, deployment_dfd,
&inprogress_checksum, &livereplaced_checksum,
error))
if (!rpmostree_syscore_deployment_get_live (sysroot, deployment, &inprogress_checksum,
&livereplaced_checksum, error))
return FALSE;

*out_is_live = (inprogress_checksum != NULL || livereplaced_checksum != NULL);
Expand Down
19 changes: 6 additions & 13 deletions src/daemon/rpmostree-sysroot-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,23 @@ gboolean rpmostree_syscore_bump_mtime (OstreeSysroot *self, GError **error);

gboolean rpmostree_syscore_deployment_get_live (OstreeSysroot *sysroot,
OstreeDeployment *deployment,
int deployment_dfd,
char **out_inprogress_checksum,
char **out_livereplaced_checksum,
GError **error);

gboolean rpmostree_syscore_deployment_is_live (OstreeSysroot *sysroot,
OstreeDeployment *deployment,
int deployment_dfd,
gboolean *out_is_live,
GError **error);

GPtrArray *rpmostree_syscore_add_deployment (OstreeSysroot *sysroot,
OstreeDeployment *new_deployment,
OstreeDeployment *merge_deployment,
gboolean pushing_rollback,
GError **error);

GPtrArray *rpmostree_syscore_filter_deployments (OstreeSysroot *sysroot,
const char *osname,
gboolean remove_pending,
gboolean remove_rollback);

gboolean rpmostree_syscore_write_deployments (OstreeSysroot *sysroot,
OstreeRepo *repo,
GPtrArray *new_deployments,
GCancellable *cancellable,
GError **error);
gboolean rpmostree_syscore_write_deployment (OstreeSysroot *sysroot,
OstreeDeployment *new_deployment,
OstreeDeployment *merge_deployment,
gboolean pushing_rollback,
GCancellable *cancellable,
GError **error);
13 changes: 5 additions & 8 deletions src/daemon/rpmostree-sysroot-upgrader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,8 @@ rpmostree_sysroot_upgrader_deploy (RpmOstreeSysrootUpgrader *self,
*/
if (!self->final_revision)
{
g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self->sysroot, new_deployment);
g_autofree char *deployment_path =
ostree_sysroot_get_deployment_dirpath (self->sysroot, new_deployment);
glnx_fd_close int deployment_dfd = -1;
if (!glnx_opendirat (ostree_sysroot_get_fd (self->sysroot), deployment_path, TRUE,
&deployment_dfd, error))
Expand All @@ -1121,13 +1122,9 @@ rpmostree_sysroot_upgrader_deploy (RpmOstreeSysrootUpgrader *self,
return FALSE;
}

g_autoptr(GPtrArray) new_deployments =
rpmostree_syscore_add_deployment (self->sysroot, new_deployment,
self->cfg_merge_deployment, FALSE, error);
if (!new_deployments)
return FALSE;
if (!rpmostree_syscore_write_deployments (self->sysroot, self->repo, new_deployments,
cancellable, error))
if (!rpmostree_syscore_write_deployment (self->sysroot, new_deployment,
self->cfg_merge_deployment, FALSE,
cancellable, error))
return FALSE;

return TRUE;
Expand Down
5 changes: 2 additions & 3 deletions src/daemon/rpmostreed-deployment-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,8 @@ rpmostreed_deployment_generate_variant (OstreeSysroot *sysroot,
variant_add_commit_details (&dict, "pending-base-", pending_base_commit);
}

if (!rpmostree_syscore_deployment_get_live (sysroot, deployment, -1,
&live_inprogress, &live_replaced,
error))
if (!rpmostree_syscore_deployment_get_live (sysroot, deployment, &live_inprogress,
&live_replaced, error))
return NULL;

if (live_inprogress)
Expand Down
13 changes: 4 additions & 9 deletions src/daemon/rpmostreed-transaction-livefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,8 @@ prepare_rollback_deployment (OstreeSysroot *sysroot,
/* Inherit kernel arguments */
ostree_deployment_set_bootconfig (new_deployment, new_bootconfig);

g_autoptr(GPtrArray) new_deployments =
rpmostree_syscore_add_deployment (sysroot, new_deployment, booted_deployment, TRUE, error);
if (!new_deployments)
return FALSE;
if (!rpmostree_syscore_write_deployments (sysroot, repo, new_deployments,
cancellable, error))
if (!rpmostree_syscore_write_deployment (sysroot, new_deployment, booted_deployment,
TRUE, cancellable, error))
return FALSE;

return TRUE;
Expand Down Expand Up @@ -519,9 +515,8 @@ livefs_transaction_execute_inner (LiveFsTransaction *self,
/* Find out whether we already have a live overlay */
g_autofree char *live_inprogress = NULL;
g_autofree char *live_replaced = NULL;
if (!rpmostree_syscore_deployment_get_live (sysroot, booted_deployment, -1,
&live_inprogress, &live_replaced,
error))
if (!rpmostree_syscore_deployment_get_live (sysroot, booted_deployment, &live_inprogress,
&live_replaced, error))
return FALSE;
const char *resuming_overlay = NULL;
if (live_inprogress != NULL)
Expand Down