Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add aliases to partitions info #4859

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions providers/os/connection/snapshot/blockdevices.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,13 @@ func (blockEntries BlockDevices) FindDevice(requested string) (BlockDevice, erro
func (device BlockDevice) GetMountablePartitions(includeAll bool) ([]*PartitionInfo, error) {
log.Debug().Str("device", device.Name).Msg("get partitions for device")

blockDevices := device.Children
blockDevices := &BlockDevices{
BlockDevices: device.Children,
}

// sort the candidates by size, so we can pick the largest one
sortBlockDevicesBySize(blockDevices)
sortBlockDevicesBySize(blockDevices.BlockDevices)
blockDevices.findAliases()

filter := func(partition BlockDevice) bool {
if partition.FsType == "" {
Expand All @@ -184,14 +187,15 @@ func (device BlockDevice) GetMountablePartitions(includeAll bool) ([]*PartitionI
}

partitions := []*PartitionInfo{}
for _, partition := range blockDevices {
for _, partition := range blockDevices.BlockDevices {
log.Debug().Str("name", partition.Name).Int64("size", int64(partition.Size)).Msg("checking partition")
if filter(partition) {
log.Debug().Str("name", partition.Name).Msg("found suitable partition")
devFsName := "/dev/" + partition.Name
partitions = append(partitions, &PartitionInfo{
Name: devFsName, FsType: partition.FsType,
Label: partition.Label, Uuid: partition.Uuid,
Aliases: partition.Aliases,
})
} else {
log.Debug().
Expand Down
6 changes: 5 additions & 1 deletion providers/os/connection/snapshot/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import (
)

type PartitionInfo struct {
Name string
// Device name (e.g. /dev/sda1)
Name string
// Filesystem type (e.g. ext4)
FsType string

// Resolved device name aliases (e.g. /dev/sda1 -> /dev/nvme0n1p1)
Aliases []string
Copy link
Contributor

Choose a reason for hiding this comment

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

can you write a comment above on what those aliases are?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated them all

Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

// (optional) Label is the partition label
Label string
// (optional) UUID is the partition UUID
Expand Down
Loading