From 9885a0a6afd80ad5669297ec750cdfa05126e674 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Tue, 11 Jul 2023 14:29:34 -0700 Subject: [PATCH] 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. --- cmd/object-api-utils.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/object-api-utils.go b/cmd/object-api-utils.go index eeddf1573..f22449818 100644 --- a/cmd/object-api-utils.go +++ b/cmd/object-api-utils.go @@ -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 }