Skip to content

Commit 0969574

Browse files
many: move BuildKernelBootInfo to overlord/install package
1 parent 5a8cded commit 0969574

File tree

5 files changed

+60
-62
lines changed

5 files changed

+60
-62
lines changed

cmd/snap-bootstrap/cmd_initramfs_mounts.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func doInstall(mst *initramfsMountsState, model *asserts.Model, sysSnaps map[sna
353353

354354
kernelSeed := sysSnaps[snap.TypeKernel]
355355
kernCompsMntPts := make(map[string]string)
356-
compSeedInfos := []gadgetInstall.CompSeedInfo{}
356+
compSeedInfos := []install.CompSeedInfo{}
357357
for _, sc := range kernelSeed.Components {
358358
seedComp := sc
359359
comp, ok := kernCompsByName[seedComp.CompSideInfo.Component.ComponentName]
@@ -388,7 +388,7 @@ func doInstall(mst *initramfsMountsState, model *asserts.Model, sysSnaps map[sna
388388
if err != nil {
389389
return err
390390
}
391-
compSeedInfos = append(compSeedInfos, gadgetInstall.CompSeedInfo{
391+
compSeedInfos = append(compSeedInfos, install.CompSeedInfo{
392392
CompInfo: compInfo,
393393
CompSeed: &seedComp,
394394
})
@@ -407,7 +407,7 @@ func doInstall(mst *initramfsMountsState, model *asserts.Model, sysSnaps map[sna
407407
needsKernelSetup := kernel.NeedsKernelDriversTree(model) && !preseed
408408

409409
isCore := !model.Classic()
410-
kernelBootInfo := gadgetInstall.BuildKernelBootInfo(
410+
kernelBootInfo := install.BuildKernelBootInfo(
411411
kernelSnap, compSeedInfos, kernelMountDir, kernCompsMntPts,
412412
isCore, needsKernelSetup)
413413

gadget/install/kernel.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
package install
2121

2222
import (
23-
"github.com/snapcore/snapd/boot"
24-
"github.com/snapcore/snapd/seed"
2523
"github.com/snapcore/snapd/snap"
2624
)
2725

@@ -51,52 +49,3 @@ type KernelModulesComponentInfo struct {
5149
// MountPoint is the root of the files from the component
5250
MountPoint string
5351
}
54-
55-
// CompSeedInfo contains information for a component from the seed and
56-
// from its metadata.
57-
type CompSeedInfo struct {
58-
CompInfo *snap.ComponentInfo
59-
CompSeed *seed.Component
60-
}
61-
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 {
70-
bootKMods := make([]boot.BootableKModsComponents, 0, len(compSeedInfos))
71-
modulesComps := make([]KernelModulesComponentInfo, 0, len(compSeedInfos))
72-
for _, compSeedInfo := range compSeedInfos {
73-
ci := compSeedInfo.CompInfo
74-
if ci.Type == snap.KernelModulesComponent {
75-
cpi := snap.MinimalComponentContainerPlaceInfo(ci.Component.ComponentName,
76-
ci.Revision, kernInfo.SnapName())
77-
modulesComps = append(modulesComps, KernelModulesComponentInfo{
78-
Name: ci.Component.ComponentName,
79-
Revision: ci.Revision,
80-
MountPoint: mntPtForComps[ci.FullName()],
81-
})
82-
bootKMods = append(bootKMods, boot.BootableKModsComponents{
83-
CompPlaceInfo: cpi,
84-
CompPath: compSeedInfo.CompSeed.Path,
85-
})
86-
}
87-
}
88-
89-
kSnapInfo := &KernelSnapInfo{
90-
Name: kernInfo.SnapName(),
91-
Revision: kernInfo.Revision,
92-
MountPoint: kernMntPoint,
93-
IsCore: isCore,
94-
ModulesComps: modulesComps,
95-
NeedsDriversTree: needsDriversTree,
96-
}
97-
98-
return KernelBootInfo{
99-
KSnapInfo: kSnapInfo,
100-
BootableKMods: bootKMods,
101-
}
102-
}

overlord/devicestate/devicemgr.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"github.com/snapcore/snapd/dirs"
3838
"github.com/snapcore/snapd/gadget"
3939
"github.com/snapcore/snapd/gadget/device"
40-
gadgetInstall "github.com/snapcore/snapd/gadget/install"
4140
"github.com/snapcore/snapd/i18n"
4241
"github.com/snapcore/snapd/kernel/fde"
4342
"github.com/snapcore/snapd/logger"
@@ -2249,7 +2248,7 @@ type systemAndEssentialSnaps struct {
22492248
*System
22502249
Seed seed.Seed
22512250
InfosByType map[snap.Type]*snap.Info
2252-
CompsByType map[snap.Type][]gadgetInstall.CompSeedInfo
2251+
CompsByType map[snap.Type][]install.CompSeedInfo
22532252
SeedSnapsByType map[snap.Type]*seed.Snap
22542253
}
22552254

@@ -2306,7 +2305,7 @@ func (m *DeviceManager) loadSystemAndEssentialSnaps(wantedSystemLabel string, ty
23062305
// like "snapd" will be skipped and not part of the EssentialSnaps list
23072306
//
23082307
snapInfos := make(map[snap.Type]*snap.Info)
2309-
compInfos := make(map[snap.Type][]gadgetInstall.CompSeedInfo)
2308+
compInfos := make(map[snap.Type][]install.CompSeedInfo)
23102309
seedSnaps := make(map[snap.Type]*seed.Snap)
23112310
for _, seedSnap := range s.EssentialSnaps() {
23122311
typ := seedSnap.EssentialType
@@ -2330,9 +2329,9 @@ func (m *DeviceManager) loadSystemAndEssentialSnaps(wantedSystemLabel string, ty
23302329
return nil, fmt.Errorf("internal error while retrieving %s for %s mode: %v",
23312330
seedSnap.SnapName(), modeForComps, err)
23322331
}
2333-
var compInfosForType []gadgetInstall.CompSeedInfo
2332+
var compInfosForType []install.CompSeedInfo
23342333
if len(snapForMode.Components) > 0 {
2335-
compInfosForType = make([]gadgetInstall.CompSeedInfo, 0, len(snapForMode.Components))
2334+
compInfosForType = make([]install.CompSeedInfo, 0, len(snapForMode.Components))
23362335
for _, sc := range snapForMode.Components {
23372336
seedComp := sc
23382337
compf, err := snapfile.Open(seedComp.Path)
@@ -2344,7 +2343,7 @@ func (m *DeviceManager) loadSystemAndEssentialSnaps(wantedSystemLabel string, ty
23442343
if err != nil {
23452344
return nil, err
23462345
}
2347-
compInfosForType = append(compInfosForType, gadgetInstall.CompSeedInfo{
2346+
compInfosForType = append(compInfosForType, install.CompSeedInfo{
23482347
CompInfo: compInfo,
23492348
CompSeed: &seedComp,
23502349
})

overlord/devicestate/handlers_install.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,10 +964,10 @@ func (m *DeviceManager) loadAndMountSystemLabelSnaps(systemLabel string, essenti
964964
return systemAndSnaps, mntPtForType, mntPtForComp, unmount, nil
965965
}
966966

967-
func kBootInfo(systemAndSnaps *systemAndEssentialSnaps, kernMntPoint string, mntPtForComps map[string]string, isCore bool) install.KernelBootInfo {
967+
func kBootInfo(systemAndSnaps *systemAndEssentialSnaps, kernMntPoint string, mntPtForComps map[string]string, isCore bool) installLogic.KernelBootInfo {
968968
kernInfo := systemAndSnaps.InfosByType[snap.TypeKernel]
969969
compSeedInfos := systemAndSnaps.CompsByType[snap.TypeKernel]
970-
return install.BuildKernelBootInfo(kernInfo, compSeedInfos, kernMntPoint,
970+
return installLogic.BuildKernelBootInfo(kernInfo, compSeedInfos, kernMntPoint,
971971
mntPtForComps, isCore, kernel.NeedsKernelDriversTree(systemAndSnaps.Model))
972972
}
973973

overlord/install/install.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/snapcore/snapd/dirs"
3939
"github.com/snapcore/snapd/gadget"
4040
"github.com/snapcore/snapd/gadget/device"
41+
gadgetInstall "github.com/snapcore/snapd/gadget/install"
4142
"github.com/snapcore/snapd/kernel/fde"
4243
"github.com/snapcore/snapd/logger"
4344
"github.com/snapcore/snapd/osutil"
@@ -81,13 +82,62 @@ type EncryptionSupportInfo struct {
8182
UnavailableWarning string
8283
}
8384

85+
// CompSeedInfo contains information for a component from the seed and
86+
// from its metadata.
87+
type CompSeedInfo struct {
88+
CompInfo *snap.ComponentInfo
89+
CompSeed *seed.Component
90+
}
91+
92+
// KernelBootInfo contains information related to the kernel used on installation.
93+
type KernelBootInfo struct {
94+
KSnapInfo *gadgetInstall.KernelSnapInfo
95+
BootableKMods []boot.BootableKModsComponents
96+
}
97+
8498
var (
8599
timeNow = time.Now
86100

87101
secbootCheckTPMKeySealingSupported = secboot.CheckTPMKeySealingSupported
88102
sysconfigConfigureTargetSystem = sysconfig.ConfigureTargetSystem
89103
)
90104

105+
// BuildKernelBootInfo constructs a KernelBootInfo.
106+
func BuildKernelBootInfo(kernInfo *snap.Info, compSeedInfos []CompSeedInfo, kernMntPoint string, mntPtForComps map[string]string, isCore, needsDriversTree bool) KernelBootInfo {
107+
bootKMods := make([]boot.BootableKModsComponents, 0, len(compSeedInfos))
108+
modulesComps := make([]gadgetInstall.KernelModulesComponentInfo, 0, len(compSeedInfos))
109+
for _, compSeedInfo := range compSeedInfos {
110+
ci := compSeedInfo.CompInfo
111+
if ci.Type == snap.KernelModulesComponent {
112+
cpi := snap.MinimalComponentContainerPlaceInfo(ci.Component.ComponentName,
113+
ci.Revision, kernInfo.SnapName())
114+
modulesComps = append(modulesComps, gadgetInstall.KernelModulesComponentInfo{
115+
Name: ci.Component.ComponentName,
116+
Revision: ci.Revision,
117+
MountPoint: mntPtForComps[ci.FullName()],
118+
})
119+
bootKMods = append(bootKMods, boot.BootableKModsComponents{
120+
CompPlaceInfo: cpi,
121+
CompPath: compSeedInfo.CompSeed.Path,
122+
})
123+
}
124+
}
125+
126+
kSnapInfo := &gadgetInstall.KernelSnapInfo{
127+
Name: kernInfo.SnapName(),
128+
Revision: kernInfo.Revision,
129+
MountPoint: kernMntPoint,
130+
IsCore: isCore,
131+
ModulesComps: modulesComps,
132+
NeedsDriversTree: needsDriversTree,
133+
}
134+
135+
return KernelBootInfo{
136+
KSnapInfo: kSnapInfo,
137+
BootableKMods: bootKMods,
138+
}
139+
}
140+
91141
// MockSecbootCheckTPMKeySealingSupported mocks secboot.CheckTPMKeySealingSupported usage by the package for testing.
92142
func MockSecbootCheckTPMKeySealingSupported(f func(tpmMode secboot.TPMProvisionMode) error) (restore func()) {
93143
old := secbootCheckTPMKeySealingSupported

0 commit comments

Comments
 (0)