func AssignQuota(m mount.Interface, path string, poduid types.UID, bytes *resource.Quantity) error {
	if bytes == nil {
		return fmt.Errorf("Attempting to assign null quota to %s", path)
	}
	ibytes := bytes.Value()
	if ok, err := SupportsQuotas(m, path); !ok {
		return fmt.Errorf("Quotas not supported on %s: %v", path, err)
	}
	quotaLock.Lock()
	defer quotaLock.Unlock()
	// Current policy is to set individual quotas on each volumes.
	// If we decide later that we want to assign one quota for all
	// volumes in a pod, we can simply remove this line of code.
	// If and when we decide permanently that we're going to adopt
	// one quota per volume, we can rip all of the pod code out.
	poduid = types.UID(uuid.NewUUID())
	if pod, ok := dirPodMap[path]; ok && pod != poduid {
		return fmt.Errorf("Requesting quota on existing directory %s but different pod %s %s", path, pod, poduid)
	}
	oid, ok := podQuotaMap[poduid]
	if ok {
		if quotaSizeMap[oid] != ibytes {
			return fmt.Errorf("Requesting quota of different size: old %v new %v", quotaSizeMap[oid], bytes)
		}
	} else {
		oid = common.BadQuotaID
	}
	id, err := createProjectID(path, oid)
	if err == nil {
		if oid != common.BadQuotaID && oid != id {
			return fmt.Errorf("Attempt to reassign quota %v to %v", oid, id)
		}
		// When enforcing quotas are enabled, we'll condition this
		// on their being disabled also.
		if ibytes > 0 {
			ibytes = -1
		}
		if err = setQuotaOnDir(path, id, ibytes); err == nil {
			quotaPodMap[id] = poduid
			quotaSizeMap[id] = ibytes
			podQuotaMap[poduid] = id
			dirQuotaMap[path] = id
			dirPodMap[path] = poduid
			podDirCountMap[poduid]++
			klog.V(4).Infof("Assigning quota ID %d (%d) to %s", id, ibytes, path)
			return nil
		}
		removeProjectID(path, id)
	}
	return fmt.Errorf("Assign quota FAILED %v", err)
}
// AssignQuota -- assign a quota to the specified directory.
// AssignQuota chooses the quota ID based on the pod UID and path.
// If the pod UID is identical to another one known, it may (but presently
// doesn't) choose the same quota ID as other volumes in the pod.
//lint:ignore SA4009 poduid is overwritten by design, see comment below
- assign a quota to the specified directory.
AssignQuota chooses the quota ID based on the pod UID and path.
If the pod UID is identical to another one known, it may (but presently
doesn't) choose the same quota ID as other volumes in the pod.
lint:ignore SA4009 poduid is overwritten by design, see comment below
// AssignQuota -- assign a quota to the specified directory . // AssignQuota chooses the quota ID based on the pod UID and path . // If the pod UID is identical to another one known it may ( but presently // doesn ' t ) choose the same quota ID as other volumes in the pod . // lint : ignore SA4009 poduid is overwritten by design see comment below
func AssignQuota(m mount.Interface, path string, poduid types.UID, bytes *resource.Quantity) error {
	if bytes == nil {
		return fmt.Errorf("Attempting to assign null quota to %s", path)
	}
	ibytes := bytes.Value()
	if ok, err := SupportsQuotas(m, path); !ok {
		return fmt.Errorf("Quotas not supported on %s: %v", path, err)
	}
	quotaLock.Lock()
	defer quotaLock.Unlock()
	poduid = types.UID(uuid.NewUUID())
	if pod, ok := dirPodMap[path]; ok && pod != poduid {
		return fmt.Errorf("Requesting quota on existing directory %s but different pod %s %s", path, pod, poduid)
	}
	oid, ok := podQuotaMap[poduid]
	if ok {
		if quotaSizeMap[oid] != ibytes {
			return fmt.Errorf("Requesting quota of different size: old %v new %v", quotaSizeMap[oid], bytes)
		}
	} else {
		oid = common.BadQuotaID
	}
	id, err := createProjectID(path, oid)
	if err == nil {
		if oid != common.BadQuotaID && oid != id {
			return fmt.Errorf("Attempt to reassign quota %v to %v", oid, id)
		}
		if ibytes > 0 {
			ibytes = -1
		}
		if err = setQuotaOnDir(path, id, ibytes); err == nil {
			quotaPodMap[id] = poduid
			quotaSizeMap[id] = ibytes
			podQuotaMap[poduid] = id
			dirQuotaMap[path] = id
			dirPodMap[path] = poduid
			podDirCountMap[poduid]++
			klog.V(4).Infof("Assigning quota ID %d (%d) to %s", id, ibytes, path)
			return nil
		}
		removeProjectID(path, id)
	}
	return fmt.Errorf("Assign quota FAILED %v", err)
}
func AssignQuota ( m mount . Interface , path string , poduid types . UID , bytes * resource . Quantity ) error { if bytes == nil { return fmt . Errorf ( " " , path ) } ibytes := bytes . Value ( ) if ok , err := SupportsQuotas ( m , path ) ; ! ok { return fmt . Errorf ( " " , path , err ) } quotaLock . Lock ( ) defer quotaLock . Unlock ( ) poduid = types . UID ( uuid . NewUUID ( ) ) if pod , ok := dirPodMap [ path ] ; ok && pod != poduid { return fmt . Errorf ( " " , path , pod , poduid ) } oid , ok := podQuotaMap [ poduid ] if ok { if quotaSizeMap [ oid ] != ibytes { return fmt . Errorf ( " " , quotaSizeMap [ oid ] , bytes ) } } else { oid = common . BadQuotaID } id , err := createProjectID ( path , oid ) if err == nil { if oid != common . BadQuotaID && oid != id { return fmt . Errorf ( " " , oid , id ) } if ibytes > 0 { ibytes = - 1 } if err = setQuotaOnDir ( path , id , ibytes ) ; err == nil { quotaPodMap [ id ] = poduid quotaSizeMap [ id ] = ibytes podQuotaMap [ poduid ] = id dirQuotaMap [ path ] = id dirPodMap [ path ] = poduid podDirCountMap [ poduid ] ++ klog . V ( 4 ) . Infof ( " " , id , ibytes , path ) return nil } removeProjectID ( path , id ) } return fmt . Errorf ( " " , err ) }
assign a quota to the specified directory.
assign a quota to the specified directory .
// Current policy is to set individual quotas on each volumes. // If we decide later that we want to assign one quota for all // volumes in a pod, we can simply remove this line of code. // If and when we decide permanently that we're going to adopt // one quota per volume, we can rip all of the pod code out. // When enforcing quotas are enabled, we'll condition this // on their being disabled also.