// FindVolumes returns Volume instances associated with this VSphereVolumes.
// EtcdClusterSpec is populated using vSphere volume metadata.
540566
func (v *VSphereVolumes) FindVolumes() ([]*Volume, error) {
	var volumes []*Volume
	ip := v.InternalIp()
	attachedTo := ""
	if ip != nil {
		attachedTo = ip.String()
	}

	etcdClusters, err := getVolMetadata()

	if err != nil {
		return nil, err
	}

	for _, etcd := range etcdClusters {
		mountPoint := vsphere.GetMountPoint(etcd.VolumeId)
		localDevice, err := getDevice(mountPoint)
		if err != nil {
			return nil, err
		}
		vol := &Volume{
			ID:          etcd.VolumeId,
			LocalDevice: localDevice,
			AttachedTo:  attachedTo,
			Mountpoint:  mountPoint,
			Status:      VolStatusValue,
			Info: VolumeInfo{
				Description: etcd.EtcdClusterName,
			},
		}

		etcdSpec := &etcdmanager.EtcdClusterSpec{
			ClusterKey: etcd.EtcdClusterName,
			NodeName:   etcd.EtcdNodeName,
		}

		var nodeNames []string
		for _, member := range etcd.Members {
			nodeNames = append(nodeNames, member.Name)
		}
		etcdSpec.NodeNames = nodeNames
		vol.Info.EtcdClusters = []*etcdmanager.EtcdClusterSpec{etcdSpec}
		volumes = append(volumes, vol)
	}
	glog.V(4).Infof("Found volumes: %v", volumes)
	return volumes, nil
}
1027794
func (pm *VolumePluginMgr) FindExpandablePluginByName(name string) (ExpandableVolumePlugin, error) {
	volumePlugin, err := pm.FindPluginByName(name)
	if err != nil {
		return nil, err
	}

	if expandableVolumePlugin, ok := volumePlugin.(ExpandableVolumePlugin); ok {
		return expandableVolumePlugin, nil
	}
	return nil, 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)
}
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}}
}
1282993
func CheckVolumeModeFilesystem(volumeSpec *volume.Spec) (bool, error) {
	if utilfeature.DefaultFeatureGate.Enabled(features.BlockVolume) {
		volumeMode, err := GetVolumeMode(volumeSpec)
		if err != nil {
			return true, err
		}
		if volumeMode == v1.PersistentVolumeBlock {
			return false, nil
		}
	}
	return true, nil
}
561513
func (c *Client) GetVolumeACL(
	ctx context.Context,
	volumeName string) (ACL, error) {

	return api.ACLInspect(ctx, c.API, volumeName)
}
828455
func (s *Scheduler) findVolume(job *Job, req *ct.VolumeReq) *Volume {
	for _, vol := range s.volumes {
		// skip destroyed or decommissioned volumes
		if vol.GetState() == ct.VolumeStateDestroyed || vol.DecommissionedAt != nil {
			continue
		}

		// skip if the app, release, type or path do not match
		if vol.AppID != job.AppID {
			continue
		}
		if vol.ReleaseID != job.ReleaseID {
			continue
		}
		if vol.JobType != job.Type {
			continue
		}
		if vol.Path != req.Path {
			continue
		}

		// skip if the volume is assigned to another job
		if vol.JobID != nil && *vol.JobID != job.ID {
			continue
		}

		// skip if we have already assigned the job to a host
		// and this volume doesn't exist on that host
		if job.HostID != "" && vol.HostID != job.HostID {
			continue
		}

		// return the matching volume
		return vol
	}
	return nil
}
923376
func (v *volumeSource) ListVolumes(ctx context.ProviderCallContext) ([]string, error) {
	pVolumes := v.client.client().CoreV1().PersistentVolumes()
	vols, err := pVolumes.List(v1.ListOptions{})
	if err != nil {
		return nil, errors.Trace(err)
	}
	volumeIds := make([]string, 0, len(vols.Items))
	for _, v := range vols.Items {
		volumeIds = append(volumeIds, v.Name)
	}
	return volumeIds, nil
}
881763
func GetVolumeAPIRoutes(name, sdkUds string) []*Route {
	volMgmtApi := newVolumeAPI(name, sdkUds)
	return volMgmtApi.Routes()
}
1352179
func (d *driver) VolumeInspect(
	ctx types.Context,
	volumeID string,
	opts *types.VolumeInspectOpts) (*types.Volume, error) {

	resp, err := mustSession(ctx).DescribeFileSystems(
		&awsefs.DescribeFileSystemsInput{FileSystemId: aws.String(volumeID)})
	if err != nil {
		return nil, err
	}

	if len(resp.FileSystems) == 0 {
		return nil, apiUtils.NewNotFoundError(volumeID)
	}

	fileSystem := resp.FileSystems[0]

	// Only volumes in "available" state
	if *fileSystem.LifeCycleState != awsefs.LifeCycleStateAvailable {
		return nil, goof.WithField("volumeID", volumeID,
			"Volume not available")
	}

	// Name is optional via tag so make sure it exists
	var fileSystemName string
	if fileSystem.Name != nil {
		fileSystemName = *fileSystem.Name
	} else {
		ctx.WithFields(log.Fields{
			"filesystemid": *fileSystem.FileSystemId,
		}).Warn("missing EFS filesystem name")
	}

	volume := &types.Volume{
		Name:        d.getPrintableName(fileSystemName),
		ID:          *fileSystem.FileSystemId,
		Size:        *fileSystem.SizeInBytes.Value,
		Attachments: nil,
	}

	var atts []*types.VolumeAttachment

	if opts.Attachments.Requested() {
		atts, err = d.getVolumeAttachments(
			ctx, *fileSystem.FileSystemId, opts.Attachments)
		if err != nil {
			return nil, err
		}
	}
	if len(atts) > 0 {
		volume.Attachments = atts
	}
	return volume, nil
}
1359305
func mapVolumeSpec(config map[string]string, spec *volume.Spec) {

	if source, err := getScaleIOPersistentVolumeSourceFromSpec(spec); err == nil {
		config[confKey.gateway] = source.Gateway
		config[confKey.system] = source.System
		config[confKey.volumeName] = source.VolumeName
		config[confKey.sslEnabled] = strconv.FormatBool(source.SSLEnabled)
		config[confKey.protectionDomain] = source.ProtectionDomain
		config[confKey.storagePool] = source.StoragePool
		config[confKey.storageMode] = source.StorageMode
		config[confKey.fsType] = source.FSType
		config[confKey.readOnly] = strconv.FormatBool(source.ReadOnly)
	}

	if source, err := getScaleIOVolumeSourceFromSpec(spec); err == nil {
		config[confKey.gateway] = source.Gateway
		config[confKey.system] = source.System
		config[confKey.volumeName] = source.VolumeName
		config[confKey.sslEnabled] = strconv.FormatBool(source.SSLEnabled)
		config[confKey.protectionDomain] = source.ProtectionDomain
		config[confKey.storagePool] = source.StoragePool
		config[confKey.storageMode] = source.StorageMode
		config[confKey.fsType] = source.FSType
		config[confKey.readOnly] = strconv.FormatBool(source.ReadOnly)
	}

	//optionals
	applyConfigDefaults(config)
}
1197173
func (vm *volumeManager) getUnattachedVolumes(expectedVolumes []string) []string {
	unattachedVolumes := []string{}
	for _, volume := range expectedVolumes {
		if !vm.actualStateOfWorld.VolumeExists(v1.UniqueVolumeName(volume)) {
			unattachedVolumes = append(unattachedVolumes, volume)
		}
	}
	return unattachedVolumes
}
143531
func (c *Host) ListVolumes() ([]*volume.Info, error) {
	var volumes []*volume.Info
	return volumes, c.c.Get("/storage/volumes", &volumes)
}
1016591
func FindOverlappingVolume(tmpl *wfv1.Template, path string) *apiv1.VolumeMount {
	if tmpl.Container == nil {
		return nil
	}
	var volMnt *apiv1.VolumeMount
	deepestLen := 0
	for _, mnt := range tmpl.Container.VolumeMounts {
		if !strings.HasPrefix(path, mnt.MountPath) {
			continue
		}
		if len(mnt.MountPath) > deepestLen {
			volMnt = &mnt
			deepestLen = len(mnt.MountPath)
		}
	}
	return volMnt
}
473820
func GetDefaultVolSpecs(
	ctx context.Context,
	spec *api.VolumeSpec,
	isUpdate bool,
) (*api.VolumeSpec, error) {
	storPolicy, err := policy.Inst()
	if err != nil {
		return nil, status.Errorf(codes.Internal, "Unable to get storage policy instance %v", err)
	}

	var policy *api.SdkStoragePolicy
	// check if custom policy passed with volume
	if spec.GetStoragePolicy() != "" {
		inspReq := &api.SdkOpenStoragePolicyInspectRequest{
			// name of storage policy specified in volSpecs
			Name: spec.GetStoragePolicy(),
		}
		// inspect will make sure user will atleast have read access
		customPolicy, customErr := storPolicy.Inspect(ctx, inspReq)
		if customErr != nil {
			return nil, customErr
		}

		policy = customPolicy.GetStoragePolicy()
	} else {
		// check if default storage policy is set
		defPolicy, err := storPolicy.DefaultInspect(context.Background(), &api.SdkOpenStoragePolicyDefaultInspectRequest{})
		if err != nil {
			// err means there is policy stored, but we are not able to retrive it
			// hence we are not allowing volume create operation
			return nil, status.Errorf(codes.Internal, "Unable to get default policy details %v", err)
		} else if defPolicy.GetStoragePolicy() == nil {
			// no default storage policy found
			return spec, nil
		}
		policy = defPolicy.GetStoragePolicy()
	}

	// track volume created using storage policy
	spec.StoragePolicy = policy.GetName()
	// check if volume update request, if allowupdate is set
	// return spec received as it is
	if isUpdate && policy.GetAllowUpdate() {
		if !policy.IsPermitted(ctx, api.Ownership_Write) {
			return nil, status.Errorf(codes.PermissionDenied, "Cannot use storage policy %v", policy.GetName())
		}
		return spec, nil
	}

	return mergeVolumeSpecsPolicy(spec, policy.GetPolicy(), policy.GetForce())
}
663953
func (a *ALIVolumes) FindMountedVolume(volume *Volume) (string, error) {
	device := volume.LocalDevice

	_, err := os.Stat(pathFor(device))
	if err == nil {
		return device, nil
	}
	if os.IsNotExist(err) {
		if strings.HasPrefix(device, "/dev/xvd") {
			device = "/dev/vd" + strings.TrimPrefix(device, "/dev/xvd")
			_, err = os.Stat(pathFor(device))
			return device, err
		} else if strings.HasPrefix(device, "/dev/vd") {
			device = "/dev/xvd" + strings.TrimPrefix(device, "/dev/vd")
			_, err = os.Stat(pathFor(device))
			return device, err
		}
		return "", nil
	}
	return "", fmt.Errorf("error checking for device %q: %v", device, err)
}
620706
func (lvs *loopVolumeSource) ListVolumes(ctx context.ProviderCallContext) ([]string, error) {
	// TODO(axw) implement this when we need it.
	return nil, errors.NotImplementedf("ListVolumes")
}