-
Notifications
You must be signed in to change notification settings - Fork 308
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
sysroot: Support boot counting for boot entries #3310
Open
igoropaniuk
wants to merge
1
commit into
ostreedev:main
Choose a base branch
from
igoropaniuk:boot_count
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,9 @@ struct _OstreeBootconfigParser | |
gboolean parsed; | ||
const char *separators; | ||
|
||
guint64 tries_left; | ||
guint64 tries_done; | ||
|
||
GHashTable *options; | ||
|
||
/* Additional initrds; the primary initrd is in options. */ | ||
|
@@ -56,6 +59,94 @@ ostree_bootconfig_parser_clone (OstreeBootconfigParser *self) | |
return parser; | ||
} | ||
|
||
/** | ||
* ostree_bootconfig_parser_parse_tries: | ||
* @self: Parser | ||
* @path: File path | ||
* | ||
* Parses a suffix of two counters in the form "+LEFT-DONE" from the end of the | ||
* filename (excluding file extension). | ||
*/ | ||
static void | ||
ostree_bootconfig_parser_parse_tries (OstreeBootconfigParser *self, const char *filename) | ||
{ | ||
gchar *counter = NULL; | ||
gchar *old_counter = NULL; | ||
self->tries_left = 0; | ||
self->tries_done = 0; | ||
|
||
for (;;) | ||
{ | ||
char *plus = strchr (counter ?: filename, '+'); | ||
if (plus) | ||
{ | ||
/* Look for the last "+" symbol in the filename */ | ||
counter = plus + 1; | ||
continue; | ||
} | ||
if (counter) | ||
break; | ||
|
||
/* No boot counter found */ | ||
return; | ||
} | ||
|
||
guint64 tries_left, tries_done = 0; | ||
|
||
old_counter = counter; | ||
tries_left = g_ascii_strtoull (old_counter, &counter, 10); | ||
if ((old_counter == counter) || (tries_left > INT_MAX)) | ||
return; | ||
|
||
/* Parse done counter only if present */ | ||
if (*counter == '-') | ||
{ | ||
old_counter = counter; | ||
tries_done = g_ascii_strtoull (counter + 1, &counter, 10); | ||
if ((old_counter == counter) || (tries_left > INT_MAX)) | ||
return; | ||
} | ||
|
||
self->tries_left = tries_left; | ||
self->tries_done = tries_done; | ||
} | ||
|
||
/** | ||
* ostree_bootconfig_parser_get_tries_left: | ||
* @self: Parser | ||
* | ||
* Returns: Amount of boot tries left | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add: |
||
*/ | ||
guint64 | ||
ostree_bootconfig_parser_get_tries_left (OstreeBootconfigParser *self) | ||
{ | ||
return self->tries_left; | ||
} | ||
|
||
/** | ||
* ostree_bootconfig_parser_get_tries_done: | ||
* @self: Parser | ||
* | ||
* Returns: Amount of boot tries | ||
*/ | ||
guint64 | ||
ostree_bootconfig_parser_get_tries_done (OstreeBootconfigParser *self) | ||
{ | ||
return self->tries_done; | ||
} | ||
|
||
/** | ||
* ostree_bootconfig_parser_get_tries_done: | ||
* @self: Parser | ||
* | ||
* Returns: TRUE if the boot config was parsed from existing boot config file | ||
*/ | ||
gboolean | ||
ostree_bootconfig_parser_is_parsed (OstreeBootconfigParser *self) | ||
{ | ||
return self->parsed; | ||
} | ||
|
||
/** | ||
* ostree_bootconfig_parser_parse_at: | ||
* @self: Parser | ||
|
@@ -116,6 +207,8 @@ ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self, int dfd, const | |
self->overlay_initrds = (char **)g_ptr_array_free (g_steal_pointer (&overlay_initrds), FALSE); | ||
} | ||
|
||
ostree_bootconfig_parser_parse_tries(self, glnx_basename(path)); | ||
|
||
self->parsed = TRUE; | ||
|
||
return TRUE; | ||
|
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 |
---|---|---|
|
@@ -67,4 +67,13 @@ void ostree_bootconfig_parser_set_overlay_initrds (OstreeBootconfigParser *self, | |
_OSTREE_PUBLIC | ||
char **ostree_bootconfig_parser_get_overlay_initrds (OstreeBootconfigParser *self); | ||
|
||
_OSTREE_PUBLIC | ||
guint64 ostree_bootconfig_parser_get_tries_left (OstreeBootconfigParser *self); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we want these to actually be public they'll need to be added to the |
||
|
||
_OSTREE_PUBLIC | ||
guint64 ostree_bootconfig_parser_get_tries_done (OstreeBootconfigParser *self); | ||
|
||
_OSTREE_PUBLIC | ||
gboolean ostree_bootconfig_parser_is_parsed (OstreeBootconfigParser *self); | ||
|
||
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
Oops, something went wrong.
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.
I think this one would be easier to unit test if it was just
(I also added an error so we can error if we fail to parse the numbers which seems like a good idea?)
Then it'd be good to have some unit tests for that. Actually, I will try to do a prep PR to add unit tests for some other code in this file just to start that ball.