From ebd532e2a03df6bc75d85e71ea3266ff906159e7 Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Thu, 26 Sep 2024 19:51:07 +1000 Subject: [PATCH] fix: exclude /dev/dm-* and LHv2 /dev/nvme* devices When Longhorn V2 volumes are created and attached to VMs, they appear on Harvester hosts as /dev/dm-* and /dev/nvme* devices. This is problematic, because NDM thinks those things are actual disks and creates BD CRs from them. This change is a bit of a hack until I finish the work for https://github.com/harvester/harvester/issues/5059. Signed-off-by: Tim Serong (cherry picked from commit 05ca4c70607b7e7eeddd10cac9ade8d7bc6626cc) --- pkg/controller/blockdevice/scanner.go | 8 ++++++++ pkg/filter/vendor_filter.go | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/controller/blockdevice/scanner.go b/pkg/controller/blockdevice/scanner.go index d4e7c9c5..10d1a7b9 100644 --- a/pkg/controller/blockdevice/scanner.go +++ b/pkg/controller/blockdevice/scanner.go @@ -3,6 +3,7 @@ package blockdevice import ( "fmt" "reflect" + "strings" "sync" "github.com/sirupsen/logrus" @@ -242,6 +243,13 @@ func convertBlockDeviceListToMap(bdList *diskv1.BlockDeviceList) (map[string]*di // returns true. func (s *Scanner) ApplyExcludeFiltersForDisk(disk *block.Disk) bool { for _, filter := range s.ExcludeFilters { + if strings.HasPrefix(disk.Name, "dm-") { + // None of the existing filters can handle this case, but + // we need to exclude /dev/dm-* devices because they appear + // when LHv2 volumes are attached to VMs. + logrus.Debugf("block device /dev/%s ignored because it's a dm device", disk.Name) + return true + } if filter.ApplyDiskFilter(disk) { logrus.Debugf("block device /dev/%s ignored by %s", disk.Name, filter.Name) return true diff --git a/pkg/filter/vendor_filter.go b/pkg/filter/vendor_filter.go index 8d79a9fd..62e39eed 100644 --- a/pkg/filter/vendor_filter.go +++ b/pkg/filter/vendor_filter.go @@ -8,10 +8,14 @@ import ( const ( vendorFilterName = "vendor filter" vendorFilterDefaultLonghorn = "longhorn" + // This is a hack to make sure we skip active longhorn v2 volumes, + // which appear as /dev/nvme* devices. They don't have a vendor, + // but do specify ID_MODEL=SPDK bdev Controller... + modelFilterDefaultSPDK = "SPDK bdev Controller" ) var ( - defaultExcludedVendors = []string{vendorFilterDefaultLonghorn} + defaultExcludedVendors = []string{vendorFilterDefaultLonghorn, modelFilterDefaultSPDK} ) type vendorFilter struct { @@ -36,5 +40,11 @@ func (vf *vendorFilter) Match(blockDevice *block.Disk) bool { if blockDevice.Vendor != "" && utils.MatchesIgnoredCase(vf.vendors, blockDevice.Vendor) { return true } - return blockDevice.BusPath != "" && utils.ContainsIgnoredCase(vf.vendors, blockDevice.BusPath) + if blockDevice.BusPath != "" && utils.ContainsIgnoredCase(vf.vendors, blockDevice.BusPath) { + return true + } + if blockDevice.Model != "" && utils.MatchesIgnoredCase(vf.vendors, blockDevice.Model) { + return true + } + return false }