// getVolumeDevicePluginDir returns the path where the CSI plugin keeps the
// symlink for a block device associated with a given specVolumeID.
// path: plugins/kubernetes.io/csi/volumeDevices/{specVolumeID}/dev
483117
func getVolumeDevicePluginDir(specVolID string, host volume.VolumeHost) string {
	sanitizedSpecVolID := utilstrings.EscapeQualifiedName(specVolID)
	return filepath.Join(host.GetVolumeDevicePluginDir(CSIPluginName), sanitizedSpecVolID, "dev")
}
418338
func (d *driver) getNewVolumeServer() (string, error) {
	//randomly select one
	if d.nfsServers != nil && len(d.nfsServers) > 0 {
		return d.nfsServers[rand.Intn(len(d.nfsServers))], nil
	}

	return "", errors.New("No NFS servers found")
}
364038
func (m *csiBlockMapper) unpublishVolumeForBlock(ctx context.Context, csi csiClient, publishPath string) error {
	// Request to unpublish a block volume from publishPath.
	// Expectation for driver is to remove block volume from the publishPath, by unmounting bind-mounted device file
	// or deleting device file.
	// Driver is responsible for deleting publishPath itself.
	// If driver doesn't implement NodeUnstageVolume, detaching the block volume from the node may be done, here.
	if err := csi.NodeUnpublishVolume(ctx, m.volumeID, publishPath); err != nil {
		klog.Error(log("blockMapper.unpublishVolumeForBlock failed: %v", err))
		return err
	}
	klog.V(4).Infof(log("blockMapper.unpublishVolumeForBlock NodeUnpublished successfully [%s]", publishPath))

	return nil
}
401593
func (kl *Kubelet) getPodContainerDir(podUID types.UID, ctrName string) string {
	return filepath.Join(kl.getPodDir(podUID), config.DefaultKubeletContainersDirName, ctrName)
}
1023581
func (kl *Kubelet) getPodVolumeDevicesDir(podUID types.UID) string {
	return filepath.Join(kl.getPodDir(podUID), config.DefaultKubeletVolumeDevicesDirName)
}
571504
func (plugin *flexVolumePlugin) GetVolumeName(spec *volume.Spec) (string, error) {
	call := plugin.NewDriverCall(getVolumeNameCmd)
	call.AppendSpec(spec, plugin.host, nil)

	_, err := call.Run()
	if isCmdNotSupportedErr(err) {
		return (*pluginDefaults)(plugin).GetVolumeName(spec)
	} else if err != nil {
		return "", err
	}

	name, err := (*pluginDefaults)(plugin).GetVolumeName(spec)
	if err != nil {
		return "", err
	}

	klog.Warning(logPrefix(plugin), "GetVolumeName is not supported yet. Defaulting to PV or volume name: ", name)

	return name, nil
}
692084
func (c *sioClient) DetachVolume(id sioVolumeID) error {
	if err := c.init(); err != nil {
		return err
	}

	iid, err := c.IID()
	if err != nil {
		return err
	}
	params := &siotypes.UnmapVolumeSdcParam{
		SdcID:                "",
		IgnoreScsiInitiators: "true",
		AllSdcs:              iid,
	}
	volClient := sio.NewVolume(c.client)
	volClient.Volume = &siotypes.Volume{ID: string(id)}
	if err := volClient.UnmapVolumeSdc(params); err != nil {
		return err
	}
	return nil
}
1041421
func GetVolumeMode(volumeSpec *volume.Spec) (v1.PersistentVolumeMode, error) {
	if volumeSpec == nil || volumeSpec.PersistentVolume == nil {
		return v1.PersistentVolumeFilesystem, nil
	}
	if volumeSpec.PersistentVolume.Spec.VolumeMode != nil {
		return *volumeSpec.PersistentVolume.Spec.VolumeMode, nil
	}
	return "", fmt.Errorf("cannot get volumeMode for volume: %v", volumeSpec.Name())
}
1240277
func (d *driver) getVolumeMapping(ctx types.Context) ([]*types.Volume, error) {

	var (
		err         error
		mapDiskByID map[string]string
		mas         []*vboxw.IMediumAttachment
		m           *vboxc.Machine
		iid         = context.MustInstanceID(ctx)
	)

	m, err = d.findMachineByInstanceID(ctx, iid)
	if err != nil {
		return nil, err
	}

	if err = m.Refresh(); err != nil {
		return nil, err
	}
	defer m.Release()

	ld, ok := context.LocalDevices(ctx)
	if !ok {
		return nil, goof.New("missing local devices")
	}
	mapDiskByID = ld.DeviceMap

	mas, err = m.GetMediumAttachments()
	if err != nil {
		return nil, err
	}

	var blockDevices []*types.Volume
	for _, ma := range mas {
		medium := d.vbox.NewMedium(ma.Medium)
		defer medium.Release()

		mid, err := medium.GetID()
		if err != nil {
			return nil, err
		}
		smid := strings.Split(mid, "-")
		if len(smid) == 0 {
			continue
		}

		location, err := medium.GetLocation()
		if err != nil {
			return nil, err
		}

		var bdn string
		var ok bool
		if bdn, ok = mapDiskByID[smid[0]]; !ok {
			continue
		}
		sdBlockDevice := &types.Volume{
			Name:   bdn,
			ID:     mid,
			Status: location,
		}
		blockDevices = append(blockDevices, sdBlockDevice)

	}
	return blockDevices, nil
}
824878
func (pm *VolumePluginMgr) FindMapperPluginBySpec(spec *Spec) (BlockVolumePlugin, error) {
	volumePlugin, err := pm.FindPluginBySpec(spec)
	if err != nil {
		return nil, err
	}

	if blockVolumePlugin, ok := volumePlugin.(BlockVolumePlugin); ok {
		return blockVolumePlugin, nil
	}
	return nil, nil
}
1041344
func GetVolumeFSType(v api.Volume) (securityapi.FSType, error) {
	switch {
	case v.HostPath != nil:
		return securityapi.FSTypeHostPath, nil
	case v.EmptyDir != nil:
		return securityapi.FSTypeEmptyDir, nil
	case v.GCEPersistentDisk != nil:
		return securityapi.FSTypeGCEPersistentDisk, nil
	case v.AWSElasticBlockStore != nil:
		return securityapi.FSTypeAWSElasticBlockStore, nil
	case v.GitRepo != nil:
		return securityapi.FSTypeGitRepo, nil
	case v.Secret != nil:
		return securityapi.FSTypeSecret, nil
	case v.NFS != nil:
		return securityapi.FSTypeNFS, nil
	case v.ISCSI != nil:
		return securityapi.FSTypeISCSI, nil
	case v.Glusterfs != nil:
		return securityapi.FSTypeGlusterfs, nil
	case v.PersistentVolumeClaim != nil:
		return securityapi.FSTypePersistentVolumeClaim, nil
	case v.RBD != nil:
		return securityapi.FSTypeRBD, nil
	case v.FlexVolume != nil:
		return securityapi.FSTypeFlexVolume, nil
	case v.Cinder != nil:
		return securityapi.FSTypeCinder, nil
	case v.CephFS != nil:
		return securityapi.FSTypeCephFS, nil
	case v.Flocker != nil:
		return securityapi.FSTypeFlocker, nil
	case v.DownwardAPI != nil:
		return securityapi.FSTypeDownwardAPI, nil
	case v.FC != nil:
		return securityapi.FSTypeFC, nil
	case v.AzureFile != nil:
		return securityapi.FSTypeAzureFile, nil
	case v.ConfigMap != nil:
		return securityapi.FSTypeConfigMap, nil
	case v.VsphereVolume != nil:
		return securityapi.FSTypeVsphereVolume, nil
	case v.Quobyte != nil:
		return securityapi.FSTypeQuobyte, nil
	case v.AzureDisk != nil:
		return securityapi.FSTypeAzureDisk, nil
	case v.PhotonPersistentDisk != nil:
		return securityapi.FSTypePhotonPersistentDisk, nil
	case v.Projected != nil:
		return securityapi.FSProjected, nil
	case v.PortworxVolume != nil:
		return securityapi.FSPortworxVolume, nil
	case v.ScaleIO != nil:
		return securityapi.FSScaleIO, nil
	case v.StorageOS != nil:
		return securityapi.FSStorageOS, nil
	}

	return "", fmt.Errorf("unknown volume type for volume: %#v", v)
}
378321
func (a *flexVolumeAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error) {
	return a.plugin.getDeviceMountPath(spec)
}
333039
func (d *DeviceMapperDriver) getVolume(volumeName string, create bool) (*DeviceMapperVolume, error) {
	tenant := getTenant(volumeName)
	metadata, err := NewMetadata(d.MetadataPath(tenant), create)
	if err != nil {
		return nil, err
	}
	vol := &DeviceMapperVolume{
		name:     volumeName,
		path:     d.volumeDir(volumeName),
		tenant:   tenant,
		driver:   d,
		Metadata: metadata,
	}

	// if create is false, check to make sure the metadata info isn't empty or equal to base
	if !create {
		deviceHash := vol.deviceHash()
		if deviceHash == "" || deviceHash == "base" {
			return nil, ErrBaseDeviceHash
		}
	}

	return vol, nil
}
768314
func getMountedVolume(
	mountedPod *mountedPod, attachedVolume *attachedVolume) MountedVolume {
	return MountedVolume{
		MountedVolume: operationexecutor.MountedVolume{
			PodName:             mountedPod.podName,
			VolumeName:          attachedVolume.volumeName,
			InnerVolumeSpecName: mountedPod.volumeSpec.Name(),
			OuterVolumeSpecName: mountedPod.outerVolumeSpecName,
			PluginName:          attachedVolume.pluginName,
			PodUID:              mountedPod.podUID,
			Mounter:             mountedPod.mounter,
			BlockVolumeMapper:   mountedPod.blockVolumeMapper,
			VolumeGidValue:      mountedPod.volumeGidValue,
			VolumeSpec:          mountedPod.volumeSpec,
			DeviceMountPath:     attachedVolume.deviceMountPath}}
}
815811
func (s *storeImpl) getVolatileInfo(serviceID string) (volatileService, bool) {
	s.serviceCacheLock.RLock()
	defer s.serviceCacheLock.RUnlock()
	cacheEntry, ok := s.serviceCache[serviceID]
	if ok && cacheEntry.CurrentState == "" {
		cacheEntry.CurrentState = string(SVCCSUnknown)
	}
	return cacheEntry, ok
}
216095
func GetVolumeMode(volUtil util.VolumeUtil, fullPath string) (v1.PersistentVolumeMode, error) {
	isdir, errdir := volUtil.IsDir(fullPath)
	if isdir {
		return v1.PersistentVolumeFilesystem, nil
	}
	// check for Block before returning errdir
	isblk, errblk := volUtil.IsBlock(fullPath)
	if isblk {
		return v1.PersistentVolumeBlock, nil
	}

	if errdir == nil && errblk == nil {
		return "", fmt.Errorf("Skipping file %q: not a directory nor block device", fullPath)
	}

	// report the first error found
	if errdir != nil {
		return "", fmt.Errorf("Directory check for %q failed: %s", fullPath, errdir)
	}
	return "", fmt.Errorf("Block device check for %q failed: %s", fullPath, errblk)
}
665847
func (c *Client) GetVolume(
	ctx context.Context, id, name string) (Volume, error) {

	if id != "" {
		name = id
	}
	volume, err := apiv1.GetIsiVolume(ctx, c.API, name)
	if err != nil {
		return nil, err
	}
	var isiVolume = &apiv1.IsiVolume{Name: name, AttributeMap: volume.AttributeMap}
	return isiVolume, nil
}