Skip to content
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

Support Installation-Date-based Slot Selection (A/B/C Update) #1525

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

ejoerns
Copy link
Member

@ejoerns ejoerns commented Sep 19, 2024

So far, RAUC theoretically supported having three slot groups (e.g. rootfs.0, rootfs.1, rootfs.2), but the slot selection algorithm prevented their use for an A/B/C update.

The algorithm simply selected the 'first' inactive slot group.
The 'first' group is implementation-defined by the data type used (i.e. by the GHashTable).

As a result, updating always alternated between two slot groups.

This PR now introduces a slightly more sophisticated slot selection algorithm which always selects the slot group with the oldest installation date.
Selecting the oldest installation date automatically ensures that all slots get their turn since once a slot is updated, it has the most recent timestamp and will be selected last.
A slot that has no installation date yet is considered outdated.

Not that the same behavior can also be used in an A/B setup together with rauc.external to ensure that two consecutive calls of rauc install populate both inactive slot groups A and B.

Fixes #1383

@ejoerns ejoerns added the enhancement Adds new functionality or enhanced handling to RAUC label Sep 19, 2024
Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 69.87952% with 25 lines in your changes missing coverage. Please review.

Project coverage is 83.27%. Comparing base (ccdffd2) to head (8143d3f).

Files with missing lines Patch % Lines
src/main.c 50.00% 12 Missing ⚠️
src/install.c 77.77% 6 Missing ⚠️
src/service.c 0.00% 4 Missing ⚠️
src/status_file.c 90.47% 2 Missing ⚠️
src/mark.c 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1525      +/-   ##
==========================================
+ Coverage   83.24%   83.27%   +0.02%     
==========================================
  Files          69       69              
  Lines       21585    21632      +47     
==========================================
+ Hits        17968    18013      +45     
- Misses       3617     3619       +2     
Flag Coverage Δ
service=false 79.97% <55.42%> (-0.09%) ⬇️
service=true 83.14% <69.87%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ejoerns ejoerns changed the title Support Installation Date-based Slot Selection (A/B/C Update) Support Installation-Date-based Slot Selection (A/B/C Update) Oct 16, 2024
Copy link
Member

@jluebbe jluebbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still have enough test cases for the per-slot status cases?

GHashTableIter iter;

g_return_val_if_fail(rootclass, NULL);

if (g_strcmp0(r_context()->config->statusfile_path, "per-slot") == 0) {
g_debug("Selecting inactive slot for class '%s'. Fallback strategy: 'first found'", rootclass);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
g_debug("Selecting inactive slot for class '%s'. Fallback strategy: 'first found'", rootclass);
g_debug("Selecting inactive slot for class '%s'. Strategy: 'first found'", rootclass);

return iterslot;
}

g_assert_nonnull(iterslot->status);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this guaranteed? What happens if the global slot status is empty?

Comment on lines +372 to +378
gchar *found = g_date_time_format(iterslot->status->installed_timestamp, RAUC_FORMAT_ISO_8601);
gchar *current = g_date_time_format(selectslot->status->installed_timestamp, RAUC_FORMAT_ISO_8601);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use g_autofree.

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
When using a global slot status, we can load the status of all slots
during RAUC startup. This should happen during (target) context setup.

This commit does not change behavior but renames
load_slot_status_globally() to r_slot_status_load_globally() and adds
the status file name and slot hash table as arguments to allow removing
calls to the r_context() method (which is not available during context
setup).

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
Adds a call to r_slot_status_load_globally() to
r_context_configure_target(), just like it already calls
r_system_status_load().

This ensures the slot status is loaded initially and the rest of the
code can safely assume the status information is filled (when using a
global status file).

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
Prepares for reworking timestamp handling and ensures using the same
format string consistently.

For later glib versions, an alternative coulde be to use
g_date_time_format_iso8601().

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
Up to now the time was stored as a gchar string in RaucSlotStatus as it
was only recorded and never modified or used for any operation.

If we now aim to use this time to base further decisions on it, we
should be able to properly handle the time as time and not as a string.

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
…date)

So far, RAUC theoretically supported having three slot groups (e.g.
rootfs.0, rootfs.1, rootfs.2), but the slot selection algorithm
prevented their use for an A/B/C update.

The algorithm simply selected the 'first' inactive slot group.
The 'first' group is implementation-defined by the data type used (i.e.
by the GHashTable).

As a result, updating always alternated between two slot groups.

This commit now introduces a slightly more sophisticated slot selection
algorithm which always selects the slot group with the oldest
installation date.
Selecting the oldest installation date automatically ensures that all
slots get their turn since once a slot is updated, it has the most
recent timestamp and will be selected last.
A slot that has no installation date yet is considered outdated.

Not that the same behavior can also be used in an A/B setup together
with 'rauc.external' to ensure that two consecutive calls of 'rauc
install' populate *both* inactive slot groups A and B.

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
Having a data-directory is the new default, thus we should update older
configs to this. It also potentially enhances test coverage for
data-directory and allows using it for testing newer features.

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
The crypt-test.conf should was meant to be used for the crypt tests.

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
With the changes made for timestamp-based slot selection, it is possible
to install to both inactive slot groups by calling 'rauc install' twice.

This extends the existing test case 'test_install_rauc_external' to
cover that, too.

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
@ejoerns
Copy link
Member Author

ejoerns commented Oct 23, 2024

Rebased onto master to resolve conflict in conftest.py (no further changes).

@jluebbe jluebbe added this to the Release v1.14 milestone Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adds new functionality or enhanced handling to RAUC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

how to select install slot on A/B boot when booting from usb (rauc.external)
2 participants