lib/deploy: Add deploy/stage APIs with options
authorJonathan Lebon <jonathan@jlebon.com>
Mon, 17 Aug 2020 13:48:17 +0000 (09:48 -0400)
committerJonathan Lebon <jonathan@jlebon.com>
Wed, 30 Sep 2020 17:29:32 +0000 (13:29 -0400)
And make the `override_kernel_argv` one of those options. This is mostly
a mechanical move here, no functional change otherwise.

Prep for adding a new option.

apidoc/ostree-sections.txt
src/libostree/libostree-devel.sym
src/libostree/ostree-sysroot-deploy.c
src/libostree/ostree-sysroot.h

index c57d7045e70aad71a33af18d6a521ede176be1f8..4ef396e62fbc94d633082a9da31f26dfd7aba57e 100644 (file)
@@ -547,7 +547,9 @@ ostree_sysroot_write_deployments
 ostree_sysroot_write_deployments_with_options
 ostree_sysroot_write_origin_file
 ostree_sysroot_stage_tree
+ostree_sysroot_stage_tree_with_options
 ostree_sysroot_deploy_tree
+ostree_sysroot_deploy_tree_with_options
 ostree_sysroot_get_merge_deployment
 ostree_sysroot_query_deployments_for
 ostree_sysroot_origin_new_from_refspec
index e2d319948c8f9c19c8dd23edd541b5dfd1b01708..3f59c399b1531451b5aede3543bdce33875d9449 100644 (file)
@@ -26,6 +26,8 @@ global:
   ostree_repo_static_delta_verify_signature;
   ostree_bootconfig_parser_get_overlay_initrds;
   ostree_bootconfig_parser_set_overlay_initrds;
+  ostree_sysroot_deploy_tree_with_options;
+  ostree_sysroot_stage_tree_with_options;
 } LIBOSTREE_2020.4;
 
 /* Stub section for the stable release *after* this development one; don't
index d97d96a83de920c9a3d26030c5ae02e3b8784da7..9425316f8fa903de900cbd52b7f059fe08095323 100644 (file)
@@ -2688,7 +2688,7 @@ sysroot_initialize_deployment (OstreeSysroot     *self,
                                const char        *osname,
                                const char        *revision,
                                GKeyFile          *origin,
-                               char             **override_kernel_argv,
+                               OstreeSysrootDeployTreeOpts *opts,
                                OstreeDeployment **out_new_deployment,
                                GCancellable      *cancellable,
                                GError           **error)
@@ -2721,7 +2721,7 @@ sysroot_initialize_deployment (OstreeSysroot     *self,
     return FALSE;
 
   _ostree_deployment_set_bootcsum (new_deployment, kernel_layout->bootcsum);
-  _ostree_deployment_set_bootconfig_from_kargs (new_deployment, override_kernel_argv);
+  _ostree_deployment_set_bootconfig_from_kargs (new_deployment, opts ? opts->override_kernel_argv : NULL);
 
   if (!prepare_deployment_etc (self, repo, new_deployment, deployment_dfd,
                                cancellable, error))
@@ -2853,13 +2853,13 @@ sysroot_finalize_deployment (OstreeSysroot     *self,
 }
 
 /**
- * ostree_sysroot_deploy_tree:
+ * ostree_sysroot_deploy_tree_with_options:
  * @self: Sysroot
  * @osname: (allow-none): osname to use for merge deployment
  * @revision: Checksum to add
  * @origin: (allow-none): Origin to use for upgrades
  * @provided_merge_deployment: (allow-none): Use this deployment for merge path
- * @override_kernel_argv: (allow-none) (array zero-terminated=1) (element-type utf8): Use these as kernel arguments; if %NULL, inherit options from provided_merge_deployment
+ * @opts: (allow-none): Options
  * @out_new_deployment: (out): The new deployment path
  * @cancellable: Cancellable
  * @error: Error
@@ -2869,23 +2869,25 @@ sysroot_finalize_deployment (OstreeSysroot     *self,
  *
  * When booted into the sysroot, you should use the
  * ostree_sysroot_stage_tree() API instead.
+ *
+ * Since: 2020.7
  */
 gboolean
