Skip to content

Commit

Permalink
Save MainVolume info and rely on it to add the missing system-data st…
Browse files Browse the repository at this point in the history
…ructure

Signed-off-by: Paul Mars <[email protected]>
  • Loading branch information
upils committed Apr 19, 2024
1 parent f533f64 commit fa1ecef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions internal/statemachine/state_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ type StateMachine struct {
// names of images for each volume
VolumeNames map[string]string

// name of the "main volume"
MainVolumeName string

Packages []string
Snaps []string
}
Expand Down Expand Up @@ -395,10 +398,14 @@ func fixMissingContent(volume *gadget.Volume, structure *gadget.VolumeStructure,
// Since so far we have no knowledge of the rootfs contents, the
// size is set to 0, and will be calculated later
func (stateMachine *StateMachine) fixMissingSystemData(lastVolumeName string, farthestOffset quantity.Offset, farthestOffsetUnknown bool, rootfsSeen bool) {
// For now we consider the main volume to be the last one
// For now we consider the main volume to be the last one unless it was previously found
volume := stateMachine.GadgetInfo.Volumes[lastVolumeName]

if !farthestOffsetUnknown || !rootfsSeen || len(stateMachine.GadgetInfo.Volumes) == 1 {
if len(stateMachine.MainVolumeName) != 0 {
volume = stateMachine.GadgetInfo.Volumes[stateMachine.MainVolumeName]
}

if !farthestOffsetUnknown || !rootfsSeen || len(stateMachine.GadgetInfo.Volumes) != 1 {
return
}
rootfsStructure := gadget.VolumeStructure{
Expand Down Expand Up @@ -470,6 +477,7 @@ func (stateMachine *StateMachine) loadState(partialStateMachine *StateMachine) e
stateMachine.ImageSizes = partialStateMachine.ImageSizes
stateMachine.VolumeOrder = partialStateMachine.VolumeOrder
stateMachine.VolumeNames = partialStateMachine.VolumeNames
stateMachine.MainVolumeName = partialStateMachine.MainVolumeName

stateMachine.Packages = partialStateMachine.Packages
stateMachine.Snaps = partialStateMachine.Snaps
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"CurrentStep":"","StepsTaken":2,"ConfDefPath":"","YamlFilePath":"/tmp/ubuntu-image-2329554237/unpack/gadget/meta/gadget.yaml","IsSeeded":true,"RootfsVolName":"","RootfsPartNum":0,"SectorSize":512,"RootfsSize":775915520,"GadgetInfo":{"Volumes":{"pc":{"schema":"gpt","bootloader":"grub","id":"","structure":[{"name":"mbr","filesystem-label":"","offset":0,"offset-write":null,"min-size":440,"size":440,"type":"mbr","role":"mbr","id":"","filesystem":"","content":[{"source":"","target":"","image":"pc-boot.img","offset":null,"size":0,"unpack":false}],"update":{"edition":1,"preserve":null}}]}},"Defaults":null,"Connections":null,"KernelCmdline":{"Allow":null,"Append":null,"Remove":null}},"ImageSizes":{"pc":3155165184},"VolumeOrder":["pc"],"VolumeNames":{"pc":"pc.img"},"Packages":null,"Snaps":null}
{"CurrentStep":"","StepsTaken":2,"ConfDefPath":"","YamlFilePath":"/tmp/ubuntu-image-2329554237/unpack/gadget/meta/gadget.yaml","IsSeeded":true,"RootfsVolName":"","RootfsPartNum":0,"SectorSize":512,"RootfsSize":775915520,"GadgetInfo":{"Volumes":{"pc":{"schema":"gpt","bootloader":"grub","id":"","structure":[{"name":"mbr","filesystem-label":"","offset":0,"offset-write":null,"min-size":440,"size":440,"type":"mbr","role":"mbr","id":"","filesystem":"","content":[{"source":"","target":"","image":"pc-boot.img","offset":null,"size":0,"unpack":false}],"update":{"edition":1,"preserve":null}}]}},"Defaults":null,"Connections":null,"KernelCmdline":{"Allow":null,"Append":null,"Remove":null}},"ImageSizes":{"pc":3155165184},"VolumeOrder":["pc"],"VolumeNames":{"pc":"pc.img"},"MainVolumeName":"","Packages":null,"Snaps":null}

0 comments on commit fa1ecef

Please sign in to comment.