Skip to content

kernel: add helpers for recording and checking modules/firmware tree version - #17680

Open
bboozzoo wants to merge 5 commits into
canonical:masterfrom
bboozzoo:bboozzoo/kernel-tree-generation-version
Open

bboozzoo wants to merge 5 commits into
canonical:masterfrom
bboozzoo:bboozzoo/kernel-tree-generation-version

Conversation

@bboozzoo

@bboozzoo bboozzoo commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Introduce versioning of the organization of the kernel modules &
firmware trees. The patch adds a helper to record the version of the
layout and another helper to check and compare indicating whether the
tree was set up by older version of the code.

Both are essential for being able to determine if the tree needs to be
rebuilt/updated when updating snapd.

Cherry picked from #17646

Related: SNAPDENG-37501

@bboozzoo
bboozzoo requested a balanced review from Copilot September 21, 2026 08:34
@bboozzoo bboozzoo added the Run nested The PR also runs tests inluded in nested suite label Sep 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The implementation is functionally sound; remaining feedback concerns minor documentation, spelling, and test cleanup.

Review effort: Balanced
Findings: 1 Medium severity · 4 Low severity

Open (5)
What changed in this PR

Adds version metadata for kernel module and firmware trees, enabling future regeneration when layouts become stale.

Changes:

  • Records generator version metadata after successful tree creation.
  • Detects missing, corrupt, older, and newer metadata versions.
  • Adds unit and spread coverage.
File Description
kernel/​kernel_drivers.go Implements metadata recording and version checking.
kernel/​export_test.go Exposes metadata test helpers.
kernel/​kernel_drivers_test.go Tests metadata and write failures.
tests/​core/​basic20plus/​task.yaml Verifies metadata on Core systems.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread kernel/kernel_drivers_test.go Outdated
Comment thread kernel/kernel_drivers.go Outdated
Comment thread kernel/kernel_drivers.go Outdated
Comment thread kernel/kernel_drivers.go Outdated
Comment thread kernel/kernel_drivers_test.go Outdated
@codecov

codecov Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.27451% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.39%. Comparing base (2cbd01b) to head (0bea319).
⚠️ Report is 26 commits behind head on master.

Files with missing lines Patch % Lines
kernel/kernel_drivers.go 86.27% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #17680      +/-   ##
==========================================
+ Coverage   78.35%   78.39%   +0.04%     
==========================================
  Files        1416     1417       +1     
  Lines      200464   200741     +277     
  Branches     2502     2503       +1     
==========================================
+ Hits       157070   157369     +299     
+ Misses      33972    33940      -32     
- Partials     9422     9432      +10     
Flag Coverage Δ
unittests 78.39% <86.27%> (+0.04%) ⬆️

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bboozzoo
bboozzoo force-pushed the bboozzoo/kernel-tree-generation-version branch from cae70a5 to 8a66a70 Compare September 21, 2026 09:43
@bboozzoo
bboozzoo requested a balanced review from Copilot September 21, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The forward-version test compares equal versions and does not exercise its intended behavior.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 2 Low severity

Open (2)
Resolved since last review (4)

Comment thread kernel/kernel_drivers_test.go Outdated
…version

Introduce versioning of the organization of the kernel modules &
firmware trees. The patch adds a helper to record the version of the
layout and another helper to check and compare indicating whether the
tree was set up by older version of the code.

Both are essential for being able to determine if the tree needs to be
rebuilt/updated when updating snapd.

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
@bboozzoo
bboozzoo force-pushed the bboozzoo/kernel-tree-generation-version branch from 8a66a70 to ffeae86 Compare September 21, 2026 10:41
@bboozzoo
bboozzoo requested a balanced review from Copilot September 21, 2026 10:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The versioning behavior, failure handling, and relevant edge cases are implemented consistently and adequately tested.

Review effort: Balanced
Findings: None

Resolved since last review (2)

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Thu Sep 24 15:08:06 UTC 2026
The following results are from: https://github.com/canonical/snapd/actions/runs/36011311318

No spread result artifacts found

No spread results JSON artifacts were available for this workflow run, so spread failures (if any) could not be reported.

@bboozzoo bboozzoo added the Auto rerun spread Auto reruns spread up to 4 times in non-draft PRs w/ >=1 approval and <20 fails in any fund. system label Sep 23, 2026
@bboozzoo bboozzoo closed this Sep 23, 2026
@bboozzoo bboozzoo reopened this Sep 23, 2026

@pedronis pedronis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

did a pass, some minor comments

Comment thread kernel/kernel_drivers.go Outdated
func readDriversTreeGeneratorMeta(destDir string) (driversTreeMeta, error) {
data, err := os.ReadFile(driversTreeMetaPath(destDir))
if errors.Is(err, fs.ErrNotExist) {
return driversTreeMeta{}, nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should this have:

GeneratorVersion: 0

to be explicit?

Comment thread kernel/kernel_drivers.go Outdated
var meta driversTreeMeta
if err := json.Unmarshal(data, &meta); err != nil {
// Treat unparseable metadata the same as missing: needs a check, or
// could be corrupted?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should this emphasize that the likely result of that is rebuilding the tree?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could also make it an error and turn into false a level above for clarity?

Comment thread kernel/kernel_drivers.go Outdated
// DriversTreeNeedsCheck returns true when the kernel modules & firmware tree at
// destDir was built by an older version of the generator code, indicating it
// may need to be checked or rebuilt.
func DriversTreeNeedsCheck(destDir string) (bool, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/NeedsCheck/Outdated perhaps?

Comment thread kernel/kernel_drivers.go
@bboozzoo
bboozzoo requested a review from pedronis September 23, 2026 13:47

@pedronis pedronis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thank you

Comment thread kernel/export_test.go Outdated
Comment thread kernel/export_test.go Outdated
Comment thread kernel/export_test.go
Comment thread kernel/export_test.go Outdated
Comment thread kernel/kernel_drivers.go Outdated
Comment thread kernel/kernel_drivers.go Outdated
Comment thread kernel/kernel_drivers.go
Comment thread kernel/kernel_drivers.go Outdated

@andrewphelpsj andrewphelpsj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

stat /run/systemd/system/"sysroot-writable-system\x2ddata-snap-$device\x2dkernel-"*

# Check the generator version
gojq '.["generator-version"]' /var/lib/snapd/kernel/"$device"-kernel/x1/kernel.json | \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

x1? I'm prob missing something but I don't see where this test installs a local kernel.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is the core suite, so running on UC and we repack the kernel in prepare, so it's always unasserted AFAIU

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

garden:ubuntu-core-26-64 .../tests/core/basic20plus# snap list pc-kernel
Name       Version        Rev  Tracking  Publisher  Notes
pc-kernel  7.0.0-38.38r1  x1   -         -          kernel,components[13]

@Mohit-Chachada Mohit-Chachada left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

Comment thread kernel/kernel_drivers.go Outdated
// A tree marked with a version *newer* than what is currently running (e.g.
// after a snapd revert) is deliberately NOT considered outdated: rebuilding
// it with older, possibly-buggy logic could regress a fix already applied
// by the newer generator. Only consider the kernel tree to be outdated of

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// by the newer generator. Only consider the kernel tree to be outdated of
// by the newer generator. Only consider the kernel tree to be outdated if

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto rerun spread Auto reruns spread up to 4 times in non-draft PRs w/ >=1 approval and <20 fails in any fund. system Run nested The PR also runs tests inluded in nested suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants