-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an API+CLI to inject metadata for bootable OSTree commits
I was doing some rpm-ostree work and I wanted to compare two OSTree commits to see if the kernel has changed. I think this should be a lot more natural. Add `ostree commit --bootable` which calls into a new generic library API `ostree_commit_metadata_for_bootable()` that discovers the kernel version and injects it as an `ostree.linux` metadata key. And for extra clarity, add an `ostree.bootable` key. It's interesting because the "core" OSTree layer is all about generic files, but this is adding special APIs around bootable OSTree commits (as opposed to e.g. flatpak as well as things like rpm-ostree's pkgcache refs). Eventually, I'd like to ensure everyone is using this and hard require this metadata key for the `ostree admin deploy` flow - mainly to prevent accidents.
- Loading branch information
Showing
11 changed files
with
163 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.0+ | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include <sys/types.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <gio/gfiledescriptorbased.h> | ||
#include <gio/gunixinputstream.h> | ||
#include "libglnx.h" | ||
#include "ostree.h" | ||
#include "ostree-core-private.h" | ||
#include "ostree-repo-os.h" | ||
#include "otutil.h" | ||
|
||
/** | ||
* ostree_commit_metadata_for_bootable: | ||
* @root: Root filesystem to be committed | ||
* @dict: Dictionary to update | ||
* | ||
* Update provided @dict with standard metadata for bootable OSTree commits. | ||
*/ | ||
_OSTREE_PUBLIC | ||
gboolean | ||
ostree_commit_metadata_for_bootable (GFile *root, GVariantDict *dict, GCancellable *cancellable, GError **error) | ||
{ | ||
g_autoptr(GFile) modules = g_file_resolve_relative_path (root, "usr/lib/modules"); | ||
g_autoptr(GFileEnumerator) dir_enum | ||
= g_file_enumerate_children (modules, OSTREE_GIO_FAST_QUERYINFO, | ||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, | ||
cancellable, error); | ||
if (!dir_enum) | ||
return glnx_prefix_error (error, "Opening usr/lib/modules"); | ||
|
||
while (TRUE) | ||
{ | ||
GFileInfo *child_info; | ||
GFile *child_path; | ||
if (!g_file_enumerator_iterate (dir_enum, &child_info, &child_path, | ||
cancellable, error)) | ||
return FALSE; | ||
if (child_info == NULL) | ||
break; | ||
if (g_file_info_get_file_type (child_info) != G_FILE_TYPE_DIRECTORY) | ||
continue; | ||
|
||
g_autoptr(GFile) kernel_path = g_file_resolve_relative_path (child_path, "vmlinuz"); | ||
if (!g_file_query_exists (kernel_path, NULL)) | ||
continue; | ||
|
||
g_variant_dict_insert (dict, OSTREE_METADATA_KEY_BOOTABLE, "b", TRUE); | ||
g_variant_dict_insert (dict, OSTREE_METADATA_KEY_LINUX, "s", g_file_info_get_name (child_info)); | ||
return TRUE; | ||
} | ||
|
||
return glnx_throw (error, "No kernel found in /usr/lib/modules"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.0+ | ||
* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <sys/stat.h> | ||
#include <gio/gio.h> | ||
#include <ostree-types.h> | ||
|
||
G_BEGIN_DECLS | ||
|
||
/** | ||
* OSTREE_METADATA_KEY_BOOTABLE: | ||
* | ||
* GVariant type `b`: Set if this commit is intended to be bootable | ||
*/ | ||
#define OSTREE_METADATA_KEY_BOOTABLE "ostree.bootable" | ||
/** | ||
* OSTREE_METADATA_KEY_LINUX: | ||
* | ||
* GVariant type `s`: Contains the Linux kernel version | ||
*/ | ||
#define OSTREE_METADATA_KEY_LINUX "ostree.linux" | ||
|
||
_OSTREE_PUBLIC | ||
gboolean | ||
ostree_commit_metadata_for_bootable (GFile *root, GVariantDict *dict, GCancellable *cancellable, GError **error); | ||
|
||
G_END_DECLS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters