Skip to content

Commit

Permalink
fix: exclude /dev/dm-* and LHv2 /dev/nvme* devices
Browse files Browse the repository at this point in the history
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
harvester/harvester#5059.

Signed-off-by: Tim Serong <tserong@suse.com>
(cherry picked from commit 05ca4c7)
  • Loading branch information
tserong authored and mergify[bot] committed Sep 27, 2024
1 parent d270896 commit ebd532e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pkg/controller/blockdevice/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package blockdevice
import (
"fmt"
"reflect"
"strings"
"sync"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions pkg/filter/vendor_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

0 comments on commit ebd532e

Please sign in to comment.