// Volume creates an instance of VolumeController
979188
func Volume() (c *VolumeController) {
	return &VolumeController{
		List:   volumeList,
		New:    volumeNew,
		Create: volumeCreate,
		Delete: volumeDelete,
		Prune:  volumePrune,
		Detail: volumeDetail,
		Raw:    volumeRaw,
	}
}
312460
func (mi *maas1Instance) volumes(
	mTag names.MachineTag, requestedVolumes []names.VolumeTag,
) (
	[]storage.Volume, []storage.VolumeAttachment, error,
) {
	var volumes []storage.Volume
	var attachments []storage.VolumeAttachment

	deviceInfo, ok := mi.maasObject.GetMap()["physicalblockdevice_set"]
	// Older MAAS servers don't support storage.
	if !ok || deviceInfo.IsNil() {
		return volumes, attachments, nil
	}

	labelsMap, ok := mi.maasObject.GetMap()["constraint_map"]
	if !ok || labelsMap.IsNil() {
		return nil, nil, errors.NotFoundf("constraint map field")
	}

	devices, err := deviceInfo.GetArray()
	if err != nil {
		return nil, nil, errors.Trace(err)
	}
	// deviceLabel is the volume label passed
	// into the acquire node call as part
	// of the storage constraints parameter.
	deviceLabels, err := labelsMap.GetMap()
	if err != nil {
		return nil, nil, errors.Annotate(err, "invalid constraint map value")
	}

	// Set up a collection of volumes tags which
	// we specifically asked for when the node was acquired.
	validVolumes := set.NewStrings()
	for _, v := range requestedVolumes {
		validVolumes.Add(v.Id())
	}

	for _, d := range devices {
		deviceAttrs, err := d.GetMap()
		if err != nil {
			return nil, nil, errors.Trace(err)
		}
		// id in devices list is numeric
		id, err := deviceAttrs["id"].GetFloat64()
		if err != nil {
			return nil, nil, errors.Annotate(err, "invalid device id")
		}
		// id in constraint_map field is a string
		idKey := strconv.Itoa(int(id))

		// Device Label.
		deviceLabelValue, ok := deviceLabels[idKey]
		if !ok {
			logger.Debugf("acquire maas node: missing volume label for id %q", idKey)
			continue
		}
		deviceLabel, err := deviceLabelValue.GetString()
		if err != nil {
			return nil, nil, errors.Annotate(err, "invalid device label")
		}
		// We don't explicitly allow the root volume to be specified yet.
		if deviceLabel == rootDiskLabel {
			continue
		}
		// We only care about the volumes we specifically asked for.
		if !validVolumes.Contains(deviceLabel) {
			continue
		}

		// HardwareId and DeviceName.
		// First try for id_path.
		idPathPrefix := "/dev/disk/by-id/"
		hardwareId, err := deviceAttrs["id_path"].GetString()
		var deviceName string
		if err == nil {
			if !strings.HasPrefix(hardwareId, idPathPrefix) {
				return nil, nil, errors.Errorf("invalid device id %q", hardwareId)
			}
			hardwareId = hardwareId[len(idPathPrefix):]
		} else {
			// On VMAAS, id_path not available so try for path instead.
			deviceName, err = deviceAttrs["name"].GetString()
			if err != nil {
				return nil, nil, errors.Annotate(err, "invalid device name")
			}
		}

		// Size.
		sizeinBytes, err := deviceAttrs["size"].GetFloat64()
		if err != nil {
			return nil, nil, errors.Annotate(err, "invalid device size")
		}

		volumeTag := names.NewVolumeTag(deviceLabel)
		vol := storage.Volume{
			volumeTag,
			storage.VolumeInfo{
				VolumeId:   volumeTag.String(),
				HardwareId: hardwareId,
				Size:       uint64(sizeinBytes / humanize.MiByte),
				Persistent: false,
			},
		}
		volumes = append(volumes, vol)

		attachment := storage.VolumeAttachment{
			volumeTag,
			mTag,
			storage.VolumeAttachmentInfo{
				DeviceName: deviceName,
				ReadOnly:   false,
			},
		}
		attachments = append(attachments, attachment)
	}
	return volumes, attachments, nil
}
171910
func (c *Client) AppVolumeList(appID string) ([]*ct.Volume, error) {
	if appID == "" {
		return nil, errors.New("controller: missing app ID")
	}
	var volumes []*ct.Volume
	return volumes, c.Get(fmt.Sprintf("/apps/%s/volumes", appID), &volumes)
}
678438
func ValidateVolume(obj *Volume) error {
	collections.volumeMutex.Lock()
	defer collections.volumeMutex.Unlock()

	// Validate key is correct
	keyStr := obj.TenantName + ":" + obj.VolumeName
	if obj.Key != keyStr {
		log.Errorf("Expecting Volume Key: %s. Got: %s", keyStr, obj.Key)
		return errors.New("Invalid Key")
	}

	// Validate each field

	return nil
}
403221
func (c *Client) CreateVolume(opts CreateVolumeOptions) (*Volume, error) {
	resp, err := c.do("POST", "/volumes/create", doOptions{
		data:    opts,
		context: opts.Context,
	})
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	var volume Volume
	if err := json.NewDecoder(resp.Body).Decode(&volume); err != nil {
		return nil, err
	}
	return &volume, nil
}
717222
func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) {
	volume, _, err := cli.VolumeInspectWithRaw(ctx, volumeID)
	return volume, err
}
956054
func (util *portworxVolumeUtil) MountVolume(m *portworxVolumeMounter, mountPath string) error {
	driver, err := util.getLocalPortworxDriver(m.plugin.host)
	if err != nil || driver == nil {
		klog.Errorf("Failed to get portworx driver. Err: %v", err)
		return err
	}

	err = driver.Mount(m.volName, mountPath)
	if err != nil {
		klog.Errorf("Error mounting Portworx Volume (%v) on Path (%v): %v", m.volName, mountPath, err)
		return err
	}
	return nil
}
365062
func (c *Client) VolumeOpt(percent int, opt *PlayOptions) error {
	return c.playerFuncWithOpt(
		"me/player/volume",
		url.Values{
			"volume_percent": []string{strconv.FormatInt(int64(percent), 10)},
		},
		opt,
	)
}
56150
func (s *VolumeServer) Mount(
	ctx context.Context,
	req *api.SdkVolumeMountRequest,
) (*api.SdkVolumeMountResponse, error) {

	if s.cluster() == nil || s.driver(ctx) == nil {
		return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
	}

	if len(req.GetVolumeId()) == 0 {
		return nil, status.Error(codes.InvalidArgument, "Must supply volume id")
	}
	if len(req.GetMountPath()) == 0 {
		return nil, status.Error(codes.InvalidArgument, "Invalid Mount Path")
	}

	// Get access rights
	err := s.checkAccessForVolumeId(ctx, req.GetVolumeId(), api.Ownership_Write)
	if err != nil {
		return nil, err
	}

	err = s.driver(ctx).Mount(req.GetVolumeId(), req.GetMountPath(), req.GetDriverOptions())
	if err != nil {
		return nil, status.Errorf(
			codes.Internal,
			"Failed to mount volume %s: %v",
			req.GetVolumeId(),
			err.Error())
	}
	return &api.SdkVolumeMountResponse{}, err
}
320362
func (c *ContivClient) VolumeList() (*[]*Volume, error) {
	// build key and URL
	url := c.baseURL + "/api/v1/volumes/"

	// http get the object
	var objList []*Volume
	err := c.httpGet(url, &objList)
	if err != nil {
		log.Debugf("Error getting volumes. Err: %v", err)
		return nil, err
	}

	return &objList, nil
}
675102
func (c *Client) UpdateVolume(p *UpdateVolumeParameter) (*Volume, error) {
	obj, err := c.Request("updateVolume", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Volume), err
}
116597
func (s *StorageProvisionerAPIv3) Volumes(args params.Entities) (params.VolumeResults, error) {
	canAccess, err := s.getStorageEntityAuthFunc()
	if err != nil {
		return params.VolumeResults{}, common.ServerError(common.ErrPerm)
	}
	results := params.VolumeResults{
		Results: make([]params.VolumeResult, len(args.Entities)),
	}
	one := func(arg params.Entity) (params.Volume, error) {
		tag, err := names.ParseVolumeTag(arg.Tag)
		if err != nil || !canAccess(tag) {
			return params.Volume{}, common.ErrPerm
		}
		volume, err := s.sb.Volume(tag)
		if errors.IsNotFound(err) {
			return params.Volume{}, common.ErrPerm
		} else if err != nil {
			return params.Volume{}, err
		}
		return storagecommon.VolumeFromState(volume)
	}
	for i, arg := range args.Entities {
		var result params.VolumeResult
		volume, err := one(arg)
		if err != nil {
			result.Error = common.ServerError(err)
		} else {
			result.Result = volume
		}
		results.Results[i] = result
	}
	return results, nil
}
1038031
func (c *Client) ResizeVolume(p *ResizeVolumeParameter) (*Volume, error) {
	obj, err := c.Request("resizeVolume", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Volume), err
}
1153428
func VolumeChange(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "volumechange", Listener: listener}
}
497482
func (c *Client) GetVolume(id string, name string) (Volume, error) {
	volume, err := c.api.GetVolume(id, name)
	if err != nil {
		return nil, err
	}
	return volume.Content, nil
}
302193
func (d *driver) Volumes(
	ctx types.Context,
	opts *types.VolumesOpts) ([]*types.Volume, error) {

	svc := mustSession(ctx)

	fileSystems, err := d.getAllFileSystems(svc)
	if err != nil {
		return nil, err
	}

	var volumesSD []*types.Volume
	for _, fileSystem := range fileSystems {
		// Make sure that name is popullated
		if fileSystem.Name == nil {
			ctx.WithFields(log.Fields{
				"filesystemid": *fileSystem.FileSystemId,
			}).Warn("missing EFS filesystem name")
			continue
		}

		// Only volumes with partition prefix
		if !strings.HasPrefix(*fileSystem.Name, d.tag+tagDelimiter) {
			continue
		}

		// Only volumes in "available" state
		if *fileSystem.LifeCycleState != awsefs.LifeCycleStateAvailable {
			continue
		}

		volumeSD := &types.Volume{
			Name:        d.getPrintableName(*fileSystem.Name),
			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 {
			volumeSD.Attachments = atts
		}
		volumesSD = append(volumesSD, volumeSD)
	}

	return volumesSD, nil
}
117932
func (d *driver) Volumes(
	ctx types.Context,
	opts *types.VolumesOpts) ([]*types.Volume, error) {

	var gceDisks []*compute.Disk
	var err error
	vols := []*types.Volume{}

	zone, err := d.validZone(ctx)
	if err != nil {
		return nil, err
	}

	if zone != nil && *zone != "" {
		// get list of disks in zone from GCE
		gceDisks, err = d.getDisks(ctx, zone)
	} else {
		// without a zone, get disks in all zones
		gceDisks, err = d.getAggregatedDisks(ctx)
	}

	if err != nil {
		ctx.Errorf("Unable to get disks from GCE API")
		return nil, goof.WithError(
			"Unable to get disks from GCE API", err)
	}

	// shortcut early if nothing is returned
	// TODO: is it an error if there are no volumes? EBS driver returns an
	// error, but other drivers (ScaleIO, RBD) return an empty slice
	if len(gceDisks) == 0 {
		return vols, nil
	}

	// convert GCE disks to libstorage types.Volume
	vols, err = d.toTypeVolume(ctx, gceDisks, opts.Attachments, zone)
	if err != nil {
		return nil, goof.WithError("error converting to types.Volume",
			err)
	}

	return vols, nil
}