Merge pull request #2669 from HuijingHei/fix-kargs

Fix `ostree admin kargs edit-in-place` fails issue
This commit is contained in:
Colin Walters 2022-07-13 16:35:28 -04:00 committed by GitHub
commit ed1146738b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 4 deletions

View File

@ -577,6 +577,7 @@ ostree_sysroot_get_repo
ostree_sysroot_get_staged_deployment
ostree_sysroot_init_osname
ostree_sysroot_deployment_set_kargs
ostree_sysroot_deployment_set_kargs_in_place
ostree_sysroot_deployment_set_mutable
ostree_sysroot_deployment_unlock
ostree_sysroot_deployment_set_pinned

View File

@ -23,6 +23,7 @@
LIBOSTREE_2022.5 {
global:
ostree_kernel_args_append_if_missing;
ostree_sysroot_deployment_set_kargs_in_place;
} LIBOSTREE_2022.4;
/* Stub section for the stable release *after* this development one; don't

View File

@ -3591,6 +3591,53 @@ ostree_sysroot_deployment_set_kargs (OstreeSysroot *self,
return TRUE;
}
/**
* ostree_sysroot_deployment_set_kargs_in_place:
* @self: Sysroot
* @deployment: A deployment
* @kargs_str: (allow none): Replace @deployment's kernel arguments
* @cancellable: Cancellable
* @error: Error
*
* Replace the kernel arguments of @deployment with the values in @kargs_str.
*/
gboolean
ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self,
OstreeDeployment *deployment,
char *kargs_str,
GCancellable *cancellable,
GError **error)
{
if (!ostree_sysroot_initialize (self, error))
return FALSE;
if (!_ostree_sysroot_ensure_boot_fd (self, error))
return FALSE;
if (!_ostree_sysroot_ensure_writable (self, error))
return FALSE;
g_assert (!ostree_deployment_is_staged (deployment));
OstreeBootconfigParser *new_bootconfig = ostree_deployment_get_bootconfig (deployment);
ostree_bootconfig_parser_set (new_bootconfig, "options", kargs_str);
g_autofree char *bootconf_name =
g_strdup_printf ("ostree-%d-%s.conf",
self->deployments->len - ostree_deployment_get_index (deployment),
ostree_deployment_get_osname (deployment));
g_autofree char *bootconfdir = g_strdup_printf ("loader.%d/entries", self->bootversion);
glnx_autofd int bootconf_dfd = -1;
if (!glnx_opendirat (self->boot_fd, bootconfdir, TRUE, &bootconf_dfd, error))
return FALSE;
if (!ostree_bootconfig_parser_write_at (new_bootconfig,
bootconf_dfd, bootconf_name,
cancellable, error))
return FALSE;
return TRUE;
}
/**
* ostree_sysroot_deployment_set_mutable:
* @self: Sysroot

View File

@ -175,6 +175,13 @@ gboolean ostree_sysroot_deployment_set_kargs (OstreeSysroot *self,
GCancellable *cancellable,
GError **error);
_OSTREE_PUBLIC
gboolean ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self,
OstreeDeployment *deployment,
char *kargs_str,
GCancellable *cancellable,
GError **error);
_OSTREE_PUBLIC
gboolean ostree_sysroot_write_deployments (OstreeSysroot *self,
GPtrArray *new_deployments,

View File

@ -67,11 +67,10 @@ ot_admin_kargs_builtin_edit_in_place (int argc, char **argv, OstreeCommandInvoca
}
}
g_auto(GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs);
g_autofree char *new_options = ostree_kernel_args_to_string (kargs);
if (!ostree_sysroot_deployment_set_kargs (sysroot, deployment,
kargs_strv,
cancellable, error))
if (!ostree_sysroot_deployment_set_kargs_in_place (sysroot, deployment, new_options,
cancellable, error))
return FALSE;
}

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Verify "ostree admin kargs edit-in-place" works
set -xeuo pipefail
. ${KOLA_EXT_DATA}/libinsttest.sh
sudo ostree admin kargs edit-in-place --append-if-missing=testarg
assert_file_has_content /boot/loader/entries/ostree-* testarg
echo "ok test `kargs edit-in-place --append-if-missing`"