From b7f6911b03db258a9a50022f0f7b0dbaf15d15a5 Mon Sep 17 00:00:00 2001 From: Akhil Mohan Date: Tue, 29 Dec 2020 09:40:43 +0530 Subject: [PATCH] feat(filter): add support for using unused partition on os-disk Signed-off-by: Akhil Mohan --- .../filter/osdiskexcludefilter.go | 2 -- pkg/mount/mountutil.go | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/ndm_daemonset/filter/osdiskexcludefilter.go b/cmd/ndm_daemonset/filter/osdiskexcludefilter.go index 7d2309120..c31c14253 100644 --- a/cmd/ndm_daemonset/filter/osdiskexcludefilter.go +++ b/cmd/ndm_daemonset/filter/osdiskexcludefilter.go @@ -90,7 +90,6 @@ func (odf *oSDiskExcludeFilter) Start() { mountPointUtil := mount.NewMountUtil(hostMountFilePath, "", mountPoint) if devPath, err := mountPointUtil.GetDiskPath(); err != nil { klog.Errorf("unable to configure os disk filter for mountpoint: %s, error: %v", mountPoint, err) - klog.Error(err) } else { odf.excludeDevPaths = append(odf.excludeDevPaths, devPath) } @@ -103,7 +102,6 @@ func (odf *oSDiskExcludeFilter) Start() { mountPointUtil := mount.NewMountUtil(defaultMountFilePath, "", mountPoint) if devPath, err := mountPointUtil.GetDiskPath(); err != nil { klog.Errorf("unable to configure os disk filter for mountpoint: %s, error: %v", mountPoint, err) - klog.Error(err) } else { odf.excludeDevPaths = append(odf.excludeDevPaths, devPath) } diff --git a/pkg/mount/mountutil.go b/pkg/mount/mountutil.go index b0e2aabba..432ad183d 100644 --- a/pkg/mount/mountutil.go +++ b/pkg/mount/mountutil.go @@ -19,6 +19,7 @@ package mount import ( "bufio" "fmt" + "github.com/openebs/node-disk-manager/pkg/features" "io" "os" "path/filepath" @@ -116,11 +117,20 @@ func getDiskDevPath(partition string) (string, error) { return "", err } - parentDisk, ok := getParentBlockDevice(link) - if !ok { - return "", fmt.Errorf("could not find parent device for %s", link) + var disk string + var ok bool + if features.FeatureGates.IsEnabled(features.UseOSDisk) { + // the last part will be used instead of the parent disk + split := strings.Split(link, "/") + disk = split[len(split)-1] + } else { + disk, ok = getParentBlockDevice(link) + if !ok { + return "", fmt.Errorf("could not find parent device for %s", link) + } } - return "/dev/" + parentDisk, nil + + return "/dev/" + disk, nil } // getSoftLinkForPartition returns path to /sys/class/block/$partition