diff --git a/pkg/util/mount/mount_linux.go b/pkg/util/mount/mount_linux.go index e80dad590a..43a150fc02 100644 --- a/pkg/util/mount/mount_linux.go +++ b/pkg/util/mount/mount_linux.go @@ -155,41 +155,6 @@ func (m *Mounter) doMount(mounterPath string, mountCmd string, source string, ta return err } -// GetMountRefs finds all other references to the device referenced -// by mountPath; returns a list of paths. -func GetMountRefs(mounter Interface, mountPath string) ([]string, error) { - mps, err := mounter.List() - if err != nil { - return nil, err - } - // Find the device name. - deviceName := "" - // If mountPath is symlink, need get its target path. - slTarget, err := filepath.EvalSymlinks(mountPath) - if err != nil { - slTarget = mountPath - } - for i := range mps { - if mps[i].Path == slTarget { - deviceName = mps[i].Device - break - } - } - - // Find all references to the device. - var refs []string - if deviceName == "" { - glog.Warningf("could not determine device for path: %q", mountPath) - } else { - for i := range mps { - if mps[i].Device == deviceName && mps[i].Path != slTarget { - refs = append(refs, mps[i].Path) - } - } - } - return refs, nil -} - // detectSystemd returns true if OS runs with systemd as init. When not sure // (permission errors, ...), it returns false. // There may be different ways how to detect systemd, this one makes sure that @@ -352,7 +317,7 @@ func (mounter *Mounter) GetDeviceNameFromMount(mountPath, pluginDir string) (str // the mount path reference should match the given plugin directory. In case no mount path reference // matches, returns the volume name taken from its given mountPath func getDeviceNameFromMount(mounter Interface, mountPath, pluginDir string) (string, error) { - refs, err := GetMountRefs(mounter, mountPath) + refs, err := mounter.GetMountRefs(mountPath) if err != nil { glog.V(4).Infof("GetMountRefs failed for mount path %q: %v", mountPath, err) return "", err diff --git a/pkg/util/mount/mount_linux_test.go b/pkg/util/mount/mount_linux_test.go index 0324bf88d9..fdcd719e1d 100644 --- a/pkg/util/mount/mount_linux_test.go +++ b/pkg/util/mount/mount_linux_test.go @@ -113,7 +113,7 @@ func TestGetMountRefs(t *testing.T) { } for i, test := range tests { - if refs, err := GetMountRefs(fm, test.mountPath); err != nil || !setEquivalent(test.expectedRefs, refs) { + if refs, err := fm.GetMountRefs(test.mountPath); err != nil || !setEquivalent(test.expectedRefs, refs) { t.Errorf("%d. getMountRefs(%q) = %v, %v; expected %v, nil", i, test.mountPath, refs, err, test.expectedRefs) } } diff --git a/pkg/util/mount/mount_unsupported.go b/pkg/util/mount/mount_unsupported.go index 6143aec182..b2edebb566 100644 --- a/pkg/util/mount/mount_unsupported.go +++ b/pkg/util/mount/mount_unsupported.go @@ -46,12 +46,6 @@ func (mounter *Mounter) Unmount(target string) error { return unsupportedErr } -// GetMountRefs finds all other references to the device referenced -// by mountPath; returns a list of paths. -func GetMountRefs(mounter Interface, mountPath string) ([]string, error) { - return []string{}, unsupportedErr -} - func (mounter *Mounter) List() ([]MountPoint, error) { return []MountPoint{}, unsupportedErr } diff --git a/pkg/util/mount/mount_windows.go b/pkg/util/mount/mount_windows.go index 5c57a57d06..28d4103826 100644 --- a/pkg/util/mount/mount_windows.go +++ b/pkg/util/mount/mount_windows.go @@ -114,16 +114,6 @@ func (mounter *Mounter) Unmount(target string) error { return nil } -// GetMountRefs finds all other references to the device(drive) referenced -// by mountPath; returns a list of paths. -func GetMountRefs(mounter Interface, mountPath string) ([]string, error) { - refs, err := getAllParentLinks(normalizeWindowsPath(mountPath)) - if err != nil { - return nil, err - } - return refs, nil -} - // List returns a list of all mounted filesystems. todo func (mounter *Mounter) List() ([]MountPoint, error) { return []MountPoint{}, nil @@ -170,7 +160,7 @@ func (mounter *Mounter) GetDeviceNameFromMount(mountPath, pluginDir string) (str // the mount path reference should match the given plugin directory. In case no mount path reference // matches, returns the volume name taken from its given mountPath func getDeviceNameFromMount(mounter Interface, mountPath, pluginDir string) (string, error) { - refs, err := GetMountRefs(mounter, mountPath) + refs, err := mounter.GetMountRefs(mountPath) if err != nil { glog.V(4).Infof("GetMountRefs failed for mount path %q: %v", mountPath, err) return "", err @@ -458,11 +448,11 @@ func getAllParentLinks(path string) ([]string, error) { } func (mounter *Mounter) GetMountRefs(pathname string) ([]string, error) { - realpath, err := filepath.EvalSymlinks(pathname) + refs, err := getAllParentLinks(normalizeWindowsPath(pathname)) if err != nil { return nil, err } - return getMountRefsByDev(mounter, realpath) + return refs, nil } // Note that on windows, it always returns 0. We actually don't set FSGroup on diff --git a/pkg/util/mount/mount_windows_test.go b/pkg/util/mount/mount_windows_test.go index a6e26bec8a..c292e9f86b 100644 --- a/pkg/util/mount/mount_windows_test.go +++ b/pkg/util/mount/mount_windows_test.go @@ -127,7 +127,7 @@ func TestGetMountRefs(t *testing.T) { } } - if refs, err := GetMountRefs(fm, mountPath); err != nil || !setEquivalent(expectedRefs, refs) { + if refs, err := fm.GetMountRefs(mountPath); err != nil || !setEquivalent(expectedRefs, refs) { t.Errorf("getMountRefs(%q) = %v, error: %v; expected %v", mountPath, refs, err, expectedRefs) } diff --git a/pkg/volume/aws_ebs/attacher.go b/pkg/volume/aws_ebs/attacher.go index ac716ed1b0..e4178068dc 100644 --- a/pkg/volume/aws_ebs/attacher.go +++ b/pkg/volume/aws_ebs/attacher.go @@ -55,7 +55,7 @@ func (plugin *awsElasticBlockStorePlugin) NewAttacher() (volume.Attacher, error) func (plugin *awsElasticBlockStorePlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - return mount.GetMountRefs(mounter, deviceMountPath) + return mounter.GetMountRefs(deviceMountPath) } func (attacher *awsElasticBlockStoreAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string, error) { diff --git a/pkg/volume/azure_dd/azure_dd.go b/pkg/volume/azure_dd/azure_dd.go index 8310e0ab00..71934c48fe 100644 --- a/pkg/volume/azure_dd/azure_dd.go +++ b/pkg/volume/azure_dd/azure_dd.go @@ -26,7 +26,6 @@ import ( "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/types" "k8s.io/kubernetes/pkg/cloudprovider/providers/azure" - "k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume/util" ) @@ -267,5 +266,5 @@ func (plugin *azureDataDiskPlugin) ConstructVolumeSpec(volumeName, mountPath str func (plugin *azureDataDiskPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) { m := plugin.host.GetMounter(plugin.GetPluginName()) - return mount.GetMountRefs(m, deviceMountPath) + return m.GetMountRefs(deviceMountPath) } diff --git a/pkg/volume/cinder/attacher.go b/pkg/volume/cinder/attacher.go index fff3efd557..e650954328 100644 --- a/pkg/volume/cinder/attacher.go +++ b/pkg/volume/cinder/attacher.go @@ -69,7 +69,7 @@ func (plugin *cinderPlugin) NewAttacher() (volume.Attacher, error) { func (plugin *cinderPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - return mount.GetMountRefs(mounter, deviceMountPath) + return mounter.GetMountRefs(deviceMountPath) } func (attacher *cinderDiskAttacher) waitOperationFinished(volumeID string) error { diff --git a/pkg/volume/cinder/cinder.go b/pkg/volume/cinder/cinder.go index 55aec4586c..8f0cb3aad5 100644 --- a/pkg/volume/cinder/cinder.go +++ b/pkg/volume/cinder/cinder.go @@ -437,7 +437,7 @@ func (c *cinderVolumeUnmounter) TearDownAt(dir string) error { // Find Cinder volumeID to lock the right volume // TODO: refactor VolumePlugin.NewUnmounter to get full volume.Spec just like // NewMounter. We could then find volumeID there without probing MountRefs. - refs, err := mount.GetMountRefs(c.mounter, dir) + refs, err := c.mounter.GetMountRefs(dir) if err != nil { glog.V(4).Infof("GetMountRefs failed: %v", err) return err @@ -454,7 +454,7 @@ func (c *cinderVolumeUnmounter) TearDownAt(dir string) error { defer c.plugin.volumeLocks.UnlockKey(c.pdName) // Reload list of references, there might be SetUpAt finished in the meantime - refs, err = mount.GetMountRefs(c.mounter, dir) + refs, err = c.mounter.GetMountRefs(dir) if err != nil { glog.V(4).Infof("GetMountRefs failed: %v", err) return err diff --git a/pkg/volume/csi/BUILD b/pkg/volume/csi/BUILD index 54a2574eb7..95d0dd5cae 100644 --- a/pkg/volume/csi/BUILD +++ b/pkg/volume/csi/BUILD @@ -14,7 +14,6 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/features:go_default_library", - "//pkg/util/mount:go_default_library", "//pkg/util/strings:go_default_library", "//pkg/volume:go_default_library", "//pkg/volume/csi/labelmanager:go_default_library", diff --git a/pkg/volume/csi/csi_plugin.go b/pkg/volume/csi/csi_plugin.go index d10457686a..76918713f9 100644 --- a/pkg/volume/csi/csi_plugin.go +++ b/pkg/volume/csi/csi_plugin.go @@ -31,7 +31,6 @@ import ( "k8s.io/apimachinery/pkg/types" utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/kubernetes/pkg/features" - "k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume/csi/labelmanager" ) @@ -309,7 +308,7 @@ func (p *csiPlugin) NewDetacher() (volume.Detacher, error) { func (p *csiPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) { m := p.host.GetMounter(p.GetPluginName()) - return mount.GetMountRefs(m, deviceMountPath) + return m.GetMountRefs(deviceMountPath) } // BlockVolumePlugin methods diff --git a/pkg/volume/fc/attacher.go b/pkg/volume/fc/attacher.go index 77549e9b5b..69d14fbff1 100644 --- a/pkg/volume/fc/attacher.go +++ b/pkg/volume/fc/attacher.go @@ -51,7 +51,7 @@ func (plugin *fcPlugin) NewAttacher() (volume.Attacher, error) { func (plugin *fcPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - return mount.GetMountRefs(mounter, deviceMountPath) + return mounter.GetMountRefs(deviceMountPath) } func (attacher *fcAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string, error) { diff --git a/pkg/volume/fc/fc.go b/pkg/volume/fc/fc.go index 4160fe055c..4bbacfce70 100644 --- a/pkg/volume/fc/fc.go +++ b/pkg/volume/fc/fc.go @@ -237,7 +237,7 @@ func (plugin *fcPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volu // globalPDPath : plugins/kubernetes.io/fc/50060e801049cfd1-lun-0 var globalPDPath string mounter := plugin.host.GetMounter(plugin.GetPluginName()) - paths, err := mount.GetMountRefs(mounter, mountPath) + paths, err := mounter.GetMountRefs(mountPath) if err != nil { return nil, err } diff --git a/pkg/volume/fc/fc_test.go b/pkg/volume/fc/fc_test.go index ecc4155c7f..828552e0fd 100644 --- a/pkg/volume/fc/fc_test.go +++ b/pkg/volume/fc/fc_test.go @@ -441,7 +441,7 @@ func Test_ConstructVolumeSpec(t *testing.T) { "/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~fc/fc-in-pod2", } for _, path := range mountPaths { - refs, err := mount.GetMountRefs(fm, path) + refs, err := fm.GetMountRefs(path) if err != nil { t.Errorf("couldn't get mountrefs. err: %v", err) } @@ -488,7 +488,7 @@ func Test_ConstructVolumeSpecNoRefs(t *testing.T) { "/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~fc/fc-in-pod1", } for _, path := range mountPaths { - refs, _ := mount.GetMountRefs(fm, path) + refs, _ := fm.GetMountRefs(path) var globalPDPath string for _, ref := range refs { if strings.Contains(ref, "kubernetes.io/fc") { diff --git a/pkg/volume/flexvolume/plugin.go b/pkg/volume/flexvolume/plugin.go index 861ab4a3bb..68bcf094d5 100644 --- a/pkg/volume/flexvolume/plugin.go +++ b/pkg/volume/flexvolume/plugin.go @@ -265,7 +265,7 @@ func (plugin *flexVolumePlugin) isUnsupported(command string) bool { func (plugin *flexVolumePlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - return mount.GetMountRefs(mounter, deviceMountPath) + return mounter.GetMountRefs(deviceMountPath) } func (plugin *flexVolumePlugin) getDeviceMountPath(spec *volume.Spec) (string, error) { diff --git a/pkg/volume/gce_pd/attacher.go b/pkg/volume/gce_pd/attacher.go index 21d8545b08..8a6256b617 100644 --- a/pkg/volume/gce_pd/attacher.go +++ b/pkg/volume/gce_pd/attacher.go @@ -29,7 +29,6 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/kubernetes/pkg/cloudprovider/providers/gce" - "k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/volume" volumeutil "k8s.io/kubernetes/pkg/volume/util" ) @@ -57,7 +56,7 @@ func (plugin *gcePersistentDiskPlugin) NewAttacher() (volume.Attacher, error) { func (plugin *gcePersistentDiskPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - return mount.GetMountRefs(mounter, deviceMountPath) + return mounter.GetMountRefs(deviceMountPath) } // Attach checks with the GCE cloud provider if the specified volume is already diff --git a/pkg/volume/iscsi/attacher.go b/pkg/volume/iscsi/attacher.go index 0ca2f4d5fe..59c528b361 100644 --- a/pkg/volume/iscsi/attacher.go +++ b/pkg/volume/iscsi/attacher.go @@ -49,7 +49,7 @@ func (plugin *iscsiPlugin) NewAttacher() (volume.Attacher, error) { func (plugin *iscsiPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) { mounter := plugin.host.GetMounter(iscsiPluginName) - return mount.GetMountRefs(mounter, deviceMountPath) + return mounter.GetMountRefs(deviceMountPath) } func (attacher *iscsiAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string, error) { diff --git a/pkg/volume/iscsi/iscsi.go b/pkg/volume/iscsi/iscsi.go index 687f2cc6a3..de82fa1652 100644 --- a/pkg/volume/iscsi/iscsi.go +++ b/pkg/volume/iscsi/iscsi.go @@ -203,7 +203,7 @@ func (plugin *iscsiPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*v // Find globalPDPath from pod volume directory(mountPath) var globalPDPath string mounter := plugin.host.GetMounter(plugin.GetPluginName()) - paths, err := mount.GetMountRefs(mounter, mountPath) + paths, err := mounter.GetMountRefs(mountPath) if err != nil { return nil, err } diff --git a/pkg/volume/photon_pd/attacher.go b/pkg/volume/photon_pd/attacher.go index 54370d6049..368b9bea94 100644 --- a/pkg/volume/photon_pd/attacher.go +++ b/pkg/volume/photon_pd/attacher.go @@ -182,7 +182,7 @@ func (attacher *photonPersistentDiskAttacher) GetDeviceMountPath(spec *volume.Sp // by deviceMountPath; returns a list of paths. func (plugin *photonPersistentDiskPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - return mount.GetMountRefs(mounter, deviceMountPath) + return mounter.GetMountRefs(deviceMountPath) } // MountDevice mounts device to global mount point. diff --git a/pkg/volume/rbd/attacher.go b/pkg/volume/rbd/attacher.go index 9a74a608c3..628f985ecc 100644 --- a/pkg/volume/rbd/attacher.go +++ b/pkg/volume/rbd/attacher.go @@ -58,7 +58,7 @@ func (plugin *rbdPlugin) newDetacherInternal(manager diskManager) (volume.Detach // GetDeviceMountRefs implements AttachableVolumePlugin.GetDeviceMountRefs. func (plugin *rbdPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - return mount.GetMountRefs(mounter, deviceMountPath) + return mounter.GetMountRefs(deviceMountPath) } // rbdAttacher implements volume.Attacher interface. diff --git a/pkg/volume/vsphere_volume/attacher.go b/pkg/volume/vsphere_volume/attacher.go index 0cf3440d8a..ad6698de84 100644 --- a/pkg/volume/vsphere_volume/attacher.go +++ b/pkg/volume/vsphere_volume/attacher.go @@ -191,7 +191,7 @@ func (attacher *vsphereVMDKAttacher) GetDeviceMountPath(spec *volume.Spec) (stri // by deviceMountPath; returns a list of paths. func (plugin *vsphereVolumePlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - return mount.GetMountRefs(mounter, deviceMountPath) + return mounter.GetMountRefs(deviceMountPath) } // MountDevice mounts device to global mount point.