Skip to content

Commit

Permalink
disk: cover all entities in PartitionTable.features()
Browse files Browse the repository at this point in the history
Add a case for every entity type in the PartitionTable.features()
callback.  More importantly, panic if any entity type is not covered by
a case.  This ensures that when a new entity type is added, we need to
consider whether it needs to be represented as a feature, added to an
existing one, or ignored.

Co-authored-by: Michael Vogt <[email protected]>
  • Loading branch information
achilleas-k and mvo5 committed Nov 28, 2024
1 parent de9034d commit 2c84447
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/disk/partition_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,16 +841,20 @@ type partitionTableFeatures struct {
Swap bool
}

// features examines all of the PartitionTable entities
// and returns a struct with flags set for each feature used
// features examines all of the PartitionTable entities and returns a struct
// with flags set for each feature used. The meaning of "feature" here is quite
// broad. Most disk Entity types are represented by a feature and the existence
// of at least one type in the partition table means the feature is
// represented. For Filesystem entities, there is a separate feature for each
// filesystem type
func (pt *PartitionTable) features() partitionTableFeatures {
var ptFeatures partitionTableFeatures

introspectPT := func(e Entity, path []Entity) error {
switch ent := e.(type) {
case *LVMLogicalVolume:
case *LVMVolumeGroup, *LVMLogicalVolume:
ptFeatures.LVM = true
case *Btrfs:
case *Btrfs, *BtrfsSubvolume:
ptFeatures.Btrfs = true
case *Filesystem:
switch ent.GetFSType() {
Expand All @@ -867,6 +871,9 @@ func (pt *PartitionTable) features() partitionTableFeatures {
ptFeatures.Swap = true
case *LUKSContainer:
ptFeatures.LUKS = true
case *PartitionTable, *Partition:
default:
panic(fmt.Errorf("unknown entity type %T", e))
}
return nil
}
Expand Down

0 comments on commit 2c84447

Please sign in to comment.