Skip to content

Commit

Permalink
🐛 properly handle volumes for fedora snapshot scanning (#3952)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey authored May 10, 2024
1 parent 0e80388 commit b3d38e3
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 5 deletions.
15 changes: 10 additions & 5 deletions providers/os/connection/snapshot/blockdevices.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (blockEntries blockDevices) GetBlockEntryByName(name string) (*fsInfo, erro
log.Debug().Msg("found match")
for i := range d.Children {
entry := d.Children[i]
if entry.IsNoBootVolumeAndUnmounted() {
if entry.IsNotBootOrRootVolumeAndUnmounted() {
devFsName := "/dev/" + entry.Name
return &fsInfo{name: devFsName, fstype: entry.FsType}, nil
}
Expand Down Expand Up @@ -112,7 +112,8 @@ func findVolume(children []blockDevice) *fsInfo {
var fs *fsInfo
for i := range children {
entry := children[i]
if entry.IsNoBootVolumeAndUnmounted() {
if entry.IsNotBootOrRootVolumeAndUnmounted() {
// we are NOT searching for the root volume here, so we can exclude the "sda" and "xvda" volumes
devFsName := "/dev/" + entry.Name
fs = &fsInfo{name: devFsName, fstype: entry.FsType}
}
Expand All @@ -121,9 +122,13 @@ func findVolume(children []blockDevice) *fsInfo {
}

func (entry blockDevice) IsNoBootVolume() bool {
return entry.Uuid != "" && entry.FsType != "" && entry.FsType != "vfat" && entry.Label != "EFI" && entry.Label != "boot" && entry.FsUse == ""
return entry.Uuid != "" && entry.FsType != "" && entry.FsType != "vfat" && entry.Label != "EFI" && entry.Label != "boot"
}

func (entry blockDevice) IsNoBootVolumeAndUnmounted() bool {
return entry.IsNoBootVolume() && entry.MountPoint == ""
func (entry blockDevice) IsRootVolume() bool {
return strings.Contains(entry.Name, "sda") || strings.Contains(entry.Name, "xvda") || strings.Contains(entry.Name, "nvme0n1")
}

func (entry blockDevice) IsNotBootOrRootVolumeAndUnmounted() bool {
return entry.IsNoBootVolume() && entry.MountPoint == "" && !entry.IsRootVolume()
}
14 changes: 14 additions & 0 deletions providers/os/connection/snapshot/blockdevices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,17 @@ func TestAttachedBlockEntryMultipleMatch(t *testing.T) {
require.Equal(t, "xfs", info.fstype)
require.True(t, strings.Contains(info.name, "xvdh4"))
}

func TestAttachedBlockEntryFedora(t *testing.T) {
data, err := os.ReadFile("./testdata/fedora_attached.json")
require.NoError(t, err)

blockEntries := blockDevices{}
err = json.Unmarshal(data, &blockEntries)
require.NoError(t, err)

info, err := blockEntries.GetUnnamedBlockEntry()
require.NoError(t, err)
require.Equal(t, "xfs", info.fstype)
require.True(t, strings.Contains(info.name, "xvdh4"))
}
116 changes: 116 additions & 0 deletions providers/os/connection/snapshot/testdata/fedora_attached.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"blockdevices": [
{
"name": "xvda",
"fstype": null,
"fsver": null,
"label": null,
"uuid": null,
"fsavail": null,
"fsuse%": null,
"mountpoints": [
null
],
"children": [
{
"name": "xvda1",
"fstype": "xfs",
"fsver": null,
"label": "/",
"uuid": "ddd4de1a-d036-454d-ba9a-a04efe92aa41",
"fsavail": "6.4G",
"fsuse%": "19%",
"mountpoints": [
"/"
]
},
{
"name": "xvda127",
"fstype": null,
"fsver": null,
"label": null,
"uuid": null,
"fsavail": null,
"fsuse%": null,
"mountpoints": [
null
]
},
{
"name": "xvda128",
"fstype": "vfat",
"fsver": "FAT16",
"label": null,
"uuid": "E6E9-5CB0",
"fsavail": "8.7M",
"fsuse%": "13%",
"mountpoints": [
"/boot/efi"
]
}
]
},
{
"name": "xvdh",
"fstype": null,
"fsver": null,
"label": null,
"uuid": null,
"fsavail": null,
"fsuse%": null,
"mountpoints": [
null
],
"children": [
{
"name": "xvdh1",
"fstype": null,
"fsver": null,
"label": null,
"uuid": null,
"fsavail": null,
"fsuse%": null,
"mountpoints": [
null
]
},
{
"name": "xvdh2",
"fstype": "vfat",
"fsver": "FAT16",
"label": "EFI-SYSTEM",
"uuid": "F6BC-CA0C",
"fsavail": null,
"fsuse%": null,
"mountpoints": [
null
]
},
{
"name": "xvdh3",
"fstype": "ext4",
"fsver": "1.0",
"label": "boot",
"uuid": "04645376-3f91-4b60-98f5-455ec712d4c5",
"fsavail": null,
"fsuse%": null,
"mountpoints": [
null
]
},
{
"name": "xvdh4",
"fstype": "xfs",
"fsver": null,
"label": "root",
"uuid": "abfe041f-7315-4fc8-a707-c599cd4b87fa",
"fsavail": null,
"fsuse%": "35%",
"mountpoints": [
null
]
}
]
}
]
}

0 comments on commit b3d38e3

Please sign in to comment.