Skip to content

Commit

Permalink
- add loop device support
Browse files Browse the repository at this point in the history
- add dm support to os disk filter

Signed-off-by: Akhil Mohan <[email protected]>
  • Loading branch information
akhilerm committed Oct 30, 2020
1 parent 8958abd commit df69708
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
13 changes: 2 additions & 11 deletions cmd/ndm_daemonset/filter/osdiskexcludefilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,8 @@ func (odf *oSDiskExcludeFilter) Exclude(blockDevice *blockdevice.BlockDevice) bo
}
regex := "^" + excludeDevPath + partitionRegex

// if the device is a dm device, need to check the /dev/mapper instead of /dev/dm-* because the
// mounts file will always have entry to the mapper path
var deviceMountPath string
if util.Contains(blockdevice.DeviceMapperDeviceTypes, blockDevice.DeviceAttributes.DeviceType) {
deviceMountPath = blockDevice.DMInfo.DevMapperPath
} else {
deviceMountPath = blockDevice.DevPath
}

klog.Infof("applying os-filter regex %s on %s", regex, deviceMountPath)
if util.IsMatchRegex(regex, deviceMountPath) {
klog.Infof("applying os-filter regex %s on %s", regex, blockDevice.DevPath)
if util.IsMatchRegex(regex, blockDevice.DevPath) {
return false
}
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/ndm_daemonset/probe/udevprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ func (up *udevProbe) scan() error {
deviceDetails.DevPath, deviceDetails.FSInfo.FileSystemUUID)
}

diskInfo = append(diskInfo, deviceDetails)

sysfsDevice, err := sysfs.NewSysFsDeviceFromDevPath(deviceDetails.DevPath)
// TODO if error occurs a rescan may be required
if err != nil {
Expand All @@ -239,6 +237,8 @@ func (up *udevProbe) scan() error {
deviceDetails.DeviceAttributes.DeviceType = deviceType
klog.Infof("Device: %s is of type: %s", deviceDetails.DevPath, deviceDetails.DeviceAttributes.DeviceType)
}

diskInfo = append(diskInfo, deviceDetails)
}
newUdevice.UdevDeviceUnref()
}
Expand Down Expand Up @@ -305,7 +305,6 @@ func (up *udevProbe) FillBlockDeviceDetails(blockDevice *blockdevice.BlockDevice
Links: udevDiskDetails.ByPathDevLinks,
})
}
blockDevice.DeviceAttributes.DeviceType = udevDiskDetails.DiskType

// 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
Expand All @@ -314,7 +313,7 @@ func (up *udevProbe) FillBlockDeviceDetails(blockDevice *blockdevice.BlockDevice
blockDevice.PartitionInfo.PartitionTableType = udevDiskDetails.PartitionTableType

// if this is a partition, partition number and partition UUID need to be filled
if udevDiskDetails.DiskType == libudevwrapper.UDEV_PARTITION {
if udevDiskDetails.DiskType == blockdevice.BlockDeviceTypePartition {
blockDevice.PartitionInfo.PartitionNumber = udevDiskDetails.PartitionNumber
}
}
Expand Down
1 change: 1 addition & 0 deletions cmd/ndm_daemonset/probe/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func generateUUID(bd blockdevice.BlockDevice) (string, bool) {

switch {
case bd.DeviceAttributes.DeviceType == blockdevice.BlockDeviceTypeLoop:
// hostname and device name, i.e /dev/loopX will be used for generating uuid
hostName, _ := os.Hostname()
klog.Infof("device(%s) is a loop device, using node name: %s and path: %s", bd.DevPath, hostName, bd.DevPath)
uuidField = hostName + bd.DevPath
Expand Down
13 changes: 12 additions & 1 deletion pkg/mount/mountutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,18 @@ func getCmdlineFile() string {
}

func getDeviceName(devPath string) string {
return strings.Replace(devPath, "/dev/", "", 1)
var err error
var deviceName string

deviceName = devPath
// if the device is a dm device
if strings.HasPrefix(devPath, "/dev/mapper") {
deviceName, err = filepath.EvalSymlinks(devPath)
if err != nil {
return ""
}
}
return strings.Replace(deviceName, "/dev/", "", 1)
}

func fileExists(file string) bool {
Expand Down

0 comments on commit df69708

Please sign in to comment.