// ForceDeleteVolume force deletes a volume by resetting the ownership of
// all descendent directories to the current user prior to issuing a delete
// call.
14831
func (c *Client) ForceDeleteVolume(ctx context.Context, name string) error {

	var (
		user       = c.API.User()
		vpl        = len(c.API.VolumesPath()) + 1
		errs       = make(chan error)
		queryDone  = make(chan int)
		childPaths = make(chan string)
		setACLWait = &sync.WaitGroup{}
		setACLChan = newConcurrentHTTPChan()
		setACLDone = make(chan int)
		mode       = apiv2.FileMode(0755)
		acl        = &apiv2.ACL{
			Action:        &apiv2.PActionTypeReplace,
			Authoritative: &apiv2.PAuthoritativeTypeMode,
			Owner: &apiv2.Persona{
				ID: &apiv2.PersonaID{
					ID:   user,
					Type: apiv2.PersonaIDTypeUser,
				},
			},
			Mode: &mode,
		}
	)

	go func() {
		queryChan, queryErrs := apiv2.ContainerChildrenGetQuery(
			ctx, c.API, name, 1000, -1, "container", "ASC",
			[]string{"container_path", "name"},
			[]string{"owner", "name", "container_path"})

		go func() {
			if err := <-queryErrs; err != nil {
				errs <- err
				close(errs)
			}
		}()

		go func() {
			for child := range queryChan {
				if strings.EqualFold(user, *child.Owner) {
					continue
				}
				setACLWait.Add(1)
				go func(s string) {
					childPaths <- s
				}(path.Join(*child.Path, *child.Name)[vpl:])
			}
			close(queryDone)
		}()
	}()

	go func() {
		for childPath := range childPaths {
			go func(childPath string) {
				<-setACLChan
				if err := apiv2.ACLUpdate(
					ctx,
					c.API,
					childPath,
					acl); err != nil {
					go func(childPath string) {
						childPaths <- childPath
					}(childPath)
				} else {
					setACLWait.Done()
				}
				setACLChan <- true
			}(childPath)
		}
	}()

	go func() {
		<-queryDone
		setACLWait.Wait()
		close(setACLDone)
	}()

	select {
	case <-setACLDone:
	case err := <-errs:
		if err != nil {
			return err
		}
	}

	return c.DeleteVolume(ctx, name)
}
1313410
func (s *VolumeSource) DestroyVolumes(ctx context.ProviderCallContext, volIds []string) ([]error, error) {
	s.MethodCall(s, "DestroyVolumes", ctx, volIds)
	if s.DestroyVolumesFunc != nil {
		return s.DestroyVolumesFunc(ctx, volIds)
	}
	return nil, errors.NotImplementedf("DestroyVolumes")
}
310816
func (_m *APIClient) VolumeRemove(ctx context.Context, volumeID string, force bool) error {
	ret := _m.Called(ctx, volumeID, force)

	var r0 error
	if rf, ok := ret.Get(0).(func(context.Context, string, bool) error); ok {
		r0 = rf(ctx, volumeID, force)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
231657
func (client *QuobyteClient) DeleteVolumeByName(volumeName, tenant string) error {
	uuid, err := client.ResolveVolumeNameToUUID(volumeName, tenant)
	if err != nil {
		return err
	}

	return client.DeleteVolume(uuid)
}
268754
func (client *QuobyteClient) DeleteVolume(UUID string) error {
	return client.sendRequest(
		"deleteVolume",
		&volumeUUID{
			VolumeUUID: UUID,
		},
		nil)
}
1322194
func DestroyVolumes(a mesos.AgentID, v ...mesos.Resource) *master.Call {
	return &master.Call{
		Type: master.Call_DESTROY_VOLUMES,
		DestroyVolumes: &master.Call_DestroyVolumes{
			AgentID: a,
			Volumes: v,
		},
	}
}
682057
func (q *Query) ForceDelete(values ...interface{}) (Result, error) {
	if q.stickyErr != nil {
		return nil, q.stickyErr
	}
	if q.model == nil {
		return nil, errModelNil
	}
	q.deleted = true

	model, err := q.newModel(values...)
	if err != nil {
		return nil, err
	}

	if q.model != nil {
		err = q.model.BeforeDelete(q.ctx, q.db)
		if err != nil {
			return nil, err
		}
	}

	res, err := q.returningQuery(model, newDeleteQuery(q))
	if err != nil {
		return nil, err
	}

	if q.model != nil {
		err = q.model.AfterDelete(q.ctx, q.db)
		if err != nil {
			return nil, err
		}
	}

	return res, nil
}
1230762
func (u *storageosUtil) DeleteVolume(d *storageosDeleter) error {
	if err := u.NewAPI(d.apiCfg); err != nil {
		return err
	}

	// Deletes must be forced as the StorageOS API will not normally delete
	// volumes that it thinks are mounted.  We can't be sure the unmount was
	// registered via the API so we trust k8s to only delete volumes it knows
	// are unmounted.
	opts := storageostypes.DeleteOptions{
		Name:      d.volName,
		Namespace: d.volNamespace,
		Force:     true,
	}
	return u.api.VolumeDelete(opts)
}
676832
func (c *Client) RemoveVolumeWithOptions(opts RemoveVolumeOptions) error {
	path := "/volumes/" + opts.Name
	resp, err := c.do("DELETE", path+"?"+queryString(opts), doOptions{context: opts.Context})
	if err != nil {
		if e, ok := err.(*Error); ok {
			if e.Status == http.StatusNotFound {
				return ErrNoSuchVolume
			}
			if e.Status == http.StatusConflict {
				return ErrVolumeInUse
			}
		}
		return err
	}
	defer resp.Body.Close()
	return nil
}
535014
func (v *volumeSource) DestroyVolumes(ctx context.ProviderCallContext, volIds []string) ([]error, error) {
	logger.Debugf("destroy k8s volumes: %v", volIds)
	pVolumes := v.client.client().CoreV1().PersistentVolumes()
	return foreachVolume(volIds, func(volumeId string) error {
		vol, err := pVolumes.Get(volumeId, v1.GetOptions{IncludeUninitialized: true})
		if err != nil && !k8serrors.IsNotFound(err) {
			return errors.Annotatef(err, "getting volume %v to delete", volumeId)
		}
		if err == nil && vol.Spec.ClaimRef != nil {
			claimRef := vol.Spec.ClaimRef
			pClaims := v.client.client().CoreV1().PersistentVolumeClaims(claimRef.Namespace)
			err := pClaims.Delete(claimRef.Name, &v1.DeleteOptions{PropagationPolicy: &defaultPropagationPolicy})
			if err != nil && !k8serrors.IsNotFound(err) {
				return errors.Annotatef(err, "destroying volume claim %v", claimRef.Name)
			}
		}
		if err := pVolumes.Delete(
			volumeId,
			&v1.DeleteOptions{PropagationPolicy: &defaultPropagationPolicy},
		); !k8serrors.IsNotFound(err) {
			return errors.Annotate(err, "destroying k8s volumes")
		}
		return nil
	}), nil
}
808424
func (c *FakeVolumeAttachments) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error {
	action := testing.NewRootDeleteCollectionAction(volumeattachmentsResource, listOptions)

	_, err := c.Fake.Invokes(action, &storagev1.VolumeAttachmentList{})
	return err
}
274580
func (dfs *DistributedFilesystem) Destroy(tenantID string) error {
	vol, err := dfs.disk.Get(tenantID)
	if err != nil {
		glog.Errorf("Error destroying DFS:  Could not get volume for tenant %s: %s", tenantID, err)
	} else {
		// Remove all the stuff we need a volume object for
		snapshots, err := vol.Snapshots()
		if err != nil {
			glog.Errorf("Could not get snapshots for tenant %s: %s", tenantID, err)
		} else {
			for _, snapshot := range snapshots {
				if err := dfs.Delete(snapshot); err != nil {
					glog.Errorf("Could not remove snapshot %s for tenant %s: %s", snapshot, tenantID, err)
				}
			}
		}

		if err := dfs.unexport(vol.Path()); err != nil {
			glog.Errorf("Could not unexport path %s: %s", vol.Path(), err)
		}
	}

	if err := dfs.deleteImages(tenantID, docker.Latest); err != nil {
		glog.Errorf("Could not delete images for tenant %s: %s", tenantID, err)
	}

	if err := dfs.disk.Remove(tenantID); err != nil {
		glog.Errorf("Could not remove application data for tenant %s: %s", tenantID, err)
		return err
	}

	return nil
}
1248087
func (c *cinderPlugin) VolumeDelete(pv *v1.PersistentVolume) error {
	if pv == nil || pv.Spec.Cinder == nil {
		return fmt.Errorf("invalid Cinder PV: %v", pv)
	}
	volumeID := pv.Spec.Cinder.VolumeID
	err := c.cloud.DeleteVolume(volumeID)
	if err != nil {
		return err
	}

	return nil
}
1311844
func (a *Agent) ForceLeave(node string) error {
	_, err := a.client.write("/v1/agent/force-leave?node="+node, nil, nil, nil)
	return err
}
897591
func (_m *API) VirtualizationRemove(ctx context.Context, ID string, volumes bool, force bool) error {
	ret := _m.Called(ctx, ID, volumes, force)

	var r0 error
	if rf, ok := ret.Get(0).(func(context.Context, string, bool, bool) error); ok {
		r0 = rf(ctx, ID, volumes, force)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
658541
func (f *flexVolumeUnmounter) TearDown() error {
	path := f.GetPath()
	return f.TearDownAt(path)
}
1344516
func (m *sioMgr) DeleteVolume(volName string) error {
	client, err := m.getClient()
	if err != nil {
		return err
	}

	vol, err := client.FindVolume(volName)
	if err != nil {
		return err
	}

	if err := client.DeleteVolume(sioVolumeID(vol.ID)); err != nil {
		klog.Error(log("failed to delete volume %s: %v", volName, err))
		return err
	}

	klog.V(4).Info(log("deleted volume %s successfully", volName))
	return nil

}