Fix hasSpaceFor in SNSD setup (#17630)

If drive is offline or filled we divide by 0.

Fixes #17629

Bonus: Reject when any valid disk exceeds minimum inode threshold.
This commit is contained in:
Klaus Post 2023-07-11 14:29:34 -07:00 committed by GitHub
parent f64d62b01d
commit 9885a0a6af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1166,7 +1166,7 @@ func hasSpaceFor(di []*DiskInfo, size int64) (bool, error) {
var total uint64
var nDisks int
for _, disk := range di {
if disk == nil || disk.Total == 0 || (disk.FreeInodes < diskMinInodes && disk.UsedInodes > 0) {
if disk == nil || disk.Total == 0 {
// Disk offline, no inodes or something else is wrong.
continue
}
@ -1175,16 +1175,20 @@ func hasSpaceFor(di []*DiskInfo, size int64) (bool, error) {
available += disk.Total - disk.Used
}
if nDisks < len(di)/2 {
if nDisks < len(di)/2 || nDisks <= 0 {
return false, fmt.Errorf("not enough online disks to calculate the available space, expected (%d)/(%d)", (len(di)/2)+1, nDisks)
}
// Check we have enough on each disk, ignoring diskFillFraction.
perDisk := size / int64(nDisks)
for _, disk := range di {
if disk == nil || disk.Total == 0 || (disk.FreeInodes < diskMinInodes && disk.UsedInodes > 0) {
if disk == nil || disk.Total == 0 {
continue
}
if disk.FreeInodes < diskMinInodes && disk.UsedInodes > 0 {
// We have an inode count, but not enough inodes.
return false, nil
}
if int64(disk.Free) <= perDisk {
return false, nil
}