Skip to content

Commit 89f7545

Browse files
committed
Use the available drive count to calculate the size of each allocation.
Signed-off-by: Anthony Floeder <anthony.floeder@hpe.com>
1 parent 077580a commit 89f7545

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

pkg/manager-nnf/allocation_policy.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,18 @@ func (p *SpareAllocationPolicy) CheckAndAdjustCapacity() error {
161161

162162
if p.compliance != RelaxedAllocationComplianceType {
163163

164-
if len(p.storage) < SpareAllocationPolicyMinimumDriveCount {
165-
return fmt.Errorf("Insufficient drive count. Required: %d Available: %d", SpareAllocationPolicyMinimumDriveCount, len(p.storage))
164+
driveCount := uint64(len(p.storage))
165+
if driveCount < SpareAllocationPolicyMinimumDriveCount {
166+
return fmt.Errorf("Insufficient drive count. Required: %d Available: %d", SpareAllocationPolicyMinimumDriveCount, driveCount)
166167
}
167168

168169
roundUpToMultiple := func(n, m uint64) uint64 { // Round 'n' up to a multiple of 'm'
169170
return ((n + m - 1) / m) * m
170171
}
171172

172173
// Validate each drive can contribute sufficient capacity towards the entire pool.
173-
poolCapacityBytes := roundUpToMultiple(p.capacityBytes, SpareAllocationPolicyMinimumDriveCount)
174-
driveCapacityBytes := roundUpToMultiple(poolCapacityBytes/SpareAllocationPolicyMinimumDriveCount, 4096)
174+
poolCapacityBytes := roundUpToMultiple(p.capacityBytes, driveCount)
175+
driveCapacityBytes := roundUpToMultiple(poolCapacityBytes/driveCount, 4096)
175176

176177
for _, s := range p.storage {
177178
if driveCapacityBytes > s.UnallocatedBytes() {
@@ -180,7 +181,7 @@ func (p *SpareAllocationPolicy) CheckAndAdjustCapacity() error {
180181
}
181182

182183
// Adjust the pool's capacity such that it is a multiple of the number drives.
183-
p.capacityBytes = driveCapacityBytes * uint64(len(p.storage))
184+
p.capacityBytes = driveCapacityBytes * driveCount
184185
}
185186

186187
if availableBytes < p.capacityBytes {
@@ -193,7 +194,8 @@ func (p *SpareAllocationPolicy) CheckAndAdjustCapacity() error {
193194
// Allocate - allocate the storage
194195
func (p *SpareAllocationPolicy) Allocate() ([]nvme.ProvidingVolume, error) {
195196

196-
perStorageCapacityBytes := p.capacityBytes / uint64(len(p.storage))
197+
driveCount := uint64(len(p.storage))
198+
perStorageCapacityBytes := p.capacityBytes / driveCount
197199
remainingCapacityBytes := p.capacityBytes
198200

199201
volumes := []nvme.ProvidingVolume{}
@@ -204,7 +206,7 @@ func (p *SpareAllocationPolicy) Allocate() ([]nvme.ProvidingVolume, error) {
204206
// Leftover bytes are placed on trailing volume; note that this
205207
// is never the case for strict allocation in which the requested
206208
// allocation must be a multiple of the storage size.
207-
if idx == len(p.storage)-1 {
209+
if idx == int(driveCount-1) {
208210
capacityBytes = remainingCapacityBytes
209211
}
210212

0 commit comments

Comments
 (0)