diff --git a/cmd/ndm_daemonset/filter/pathfilter.go b/cmd/ndm_daemonset/filter/pathfilter.go index 27677ee03..77221d909 100644 --- a/cmd/ndm_daemonset/filter/pathfilter.go +++ b/cmd/ndm_daemonset/filter/pathfilter.go @@ -18,6 +18,8 @@ package filter import ( "github.com/openebs/node-disk-manager/blockdevice" + libudevwrapper "github.com/openebs/node-disk-manager/pkg/udev" + "strings" "github.com/openebs/node-disk-manager/cmd/ndm_daemonset/controller" @@ -100,7 +102,19 @@ func (pf *pathFilter) Include(blockDevice *blockdevice.BlockDevice) bool { return true } } - return util.MatchIgnoredCase(pf.includePaths, blockDevice.DevPath) + if util.MatchIgnoredCase(pf.includePaths, blockDevice.DevPath) { + return true + } + for _, link := range blockDevice.DevLinks { + if link.Kind == libudevwrapper.SYMLINK { + for _, symlink := range link.Links { + if util.Contains(pf.includePaths, symlink) { + return true + } + } + } + } + return false } // Exclude returns true if the disk path does not match any given @@ -116,5 +130,17 @@ func (pf *pathFilter) Exclude(blockDevice *blockdevice.BlockDevice) bool { return false } } - return !util.MatchIgnoredCase(pf.excludePaths, blockDevice.DevPath) + if util.MatchIgnoredCase(pf.excludePaths, blockDevice.DevPath) { + return false + } + for _, link := range blockDevice.DevLinks { + if link.Kind == libudevwrapper.SYMLINK { + for _, symlink := range link.Links { + if util.Contains(pf.excludePaths, symlink) { + return false + } + } + } + } + return true } diff --git a/cmd/ndm_daemonset/probe/udevprobe.go b/cmd/ndm_daemonset/probe/udevprobe.go index 2ef30799b..620cb6d93 100644 --- a/cmd/ndm_daemonset/probe/udevprobe.go +++ b/cmd/ndm_daemonset/probe/udevprobe.go @@ -325,6 +325,13 @@ func (up *udevProbe) FillBlockDeviceDetails(blockDevice *blockdevice.BlockDevice }) } + if len(udevDiskDetails.SymLinks) != 0 { + blockDevice.DevLinks = append(blockDevice.DevLinks, blockdevice.DevLink{ + Kind: libudevwrapper.SYMLINK, + Links: udevDiskDetails.SymLinks, + }) + } + // filesystem info of the attached device. Only filesystem data will be filled in the struct, // as the mountpoint related information will be filled in by the mount probe blockDevice.FSInfo.FileSystem = udevDiskDetails.FileSystem diff --git a/cmd/ndm_daemonset/probe/udevprobe_test.go b/cmd/ndm_daemonset/probe/udevprobe_test.go index aea7658a0..3feb6fa6c 100644 --- a/cmd/ndm_daemonset/probe/udevprobe_test.go +++ b/cmd/ndm_daemonset/probe/udevprobe_test.go @@ -125,6 +125,12 @@ func TestFillDiskDetails(t *testing.T) { Links: mockOsDiskDetails.ByPathDevLinks, }) } + if len(mockOsDiskDetails.SymLinks) > 0 { + expectedDiskInfo.DevLinks = append(expectedDiskInfo.DevLinks, blockdevice.DevLink{ + Kind: libudevwrapper.SYMLINK, + Links: mockOsDiskDetails.SymLinks, + }) + } // The devlinks are compared separately as the ordering of devlinks can be different in some systems // eg: ubuntu 20.04 in github actions diff --git a/pkg/blkid/blkid.go b/pkg/blkid/blkid.go index f0c117fb9..e99c37245 100644 --- a/pkg/blkid/blkid.go +++ b/pkg/blkid/blkid.go @@ -31,8 +31,8 @@ import ( ) const ( - fsTypeIdentifier = "TYPE" - labelIdentifier = "LABEL" + fsTypeIdentifier = "TYPE" + labelIdentifier = "LABEL" partitionTableUUIDIdentifier = "PTUUID" partitionEntryUUIDIdentifier = "PARTUUID" ) diff --git a/pkg/udev/common.go b/pkg/udev/common.go index 89027f6a5..1bd9b0dba 100644 --- a/pkg/udev/common.go +++ b/pkg/udev/common.go @@ -60,6 +60,8 @@ const ( UDEV_DEVLINKS = "DEVLINKS" // udev attribute contain devlinks of a disk BY_ID_LINK = "by-id" // by-path devlink contains this string BY_PATH_LINK = "by-path" // by-path devlink contains this string + BY_UUID_LINK = "by-uuid" // by-uuid devlink contains the string + BY_PARTUUID_LINK = "by-partuuid" // by-partuuid devlink contains the string LINK_ID_INDEX = 4 // this is used to get link index from dev link UDEV_FS_TYPE = "ID_FS_TYPE" // file system type the partition UDEV_FS_UUID = "ID_FS_UUID" // UUID of the filesystem present @@ -71,6 +73,8 @@ const ( UDEV_DM_UUID = "DM_UUID" // udev attribute to get the device mapper uuid // UDEV_DM_NAME is udev attribute to get the name of the dm device. This is used to generate the device mapper path UDEV_DM_NAME = "DM_NAME" + // SYMLINK is used to represent any manually created device symlinks + SYMLINK = "symlink" ) // UdevDiskDetails struct contain different attribute of disk. @@ -82,6 +86,7 @@ type UdevDiskDetails struct { Path string // Path is Path of a disk. ByIdDevLinks []string // ByIdDevLinks contains by-id devlinks ByPathDevLinks []string // ByPathDevLinks contains by-path devlinks + SymLinks []string // SymLinks contains device symlinks if any DiskType string // DeviceType can be disk, partition // IDType is used for uuid generation using the legacy algorithm IDType string @@ -112,6 +117,7 @@ func (device *UdevDevice) DiskInfoFromLibudev() UdevDiskDetails { Path: device.GetPropertyValue(UDEV_DEVNAME), ByIdDevLinks: devLinks[BY_ID_LINK], ByPathDevLinks: devLinks[BY_PATH_LINK], + SymLinks: devLinks[SYMLINK], DiskType: device.GetDevtype(), IDType: device.GetPropertyValue(UDEV_TYPE), FileSystem: device.GetFileSystemInfo(), @@ -210,6 +216,7 @@ func (device *UdevDevice) GetDevLinks() map[string][]string { devLinkMap := make(map[string][]string) byIdLink := make([]string, 0) byPathLink := make([]string, 0) + symLink := make([]string, 0) for _, link := range strings.Split(device.GetPropertyValue(UDEV_DEVLINKS), " ") { /* devlink is like - /dev/disk/by-id/scsi-0Google_PersistentDisk_demo-disk @@ -228,12 +235,14 @@ func (device *UdevDevice) GetDevLinks() map[string][]string { } else { byIdLink = append(byIdLink, link) } - } - if util.Contains(parts, BY_PATH_LINK) { + } else if util.Contains(parts, BY_PATH_LINK) { byPathLink = append(byPathLink, link) } + // we can add very dev link in symlink map as there is a 1:1 mapping between the two links + symLink = append(symLink, link) } devLinkMap[BY_ID_LINK] = byIdLink devLinkMap[BY_PATH_LINK] = byPathLink + devLinkMap[SYMLINK] = symLink return devLinkMap } diff --git a/pkg/udev/common_test.go b/pkg/udev/common_test.go index 5c98d94fc..8bdad1823 100644 --- a/pkg/udev/common_test.go +++ b/pkg/udev/common_test.go @@ -85,6 +85,7 @@ func TestDiskInfoFromLibudev(t *testing.T) { Path: diskDetails.DevNode, ByIdDevLinks: diskDetails.ByIdDevLinks, ByPathDevLinks: diskDetails.ByPathDevLinks, + SymLinks: diskDetails.SymLinks, PartitionTableType: diskDetails.PartTableType, IDType: diskDetails.IdType, } @@ -101,8 +102,10 @@ func TestDiskInfoFromLibudev(t *testing.T) { // need to make this nil as devlinks already compared. test.expectedDetails.ByIdDevLinks = nil test.expectedDetails.ByPathDevLinks = nil + test.expectedDetails.SymLinks = nil test.actualDetails.ByIdDevLinks = nil test.actualDetails.ByPathDevLinks = nil + test.actualDetails.SymLinks = nil assert.Equal(t, test.expectedDetails, test.actualDetails) }) } diff --git a/pkg/udev/mockdata.go b/pkg/udev/mockdata.go index 43dd39073..4c5e2079d 100644 --- a/pkg/udev/mockdata.go +++ b/pkg/udev/mockdata.go @@ -55,6 +55,7 @@ type MockOsDiskDetails struct { IdType string ByIdDevLinks []string ByPathDevLinks []string + SymLinks []string Dependents bd.DependentBlockDevices } @@ -108,6 +109,7 @@ func MockDiskDetails() (MockOsDiskDetails, error) { devLinks := device.GetDevLinks() diskDetails.ByIdDevLinks = devLinks[BY_ID_LINK] diskDetails.ByPathDevLinks = devLinks[BY_PATH_LINK] + diskDetails.SymLinks = devLinks[SYMLINK] return diskDetails, nil }