-ostree_sysroot_deploy_tree (OstreeSysroot     *self,
-                            const char        *osname,
-                            const char        *revision,
-                            GKeyFile          *origin,
-                            OstreeDeployment  *provided_merge_deployment,
-                            char             **override_kernel_argv,
-                            OstreeDeployment **out_new_deployment,
-                            GCancellable      *cancellable,
-                            GError           **error)
+ostree_sysroot_deploy_tree_with_options (OstreeSysroot     *self,
+                                         const char        *osname,
+                                         const char        *revision,
+                                         GKeyFile          *origin,
+                                         OstreeDeployment  *provided_merge_deployment,
+                                         OstreeSysrootDeployTreeOpts *opts,
+                                         OstreeDeployment **out_new_deployment,
+                                         GCancellable      *cancellable,
+                                         GError           **error)
 {
   if (!_ostree_sysroot_ensure_writable (self, error))
     return FALSE;
 
   g_autoptr(OstreeDeployment) deployment = NULL;
-  if (!sysroot_initialize_deployment (self, osname, revision, origin, override_kernel_argv,
+  if (!sysroot_initialize_deployment (self, osname, revision, origin, opts,
                                       &deployment, cancellable, error))
     return FALSE;
 
@@ -2897,6 +2899,39 @@ ostree_sysroot_deploy_tree (OstreeSysroot     *self,
   return TRUE;
 }
 
+/**
+ * ostree_sysroot_deploy_tree:
+ * @self: Sysroot
+ * @osname: (allow-none): osname to use for merge deployment
+ * @revision: Checksum to add
+ * @origin: (allow-none): Origin to use for upgrades
+ * @provided_merge_deployment: (allow-none): Use this deployment for merge path
+ * @override_kernel_argv: (allow-none) (array zero-terminated=1) (element-type utf8): Use these as kernel arguments; if %NULL, inherit options from provided_merge_deployment
+ * @out_new_deployment: (out): The new deployment path
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Older version of ostree_sysroot_stage_tree_with_options().
+ *
+ * Since: 2018.5
+ */
+gboolean
+ostree_sysroot_deploy_tree (OstreeSysroot     *self,
+                            const char        *osname,
+                            const char        *revision,
+                            GKeyFile          *origin,
+                            OstreeDeployment  *provided_merge_deployment,
+                            char             **override_kernel_argv,
+                            OstreeDeployment **out_new_deployment,
+                            GCancellable      *cancellable,
+                            GError           **error)
+{
+  OstreeSysrootDeployTreeOpts opts = { .override_kernel_argv = override_kernel_argv };
+  return ostree_sysroot_deploy_tree_with_options (self, osname, revision, origin,
+                                                  provided_merge_deployment, &opts,
+                                                  out_new_deployment, cancellable, error);
+}
+
 /* Serialize information about a deployment to a variant, used by the staging
  * code.
  */
@@ -2968,8 +3003,7 @@ _ostree_sysroot_deserialize_deployment_from_variant (GVariant *v,
  * @cancellable: Cancellable
  * @error: Error
  *
- * Like ostree_sysroot_deploy_tree(), but "finalization" only occurs at OS
- * shutdown time.
+ * Older version of ostree_sysroot_stage_tree_with_options().
  *
  * Since: 2018.5
  */
@@ -2983,6 +3017,41 @@ ostree_sysroot_stage_tree (OstreeSysroot     *self,
                            OstreeDeployment **out_new_deployment,
                            GCancellable      *cancellable,
                            GError           **error)
+{
+  OstreeSysrootDeployTreeOpts opts = { .override_kernel_argv = override_kernel_argv };
+  return ostree_sysroot_stage_tree_with_options (self, osname, revision, origin,
+                                                 merge_deployment, &opts,
+                                                 out_new_deployment, cancellable, error);
+}
+
+
+/**
+ * ostree_sysroot_stage_tree_with_options:
+ * @self: Sysroot
+ * @osname: (allow-none): osname to use for merge deployment
+ * @revision: Checksum to add
+ * @origin: (allow-none): Origin to use for upgrades
+ * @merge_deployment: (allow-none): Use this deployment for merge path
+ * @opts: Options
+ * @out_new_deployment: (out): The new deployment path
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Like ostree_sysroot_deploy_tree(), but "finalization" only occurs at OS
+ * shutdown time.
+ *
+ * Since: 2020.7
+ */
+gboolean
+ostree_sysroot_stage_tree_with_options (OstreeSysroot     *self,
+                                        const char        *osname,
+                                        const char        *revision,
+                                        GKeyFile          *origin,
+                                        OstreeDeployment  *merge_deployment,
+                                        OstreeSysrootDeployTreeOpts *opts,
+                                        OstreeDeployment **out_new_deployment,
+                                        GCancellable      *cancellable,
+                                        GError           **error)
 {
   if (!_ostree_sysroot_ensure_writable (self, error))
     return FALSE;
@@ -3014,8 +3083,8 @@ ostree_sysroot_stage_tree (OstreeSysroot     *self,
     } /* OSTREE_SYSROOT_DEBUG_TEST_STAGED_PATH */
 
   g_autoptr(OstreeDeployment) deployment = NULL;
-  if (!sysroot_initialize_deployment (self, osname, revision, origin, override_kernel_argv,
-                                      &deployment, cancellable, error))
+  if (!sysroot_initialize_deployment (self, osname, revision, origin, opts, &deployment,
+                                      cancellable, error))
     return FALSE;
 
   /* Write out the origin file using the sepolicy from the non-merged root for
@@ -3050,9 +3119,9 @@ ostree_sysroot_stage_tree (OstreeSysroot     *self,
     g_variant_builder_add (builder, "{sv}", "merge-deployment",
                            serialize_deployment_to_variant (merge_deployment));
 
-  if (override_kernel_argv)
+  if (opts && opts->override_kernel_argv)
     g_variant_builder_add (builder, "{sv}", "kargs",
-                           g_variant_new_strv ((const char *const*)override_kernel_argv, -1));
+                           g_variant_new_strv ((const char *const*)opts->override_kernel_argv, -1));
 
   const char *parent = dirname (strdupa (_OSTREE_SYSROOT_RUNSTATE_STAGED));
   if (!glnx_shutil_mkdir_p_at (AT_FDCWD, parent, 0755, cancellable, error))
index d9f5a5468583c533c706675e9872dfea68ac8da9..45d6d63cc4573c85f393c73c3245569cfd45d953 100644 (file)
@@ -186,6 +186,13 @@ gboolean ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
                                                         GCancellable      *cancellable,
                                                         GError           **error);
 
+typedef struct {
+  gboolean unused_bools[8];
+  int unused_ints[8];
+  char **override_kernel_argv;
+  gpointer unused_ptrs[7];
+} OstreeSysrootDeployTreeOpts;
+
 _OSTREE_PUBLIC
 gboolean ostree_sysroot_deploy_tree (OstreeSysroot     *self,
                                      const char        *osname,
@@ -197,6 +204,17 @@ gboolean ostree_sysroot_deploy_tree (OstreeSysroot     *self,
                                      GCancellable      *cancellable,
                                      GError           **error);
 
+_OSTREE_PUBLIC
+gboolean ostree_sysroot_deploy_tree_with_options (OstreeSysroot     *self,
+                                                  const char        *osname,
+                                                  const char        *revision,
+                                                  GKeyFile          *origin,
+                                                  OstreeDeployment  *provided_merge_deployment,
+                                                  OstreeSysrootDeployTreeOpts *opts,
+                                                  OstreeDeployment **out_new_deployment,
+                                                  GCancellable      *cancellable,
+                                                  GError           **error);
+
 _OSTREE_PUBLIC
 gboolean ostree_sysroot_stage_tree (OstreeSysroot     *self,
                                     const char        *osname,
@@ -208,6 +226,18 @@ gboolean ostree_sysroot_stage_tree (OstreeSysroot     *self,
                                     GCancellable      *cancellable,
                                     GError           **error);
 
+_OSTREE_PUBLIC
+gboolean ostree_sysroot_stage_tree_with_options (OstreeSysroot     *self,
+                                                 const char        *osname,
+                                                 const char        *revision,
+                                                 GKeyFile          *origin,
+                                                 OstreeDeployment  *merge_deployment,
+                                                 OstreeSysrootDeployTreeOpts *opts,
+                                                 OstreeDeployment **out_new_deployment,
+                                                 GCancellable      *cancellable,
+                                                 GError           **error);
+
+
 _OSTREE_PUBLIC
 gboolean ostree_sysroot_deployment_set_mutable (OstreeSysroot     *self,
                                                 OstreeDeployment  *deployment,