// GetDeviceMountPath returns a path where the device should
// point which should be bind mounted for individual volumes.
197066
func (attacher *vsphereVMDKAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error) {
	volumeSource, _, err := getVolumeSource(spec)
	if err != nil {
		return "", err
	}

	return makeGlobalPDPath(attacher.host, volumeSource.VolumePath), nil
}
263939
func GetContainerPath(pv *v1.PersistentVolume, config MountConfig) (string, error) {
	relativePath, err := filepath.Rel(config.HostDir, pv.Spec.Local.Path)
	if err != nil {
		return "", fmt.Errorf("Could not get relative path for pv %q: %v", pv.Name, err)
	}

	return filepath.Join(config.MountDir, relativePath), nil
}
21834
func (devices *DeviceSet) UnmountDevice(hash, mountPath string) error {
	logrus.Debugf("devmapper: UnmountDevice(hash=%s)", hash)
	defer logrus.Debugf("devmapper: UnmountDevice(hash=%s) END", hash)

	info, err := devices.lookupDeviceWithLock(hash)
	if err != nil {
		return err
	}

	info.lock.Lock()
	defer info.lock.Unlock()

	devices.Lock()
	defer devices.Unlock()

	// If there are running containers when daemon crashes, during daemon
	// restarting, it will kill running containers and will finally call
	// Put() without calling Get(). So info.MountCount may become negative.
	// if info.mountCount goes negative, we do the unmount and assign
	// it to 0.

	info.mountCount--
	if info.mountCount > 0 {
		return nil
	} else if info.mountCount < 0 {
		logrus.Warnf("devmapper: Mount count of device went negative. Put() called without matching Get(). Resetting count to 0")
		info.mountCount = 0
	}

	logrus.Debugf("devmapper: Unmount(%s)", mountPath)
	if err := syscall.Unmount(mountPath, syscall.MNT_DETACH); err != nil {
		return err
	}
	logrus.Debugf("devmapper: Unmount done")

	if err := devices.deactivateDevice(info); err != nil {
		return err
	}

	info.mountPath = ""

	return nil
}
978886
func GetPath(mounter volume.Mounter) (string, error) {
	path := mounter.GetPath()
	if path == "" {
		return "", fmt.Errorf("Path is empty %s", reflect.TypeOf(mounter).String())
	}
	return path, nil
}
817107
func GetMounts() ([]*mount.Info, error) {
	if os.Getenv(testDeviceEnv) != "" {
		return testGetMounts()
	}
	return mount.GetMounts()
}
281175
func (ops *vsphereOps) DevicePath(diskPath string) (string, error) {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	vmObj, err := ops.renewVM(ctx, ops.vm)
	if err != nil {
		return "", err
	}

	attached, err := vmObj.IsDiskAttached(ctx, diskPath)
	if err != nil {
		return "", fmt.Errorf("failed to check if disk: %s is attached on vm: %s. err: %v",
			diskPath, vmObj.Name(), err)
	}

	if !attached {
		return "", fmt.Errorf("disk: %s is not attached on vm: %s", diskPath, vmObj.Name())
	}

	diskUUID, err := vmObj.Datacenter.GetVirtualDiskPage83Data(ctx, diskPath)
	if err != nil {
		logrus.Errorf("failed to get device path for disk: %s on vm: %s", diskPath, vmObj.Name())
		return "", err
	}

	return path.Join(diskByIDPath, diskSCSIPrefix+diskUUID), nil
}
52321
func getMountRefsByDev(mounter Interface, mountPath string) ([]string, error) {
	mps, err := mounter.List()
	if err != nil {
		return nil, err
	}

	// Finding the device mounted to mountPath
	diskDev := ""
	for i := range mps {
		if mountPath == mps[i].Path {
			diskDev = mps[i].Device
			break
		}
	}

	// Find all references to the device.
	var refs []string
	for i := range mps {
		if mps[i].Device == diskDev || mps[i].Device == mountPath {
			if mps[i].Path != mountPath {
				refs = append(refs, mps[i].Path)
			}
		}
	}
	return refs, nil
}
103612
func (v *OpenstackVolumes) FindMountedVolume(volume *Volume) (string, error) {
	device := volume.LocalDevice

	_, err := os.Stat(pathFor(device))
	if err == nil {
		return device, nil
	}
	if os.IsNotExist(err) {
		return "", nil
	}
	return "", fmt.Errorf("error checking for device %q: %v", device, err)
}
482095
func (d *DeviceMapperDriver) devicePath(deviceHash string) string {
	return fmt.Sprintf("/dev/mapper/%s", d.deviceName(deviceHash))
}
114088
func (attacher *rbdAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error) {
	img, err := getVolumeSourceImage(spec)
	if err != nil {
		return "", err
	}
	pool, err := getVolumeSourcePool(spec)
	if err != nil {
		return "", err
	}
	return makePDNameInternal(attacher.plugin.host, pool, img), nil
}
111438
func (v VolumePathHandler) GetDeviceSymlinkRefs(devPath string, mapPath string) ([]string, error) {
	var refs []string
	files, err := ioutil.ReadDir(mapPath)
	if err != nil {
		return nil, fmt.Errorf("Directory cannot read %v", err)
	}
	for _, file := range files {
		if file.Mode()&os.ModeSymlink != os.ModeSymlink {
			continue
		}
		filename := file.Name()
		fp, err := os.Readlink(filepath.Join(mapPath, filename))
		if err != nil {
			return nil, fmt.Errorf("Symbolic link cannot be retrieved %v", err)
		}
		klog.V(5).Infof("GetDeviceSymlinkRefs: filepath: %v, devPath: %v", fp, devPath)
		if fp == devPath {
			refs = append(refs, filepath.Join(mapPath, filename))
		}
	}
	klog.V(5).Infof("GetDeviceSymlinkRefs: refs %v", refs)
	return refs, nil
}
1194591
func (devices *DeviceSet) MountDevice(hash, path string, moptions graphdriver.MountOpts) error {
	info, err := devices.lookupDeviceWithLock(hash)
	if err != nil {
		return err
	}

	if info.Deleted {
		return fmt.Errorf("devmapper: Can't mount device %v as it has been marked for deferred deletion", info.Hash)
	}

	info.lock.Lock()
	defer info.lock.Unlock()

	devices.Lock()
	defer devices.Unlock()

	if err := devices.activateDeviceIfNeeded(info, false); err != nil {
		return fmt.Errorf("devmapper: Error activating devmapper device for '%s': %s", hash, err)
	}

	fstype, err := ProbeFsType(info.DevName())
	if err != nil {
		return err
	}

	options := ""

	if fstype == "xfs" {
		// XFS needs nouuid or it can't mount filesystems with the same fs
		options = joinMountOptions(options, "nouuid")
	}

	mountOptions := devices.mountOptions
	if len(moptions.Options) > 0 {
		addNouuid := strings.Contains("nouuid", mountOptions)
		mountOptions = strings.Join(moptions.Options, ",")
		if addNouuid {
			mountOptions = fmt.Sprintf("nouuid,%s", mountOptions)
		}
	}

	options = joinMountOptions(options, mountOptions)
	options = joinMountOptions(options, label.FormatMountLabel("", moptions.MountLabel))

	if err := mount.Mount(info.DevName(), path, fstype, options); err != nil {
		return fmt.Errorf("devmapper: Error mounting '%s' on '%s': %s\n%v", info.DevName(), path, err, string(dmesg.Dmesg(256)))
	}

	if fstype == "xfs" && devices.xfsNospaceRetries != "" {
		if err := devices.xfsSetNospaceRetries(info); err != nil {
			unix.Unmount(path, unix.MNT_DETACH)
			devices.deactivateDevice(info)
			return err
		}
	}

	return nil
}
1034569
func getDiskByIDPaths(pdName string, partition string) []string {
	devicePaths := []string{
		filepath.Join(diskByIDPath, diskGooglePrefix+pdName),
		filepath.Join(diskByIDPath, diskScsiGooglePrefix+pdName),
	}

	if partition != "" {
		for i, path := range devicePaths {
			devicePaths[i] = path + diskPartitionSuffix + partition
		}
	}

	return devicePaths
}
784867
func checkCrossDeviceMounts(endpoints EndpointList) (err error) {
	var absPaths []string
	for _, endpoint := range endpoints {
		if endpoint.IsLocal {
			var absPath string
			absPath, err = filepath.Abs(endpoint.Path)
			if err != nil {
				return err
			}
			absPaths = append(absPaths, absPath)
		}
	}
	return mountinfo.CheckCrossDevice(absPaths)
}
1116087
func (s *ec2Ops) getActualDevicePath(ipDevicePath, volumeID string) (string, error) {
	letter := ipDevicePath[len(ipDevicePath)-1:]
	devicePath := awsDevicePrefix + letter
	if _, err := os.Stat(devicePath); err == nil {
		return s.getParentDevice(devicePath)
	}
	devicePath = awsDevicePrefixWithX + letter
	if _, err := os.Stat(devicePath); err == nil {
		return s.getParentDevice(devicePath)
	}

	devicePath = awsDevicePrefixWithH + letter
	if _, err := os.Stat(devicePath); err == nil {
		return s.getParentDevice(devicePath)
	}

	// Check if the EBS volumes are exposed as NVMe drives
	found := false
	for _, instancePrefix := range nvmeInstanceTypes {
		if strings.HasPrefix(s.instanceType, instancePrefix) {
			found = true
			break
		}
	}

	if !found {
		return "", fmt.Errorf("unable to map volume %v with block device mapping %v to an"+
			" actual device path on the host", volumeID, ipDevicePath)
	}

	devicePath, err := s.getNvmeDeviceFromVolumeID(volumeID)
	if err != nil {
		return "", err
	}
	if _, err := os.Stat(devicePath); err != nil {
		return "", err
	}
	return devicePath, nil

}
832500
func (vm VirtualMachine) FindDevice(p func(Device) bool, types ...BusType) bool {
	return vm.walkDevices(p, types...)
}
125759
func getMountsMap(path string) (string, string, error) {
	arr := strings.SplitN(path, ":", 2)
	if len(arr) == 2 {
		return arr[0], arr[1], nil
	}
	return "", "", errors.Errorf("unable to get host and container dir")
}