Skip to content

Commit 2b388eb

Browse files
many: create KernelBootInfo struct to be returned by BuildKernelBootInfo
1 parent 8b8b8c3 commit 2b388eb

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

cmd/snap-bootstrap/cmd_initramfs_mounts.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,12 @@ func doInstall(mst *initramfsMountsState, model *asserts.Model, sysSnaps map[sna
384384
}
385385

386386
isCore := !model.Classic()
387-
kernelSnapInfo, bootKMods := gadgetInstall.KernelBootInfo(
387+
kernelBootInfo := gadgetInstall.BuildKernelBootInfo(
388388
kernelSnap, compSeedInfos, kernelMountDir, kernCompsMntPts,
389389
isCore, model.NeedsKernelSetup())
390390

391391
bootDevice := ""
392-
installedSystem, err := gadgetInstallRun(model, gadgetMountDir, kernelSnapInfo, bootDevice, options, installObserver, timings.New(nil))
392+
installedSystem, err := gadgetInstallRun(model, gadgetMountDir, kernelBootInfo.KSnapInfo, bootDevice, options, installObserver, timings.New(nil))
393393
if err != nil {
394394
return err
395395
}
@@ -421,7 +421,7 @@ func doInstall(mst *initramfsMountsState, model *asserts.Model, sysSnaps map[sna
421421
KernelPath: sysSnaps[snap.TypeKernel].Path,
422422
UnpackedGadgetDir: gadgetMountDir,
423423
RecoverySystemLabel: mst.recoverySystem,
424-
KernelMods: bootKMods,
424+
KernelMods: kernelBootInfo.BootableKMods,
425425
}
426426

427427
if err := bootMakeRunnableStandaloneSystem(model, bootWith, trustedInstallObserver); err != nil {

gadget/install/kernel.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,21 @@ type KernelModulesComponentInfo struct {
5252
MountPoint string
5353
}
5454

55+
// CompSeedInfo contains information for a component from the seed and
56+
// from its metadata.
5557
type CompSeedInfo struct {
5658
CompInfo *snap.ComponentInfo
5759
CompSeed *seed.Component
5860
}
5961

60-
func KernelBootInfo(kernInfo *snap.Info, compSeedInfos []CompSeedInfo, kernMntPoint string, mntPtForComps map[string]string, isCore, needsDriversTree bool) (*KernelSnapInfo, []boot.BootableKModsComponents) {
62+
// KernelBootInfo contains information related to the kernel used on installation.
63+
type KernelBootInfo struct {
64+
KSnapInfo *KernelSnapInfo
65+
BootableKMods []boot.BootableKModsComponents
66+
}
67+
68+
// BuildKernelBootInfo constructs a KernelBootInfo.
69+
func BuildKernelBootInfo(kernInfo *snap.Info, compSeedInfos []CompSeedInfo, kernMntPoint string, mntPtForComps map[string]string, isCore, needsDriversTree bool) KernelBootInfo {
6170
bootKMods := make([]boot.BootableKModsComponents, 0, len(compSeedInfos))
6271
modulesComps := make([]KernelModulesComponentInfo, 0, len(compSeedInfos))
6372
for _, compSeedInfo := range compSeedInfos {
@@ -86,5 +95,8 @@ func KernelBootInfo(kernInfo *snap.Info, compSeedInfos []CompSeedInfo, kernMntPo
8695
NeedsDriversTree: needsDriversTree,
8796
}
8897

89-
return kSnapInfo, bootKMods
98+
return KernelBootInfo{
99+
KSnapInfo: kSnapInfo,
100+
BootableKMods: bootKMods,
101+
}
90102
}

overlord/devicestate/devicestate_install_mode_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,7 +2509,8 @@ func (s *deviceMgrInstallModeSuite) testFactoryResetNoEncryptionHappyFull(c *C,
25092509
}
25102510
var kModsRevs map[string]snap.Revision
25112511
if withKMods {
2512-
kModsRevs = map[string]snap.Revision{"kcomp1": snap.R(7), "kcomp2": snap.R(14)}
2512+
kModsRevs = map[string]snap.Revision{"kcomp1": snap.R(7),
2513+
"kcomp2": snap.R(14), "kcomp3": snap.R(21)}
25132514
}
25142515
seedOpts := mockSystemSeedWithLabelOpts{
25152516
isClassic: false,
@@ -2608,7 +2609,8 @@ func (s *deviceMgrInstallModeSuite) testFactoryResetEncryptionHappyFull(c *C, wi
26082609
}
26092610
var kModsRevs map[string]snap.Revision
26102611
if withKMods {
2611-
kModsRevs = map[string]snap.Revision{"kcomp1": snap.R(7), "kcomp2": snap.R(14)}
2612+
kModsRevs = map[string]snap.Revision{"kcomp1": snap.R(7), "kcomp2": snap.R(14),
2613+
"kcomp3": snap.R(21)}
26122614
}
26132615
seedOpts := mockSystemSeedWithLabelOpts{
26142616
isClassic: false,

overlord/devicestate/handlers_install.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,13 @@ func (m *DeviceManager) doSetupRunSystem(t *state.Task, _ *tomb.Tomb) error {
285285

286286
kernMntPoint := mntPtForType[snap.TypeKernel]
287287
isCore := !deviceCtx.Classic()
288-
kSnapInfo, bootKMods := kModsInfo(systemAndSnaps, kernMntPoint, mntPtForComps, isCore)
288+
kBootInfo := kBootInfo(systemAndSnaps, kernMntPoint, mntPtForComps, isCore)
289289

290290
timings.Run(perfTimings, "install-run", "Install the run system", func(tm timings.Measurer) {
291291
st.Unlock()
292292
defer st.Lock()
293-
installedSystem, err = installRun(model, gadgetDir, kSnapInfo, "", bopts, installObserver, tm)
293+
installedSystem, err = installRun(model, gadgetDir, kBootInfo.KSnapInfo, "",
294+
bopts, installObserver, tm)
294295
})
295296
if err != nil {
296297
return fmt.Errorf("cannot install system: %v", err)
@@ -330,7 +331,7 @@ func (m *DeviceManager) doSetupRunSystem(t *state.Task, _ *tomb.Tomb) error {
330331
UnpackedGadgetDir: gadgetDir,
331332

332333
RecoverySystemLabel: modeEnv.RecoverySystem,
333-
KernelMods: bootKMods,
334+
KernelMods: kBootInfo.BootableKMods,
334335
}
335336
timings.Run(perfTimings, "boot-make-runnable", "Make target system runnable", func(timings.Measurer) {
336337
err = bootMakeRunnable(deviceCtx.Model(), bootWith, trustedInstallObserver)
@@ -566,15 +567,16 @@ func (m *DeviceManager) doFactoryResetRunSystem(t *state.Task, _ *tomb.Tomb) err
566567

567568
kernMntPoint := mntPtForType[snap.TypeKernel]
568569
isCore := !deviceCtx.Classic()
569-
kSnapInfo, bootKMods := kModsInfo(systemAndSnaps, kernMntPoint, mntPtForComps, isCore)
570+
kBootInfo := kBootInfo(systemAndSnaps, kernMntPoint, mntPtForComps, isCore)
570571

571572
// run the create partition code
572573
logger.Noticef("create and deploy partitions")
573574
var installedSystem *install.InstalledSystemSideData
574575
timings.Run(perfTimings, "factory-reset", "Factory reset", func(tm timings.Measurer) {
575576
st.Unlock()
576577
defer st.Lock()
577-
installedSystem, err = installFactoryReset(model, gadgetDir, kSnapInfo, "", bopts, installObserver, tm)
578+
installedSystem, err = installFactoryReset(model, gadgetDir, kBootInfo.KSnapInfo,
579+
"", bopts, installObserver, tm)
578580
})
579581
if err != nil {
580582
return fmt.Errorf("cannot perform factory reset: %v", err)
@@ -659,7 +661,7 @@ func (m *DeviceManager) doFactoryResetRunSystem(t *state.Task, _ *tomb.Tomb) err
659661
UnpackedGadgetDir: gadgetDir,
660662

661663
RecoverySystemLabel: modeEnv.RecoverySystem,
662-
KernelMods: bootKMods,
664+
KernelMods: kBootInfo.BootableKMods,
663665
}
664666
timings.Run(perfTimings, "boot-make-runnable", "Make target system runnable", func(timings.Measurer) {
665667
err = bootMakeRunnableAfterDataReset(deviceCtx.Model(), bootWith, trustedInstallObserver)
@@ -961,10 +963,10 @@ func (m *DeviceManager) loadAndMountSystemLabelSnaps(systemLabel string, essenti
961963
return systemAndSnaps, mntPtForType, mntPtForComp, unmount, nil
962964
}
963965

964-
func kModsInfo(systemAndSnaps *systemAndEssentialSnaps, kernMntPoint string, mntPtForComps map[string]string, isCore bool) (*install.KernelSnapInfo, []boot.BootableKModsComponents) {
966+
func kBootInfo(systemAndSnaps *systemAndEssentialSnaps, kernMntPoint string, mntPtForComps map[string]string, isCore bool) install.KernelBootInfo {
965967
kernInfo := systemAndSnaps.InfosByType[snap.TypeKernel]
966968
compSeedInfos := systemAndSnaps.CompsByType[snap.TypeKernel]
967-
return install.KernelBootInfo(kernInfo, compSeedInfos, kernMntPoint,
969+
return install.BuildKernelBootInfo(kernInfo, compSeedInfos, kernMntPoint,
968970
mntPtForComps, isCore, systemAndSnaps.Model.NeedsKernelSetup())
969971
}
970972

@@ -1079,13 +1081,14 @@ func (m *DeviceManager) doInstallFinish(t *state.Task, _ *tomb.Tomb) error {
10791081

10801082
// Find out kernel-modules components in the seed
10811083
isCore := !deviceCtx.Classic()
1082-
kSnapInfo, bootKMods := kModsInfo(systemAndSnaps, kernMntPoint, mntPtForComps, isCore)
1084+
kBootInfo := kBootInfo(systemAndSnaps, kernMntPoint, mntPtForComps, isCore)
10831085

10841086
logger.Debugf("writing content to partitions")
10851087
timings.Run(perfTimings, "install-content", "Writing content to partitions", func(tm timings.Measurer) {
10861088
st.Unlock()
10871089
defer st.Lock()
1088-
_, err = installWriteContent(mergedVols, allLaidOutVols, encryptSetupData, kSnapInfo, installObserver, perfTimings)
1090+
_, err = installWriteContent(mergedVols, allLaidOutVols, encryptSetupData,
1091+
kBootInfo.KSnapInfo, installObserver, perfTimings)
10891092
})
10901093
if err != nil {
10911094
return fmt.Errorf("cannot write content: %v", err)
@@ -1155,7 +1158,7 @@ func (m *DeviceManager) doInstallFinish(t *state.Task, _ *tomb.Tomb) error {
11551158
UnpackedGadgetDir: mntPtForType[snap.TypeGadget],
11561159

11571160
RecoverySystemLabel: systemLabel,
1158-
KernelMods: bootKMods,
1161+
KernelMods: kBootInfo.BootableKMods,
11591162
}
11601163

11611164
// installs in system-seed{,-null} partition: grub.cfg, grubenv

0 commit comments

Comments
 (0)