From 92be53be564a5eb6349c4fd05cbcd4d52a2cc796 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 20 Mar 2017 10:19:04 -0400 Subject: [PATCH 1/2] sysroot: Add ostree_sysroot_write_deployments_with_options() More sophisticated users of libostree like rpm-ostree need control over things like the system repository. Previously we introduced a "no cleanup" flag to `ostree_sysroot_simple_write_deployment()`, but that's a high level API that does filtering on its own. Since rpm-ostree needs more control, let's expose the bare essentials of the "sysroot commit" operation with an extensible options structure, where one of the options is whether or not to do post-transaction repository operations. --- apidoc/ostree-sections.txt | 1 + src/libostree/libostree.sym | 1 + src/libostree/ostree-sysroot-deploy.c | 36 +++++++++++++++++++------- src/libostree/ostree-sysroot-private.h | 6 ----- src/libostree/ostree-sysroot.c | 5 ++-- src/libostree/ostree-sysroot.h | 14 ++++++++++ 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/apidoc/ostree-sections.txt b/apidoc/ostree-sections.txt index c323065f35..6f0cf4a826 100644 --- a/apidoc/ostree-sections.txt +++ b/apidoc/ostree-sections.txt @@ -473,6 +473,7 @@ ostree_sysroot_deployment_set_kargs ostree_sysroot_deployment_set_mutable ostree_sysroot_deployment_unlock ostree_sysroot_write_deployments +ostree_sysroot_write_deployments_with_options ostree_sysroot_write_origin_file ostree_sysroot_deploy_tree ostree_sysroot_get_merge_deployment diff --git a/src/libostree/libostree.sym b/src/libostree/libostree.sym index 8530bc75de..749b0c3670 100644 --- a/src/libostree/libostree.sym +++ b/src/libostree/libostree.sym @@ -391,6 +391,7 @@ global: ostree_check_version; ostree_diff_dirs_with_options; ostree_sepolicy_new_at; + ostree_sysroot_write_deployments_with_options; } LIBOSTREE_2017.3; /* Stub section for the stable release *after* this development one; don't diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index 45707fe7b2..99b0f2fb2a 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -1686,8 +1686,8 @@ is_ro_mount (const char *path) * @cancellable: Cancellable * @error: Error * - * Assuming @new_deployments have already been deployed in place on - * disk, atomically update bootloader configuration. + * Older verison of ostree_sysroot_write_deployments() - will perform + * post-deployment cleanup by default. */ gboolean ostree_sysroot_write_deployments (OstreeSysroot *self, @@ -1695,16 +1695,32 @@ ostree_sysroot_write_deployments (OstreeSysroot *self, GCancellable *cancellable, GError **error) { - return _ostree_sysroot_write_deployments_internal (self, new_deployments, - TRUE, cancellable, error); + OstreeSysrootWriteDeploymentsOpts opts = { .do_postclean = TRUE }; + return ostree_sysroot_write_deployments_with_options (self, new_deployments, &opts, + cancellable, error); } +/** + * ostree_sysroot_write_deployments_with_options: + * @self: Sysroot + * @new_deployments: (element-type OstreeDeployment): List of new deployments + * @opts: Options + * @cancellable: Cancellable + * @error: Error + * + * Assuming @new_deployments have already been deployed in place on disk via + * ostree_sysroot_deploy_tree(), atomically update bootloader configuration. By + * default, no-post-transaction cleanup will be performed. You should invoke + * ostree_sysroot_cleanup() at some point after the transaction, or specify + * `do_postclean` in @opts. Skipping the post-transaction cleanup is useful + * if for example you want to control pruning of the repository. + */ gboolean -_ostree_sysroot_write_deployments_internal (OstreeSysroot *self, - GPtrArray *new_deployments, - gboolean do_clean, - GCancellable *cancellable, - GError **error) +ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, + GPtrArray *new_deployments, + OstreeSysrootWriteDeploymentsOpts *opts, + GCancellable *cancellable, + GError **error) { gboolean ret = FALSE; guint i; @@ -1930,7 +1946,7 @@ _ostree_sysroot_write_deployments_internal (OstreeSysroot *self, /* And finally, cleanup of any leftover data. */ - if (do_clean) + if (opts->do_postclean) { if (!ostree_sysroot_cleanup (self, cancellable, error)) { diff --git a/src/libostree/ostree-sysroot-private.h b/src/libostree/ostree-sysroot-private.h index 18fc0cb05e..c2f5d2d97d 100644 --- a/src/libostree/ostree-sysroot-private.h +++ b/src/libostree/ostree-sysroot-private.h @@ -114,10 +114,4 @@ gboolean _ostree_sysroot_cleanup_internal (OstreeSysroot *sysroot, GCancellable *cancellable, GError **error); -gboolean _ostree_sysroot_write_deployments_internal (OstreeSysroot *self, - GPtrArray *new_deployments, - gboolean do_clean, - GCancellable *cancellable, - GError **error); - G_END_DECLS diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c index 575cb6dfe7..c4f608a288 100644 --- a/src/libostree/ostree-sysroot.c +++ b/src/libostree/ostree-sysroot.c @@ -1553,6 +1553,7 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, g_autoptr(GPtrArray) deployments = NULL; g_autoptr(GPtrArray) new_deployments = g_ptr_array_new_with_free_func (g_object_unref); const gboolean postclean = (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN) == 0; + OstreeSysrootWriteDeploymentsOpts write_opts = { .do_postclean = postclean }; gboolean retain = (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN) > 0; const gboolean make_default = !((flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT) > 0); gboolean added_new = FALSE; @@ -1603,8 +1604,8 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, added_new = TRUE; } - if (!_ostree_sysroot_write_deployments_internal (sysroot, new_deployments, - postclean, cancellable, error)) + if (!ostree_sysroot_write_deployments_with_options (sysroot, new_deployments, &write_opts, + cancellable, error)) goto out; ret = TRUE; diff --git a/src/libostree/ostree-sysroot.h b/src/libostree/ostree-sysroot.h index 1e98cc10e3..09614b5552 100644 --- a/src/libostree/ostree-sysroot.h +++ b/src/libostree/ostree-sysroot.h @@ -145,6 +145,20 @@ gboolean ostree_sysroot_write_deployments (OstreeSysroot *self, GCancellable *cancellable, GError **error); +typedef struct { + gboolean do_postclean; + gboolean unused_bools[7]; + int unused_ints[7]; + gpointer unused_ptrs[7]; +} OstreeSysrootWriteDeploymentsOpts; + +_OSTREE_PUBLIC +gboolean ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, + GPtrArray *new_deployments, + OstreeSysrootWriteDeploymentsOpts *opts, + GCancellable *cancellable, + GError **error); + _OSTREE_PUBLIC gboolean ostree_sysroot_deploy_tree (OstreeSysroot *self, const char *osname, From ae59f35afdd8bb0bddb376f673a268d9d3ca574c Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 23 Mar 2017 14:32:19 -0400 Subject: [PATCH 2/2] fixup! sysroot: Add ostree_sysroot_write_deployments_with_options() --- src/libostree/ostree-sysroot-deploy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index 99b0f2fb2a..acbf4619f2 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -1686,8 +1686,8 @@ is_ro_mount (const char *path) * @cancellable: Cancellable * @error: Error * - * Older verison of ostree_sysroot_write_deployments() - will perform - * post-deployment cleanup by default. + * Older version of ostree_sysroot_write_deployments_with_options(). This + * version will perform post-deployment cleanup by default. */ gboolean ostree_sysroot_write_deployments (OstreeSysroot *self, @@ -1710,7 +1710,7 @@ ostree_sysroot_write_deployments (OstreeSysroot *self, * * Assuming @new_deployments have already been deployed in place on disk via * ostree_sysroot_deploy_tree(), atomically update bootloader configuration. By - * default, no-post-transaction cleanup will be performed. You should invoke + * default, no post-transaction cleanup will be performed. You should invoke * ostree_sysroot_cleanup() at some point after the transaction, or specify * `do_postclean` in @opts. Skipping the post-transaction cleanup is useful * if for example you want to control pruning of the repository.