From b3d38e303f4e7f8c2e29d0f8fdd6e35411bcca8f Mon Sep 17 00:00:00 2001 From: vjeffrey Date: Thu, 9 May 2024 21:10:09 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20properly=20handle=20volumes=20fo?= =?UTF-8?q?r=20fedora=20snapshot=20scanning=20(#3952)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../os/connection/snapshot/blockdevices.go | 15 ++- .../connection/snapshot/blockdevices_test.go | 14 +++ .../snapshot/testdata/fedora_attached.json | 116 ++++++++++++++++++ 3 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 providers/os/connection/snapshot/testdata/fedora_attached.json diff --git a/providers/os/connection/snapshot/blockdevices.go b/providers/os/connection/snapshot/blockdevices.go index 47905bf995..7fbdb0a56a 100644 --- a/providers/os/connection/snapshot/blockdevices.go +++ b/providers/os/connection/snapshot/blockdevices.go @@ -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 } @@ -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} } @@ -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() } diff --git a/providers/os/connection/snapshot/blockdevices_test.go b/providers/os/connection/snapshot/blockdevices_test.go index 22bd8d01f4..6596569266 100644 --- a/providers/os/connection/snapshot/blockdevices_test.go +++ b/providers/os/connection/snapshot/blockdevices_test.go @@ -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")) +} diff --git a/providers/os/connection/snapshot/testdata/fedora_attached.json b/providers/os/connection/snapshot/testdata/fedora_attached.json new file mode 100644 index 0000000000..1ea3642b0b --- /dev/null +++ b/providers/os/connection/snapshot/testdata/fedora_attached.json @@ -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 + ] + } + ] + } + ] +} \ No newline at end of file