From 42e716a094927ae24d5b3c423e254193001c7559 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 30 Aug 2019 14:11:18 -0700 Subject: [PATCH] formatsToDrivesInfo should return drives with correct order (#8157) This is a defensive change to avoid any future issues, from this part of the code. New change also ensures to populate UUID if present for the right disk. --- cmd/xl-sets.go | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/cmd/xl-sets.go b/cmd/xl-sets.go index 8fb04d05d..edc69ede0 100644 --- a/cmd/xl-sets.go +++ b/cmd/xl-sets.go @@ -1251,35 +1251,29 @@ fi */ func formatsToDrivesInfo(endpoints EndpointList, formats []*formatXLV3, sErrs []error) (beforeDrives []madmin.DriveInfo) { + beforeDrives = make([]madmin.DriveInfo, len(endpoints)) // Existing formats are available (i.e. ok), so save it in // result, also populate disks to be healed. for i, format := range formats { drive := endpoints.GetString(i) + var state = madmin.DriveStateCorrupt switch { case format != nil: - beforeDrives = append(beforeDrives, madmin.DriveInfo{ - UUID: format.XL.This, - Endpoint: drive, - State: madmin.DriveStateOk, - }) + state = madmin.DriveStateOk case sErrs[i] == errUnformattedDisk: - beforeDrives = append(beforeDrives, madmin.DriveInfo{ - UUID: "", - Endpoint: drive, - State: madmin.DriveStateMissing, - }) + state = madmin.DriveStateMissing case sErrs[i] == errDiskNotFound: - beforeDrives = append(beforeDrives, madmin.DriveInfo{ - UUID: "", - Endpoint: drive, - State: madmin.DriveStateOffline, - }) - default: - beforeDrives = append(beforeDrives, madmin.DriveInfo{ - UUID: "", - Endpoint: drive, - State: madmin.DriveStateCorrupt, - }) + state = madmin.DriveStateOffline + } + beforeDrives[i] = madmin.DriveInfo{ + UUID: func() string { + if format != nil { + return format.XL.This + } + return "" + }(), + Endpoint: drive, + State: state, } }