Skip to content

Commit

Permalink
Handle empty capacity when a drive cannot be found. (#101)
Browse files Browse the repository at this point in the history
Avoid doing a divide-by-zero and panicing the process.

Signed-off-by: Dean Roehrich <[email protected]>
  • Loading branch information
roehrich-hpe authored Jun 7, 2024
1 parent e8ded5e commit 9d0ccb5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/manager-nvme/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,12 @@ func (mgr *Manager) StorageIdStoragePoolsStoragePoolIdGet(storageId, storagePool
},
}

model.RemainingCapacityPercent = int64(float64(s.unallocatedBytes/s.capacityBytes) * 100.0)
if s.capacityBytes == 0 {
// If a drive could not be found, don't divide by zero.
model.RemainingCapacityPercent = 0
} else {
model.RemainingCapacityPercent = int64(float64(s.unallocatedBytes/s.capacityBytes) * 100.0)
}

return nil
}
Expand Down

0 comments on commit 9d0ccb5

Please sign in to comment.