-
Notifications
You must be signed in to change notification settings - Fork 307
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
Add an API+CLI to inject metadata for bootable OSTree commits #2296
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,83 @@ | ||
/* | ||
* 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. | ||
* Since: 2021.1 | ||
*/ | ||
_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"); | ||
|
||
g_autofree char *linux_release = NULL; | ||
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)) | ||
cgwalters marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue; | ||
|
||
if (linux_release != NULL) | ||
return glnx_throw (error, "Multiple kernels found in /usr/lib/modules"); | ||
|
||
linux_release = g_strdup (g_file_info_get_name (child_info)); | ||
} | ||
|
||
if (linux_release) | ||
{ | ||
g_variant_dict_insert (dict, OSTREE_METADATA_KEY_BOOTABLE, "b", TRUE); | ||
g_variant_dict_insert (dict, OSTREE_METADATA_KEY_LINUX, "s", linux_release); | ||
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,47 @@ | ||
/* | ||
* 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 | ||
* Since: 2021.1 | ||
*/ | ||
#define OSTREE_METADATA_KEY_BOOTABLE "ostree.bootable" | ||
/** | ||
* OSTREE_METADATA_KEY_LINUX: | ||
* | ||
* GVariant type `s`: Contains the Linux kernel release (i.e. `uname -r`) | ||
* Since: 2021.1 | ||
*/ | ||
#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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like pretty much the same logic of https://github.com/ostreedev/ostree/blob/v2020.8/src/libostree/ostree-sysroot-deploy.c#L1054
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah...hard to share logic because using the libostree API abstraction means the content to be committed may not be realized as physical files, and we need to support that here. (For example, this API allows reading from an
archive
repository directly, and while it's usually better to have a checkout, it can be very convenient to do some operations on an archive repo directly)Whereas the sysroot logic always operates on a
bare
repo with real files.That logic is also trying to handle the legacy cases, which this one is explicitly not supporting.