From 573b4dfe6257409fedcfee07a48358b498afc036 Mon Sep 17 00:00:00 2001 From: Satoru Takeuchi Date: Thu, 5 May 2022 11:46:56 +0000 Subject: [PATCH] osd: fix disk uuid management - disk UUID should only be got for "disk" type device. - It's not necessary to fail prepare job when failing to get disk UUID - We should consider that `sgdisk` reports UUID even if there is no GPT. Closes: https://github.com/rook/rook/issues/9948 Signed-off-by: Satoru Takeuchi (cherry picked from commit 4c46dd1abd83b537dbf3ea55dd9c67721a253df5) --- pkg/clusterd/disk.go | 8 +++++--- pkg/daemon/discover/discover.go | 2 +- pkg/util/sys/device.go | 12 +++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/pkg/clusterd/disk.go b/pkg/clusterd/disk.go index 306bb629f..b23f444e1 100644 --- a/pkg/clusterd/disk.go +++ b/pkg/clusterd/disk.go @@ -128,10 +128,12 @@ func PopulateDeviceInfo(d string, executor exec.Executor) (*sys.LocalDisk, error // get the UUID for disks var diskUUID string - if diskType != sys.PartType { - diskUUID, err = sys.GetDiskUUID(d, executor) + if diskType == sys.DiskType { + uuid, err := sys.GetDiskUUID(d, executor) if err != nil { - return nil, err + logger.Warning(err) + } else { + diskUUID = uuid } } diff --git a/pkg/daemon/discover/discover.go b/pkg/daemon/discover/discover.go index 7fd2ee821..990151360 100644 --- a/pkg/daemon/discover/discover.go +++ b/pkg/daemon/discover/discover.go @@ -245,7 +245,7 @@ func checkMatchingDevice(checkDev sys.LocalDisk, devices []sys.LocalDisk) *sys.L // check if devices should be considered the same. the uuid can be // unstable, so we also use the reported serial and device name, which // appear to be more stable. - if checkDev.UUID == dev.UUID { + if checkDev.UUID != "" && dev.UUID != "" && checkDev.UUID == dev.UUID { return &devices[i] } diff --git a/pkg/util/sys/device.go b/pkg/util/sys/device.go index fc96c07e2..ae631bd8f 100644 --- a/pkg/util/sys/device.go +++ b/pkg/util/sys/device.go @@ -23,6 +23,8 @@ import ( "strconv" "strings" + "github.com/pkg/errors" + "github.com/google/uuid" "github.com/rook/rook/pkg/util/exec" ) @@ -255,8 +257,7 @@ func GetDeviceFilesystems(device string, executor exec.Executor) (string, error) // GetDiskUUID look up the UUID for a disk. func GetDiskUUID(device string, executor exec.Executor) (string, error) { if _, err := osexec.LookPath(sgdiskCmd); err != nil { - logger.Warningf("sgdisk not found. skipping disk UUID.") - return "sgdiskNotFound", nil + return "", errors.Wrap(err, "sgdisk not found") } devicePath := strings.Split(device, "/") @@ -266,7 +267,7 @@ func GetDiskUUID(device string, executor exec.Executor) (string, error) { output, err := executor.ExecuteCommandWithOutput(sgdiskCmd, "--print", device) if err != nil { - return "", err + return "", errors.Wrapf(err, "sgdisk failed. output=%s", output) } return parseUUID(device, output) @@ -329,6 +330,11 @@ func parseUUID(device, output string) (string, error) { // find the line with the uuid lines := strings.Split(output, "\n") for _, line := range lines { + // If GPT is not found in a disk, sgdisk creates a new GPT in memory and reports its UUID. + // This ID changes each call and is not appropriate to identify the device. + if strings.Contains(line, "Creating new GPT entries in memory.") { + break + } if strings.Contains(line, "Disk identifier (GUID)") { words := strings.Split(line, " ") for _, word := range words {